Skip to content

Commit 9195314

Browse files
wonder-sknirvn
authored andcommitted
[vertex tool] "current layer" mode default + locked feature improvements
When a feature is locked: - vertex tool will not highlight other features - vertex tool will not allow selection of vertices from other features
1 parent e1419af commit 9195314

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/app/qgisapp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2984,7 +2984,7 @@ void QgisApp::createToolBars()
29842984
vertexToolButton->addAction( mActionVertexTool );
29852985
vertexToolButton->addAction( mActionVertexToolActiveLayer );
29862986
QAction *defActionVertexTool = mActionVertexTool;
2987-
switch ( settings.enumValue( QStringLiteral( "UI/defaultVertexTool" ), QgsVertexTool::AllLayers ) )
2987+
switch ( settings.enumValue( QStringLiteral( "UI/defaultVertexTool" ), QgsVertexTool::ActiveLayer ) )
29882988
{
29892989
case QgsVertexTool::AllLayers:
29902990
defActionVertexTool = mActionVertexTool;

src/app/vertextool/qgsvertextool.cpp

+17-12
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,12 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
490490
QList<Vertex> selectedVertices;
491491
QList<Vertex> editorVertices;
492492

493+
// the logic for selecting vertices using rectangle:
494+
// - if we have a bound (locked) feature, we only allow selection of its vertices
495+
// - if we don't have a bound feature, we can select vertices from any feature,
496+
// but if there are some vertices coming from layer(s) with selected feature,
497+
// we give them precedence.
498+
493499
// for each editable layer, select vertices
494500
const auto layers = canvas()->layers();
495501
const auto editableLayers = editableVectorLayers();
@@ -498,11 +504,17 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
498504
if ( mMode == ActiveLayer && vlayer != currentVectorLayer() )
499505
continue;
500506

507+
if ( mSelectedFeature && mSelectedFeature->layer() != vlayer )
508+
continue; // with locked feature we only allow selection of its vertices
509+
501510
QgsRectangle layerRect = toLayerCoordinates( vlayer, map_rect );
502511
QgsFeature f;
503512
QgsFeatureIterator fi = vlayer->getFeatures( QgsFeatureRequest( layerRect ).setNoAttributes() );
504513
while ( fi.nextFeature( f ) )
505514
{
515+
if ( mSelectedFeature && mSelectedFeature->featureId() != f.id() )
516+
continue; // with locked feature we only allow selection of its vertices
517+
506518
bool isFeatureSelected = vlayer->selectedFeatureIds().contains( f.id() );
507519
QgsGeometry g = f.geometry();
508520
for ( int i = 0; i < g.constGet()->nCoordinates(); ++i )
@@ -514,22 +526,13 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
514526

515527
if ( isFeatureSelected )
516528
selectedVertices << Vertex( vlayer, f.id(), i );
517-
518-
if ( mSelectedFeature && mSelectedFeature->featureId() == f.id() && mSelectedFeature->layer() == vlayer )
519-
editorVertices << Vertex( vlayer, f.id(), i );
520529
}
521530
}
522531
}
523532
}
524533

525-
// If there were any vertices that come from a feature currently binded to the node editor, use just verices from
526-
// that feature, otherwise if there were any vertices from selected features, use just vertices from those selected features.
527-
// This allows user to select a bunch of features in complex situations to constrain the selection.
528-
if ( !editorVertices.isEmpty() )
529-
{
530-
vertices = editorVertices;
531-
}
532-
else if ( !selectedVertices.isEmpty() )
534+
// here's where we give precedence to vertices of selected features in case there's no bound (locked) feature
535+
if ( !mSelectedFeature && !selectedVertices.isEmpty() )
533536
{
534537
vertices = selectedVertices;
535538
}
@@ -1122,7 +1125,9 @@ void QgsVertexTool::mouseMoveNotDragging( QgsMapMouseEvent *e )
11221125
m = snapToPolygonInterior( e );
11231126
}
11241127

1125-
updateFeatureBand( m );
1128+
// when we are "locked" to a feature, we don't want to highlight any other features
1129+
// so the user does not get distracted
1130+
updateFeatureBand( mSelectedFeature ? QgsPointLocator::Match() : m );
11261131
}
11271132

11281133
void QgsVertexTool::updateVertexBand( const QgsPointLocator::Match &m )

0 commit comments

Comments
 (0)