Skip to content

Commit

Permalink
Fix node tool duplicates nodes when topological editing and
Browse files Browse the repository at this point in the history
snap are both enabled (fix #13466)
  • Loading branch information
nyalldawson committed Oct 9, 2015
1 parent fcb3bbe commit 910dc16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
24 changes: 16 additions & 8 deletions src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -339,6 +339,7 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QgsMapMouseEvent* e )
if ( !mSelectedFeature )
return;

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

QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down
3 changes: 2 additions & 1 deletion src/app/nodetool/qgsmaptoolnodetool.h
Expand Up @@ -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*/
Expand Down

0 comments on commit 910dc16

Please sign in to comment.