From dc402620aae86fd22adec3a10d53a32ec3bb4125 Mon Sep 17 00:00:00 2001 From: Blottiere Paul Date: Mon, 11 Jun 2018 08:36:38 +0100 Subject: [PATCH] Add an enum for vertex tool mode --- src/app/qgisapp.cpp | 15 +++++++-------- src/app/vertextool/qgsvertextool.cpp | 8 ++++---- src/app/vertextool/qgsvertextool.h | 12 ++++++++++-- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 66a730154d5b..147a9ead9b1f 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -2879,18 +2879,17 @@ void QgisApp::createToolBars() mAdvancedDigitizeToolBar->insertWidget( mActionRotateFeature, moveFeatureButton ); // vertex tool button - QToolButton *vertexToolButton = new QToolButton( mDigitizeToolBar ); + QToolButton *vertexToolButton = qobject_cast( mDigitizeToolBar->widgetForAction( mActionVertexTool ) ); vertexToolButton->setPopupMode( QToolButton::MenuButtonPopup ); vertexToolButton->addAction( mActionVertexTool ); vertexToolButton->addAction( mActionVertexToolActiveLayer ); - mAdvancedDigitizeToolBar->insertWidget( mActionDeleteSelected, vertexToolButton ); QAction *defActionVertexTool = mActionVertexTool; - switch ( settings.value( QStringLiteral( "UI/defaultVertexTool" ), 0 ).toInt() ) + switch ( settings.enumValue( QStringLiteral( "UI/defaultVertexTool" ), QgsVertexTool::AllLayers ) ) { - case 0: + case QgsVertexTool::AllLayers: defActionVertexTool = mActionVertexTool; break; - case 1: + case QgsVertexTool::ActiveLayer: defActionVertexTool = mActionVertexToolActiveLayer; break; }; @@ -3501,7 +3500,7 @@ void QgisApp::createCanvasTools() mMapTools.mDeletePart->setAction( mActionDeletePart ); mMapTools.mVertexTool = new QgsVertexTool( mMapCanvas, mAdvancedDigitizingDockWidget ); mMapTools.mVertexTool->setAction( mActionVertexTool ); - mMapTools.mVertexToolActiveLayer = new QgsVertexTool( mMapCanvas, mAdvancedDigitizingDockWidget, true ); + mMapTools.mVertexToolActiveLayer = new QgsVertexTool( mMapCanvas, mAdvancedDigitizingDockWidget, QgsVertexTool::ActiveLayer ); mMapTools.mVertexToolActiveLayer->setAction( mActionVertexToolActiveLayer ); mMapTools.mRotatePointSymbolsTool = new QgsMapToolRotatePointSymbols( mMapCanvas ); mMapTools.mRotatePointSymbolsTool->setAction( mActionRotatePointSymbols ); @@ -13612,9 +13611,9 @@ void QgisApp::toolButtonActionTriggered( QAction *action ) else if ( action == mActionMoveFeatureCopy ) settings.setValue( QStringLiteral( "UI/defaultMoveTool" ), 1 ); else if ( action == mActionVertexTool ) - settings.setValue( QStringLiteral( "UI/defaultVertexTool" ), 0 ); + settings.setEnumValue( QStringLiteral( "UI/defaultVertexTool" ), QgsVertexTool::AllLayers ); else if ( action == mActionVertexToolActiveLayer ) - settings.setValue( QStringLiteral( "UI/defaultVertexTool" ), 1 ); + settings.setEnumValue( QStringLiteral( "UI/defaultVertexTool" ), QgsVertexTool::ActiveLayer ); bt->setDefaultAction( action ); } diff --git a/src/app/vertextool/qgsvertextool.cpp b/src/app/vertextool/qgsvertextool.cpp index 2f8b1f7efe8c..e5e41da021ed 100644 --- a/src/app/vertextool/qgsvertextool.cpp +++ b/src/app/vertextool/qgsvertextool.cpp @@ -227,9 +227,9 @@ class SelectedMatchFilter : public QgsPointLocator::MatchFilter // -QgsVertexTool::QgsVertexTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDock, bool activeLayerOnly ) +QgsVertexTool::QgsVertexTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDock, VertexToolMode mode ) : QgsMapToolAdvancedDigitizing( canvas, cadDock ) - , mActiveLayerOnly( activeLayerOnly ) + , mMode( mode ) { setAdvancedDigitizingAllowed( false ); @@ -479,7 +479,7 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e ) if ( !vlayer || !vlayer->isEditable() || !vlayer->isSpatial() ) continue; - if ( mActiveLayerOnly && vlayer != currentVectorLayer() ) + if ( mMode == ActiveLayer && vlayer != currentVectorLayer() ) continue; QgsRectangle layerRect = toLayerCoordinates( vlayer, map_rect ); @@ -695,7 +695,7 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e ) } // if there is no match from the current layer, try to use any editable vector layer - if ( !m.isValid() && !mActiveLayerOnly ) + if ( !m.isValid() && mMode == AllLayers ) { const auto layers = canvas()->layers(); for ( QgsMapLayer *layer : layers ) diff --git a/src/app/vertextool/qgsvertextool.h b/src/app/vertextool/qgsvertextool.h index 847eeda4fb90..ad75785c1e70 100644 --- a/src/app/vertextool/qgsvertextool.h +++ b/src/app/vertextool/qgsvertextool.h @@ -61,7 +61,15 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing { Q_OBJECT public: - QgsVertexTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDock, bool activeLayerOnly = false ); + + enum VertexToolMode + { + ActiveLayer, + AllLayers + }; + Q_ENUM( VertexToolMode ); + + QgsVertexTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDock, VertexToolMode mode = QgsVertexTool::AllLayers ); //! Cleanup canvas items we have created ~QgsVertexTool() override; @@ -405,7 +413,7 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing //! Starting vertex when using range selection (null if not yet selected) std::unique_ptr mRangeSelectionFirstVertex; - bool mActiveLayerOnly = false; + VertexToolMode mMode = AllLayers; };