Skip to content

Commit

Permalink
Add topological points on background layers for qgsmaptooladdfeature
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti authored and nyalldawson committed Nov 20, 2019
1 parent bcdbc3a commit 47bc117
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/app/qgsmaptooladdfeature.cpp
Expand Up @@ -65,28 +65,40 @@ void QgsMapToolAddFeature::digitized( const QgsFeature &f )
QgsVectorLayer *vlayer = currentVectorLayer();
bool res = addFeature( vlayer, f, false );

if ( res && ( mode() == CaptureLine || mode() == CapturePolygon ) )
if ( res )
{
//add points to other features to keep topology up-to-date
bool topologicalEditing = QgsProject::instance()->topologicalEditing();
if ( mode() == CaptureLine || mode() == CapturePolygon )
{

//use always topological editing for avoidIntersection.
//Otherwise, no way to guarantee the geometries don't have a small gap in between.
const QList<QgsVectorLayer *> intersectionLayers = QgsProject::instance()->avoidIntersectionsLayers();
//use always topological editing for avoidIntersection.
//Otherwise, no way to guarantee the geometries don't have a small gap in between.
const QList<QgsVectorLayer *> intersectionLayers = QgsProject::instance()->avoidIntersectionsLayers();

if ( !intersectionLayers.isEmpty() ) //try to add topological points also to background layers
{
for ( QgsVectorLayer *vl : intersectionLayers )
if ( !intersectionLayers.isEmpty() ) //try to add topological points also to background layers
{
//can only add topological points if background layer is editable...
if ( vl->geometryType() == QgsWkbTypes::PolygonGeometry && vl->isEditable() )
for ( QgsVectorLayer *vl : intersectionLayers )
{
vl->addTopologicalPoints( f.geometry() );
//can only add topological points if background layer is editable...
if ( vl->geometryType() == QgsWkbTypes::PolygonGeometry && vl->isEditable() )
{
vl->addTopologicalPoints( f.geometry() );
}
}
}
}
else if ( topologicalEditing )
if ( topologicalEditing )
{
QList<QgsPointLocator::Match> sm = snappingMatches();
Q_ASSERT( f.geometry().constGet()->vertexCount() == sm.size() );
for ( int i = 0; i < sm.size() ; ++i )
{
if ( sm.at( i ).layer() )
{
sm.at( i ).layer()->addTopologicalPoints( f.geometry().vertexAt( i ) );
}
}
vlayer->addTopologicalPoints( f.geometry() );
}
}
Expand Down

0 comments on commit 47bc117

Please sign in to comment.