From 3ebf43703e50362776acf5b0fee6850decb12d0d Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Wed, 25 Oct 2023 17:48:02 +0700 Subject: [PATCH] Fix copy/pasting of features to/from the same layer ignores avoid overlap settings --- src/app/qgisapp.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 212512731868..eb76360f9c04 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -10202,6 +10202,37 @@ void QgisApp::pasteFromClipboard( QgsMapLayer *destinationLayer ) if ( duplicateFeature ) { pastedFeatures = features; + + for ( auto &feature : pastedFeatures ) + { + QgsGeometry geom = feature.geometry(); + + if ( !( geom.isEmpty() || geom.isNull( ) ) ) + { + // avoid intersection if enabled in digitize settings + QList avoidIntersectionsLayers; + switch ( QgsProject::instance()->avoidIntersectionsMode() ) + { + case Qgis::AvoidIntersectionsMode::AvoidIntersectionsCurrentLayer: + avoidIntersectionsLayers.append( pasteVectorLayer ); + break; + case Qgis::AvoidIntersectionsMode::AvoidIntersectionsLayers: + avoidIntersectionsLayers = QgsProject::instance()->avoidIntersectionsLayers(); + break; + case Qgis::AvoidIntersectionsMode::AllowIntersections: + break; + } + if ( avoidIntersectionsLayers.size() > 0 ) + { + geom.avoidIntersectionsV2( avoidIntersectionsLayers ); + feature.setGeometry( geom ); + } + + // count collapsed geometries + if ( geom.isEmpty() || geom.isNull( ) ) + invalidGeometriesCount++; + } + } } else {