Skip to content

Commit

Permalink
Use project GPS settings destination layer in app gps digitizing classes
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 7, 2022
1 parent 544641c commit c391448
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
11 changes: 5 additions & 6 deletions src/app/gps/qgsappgpsdigitizing.cpp
Expand Up @@ -64,10 +64,10 @@ QgsAppGpsDigitizing::QgsAppGpsDigitizing( QgsAppGpsConnection *connection, QgsMa
connect( mAcquisitionTimer.get(), &QTimer::timeout,
this, &QgsAppGpsDigitizing::switchAcquisition );

connect( mCanvas, &QgsMapCanvas::currentLayerChanged,
connect( QgsProject::instance()->gpsSettings(), &QgsProjectGpsSettings::destinationLayerChanged,
this, &QgsAppGpsDigitizing::updateTimestampDestinationFields );

updateTimestampDestinationFields( mCanvas->currentLayer() );
updateTimestampDestinationFields( QgsProject::instance()->gpsSettings()->destinationLayer() );

connect( mConnection, &QgsAppGpsConnection::stateChanged, this, &QgsAppGpsDigitizing::gpsStateChanged );
connect( mConnection, &QgsAppGpsConnection::connected, this, &QgsAppGpsDigitizing::gpsConnected );
Expand Down Expand Up @@ -130,7 +130,7 @@ void QgsAppGpsDigitizing::resetFeature()

void QgsAppGpsDigitizing::addFeature()
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
QgsVectorLayer *vlayer = QgsProject::instance()->gpsSettings()->destinationLayer();
if ( !vlayer )
return;

Expand Down Expand Up @@ -318,7 +318,7 @@ void QgsAppGpsDigitizing::addFeature()

void QgsAppGpsDigitizing::setTimeStampDestination( const QString &fieldName )
{
if ( QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ) )
if ( QgsVectorLayer *vlayer = QgsProject::instance()->gpsSettings()->destinationLayer() )
{
mPreferredTimestampFields[ vlayer->id() ] = fieldName;
}
Expand Down Expand Up @@ -506,9 +506,8 @@ void QgsAppGpsDigitizing::gpsStateChanged( const QgsGpsInformation &info )
}
}

void QgsAppGpsDigitizing::updateTimestampDestinationFields( QgsMapLayer *mapLayer )
void QgsAppGpsDigitizing::updateTimestampDestinationFields( QgsVectorLayer *vlayer )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mapLayer );
if ( vlayer )
{
// Restore preferred if stored
Expand Down
2 changes: 1 addition & 1 deletion src/app/gps/qgsappgpsdigitizing.h
Expand Up @@ -77,7 +77,7 @@ class APP_EXPORT QgsAppGpsDigitizing: public QObject
/**
* Updates compatible fields for timestamp recording
*/
void updateTimestampDestinationFields( QgsMapLayer *mapLayer );
void updateTimestampDestinationFields( QgsVectorLayer *mapLayer );
void logNmeaSentence( const QString &nmeaString ); // added to handle 'raw' data

void startLogging();
Expand Down
3 changes: 1 addition & 2 deletions src/app/gps/qgsappgpssettingsmenu.cpp
Expand Up @@ -299,8 +299,7 @@ void QgsAppGpsSettingsMenu::setCurrentTimeStampField( const QString &fieldName )

void QgsAppGpsSettingsMenu::timeStampMenuAboutToShow()
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( QgisApp::instance()->activeLayer() );
mFieldProxyModel->sourceFieldModel()->setLayer( vlayer );
mFieldProxyModel->sourceFieldModel()->setLayer( QgsProject::instance()->gpsSettings()->destinationLayer() );

mTimeStampDestinationFieldMenu->clear();
bool foundPreviousField = false;
Expand Down
11 changes: 6 additions & 5 deletions src/app/gps/qgsgpstoolbar.cpp
Expand Up @@ -151,13 +151,13 @@ QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *can
mConnectAction->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/gpsicons/mIconGpsDisconnect.svg" ) ) );
mConnectAction->setEnabled( true );
mRecenterAction->setEnabled( true );
mAddFeatureAction->setEnabled( true );
mAddFeatureAction->setEnabled( static_cast< bool >( QgsProject::instance()->gpsSettings()->destinationLayer() ) );
mAddTrackVertexAction->setEnabled( mEnableAddVertexButton );
break;
}
} );

connect( QgisApp::instance(), &QgisApp::activeLayerChanged,
connect( QgsProject::instance()->gpsSettings(), &QgsProjectGpsSettings::destinationLayerChanged,
this, &QgsGpsToolBar::updateCloseFeatureButton );

connect( QgsProject::instance()->gpsSettings(), &QgsProjectGpsSettings::automaticallyAddTrackVerticesChanged, this, [ = ]( bool enabled ) { setAddVertexButtonEnabled( !enabled ); } );
Expand All @@ -183,12 +183,13 @@ void QgsGpsToolBar::updateLocationLabel( const QgsPoint &point )
}
}

void QgsGpsToolBar::updateCloseFeatureButton( QgsMapLayer *lyr )
void QgsGpsToolBar::updateCloseFeatureButton( QgsVectorLayer *vlayer )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( lyr );

if ( !( vlayer && vlayer->isValid() ) )
{
mAddFeatureAction->setEnabled( false );
return;
}

// Add feature button tracks edit state of layer
if ( vlayer != mLastLayer )
Expand Down
2 changes: 1 addition & 1 deletion src/app/gps/qgsgpstoolbar.h
Expand Up @@ -49,7 +49,7 @@ class QgsGpsToolBar : public QToolBar
private slots:

void updateLocationLabel( const QgsPoint &point );
void updateCloseFeatureButton( QgsMapLayer *lyr );
void updateCloseFeatureButton( QgsVectorLayer *lyr );
void layerEditStateChanged();

private:
Expand Down

0 comments on commit c391448

Please sign in to comment.