Skip to content
Permalink
Browse files

Add an enum for vertex tool mode

  • Loading branch information
pblottiere authored and nyalldawson committed Jun 11, 2018
1 parent 8ecc5b9 commit dc402620aae86fd22adec3a10d53a32ec3bb4125
Showing with 21 additions and 14 deletions.
  1. +7 −8 src/app/qgisapp.cpp
  2. +4 −4 src/app/vertextool/qgsvertextool.cpp
  3. +10 −2 src/app/vertextool/qgsvertextool.h
@@ -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;
};
@@ -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 );
}
@@ -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 )
@@ -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<Vertex> mRangeSelectionFirstVertex;

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


0 comments on commit dc40262

Please sign in to comment.
You can’t perform that action at this time.