Skip to content

Commit

Permalink
Add a dropdown menu for vertex tool and active layer option
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere authored and nyalldawson committed Jul 20, 2018
1 parent 6363aba commit c67d09c
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 25 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
<file>themes/default/mActionNewGeoPackageLayer.svg</file>
<file>themes/default/mActionNewVectorLayer.svg</file>
<file>themes/default/mActionVertexTool.svg</file>
<file>themes/default/mActionVertexToolActiveLayer.svg</file>
<file>themes/default/mActionOffsetCurve.svg</file>
<file>themes/default/mActionOpenTable.svg</file>
<file>themes/default/mActionAddTable.svg</file>
Expand Down
153 changes: 136 additions & 17 deletions images/themes/default/mActionVertexTool.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions images/themes/default/mActionVertexToolActiveLayer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,7 @@ QgisApp::~QgisApp()
delete mMapTools.mMoveFeatureCopy;
delete mMapTools.mMoveLabel;
delete mMapTools.mVertexTool;
delete mMapTools.mVertexToolActiveLayer;
delete mMapTools.mOffsetCurve;
delete mMapTools.mPinLabels;
delete mMapTools.mReshapeFeatures;
Expand Down Expand Up @@ -2024,6 +2025,7 @@ void QgisApp::createActions()
connect( mActionMergeFeatureAttributes, &QAction::triggered, this, &QgisApp::mergeAttributesOfSelectedFeatures );
connect( mActionMultiEditAttributes, &QAction::triggered, this, &QgisApp::modifyAttributesOfSelectedFeatures );
connect( mActionVertexTool, &QAction::triggered, this, &QgisApp::vertexTool );
connect( mActionVertexToolActiveLayer, &QAction::triggered, this, &QgisApp::vertexToolActiveLayer );
connect( mActionRotatePointSymbols, &QAction::triggered, this, &QgisApp::rotatePointSymbols );
connect( mActionOffsetPointSymbol, &QAction::triggered, this, &QgisApp::offsetPointSymbol );
connect( mActionSnappingOptions, &QAction::triggered, this, &QgisApp::snappingOptions );
Expand Down Expand Up @@ -2311,6 +2313,7 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction( mActionMergeFeatures );
mMapToolGroup->addAction( mActionMergeFeatureAttributes );
mMapToolGroup->addAction( mActionVertexTool );
mMapToolGroup->addAction( mActionVertexToolActiveLayer );
mMapToolGroup->addAction( mActionRotatePointSymbols );
mMapToolGroup->addAction( mActionOffsetPointSymbol );
mMapToolGroup->addAction( mActionPinLabels );
Expand Down Expand Up @@ -2875,6 +2878,16 @@ void QgisApp::createToolBars()
connect( moveFeatureButton, &QToolButton::triggered, this, &QgisApp::toolButtonActionTriggered );
mAdvancedDigitizeToolBar->insertWidget( mActionRotateFeature, moveFeatureButton );

// vertex tool button
QToolButton *vertexToolButton = new QToolButton( mDigitizeToolBar );
vertexToolButton->setPopupMode( QToolButton::MenuButtonPopup );
vertexToolButton->addAction( mActionVertexTool );
vertexToolButton->addAction( mActionVertexToolActiveLayer );
mAdvancedDigitizeToolBar->insertWidget( mActionDeleteSelected, vertexToolButton );
QAction *defActionVertexTool = mActionVertexTool;
vertexToolButton->setDefaultAction( defActionVertexTool );
connect( vertexToolButton, &QToolButton::triggered, this, &QgisApp::toolButtonActionTriggered );

bt = new QToolButton();
bt->setPopupMode( QToolButton::MenuButtonPopup );
bt->addAction( mActionRotatePointSymbols );
Expand Down Expand Up @@ -3185,6 +3198,7 @@ void QgisApp::setTheme( const QString &themeName )
mActionSplitParts->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionSplitParts.svg" ) ) );
mActionDeleteSelected->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionDeleteSelected.svg" ) ) );
mActionVertexTool->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionVertexTool.svg" ) ) );
mActionVertexToolActiveLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionVertexToolActiveLayer.svg" ) ) );
mActionSimplifyFeature->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionSimplify.svg" ) ) );
mActionUndo->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionUndo.svg" ) ) );
mActionRedo->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionRedo.svg" ) ) );
Expand Down Expand Up @@ -3478,6 +3492,8 @@ 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->setAction( mActionVertexToolActiveLayer );
mMapTools.mRotatePointSymbolsTool = new QgsMapToolRotatePointSymbols( mMapCanvas );
mMapTools.mRotatePointSymbolsTool->setAction( mActionRotatePointSymbols );
mMapTools.mOffsetPointSymbolTool = new QgsMapToolOffsetPointSymbol( mMapCanvas );
Expand Down Expand Up @@ -8245,6 +8261,11 @@ void QgisApp::vertexTool()
mMapCanvas->setMapTool( mMapTools.mVertexTool );
}

void QgisApp::vertexToolActiveLayer()
{
mMapCanvas->setMapTool( mMapTools.mVertexToolActiveLayer );
}

void QgisApp::rotatePointSymbols()
{
mMapCanvas->setMapTool( mMapTools.mRotatePointSymbolsTool );
Expand Down Expand Up @@ -11927,6 +11948,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
mActionRotateFeature->setEnabled( false );
mActionOffsetCurve->setEnabled( false );
mActionVertexTool->setEnabled( false );
mActionVertexToolActiveLayer->setEnabled( false );
mActionDeleteSelected->setEnabled( false );
mActionCutFeatures->setEnabled( false );
mActionCopyFeatures->setEnabled( false );
Expand Down Expand Up @@ -12108,6 +12130,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
mActionMoveFeatureCopy->setEnabled( isEditable && canChangeGeometry );
mActionRotateFeature->setEnabled( isEditable && canChangeGeometry );
mActionVertexTool->setEnabled( isEditable && canChangeGeometry );
mActionVertexToolActiveLayer->setEnabled( isEditable && canChangeGeometry );

if ( vlayer->geometryType() == QgsWkbTypes::PointGeometry )
{
Expand Down Expand Up @@ -12262,6 +12285,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
mActionFillRing->setEnabled( false );
mActionAddPart->setEnabled( false );
mActionVertexTool->setEnabled( false );
mActionVertexToolActiveLayer->setEnabled( false );
mActionMoveFeature->setEnabled( false );
mActionMoveFeatureCopy->setEnabled( false );
mActionRotateFeature->setEnabled( false );
Expand Down
5 changes: 4 additions & 1 deletion src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1392,8 +1392,10 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void mergeAttributesOfSelectedFeatures();
//! Modifies the attributes of selected features via feature form
void modifyAttributesOfSelectedFeatures();
//! provides operations with nodes
//! provides operations with nodes on all layers
void vertexTool();
//! provides operations with nodes on active layer only
void vertexToolActiveLayer();
//! activates the rotate points tool
void rotatePointSymbols();
//! activates the offset point symbol tool
Expand Down Expand Up @@ -2000,6 +2002,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsMapTool *mDeleteRing = nullptr;
QgsMapTool *mDeletePart = nullptr;
QgsMapTool *mVertexTool = nullptr;
QgsMapTool *mVertexToolActiveLayer = nullptr;
QgsMapTool *mRotatePointSymbolsTool = nullptr;
QgsMapTool *mOffsetPointSymbolTool = nullptr;
QgsMapTool *mAnnotation = nullptr;
Expand Down
9 changes: 4 additions & 5 deletions src/app/vertextool/qgsvertextool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ class SelectedMatchFilter : public QgsPointLocator::MatchFilter
//


QgsVertexTool::QgsVertexTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDock )
QgsVertexTool::QgsVertexTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDock, bool activeLayerOnly )
: QgsMapToolAdvancedDigitizing( canvas, cadDock )
, mActiveLayerOnly( activeLayerOnly )
{
setAdvancedDigitizingAllowed( false );

Expand Down Expand Up @@ -470,8 +471,6 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
QList<Vertex> vertices;
QList<Vertex> selectedVertices;

const bool allLayers = canvas()->snappingUtils()->config().editVerticesOnAllLayers();

// for each editable layer, select vertices
const auto layers = canvas()->layers();
for ( QgsMapLayer *layer : layers )
Expand All @@ -480,7 +479,7 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
if ( !vlayer || !vlayer->isEditable() || !vlayer->isSpatial() )
continue;

if ( !allLayers && vlayer != currentVectorLayer() )
if ( mActiveLayerOnly && vlayer != currentVectorLayer() )
continue;

QgsRectangle layerRect = toLayerCoordinates( vlayer, map_rect );
Expand Down Expand Up @@ -696,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() && oldConfig.editVerticesOnAllLayers() )
if ( !m.isValid() && !mActiveLayerOnly )
{
const auto layers = canvas()->layers();
for ( QgsMapLayer *layer : layers )
Expand Down
4 changes: 3 additions & 1 deletion src/app/vertextool/qgsvertextool.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
{
Q_OBJECT
public:
QgsVertexTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDock );
QgsVertexTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDock, bool activeLayerOnly = false );

//! Cleanup canvas items we have created
~QgsVertexTool() override;
Expand Down Expand Up @@ -404,6 +404,8 @@ 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;
};


Expand Down
Loading

0 comments on commit c67d09c

Please sign in to comment.