Skip to content

Commit

Permalink
Vertex tool: add topopoints to all editable layers
Browse files Browse the repository at this point in the history
  • Loading branch information
JuhoErvasti authored and nyalldawson committed Oct 1, 2024
1 parent 8f7dad4 commit 48ae8e2
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/app/vertextool/qgsvertextool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2258,29 +2258,46 @@ void QgsVertexTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocato
{
// topo editing: add vertex to existing segments when moving/adding a vertex to such segment.

// compute layers we have to add topological point on (modified ones + snapped one)
QSet<QgsVectorLayer *> targetLayers( edits.keyBegin(), edits.keyEnd() );
if ( mapPointMatch->layer() )
targetLayers << mapPointMatch->layer();
const QList<QgsMapLayer *> targetLayers = canvas()->layers( true );

for ( auto itLayerEdits = edits.begin(); itLayerEdits != edits.end(); ++itLayerEdits )
{
for ( QgsVectorLayer *targetLayer : targetLayers )
for ( QgsMapLayer *targetLayer : targetLayers )
{
QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( targetLayer );

if ( !vectorLayer || !vectorLayer->isEditable() )
continue;

if ( !( vectorLayer->geometryType() == Qgis::GeometryType::Polygon || vectorLayer->geometryType() == Qgis::GeometryType::Line ) )
continue;

// layer's CRS need to be the the same (otherwise we would need to reproject the point and it will not be coincident)
if ( targetLayer->crs() != itLayerEdits.key()->crs() )
if ( vectorLayer->crs() != itLayerEdits.key()->crs() )
continue;

vectorLayer->beginEditCommand( tr( "Topological points added by 'Vertex Tool'" ) );

bool topoPointsAdded = false;

for ( auto itFeatEdit = itLayerEdits->begin(); itFeatEdit != itLayerEdits->end(); ++itFeatEdit )
{
for ( QgsPoint point : itFeatEdit->newPoints )
{
if ( !point.is3D() )
point.addZValue( defaultZValue() );

targetLayer->addTopologicalPoints( point );
int res = vectorLayer->addTopologicalPoints( point );

if ( res == 0 )
topoPointsAdded = true;
}
}

if ( topoPointsAdded )
vectorLayer->endEditCommand();
else
vectorLayer->destroyEditCommand();
}
}
}
Expand Down

0 comments on commit 48ae8e2

Please sign in to comment.