Skip to content

Commit

Permalink
Only enable reset track button when a track exists
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 7, 2022
1 parent 5152259 commit 7ea1224
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/app/gps/qgsappgpsdigitizing.cpp
Expand Up @@ -93,8 +93,9 @@ void QgsAppGpsDigitizing::addVertex()
// we store the capture list in wgs84 and then transform to layer crs when
// calling close feature
const QgsPoint pointWgs84 = QgsPoint( mLastGpsPositionWgs84.x(), mLastGpsPositionWgs84.y(), mLastElevation );
mCaptureListWgs84.push_back( pointWgs84 );

const bool trackWasEmpty = mCaptureListWgs84.empty();
mCaptureListWgs84.push_back( pointWgs84 );

// we store the rubber band points in map canvas CRS so transform to map crs
// potential problem with transform errors and wrong coordinates if map CRS is changed after points are stored - SLM
Expand All @@ -118,14 +119,22 @@ void QgsAppGpsDigitizing::addVertex()
}

mRubberBand->addPoint( mapPoint );

if ( trackWasEmpty )
emit trackIsEmptyChanged( false );
}

void QgsAppGpsDigitizing::resetFeature()
{
mBlockGpsStateChanged++;
createRubberBand(); //deletes existing rubberband

const bool trackWasEmpty = mCaptureListWgs84.isEmpty();
mCaptureListWgs84.clear();
mBlockGpsStateChanged--;

if ( !trackWasEmpty )
emit trackIsEmptyChanged( true );
}

void QgsAppGpsDigitizing::addFeature()
Expand Down Expand Up @@ -282,6 +291,7 @@ void QgsAppGpsDigitizing::addFeature()

f.setGeometry( g );
QgsFeatureAction action( tr( "Feature added" ), f, vlayer, QUuid(), -1, this );

if ( action.addFeature( attrMap ) )
{
if ( QgsProject::instance()->gpsSettings()->automaticallyCommitFeatures() )
Expand All @@ -304,6 +314,10 @@ void QgsAppGpsDigitizing::addFeature()
} // action.addFeature()

mBlockGpsStateChanged--;

if ( mCaptureListWgs84.empty() )
emit trackIsEmptyChanged( true );

break;
}

Expand Down
5 changes: 5 additions & 0 deletions src/app/gps/qgsappgpsdigitizing.h
Expand Up @@ -62,6 +62,11 @@ class APP_EXPORT QgsAppGpsDigitizing: public QObject

signals:

/**
* Emitted whenever the current track changes from being empty to non-empty or vice versa.
*/
void trackIsEmptyChanged( bool isEmpty );

void timeStampDestinationChanged( const QString &fieldName );

private slots:
Expand Down
6 changes: 6 additions & 0 deletions src/app/gps/qgsgpstoolbar.cpp
Expand Up @@ -121,6 +121,7 @@ QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *can
mRecenterAction->setEnabled( false );
mAddFeatureAction->setEnabled( false );
mAddTrackVertexAction->setEnabled( false );
mResetFeatureAction->setEnabled( false );
connect( mConnection, &QgsAppGpsConnection::statusChanged, this, [ = ]( Qgis::GpsConnectionStatus status )
{
switch ( status )
Expand Down Expand Up @@ -170,6 +171,11 @@ void QgsGpsToolBar::setAddVertexButtonEnabled( bool enabled )
mAddTrackVertexAction->setEnabled( mEnableAddVertexButton && mConnection->isConnected() );
}

void QgsGpsToolBar::setResetTrackButtonEnabled( bool enabled )
{
mResetFeatureAction->setEnabled( enabled );
}

void QgsGpsToolBar::updateLocationLabel( const QgsPoint &point )
{
if ( point.isEmpty() )
Expand Down
1 change: 1 addition & 0 deletions src/app/gps/qgsgpstoolbar.h
Expand Up @@ -45,6 +45,7 @@ class QgsGpsToolBar : public QToolBar
public slots:

void setAddVertexButtonEnabled( bool enabled );
void setResetTrackButtonEnabled( bool enabled );

private slots:

Expand Down
1 change: 1 addition & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -1420,6 +1420,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::nmeaLogFileChanged, mGpsDigitizing, &QgsAppGpsDigitizing::setNmeaLogFile );
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::timeStampDestinationChanged, mGpsDigitizing, &QgsAppGpsDigitizing::setTimeStampDestination );
connect( mGpsDigitizing, &QgsAppGpsDigitizing::timeStampDestinationChanged, mGpsSettingsMenu, &QgsAppGpsSettingsMenu::setCurrentTimeStampField );
connect( mGpsDigitizing, &QgsAppGpsDigitizing::trackIsEmptyChanged, mGpsToolBar, [ = ]( bool isEmpty ) { mGpsToolBar->setResetTrackButtonEnabled( !isEmpty ); } );

mpGpsWidget = new QgsGpsInformationWidget( mGpsConnection, mMapCanvas );
QgsPanelWidgetStack *gpsStack = new QgsPanelWidgetStack();
Expand Down

0 comments on commit 7ea1224

Please sign in to comment.