Skip to content

Commit

Permalink
[vertex tool] "current layer" mode default + locked feature improvements
Browse files Browse the repository at this point in the history
When a feature is locked:
- vertex tool will not highlight other features
- vertex tool will not allow selection of vertices from other features
  • Loading branch information
wonder-sk authored and nirvn committed Feb 15, 2019
1 parent e1419af commit 9195314
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -2984,7 +2984,7 @@ void QgisApp::createToolBars()
vertexToolButton->addAction( mActionVertexTool );
vertexToolButton->addAction( mActionVertexToolActiveLayer );
QAction *defActionVertexTool = mActionVertexTool;
switch ( settings.enumValue( QStringLiteral( "UI/defaultVertexTool" ), QgsVertexTool::AllLayers ) )
switch ( settings.enumValue( QStringLiteral( "UI/defaultVertexTool" ), QgsVertexTool::ActiveLayer ) )
{
case QgsVertexTool::AllLayers:
defActionVertexTool = mActionVertexTool;
Expand Down
29 changes: 17 additions & 12 deletions src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -490,6 +490,12 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
QList<Vertex> selectedVertices;
QList<Vertex> editorVertices;

// the logic for selecting vertices using rectangle:
// - if we have a bound (locked) feature, we only allow selection of its vertices
// - if we don't have a bound feature, we can select vertices from any feature,
// but if there are some vertices coming from layer(s) with selected feature,
// we give them precedence.

// for each editable layer, select vertices
const auto layers = canvas()->layers();
const auto editableLayers = editableVectorLayers();
Expand All @@ -498,11 +504,17 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
if ( mMode == ActiveLayer && vlayer != currentVectorLayer() )
continue;

if ( mSelectedFeature && mSelectedFeature->layer() != vlayer )
continue; // with locked feature we only allow selection of its vertices

QgsRectangle layerRect = toLayerCoordinates( vlayer, map_rect );
QgsFeature f;
QgsFeatureIterator fi = vlayer->getFeatures( QgsFeatureRequest( layerRect ).setNoAttributes() );
while ( fi.nextFeature( f ) )
{
if ( mSelectedFeature && mSelectedFeature->featureId() != f.id() )
continue; // with locked feature we only allow selection of its vertices

bool isFeatureSelected = vlayer->selectedFeatureIds().contains( f.id() );
QgsGeometry g = f.geometry();
for ( int i = 0; i < g.constGet()->nCoordinates(); ++i )
Expand All @@ -514,22 +526,13 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

if ( isFeatureSelected )
selectedVertices << Vertex( vlayer, f.id(), i );

if ( mSelectedFeature && mSelectedFeature->featureId() == f.id() && mSelectedFeature->layer() == vlayer )
editorVertices << Vertex( vlayer, f.id(), i );
}
}
}
}

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

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

void QgsVertexTool::updateVertexBand( const QgsPointLocator::Match &m )
Expand Down

0 comments on commit 9195314

Please sign in to comment.