Skip to content

Commit

Permalink
Move some digitizing settings out of info panel
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 4, 2022
1 parent 81e4a48 commit 79262c7
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 203 deletions.
20 changes: 14 additions & 6 deletions src/app/gps/qgsappgpsdigitizing.cpp
Expand Up @@ -110,7 +110,7 @@ void QgsAppGpsDigitizing::resetFeature()
mBlockGpsStateChanged--;
}

void QgsAppGpsDigitizing::closeFeature()
void QgsAppGpsDigitizing::addFeature()
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( !vlayer )
Expand Down Expand Up @@ -172,7 +172,7 @@ void QgsAppGpsDigitizing::closeFeature()
QgsFeatureAction action( tr( "Feature Added" ), f, vlayer, QUuid(), -1, this );
if ( action.addFeature( attrMap ) )
{
if ( mCbxAutoCommit->isChecked() )
if ( mAutoSave )
{
// 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 @@ -266,7 +266,7 @@ void QgsAppGpsDigitizing::closeFeature()
QgsFeatureAction action( tr( "Feature added" ), f, vlayer, QUuid(), -1, this );
if ( action.addFeature( attrMap ) )
{
if ( mCbxAutoCommit->isChecked() )
if ( mAutoSave )
{
if ( !vlayer->commitChanges() )
{
Expand Down Expand Up @@ -295,9 +295,17 @@ void QgsAppGpsDigitizing::closeFeature()
}
vlayer->triggerRepaint();

// force focus back to GPS window/ Add Feature button for ease of use by keyboard
QgisApp::instance()->activateWindow();
mBtnCloseFeature->setFocus( Qt::OtherFocusReason );
}

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

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

void QgsAppGpsDigitizing::gpsSettingsChanged()
Expand Down Expand Up @@ -407,7 +415,7 @@ void QgsAppGpsDigitizing::gpsStateChanged( const QgsGpsInformation &info )
mLastNmeaTime = newNmeaTime;
mLastElevation = newAlt;

if ( mCbxAutoAddVertices->isChecked() )
if ( mAutoAddVertices )
{
addVertex();
}
Expand Down
8 changes: 7 additions & 1 deletion src/app/gps/qgsappgpsdigitizing.h
Expand Up @@ -41,9 +41,13 @@ class QgsAppGpsDigitizing: public QObject
QgsAppGpsDigitizing( QgsAppGpsConnection *connection, QgsMapCanvas *canvas, QObject *parent = nullptr );
~QgsAppGpsDigitizing() override;

public slots:
void addVertex();
void resetFeature();
void closeFeature();
void addFeature();

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

private slots:
void gpsSettingsChanged();
Expand All @@ -59,6 +63,8 @@ class QgsAppGpsDigitizing: public QObject
QgsAppGpsConnection *mConnection = nullptr;
QgsMapCanvas *mCanvas = nullptr;

bool mAutoAddVertices = false;
bool mAutoSave = false;

QgsPointXY mLastGpsPosition;

Expand Down
36 changes: 36 additions & 0 deletions src/app/gps/qgsappgpssettingsmenu.cpp
Expand Up @@ -144,6 +144,32 @@ QgsAppGpsSettingsMenu::QgsAppGpsSettingsMenu( QWidget *parent )
addSeparator();
addAction( rotateAction );

addSeparator();

mAutoAddTrackPointAction = new QAction( tr( "Automatically Add Track Points" ), this );
mAutoAddTrackPointAction->setCheckable( true );
mAutoAddTrackPointAction->setChecked( settings.value( QStringLiteral( "autoAddVertices" ), "false", QgsSettings::Gps ).toBool() );
connect( mAutoAddTrackPointAction, &QAction::toggled, this, [ = ]( bool checked )
{
emit autoAddTrackPointsChanged( checked );
QgsSettings settings;
settings.setValue( QStringLiteral( "autoAddVertices" ), checked, QgsSettings::Gps );
} );

addAction( mAutoAddTrackPointAction );

mAutoSaveAddedFeatureAction = new QAction( tr( "Automatically Save Added Feature" ), this );
mAutoSaveAddedFeatureAction->setCheckable( true );
mAutoSaveAddedFeatureAction->setChecked( settings.value( QStringLiteral( "autoCommit" ), "false", QgsSettings::Gps ).toBool() );
connect( mAutoAddTrackPointAction, &QAction::toggled, this, [ = ]( bool checked )
{
emit autoAddFeatureChanged( checked );
QgsSettings settings;
settings.setValue( QStringLiteral( "autoCommit" ), checked, QgsSettings::Gps );
} );

addAction( mAutoSaveAddedFeatureAction );

addSeparator();
QAction *settingsAction = new QAction( tr( "GPS Settings…" ), this );
settingsAction->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionOptions.svg" ) ) );
Expand Down Expand Up @@ -187,3 +213,13 @@ QgsAppGpsSettingsMenu::MapCenteringMode QgsAppGpsSettingsMenu::mapCenteringMode(
}
}

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

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

6 changes: 6 additions & 0 deletions src/app/gps/qgsappgpssettingsmenu.h
Expand Up @@ -60,19 +60,25 @@ class QgsAppGpsSettingsMenu : public QMenu
bool bearingLineVisible() const;
bool rotateMap() const;
MapCenteringMode mapCenteringMode() const;
bool autoAddTrackPoints() const;
bool autoAddFeature() const;

signals:

void locationMarkerToggled( bool visible );
void bearingLineToggled( bool visible );
void rotateMapToggled( bool enabled );
void mapCenteringModeChanged( MapCenteringMode mode );
void autoAddTrackPointsChanged( bool enabled );
void autoAddFeatureChanged( bool enabled );

private:

QAction *mShowLocationMarkerAction = nullptr;
QAction *mShowBearingLineAction = nullptr;
QAction *mRotateMapAction = nullptr;
QAction *mAutoAddTrackPointAction = nullptr;
QAction *mAutoSaveAddedFeatureAction = nullptr;

QRadioButton *mRadioAlwaysRecenter = nullptr;
QRadioButton *mRadioRecenterWhenOutside = nullptr;
Expand Down
83 changes: 0 additions & 83 deletions src/app/gps/qgsgpsinformationwidget.cpp
Expand Up @@ -68,7 +68,6 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsAppGpsConnection *connectio
connect( mBtnSatellites, &QToolButton::clicked, this, &QgsGpsInformationWidget::mBtnSatellites_clicked );
connect( mBtnOptions, &QToolButton::clicked, this, &QgsGpsInformationWidget::mBtnOptions_clicked );
connect( mBtnDebug, &QToolButton::clicked, this, &QgsGpsInformationWidget::mBtnDebug_clicked );
connect( mBtnCloseFeature, &QPushButton::clicked, this, &QgsGpsInformationWidget::mBtnCloseFeature_clicked );
connect( mBtnResetFeature, &QToolButton::clicked, this, &QgsGpsInformationWidget::mBtnResetFeature_clicked );

mBtnPopupOptions->setAutoRaise( true );
Expand Down Expand Up @@ -186,13 +185,6 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsAppGpsConnection *connectio
// Restore state
mDateTimeFormat = mySettings.value( QStringLiteral( "dateTimeFormat" ), "", QgsSettings::Gps ).toString(); // zero-length string signifies default format

//auto digitizing behavior
mCbxAutoAddVertices->setChecked( mySettings.value( QStringLiteral( "autoAddVertices" ), "false", QgsSettings::Gps ).toBool() );

mBtnAddVertex->setEnabled( !mCbxAutoAddVertices->isChecked() );

mCbxAutoCommit->setChecked( mySettings.value( QStringLiteral( "autoCommit" ), "false", QgsSettings::Gps ).toBool() );

mBtnDebug->setVisible( mySettings.value( QStringLiteral( "showDebug" ), "false", QgsSettings::Gps ).toBool() ); // use a registry setting to control - power users/devs could set it

// status = unknown
Expand All @@ -201,9 +193,6 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsAppGpsConnection *connectio
//SLM - added functionality
mLogFile = nullptr;

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

mStackedWidget->setCurrentIndex( 3 ); // force to Options
mBtnPosition->setFocus( Qt::TabFocusReason );

Expand Down Expand Up @@ -305,8 +294,6 @@ QgsGpsInformationWidget::~QgsGpsInformationWidget()
#endif

QgsSettings mySettings;
mySettings.setValue( QStringLiteral( "autoAddVertices" ), mCbxAutoAddVertices->isChecked(), QgsSettings::Gps );
mySettings.setValue( QStringLiteral( "autoCommit" ), mCbxAutoCommit->isChecked(), QgsSettings::Gps );
mySettings.setValue( QStringLiteral( "timestampTimeZone" ), mCboTimeZones->currentText(), QgsSettings::Gps );
mySettings.setValue( QStringLiteral( "applyLeapSeconds" ), mCbxLeapSeconds->isChecked(), QgsSettings::Gps );
mySettings.setValue( QStringLiteral( "leapSecondsCorrection" ), mLeapSeconds->value(), QgsSettings::Gps );
Expand Down Expand Up @@ -626,76 +613,6 @@ void QgsGpsInformationWidget::logNmeaSentence( const QString &nmeaString )
}
}

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

if ( !( vlayer && vlayer->isValid() ) )
return;

// Add feature button tracks edit state of layer
if ( vlayer != mLastLayer )
{
if ( mLastLayer ) // disconnect previous layer
{
disconnect( mLastLayer, &QgsVectorLayer::editingStarted,
this, &QgsGpsInformationWidget::layerEditStateChanged );
disconnect( mLastLayer, &QgsVectorLayer::editingStopped,
this, &QgsGpsInformationWidget::layerEditStateChanged );
}
if ( vlayer ) // connect new layer
{
connect( vlayer, &QgsVectorLayer::editingStarted,
this, &QgsGpsInformationWidget::layerEditStateChanged );
connect( vlayer, &QgsVectorLayer::editingStopped,
this, &QgsGpsInformationWidget::layerEditStateChanged );
}
mLastLayer = vlayer;
}

QString buttonLabel = tr( "&Add Feature" );
if ( vlayer )
{
QgsVectorDataProvider *provider = vlayer->dataProvider();
const QgsWkbTypes::GeometryType layerGeometryType = vlayer->geometryType();

bool enable = provider->capabilities() & QgsVectorDataProvider::AddFeatures && // layer can add features
vlayer->isEditable() && vlayer->isSpatial();

switch ( layerGeometryType )
{
case QgsWkbTypes::PointGeometry:
buttonLabel = tr( "&Add Point" );
break;

case QgsWkbTypes::LineGeometry:
buttonLabel = tr( "&Add Line" );
break;

case QgsWkbTypes::PolygonGeometry:
buttonLabel = tr( "&Add Polygon" );
break;

case QgsWkbTypes::UnknownGeometry:
case QgsWkbTypes::NullGeometry:
enable = false;
break;
}

mBtnCloseFeature->setEnabled( enable );
}
else
{
mBtnCloseFeature->setEnabled( false );
}
mBtnCloseFeature->setText( buttonLabel );
}

void QgsGpsInformationWidget::layerEditStateChanged()
{
updateCloseFeatureButton( mLastLayer );
}

void QgsGpsInformationWidget::setStatusIndicator( Qgis::GpsFixStatus statusValue )
{
// the pixmap will be expanded to the size of the label
Expand Down
4 changes: 1 addition & 3 deletions src/app/gps/qgsgpsinformationwidget.h
Expand Up @@ -60,8 +60,6 @@ class APP_EXPORT QgsGpsInformationWidget: public QgsPanelWidget, private Ui::Qgs
void mConnectButton_toggled( bool flag );
void displayGPSInformation( const QgsGpsInformation &info );
void logNmeaSentence( const QString &nmeaString ); // added to handle 'raw' data
void updateCloseFeatureButton( QgsMapLayer *lyr );
void layerEditStateChanged();

void mBtnPosition_clicked();
void mBtnSignal_clicked();
Expand Down Expand Up @@ -105,7 +103,7 @@ class APP_EXPORT QgsGpsInformationWidget: public QgsPanelWidget, private Ui::Qgs
QgsPointXY mLastGpsPosition;

QString mDateTimeFormat; // user specified format string in registry (no UI presented)
QPointer< QgsVectorLayer > mLastLayer;

QFile *mLogFile = nullptr;
QTextStream mLogFileTextStream;

Expand Down
91 changes: 91 additions & 0 deletions src/app/gps/qgsgpstoolbar.cpp
Expand Up @@ -98,6 +98,19 @@ QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *can
} );
addAction( mRecenterAction );

addSeparator();

mAddTrackPointAction = new QAction( tr( "Add Track Point" ), this );
mAddTrackPointAction->setEnabled( false );
connect( mAddTrackPointAction, &QAction::triggered, this, &QgsGpsToolBar::addVertexClicked );
addAction( mAddTrackPointAction );

mAddFeatureAction = new QAction( tr( "Add Feature" ), this );
connect( mAddFeatureAction, &QAction::triggered, this, &QgsGpsToolBar::addFeatureClicked );
addAction( mAddFeatureAction );

addSeparator();

mShowInfoAction = new QAction( tr( "Information" ) );
mShowInfoAction->setToolTip( tr( "Show GPS Information Panel" ) );
mShowInfoAction->setCheckable( true );
Expand All @@ -116,6 +129,14 @@ QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *can
settingsButton->setPopupMode( QToolButton::InstantPopup );
settingsButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionOptions.svg" ) ) );
addWidget( settingsButton );

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

void QgsGpsToolBar::setAddVertexButtonEnabled( bool enabled )
{
mAddTrackPointAction->setEnabled( enabled );
}

void QgsGpsToolBar::updateLocationLabel( const QgsPoint &point )
Expand All @@ -130,3 +151,73 @@ void QgsGpsToolBar::updateLocationLabel( const QgsPoint &point )
mLocationLabel->setText( pos );
}
}

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

if ( !( vlayer && vlayer->isValid() ) )
return;

// Add feature button tracks edit state of layer
if ( vlayer != mLastLayer )
{
if ( mLastLayer ) // disconnect previous layer
{
disconnect( mLastLayer, &QgsVectorLayer::editingStarted,
this, &QgsGpsToolBar::layerEditStateChanged );
disconnect( mLastLayer, &QgsVectorLayer::editingStopped,
this, &QgsGpsToolBar::layerEditStateChanged );
}
if ( vlayer ) // connect new layer
{
connect( vlayer, &QgsVectorLayer::editingStarted,
this, &QgsGpsToolBar::layerEditStateChanged );
connect( vlayer, &QgsVectorLayer::editingStopped,
this, &QgsGpsToolBar::layerEditStateChanged );
}
mLastLayer = vlayer;
}

QString buttonLabel = tr( "&Add Feature" );
if ( vlayer )
{
QgsVectorDataProvider *provider = vlayer->dataProvider();
const QgsWkbTypes::GeometryType layerGeometryType = vlayer->geometryType();

bool enable = provider->capabilities() & QgsVectorDataProvider::AddFeatures && // layer can add features
vlayer->isEditable() && vlayer->isSpatial();

switch ( layerGeometryType )
{
case QgsWkbTypes::PointGeometry:
buttonLabel = tr( "&Add Point" );
break;

case QgsWkbTypes::LineGeometry:
buttonLabel = tr( "&Add Line" );
break;

case QgsWkbTypes::PolygonGeometry:
buttonLabel = tr( "&Add Polygon" );
break;

case QgsWkbTypes::UnknownGeometry:
case QgsWkbTypes::NullGeometry:
enable = false;
break;
}

mAddFeatureAction->setEnabled( enable );
}
else
{
mAddFeatureAction->setEnabled( false );
}
mAddFeatureAction->setText( buttonLabel );
}

void QgsGpsToolBar::layerEditStateChanged()
{
updateCloseFeatureButton( mLastLayer );
}

0 comments on commit 79262c7

Please sign in to comment.