Skip to content

Commit

Permalink
Store the GPS "automatically create track points" and "auto save
Browse files Browse the repository at this point in the history
feature" settings within the project, not as global settings

These settings (and more to come) relate more closely with
a particular project's setup and accordingly should be stored
in the project.
  • Loading branch information
nyalldawson committed Nov 6, 2022
1 parent 816eb16 commit 4b7668a
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 61 deletions.
17 changes: 4 additions & 13 deletions src/app/gps/qgsappgpsdigitizing.cpp
Expand Up @@ -27,6 +27,7 @@
#include "qgsfeatureaction.h"
#include "qgsgpsconnection.h"
#include "qgsappgpsconnection.h"
#include "qgsprojectgpssettings.h"

#include <QTimeZone>

Expand Down Expand Up @@ -189,7 +190,7 @@ void QgsAppGpsDigitizing::addFeature()
QgsFeatureAction action( tr( "Feature Added" ), f, vlayer, QUuid(), -1, this );
if ( action.addFeature( attrMap ) )
{
if ( mAutoSave )
if ( QgsProject::instance()->gpsSettings()->automaticallyCommitFeatures() )
{
// should canvas->isDrawing() be checked?
if ( !vlayer->commitChanges() ) //assumed to be vector layer and is editable and is in editing mode (preconditions have been tested)
Expand Down Expand Up @@ -283,7 +284,7 @@ void QgsAppGpsDigitizing::addFeature()
QgsFeatureAction action( tr( "Feature added" ), f, vlayer, QUuid(), -1, this );
if ( action.addFeature( attrMap ) )
{
if ( mAutoSave )
if ( QgsProject::instance()->gpsSettings()->automaticallyCommitFeatures() )
{
if ( !vlayer->commitChanges() )
{
Expand Down Expand Up @@ -315,16 +316,6 @@ void QgsAppGpsDigitizing::addFeature()
QgisApp::instance()->activateWindow();
}

void QgsAppGpsDigitizing::setAutoAddVertices( bool enabled )
{
mAutoAddVertices = enabled;
}

void QgsAppGpsDigitizing::setAutoSaveFeature( bool enabled )
{
mAutoSave = enabled;
}

void QgsAppGpsDigitizing::setTimeStampDestination( const QString &fieldName )
{
if ( QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ) )
Expand Down Expand Up @@ -508,7 +499,7 @@ void QgsAppGpsDigitizing::gpsStateChanged( const QgsGpsInformation &info )
mLastNmeaPosition = newNmeaPosition;
mLastElevation = newAlt;

if ( mAutoAddVertices )
if ( QgsProject::instance()->gpsSettings()->automaticallyAddTrackPoints() )
{
addVertex();
}
Expand Down
8 changes: 0 additions & 8 deletions src/app/gps/qgsappgpsdigitizing.h
Expand Up @@ -44,8 +44,6 @@ class APP_EXPORT QgsAppGpsDigitizing: public QObject
public:

static const inline QgsSettingsEntryString settingTrackLineSymbol = QgsSettingsEntryString( QStringLiteral( "track-line-symbol" ), QgsSettings::Prefix::GPS, QStringLiteral( "<symbol alpha=\"1\" name=\"gps-track-symbol\" force_rhr=\"0\" clip_to_extent=\"1\" type=\"line\"><layer enabled=\"1\" pass=\"0\" locked=\"0\" class=\"SimpleLine\"><Option type=\"Map\"><Option name=\"line_color\" type=\"QString\" value=\"219,30,42,255\"/><Option name=\"line_style\" type=\"QString\" value=\"solid\"/><Option name=\"line_width\" type=\"QString\" value=\"0.4\"/></Option></layer></symbol>" ), QStringLiteral( "Line symbol to use for GPS track line" ), Qgis::SettingsOptions(), 0 );
static const inline QgsSettingsEntryBool settingAutoAddVertices = QgsSettingsEntryBool( QStringLiteral( "auto-add-track-points" ), QgsSettings::Prefix::GPS, false, QStringLiteral( "Whether GPS track points should be automatically added" ) );
static const inline QgsSettingsEntryBool settingAutoCreateFeatures = QgsSettingsEntryBool( QStringLiteral( "auto-create-features" ), QgsSettings::Prefix::GPS, false, QStringLiteral( "Whether digitized GPS features should be automatically created" ) );

static const inline QgsSettingsEntryString settingLastLogFolder = QgsSettingsEntryString( QStringLiteral( "last-log-folder" ), QgsSettings::Prefix::GPS, QString(), QStringLiteral( "Last used folder for GPS log files" ) );

Expand All @@ -57,9 +55,6 @@ class APP_EXPORT QgsAppGpsDigitizing: public QObject
void resetFeature();
void addFeature();

void setAutoAddVertices( bool enabled );
void setAutoSaveFeature( bool enabled );

void setTimeStampDestination( const QString &fieldName );

void setNmeaLogFile( const QString &filename );
Expand Down Expand Up @@ -95,9 +90,6 @@ class APP_EXPORT QgsAppGpsDigitizing: public QObject
QgsAppGpsConnection *mConnection = nullptr;
QgsMapCanvas *mCanvas = nullptr;

bool mAutoAddVertices = false;
bool mAutoSave = false;

QgsPointXY mLastGpsPositionWgs84;

QgsRubberBand *mRubberBand = nullptr;
Expand Down
36 changes: 8 additions & 28 deletions src/app/gps/qgsappgpssettingsmenu.cpp
Expand Up @@ -22,6 +22,8 @@
#include "qgsapplication.h"
#include "qgsgpsmarker.h"
#include "qgsappgpsdigitizing.h"
#include "qgsproject.h"
#include "qgsprojectgpssettings.h"

#include <QRadioButton>
#include <QButtonGroup>
Expand Down Expand Up @@ -60,8 +62,6 @@ QgsAppGpsSettingsMenu::QgsAppGpsSettingsMenu( QWidget *parent )
{
bool showLocationMarker = true;
bool showBearingLine = false;
bool autoAddVertices = false;
bool autoCreateFeature = false;
QgsGpsCanvasBridge::MapCenteringMode mapCenteringMode = QgsGpsCanvasBridge::MapCenteringMode::WhenLeavingExtent;
bool rotateMap = false;

Expand All @@ -70,8 +70,6 @@ QgsAppGpsSettingsMenu::QgsAppGpsSettingsMenu( QWidget *parent )
showLocationMarker = QgsGpsMarker::settingShowLocationMarker.value();
showBearingLine = QgsGpsCanvasBridge::settingShowBearingLine.value();
mapCenteringMode = QgsGpsCanvasBridge::settingMapCenteringMode.value();
autoAddVertices = QgsAppGpsDigitizing::settingAutoAddVertices.value();
autoCreateFeature = QgsAppGpsDigitizing::settingAutoCreateFeatures.value();
rotateMap = QgsGpsCanvasBridge::settingRotateMap.value();
}
else
Expand All @@ -80,8 +78,6 @@ QgsAppGpsSettingsMenu::QgsAppGpsSettingsMenu( QWidget *parent )
QgsSettings settings;
showLocationMarker = settings.value( QStringLiteral( "showMarker" ), "true", QgsSettings::Gps ).toBool();
showBearingLine = settings.value( QStringLiteral( "showBearingLine" ), false, QgsSettings::Gps ).toBool();
autoAddVertices = settings.value( QStringLiteral( "autoAddVertices" ), "false", QgsSettings::Gps ).toBool();
autoCreateFeature = settings.value( QStringLiteral( "autoCommit" ), "false", QgsSettings::Gps ).toBool();
rotateMap = settings.value( QStringLiteral( "rotateMap" ), false, QgsSettings::Gps ).toBool();

const QString panMode = settings.value( QStringLiteral( "panMode" ), "recenterWhenNeeded", QgsSettings::Gps ).toString();
Expand Down Expand Up @@ -186,23 +182,17 @@ QgsAppGpsSettingsMenu::QgsAppGpsSettingsMenu( QWidget *parent )

mAutoAddTrackPointAction = new QAction( tr( "Automatically Add Track Points" ), this );
mAutoAddTrackPointAction->setCheckable( true );
mAutoAddTrackPointAction->setChecked( autoAddVertices );
connect( mAutoAddTrackPointAction, &QAction::toggled, this, [ = ]( bool checked )
{
emit autoAddTrackPointsChanged( checked );
QgsAppGpsDigitizing::settingAutoAddVertices.setValue( checked );
} );
mAutoAddTrackPointAction->setChecked( QgsProject::instance()->gpsSettings()->automaticallyAddTrackPoints() );
connect( mAutoAddTrackPointAction, &QAction::toggled, QgsProject::instance()->gpsSettings(), &QgsProjectGpsSettings::setAutomaticallyAddTrackPoints );
connect( QgsProject::instance()->gpsSettings(), &QgsProjectGpsSettings::automaticallyAddTrackPointsChanged, mAutoAddTrackPointAction, &QAction::setChecked );

addAction( mAutoAddTrackPointAction );

mAutoSaveAddedFeatureAction = new QAction( tr( "Automatically Save Added Feature" ), this );
mAutoSaveAddedFeatureAction->setCheckable( true );
mAutoSaveAddedFeatureAction->setChecked( autoCreateFeature );
connect( mAutoAddTrackPointAction, &QAction::toggled, this, [ = ]( bool checked )
{
emit autoAddFeatureChanged( checked );
QgsAppGpsDigitizing::settingAutoCreateFeatures.setValue( checked );
} );
mAutoSaveAddedFeatureAction->setChecked( QgsProject::instance()->gpsSettings()->automaticallyCommitFeatures() );
connect( mAutoSaveAddedFeatureAction, &QAction::toggled, QgsProject::instance()->gpsSettings(), &QgsProjectGpsSettings::setAutomaticallyCommitFeatures );
connect( QgsProject::instance()->gpsSettings(), &QgsProjectGpsSettings::automaticallyCommitFeaturesChanged, mAutoSaveAddedFeatureAction, &QAction::setChecked );

addAction( mAutoSaveAddedFeatureAction );

Expand Down Expand Up @@ -288,16 +278,6 @@ QgsGpsCanvasBridge::MapCenteringMode QgsAppGpsSettingsMenu::mapCenteringMode() c
}
}

bool QgsAppGpsSettingsMenu::autoAddTrackPoints() const
{
return mAutoAddTrackPointAction->isChecked();
}

bool QgsAppGpsSettingsMenu::autoAddFeature() const
{
return mAutoSaveAddedFeatureAction->isChecked();
}

void QgsAppGpsSettingsMenu::setCurrentTimeStampField( const QString &fieldName )
{
mCurrentTimeStampField = fieldName;
Expand Down
4 changes: 0 additions & 4 deletions src/app/gps/qgsappgpssettingsmenu.h
Expand Up @@ -56,8 +56,6 @@ class APP_EXPORT QgsAppGpsSettingsMenu : public QMenu
bool bearingLineVisible() const;
bool rotateMap() const;
QgsGpsCanvasBridge::MapCenteringMode mapCenteringMode() const;
bool autoAddTrackPoints() const;
bool autoAddFeature() const;

public slots:

Expand All @@ -69,8 +67,6 @@ class APP_EXPORT QgsAppGpsSettingsMenu : public QMenu
void bearingLineToggled( bool visible );
void rotateMapToggled( bool enabled );
void mapCenteringModeChanged( QgsGpsCanvasBridge::MapCenteringMode mode );
void autoAddTrackPointsChanged( bool enabled );
void autoAddFeatureChanged( bool enabled );
void timeStampDestinationChanged( const QString &fieldName );
void enableNmeaLog( bool enabled );
void nmeaLogFileChanged( const QString &filename );
Expand Down
4 changes: 4 additions & 0 deletions src/app/gps/qgsgpstoolbar.cpp
Expand Up @@ -23,6 +23,7 @@
#include "qgisapp.h"
#include "qgsappgpssettingsmenu.h"
#include "qgsapplication.h"
#include "qgsprojectgpssettings.h"

#include <QLabel>
#include <QToolButton>
Expand Down Expand Up @@ -158,6 +159,9 @@ QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *can

connect( QgisApp::instance(), &QgisApp::activeLayerChanged,
this, &QgsGpsToolBar::updateCloseFeatureButton );

connect( QgsProject::instance()->gpsSettings(), &QgsProjectGpsSettings::automaticallyAddTrackPointsChanged, this, [ = ]( bool enabled ) { setAddVertexButtonEnabled( !enabled ); } );
setAddVertexButtonEnabled( !QgsProject::instance()->gpsSettings()->automaticallyAddTrackPoints() );
}

void QgsGpsToolBar::setAddVertexButtonEnabled( bool enabled )
Expand Down
6 changes: 0 additions & 6 deletions src/app/qgisapp.cpp
Expand Up @@ -1403,9 +1403,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers
addToolBar( mGpsToolBar );

mGpsDigitizing = new QgsAppGpsDigitizing( mGpsConnection, mMapCanvas, this );
mGpsDigitizing->setAutoAddVertices( mGpsSettingsMenu->autoAddTrackPoints() );
mGpsDigitizing->setAutoSaveFeature( mGpsSettingsMenu->autoAddFeature() );
mGpsToolBar->setAddVertexButtonEnabled( !mGpsSettingsMenu->autoAddTrackPoints() );
connect( mGpsToolBar, &QgsGpsToolBar::addFeatureClicked, mGpsDigitizing, &QgsAppGpsDigitizing::addFeature );
connect( mGpsToolBar, &QgsGpsToolBar::addVertexClicked, mGpsDigitizing, &QgsAppGpsDigitizing::addVertex );
connect( mGpsToolBar, &QgsGpsToolBar::resetFeatureClicked, mGpsDigitizing, &QgsAppGpsDigitizing::resetFeature );
Expand All @@ -1419,9 +1416,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::bearingLineToggled, mGpsCanvasBridge, &QgsGpsCanvasBridge::setBearingLineVisible );
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::rotateMapToggled, mGpsCanvasBridge, &QgsGpsCanvasBridge::setRotateMap );
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::mapCenteringModeChanged, mGpsCanvasBridge, &QgsGpsCanvasBridge::setMapCenteringMode );
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::autoAddTrackPointsChanged, mGpsDigitizing, &QgsAppGpsDigitizing::setAutoAddVertices );
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::autoAddTrackPointsChanged, this, [ = ]( bool enabled ) { mGpsToolBar->setAddVertexButtonEnabled( !enabled ); } );
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::autoAddFeatureChanged, mGpsDigitizing, &QgsAppGpsDigitizing::setAutoSaveFeature );
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::enableNmeaLog, mGpsDigitizing, &QgsAppGpsDigitizing::setNmeaLoggingEnabled );
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::nmeaLogFileChanged, mGpsDigitizing, &QgsAppGpsDigitizing::setNmeaLogFile );
connect( mGpsSettingsMenu, &QgsAppGpsSettingsMenu::timeStampDestinationChanged, mGpsDigitizing, &QgsAppGpsDigitizing::setTimeStampDestination );
Expand Down
2 changes: 0 additions & 2 deletions src/app/qgssettingsregistryapp.cpp
Expand Up @@ -71,8 +71,6 @@ QgsSettingsRegistryApp::QgsSettingsRegistryApp()
addSettingsEntry( &QgsGpsCanvasBridge::settingRotateMap );

addSettingsEntry( &QgsAppGpsDigitizing::settingTrackLineSymbol );
addSettingsEntry( &QgsAppGpsDigitizing::settingAutoAddVertices );
addSettingsEntry( &QgsAppGpsDigitizing::settingAutoCreateFeatures );

addSettingsEntry( &QgsGpsMarker::settingLocationMarkerSymbol );
addSettingsEntry( &QgsGpsMarker::settingShowLocationMarker );
Expand Down

0 comments on commit 4b7668a

Please sign in to comment.