Navigation Menu

Skip to content

Commit

Permalink
Add topological points on background layers for qgsmaptooladdfeature
Browse files Browse the repository at this point in the history
(cherry picked from commit 47bc117)
  • Loading branch information
lbartoletti authored and nyalldawson committed Nov 21, 2019
1 parent 6f171fd commit 32c9b30
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 32c9b30

Please sign in to comment.