Skip to content

Commit 7ea1224

Browse files
committedNov 7, 2022
Only enable reset track button when a track exists
1 parent 5152259 commit 7ea1224

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed
 

‎src/app/gps/qgsappgpsdigitizing.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ void QgsAppGpsDigitizing::addVertex()
9393
// we store the capture list in wgs84 and then transform to layer crs when
9494
// calling close feature
9595
const QgsPoint pointWgs84 = QgsPoint( mLastGpsPositionWgs84.x(), mLastGpsPositionWgs84.y(), mLastElevation );
96-
mCaptureListWgs84.push_back( pointWgs84 );
9796

97+
const bool trackWasEmpty = mCaptureListWgs84.empty();
98+
mCaptureListWgs84.push_back( pointWgs84 );
9899

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

120121
mRubberBand->addPoint( mapPoint );
122+
123+
if ( trackWasEmpty )
124+
emit trackIsEmptyChanged( false );
121125
}
122126

123127
void QgsAppGpsDigitizing::resetFeature()
124128
{
125129
mBlockGpsStateChanged++;
126130
createRubberBand(); //deletes existing rubberband
131+
132+
const bool trackWasEmpty = mCaptureListWgs84.isEmpty();
127133
mCaptureListWgs84.clear();
128134
mBlockGpsStateChanged--;
135+
136+
if ( !trackWasEmpty )
137+
emit trackIsEmptyChanged( true );
129138
}
130139

131140
void QgsAppGpsDigitizing::addFeature()
@@ -282,6 +291,7 @@ void QgsAppGpsDigitizing::addFeature()
282291

283292
f.setGeometry( g );
284293
QgsFeatureAction action( tr( "Feature added" ), f, vlayer, QUuid(), -1, this );
294+
285295
if ( action.addFeature( attrMap ) )
286296
{
287297
if ( QgsProject::instance()->gpsSettings()->automaticallyCommitFeatures() )
@@ -304,6 +314,10 @@ void QgsAppGpsDigitizing::addFeature()
304314
} // action.addFeature()
305315

306316
mBlockGpsStateChanged--;
317+
318+
if ( mCaptureListWgs84.empty() )
319+
emit trackIsEmptyChanged( true );
320+
307321
break;
308322
}
309323

‎src/app/gps/qgsappgpsdigitizing.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class APP_EXPORT QgsAppGpsDigitizing: public QObject
6262

6363
signals:
6464

65+
/**
66+
* Emitted whenever the current track changes from being empty to non-empty or vice versa.
67+
*/
68+
void trackIsEmptyChanged( bool isEmpty );
69+
6570
void timeStampDestinationChanged( const QString &fieldName );
6671

6772
private slots:

‎src/app/gps/qgsgpstoolbar.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *can
121121
mRecenterAction->setEnabled( false );
122122
mAddFeatureAction->setEnabled( false );
123123
mAddTrackVertexAction->setEnabled( false );
124+
mResetFeatureAction->setEnabled( false );
124125
connect( mConnection, &QgsAppGpsConnection::statusChanged, this, [ = ]( Qgis::GpsConnectionStatus status )
125126
{
126127
switch ( status )
@@ -170,6 +171,11 @@ void QgsGpsToolBar::setAddVertexButtonEnabled( bool enabled )
170171
mAddTrackVertexAction->setEnabled( mEnableAddVertexButton && mConnection->isConnected() );
171172
}
172173

174+
void QgsGpsToolBar::setResetTrackButtonEnabled( bool enabled )
175+
{
176+
mResetFeatureAction->setEnabled( enabled );
177+
}
178+
173179
void QgsGpsToolBar::updateLocationLabel( const QgsPoint &point )
174180
{
175181
if ( point.isEmpty() )

‎src/app/gps/qgsgpstoolbar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class QgsGpsToolBar : public QToolBar
4545
public slots:
4646

4747
void setAddVertexButtonEnabled( bool enabled );
48+
void setResetTrackButtonEnabled( bool enabled );
4849

4950
private slots:
5051

‎src/app/qgisapp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers
14201420
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::nmeaLogFileChanged, mGpsDigitizing, &QgsAppGpsDigitizing::setNmeaLogFile );
14211421
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::timeStampDestinationChanged, mGpsDigitizing, &QgsAppGpsDigitizing::setTimeStampDestination );
14221422
connect( mGpsDigitizing, &QgsAppGpsDigitizing::timeStampDestinationChanged, mGpsSettingsMenu, &QgsAppGpsSettingsMenu::setCurrentTimeStampField );
1423+
connect( mGpsDigitizing, &QgsAppGpsDigitizing::trackIsEmptyChanged, mGpsToolBar, [ = ]( bool isEmpty ) { mGpsToolBar->setResetTrackButtonEnabled( !isEmpty ); } );
14231424

14241425
mpGpsWidget = new QgsGpsInformationWidget( mGpsConnection, mMapCanvas );
14251426
QgsPanelWidgetStack *gpsStack = new QgsPanelWidgetStack();

0 commit comments

Comments
 (0)
Please sign in to comment.