Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add an enum for vertex tool mode
  • Loading branch information
pblottiere authored and nyalldawson committed Jul 20, 2018
1 parent 8ecc5b9 commit dc40262
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
15 changes: 7 additions & 8 deletions src/app/qgisapp.cpp
Expand Up @@ -2879,18 +2879,17 @@ void QgisApp::createToolBars()
mAdvancedDigitizeToolBar->insertWidget( mActionRotateFeature, moveFeatureButton );

// vertex tool button
QToolButton *vertexToolButton = new QToolButton( mDigitizeToolBar );
QToolButton *vertexToolButton = qobject_cast<QToolButton *>( 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;
};
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down
12 changes: 10 additions & 2 deletions src/app/vertextool/qgsvertextool.h
Expand Up @@ -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;
Expand Down Expand Up @@ -405,7 +413,7 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
//! Starting vertex when using range selection (null if not yet selected)
std::unique_ptr<Vertex> mRangeSelectionFirstVertex;

bool mActiveLayerOnly = false;
VertexToolMode mMode = AllLayers;
};


Expand Down

0 comments on commit dc40262

Please sign in to comment.