Skip to content
Permalink
Browse files

Fix node tool duplicates nodes when topological editing and

snap are both enabled (fix #13466)
  • Loading branch information
nyalldawson committed Oct 9, 2015
1 parent fcb3bbe commit 910dc169ba376e791aca743926cc5093e8b52cc8
Showing with 18 additions and 9 deletions.
  1. +16 −8 src/app/nodetool/qgsmaptoolnodetool.cpp
  2. +2 −1 src/app/nodetool/qgsmaptoolnodetool.h
@@ -339,6 +339,7 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QgsMapMouseEvent* e )
if ( !mSelectedFeature )
return;

QgsFeatureIds movedFids( mMoveRubberBands.keys().toSet() );
removeRubberBands();

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

int QgsMapToolNodeTool::insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults, QgsVectorLayer* editedLayer )
int QgsMapToolNodeTool::insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults, QgsVectorLayer* editedLayer, const QgsFeatureIds& skipFids )
{
QgsPoint layerPoint;

if ( !editedLayer || !editedLayer->isEditable() )
{
return 1;
}

//transform snaping coordinates to layer crs first
QList<QgsSnappingResult> transformedSnapResults = snapResults;
QList<QgsSnappingResult>::iterator it = transformedSnapResults.begin();
for ( ; it != transformedSnapResults.constEnd(); ++it )
QList<QgsSnappingResult> transformedSnapResults;
QgsFeatureIds addedFeatures;
QList<QgsSnappingResult>::const_iterator it = snapResults.constBegin();
for ( ; it != snapResults.constEnd(); ++it )
{
//skip if id is in skip list or we have already added a vertex to a feature
if ( skipFids.contains( it->snappedAtGeometry ) || addedFeatures.contains( it->snappedAtGeometry ) )
continue;

QgsPoint layerPoint = toLayerCoordinates( editedLayer, it->snappedVertex );
it->snappedVertex = layerPoint;
QgsSnappingResult result( *it );
result.snappedVertex = layerPoint;
transformedSnapResults << result;
addedFeatures << it->snappedAtGeometry;
}

return editedLayer->insertSegmentVerticesForSnap( transformedSnapResults );
@@ -105,8 +105,9 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
This is useful for topological editing if snap to segment is enabled.
@param snapResults results collected from the snapping operation
@param editedLayer pointer to the editing layer
@param skipFids set of feature IDs to avoid inserting vertices in
@return 0 in case of success*/
int insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults, QgsVectorLayer* editedLayer );
int insertSegmentVerticesForSnap( const QList<QgsSnappingResult>& snapResults, QgsVectorLayer* editedLayer , const QgsFeatureIds& skipFids );

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

0 comments on commit 910dc16

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