Skip to content

Commit 910dc16

Browse files
committed
Fix node tool duplicates nodes when topological editing and
snap are both enabled (fix #13466)
1 parent fcb3bbe commit 910dc16

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/app/nodetool/qgsmaptoolnodetool.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QgsMapMouseEvent* e )
339339
if ( !mSelectedFeature )
340340
return;
341341

342+
QgsFeatureIds movedFids( mMoveRubberBands.keys().toSet() );
342343
removeRubberBands();
343344

344345
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
@@ -383,7 +384,8 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QgsMapMouseEvent* e )
383384
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
384385
if ( topologicalEditing )
385386
{
386-
insertSegmentVerticesForSnap( snapResults, vlayer );
387+
//insert vertices for snap, but don't add them to features which already has a vertex being moved
388+
insertSegmentVerticesForSnap( snapResults, vlayer, movedFids );
387389
}
388390
}
389391
else
@@ -602,22 +604,28 @@ QgsPoint QgsMapToolNodeTool::snapPointFromResults( const QList<QgsSnappingResult
602604
}
603605
}
604606

605-
int QgsMapToolNodeTool::insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults, QgsVectorLayer* editedLayer )
607+
int QgsMapToolNodeTool::insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults, QgsVectorLayer* editedLayer, const QgsFeatureIds& skipFids )
606608
{
607-
QgsPoint layerPoint;
608-
609609
if ( !editedLayer || !editedLayer->isEditable() )
610610
{
611611
return 1;
612612
}
613613

614614
//transform snaping coordinates to layer crs first
615-
QList<QgsSnappingResult> transformedSnapResults = snapResults;
616-
QList<QgsSnappingResult>::iterator it = transformedSnapResults.begin();
617-
for ( ; it != transformedSnapResults.constEnd(); ++it )
615+
QList<QgsSnappingResult> transformedSnapResults;
616+
QgsFeatureIds addedFeatures;
617+
QList<QgsSnappingResult>::const_iterator it = snapResults.constBegin();
618+
for ( ; it != snapResults.constEnd(); ++it )
618619
{
620+
//skip if id is in skip list or we have already added a vertex to a feature
621+
if ( skipFids.contains( it->snappedAtGeometry ) || addedFeatures.contains( it->snappedAtGeometry ) )
622+
continue;
623+
619624
QgsPoint layerPoint = toLayerCoordinates( editedLayer, it->snappedVertex );
620-
it->snappedVertex = layerPoint;
625+
QgsSnappingResult result( *it );
626+
result.snappedVertex = layerPoint;
627+
transformedSnapResults << result;
628+
addedFeatures << it->snappedAtGeometry;
621629
}
622630

623631
return editedLayer->insertSegmentVerticesForSnap( transformedSnapResults );

src/app/nodetool/qgsmaptoolnodetool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
105105
This is useful for topological editing if snap to segment is enabled.
106106
@param snapResults results collected from the snapping operation
107107
@param editedLayer pointer to the editing layer
108+
@param skipFids set of feature IDs to avoid inserting vertices in
108109
@return 0 in case of success*/
109-
int insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults, QgsVectorLayer* editedLayer );
110+
int insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults, QgsVectorLayer* editedLayer , const QgsFeatureIds& skipFids );
110111

111112
/** Snapper object that reads the settings from project and option
112113
and applies it to the map canvas*/

0 commit comments

Comments
 (0)