From d29c2196f3487e44a00d3db094f6cf0cdd1d06dd Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sat, 16 Sep 2023 09:51:00 +0700 Subject: [PATCH] [maptools] Fix extra duplicated feature when using the copy+move map tool action --- src/app/qgsmaptoolmovefeature.cpp | 1 + src/core/vector/qgsvectorlayertools.cpp | 36 ++++++++++++------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/app/qgsmaptoolmovefeature.cpp b/src/app/qgsmaptoolmovefeature.cpp index f19d53313e07..292a24d0118d 100644 --- a/src/app/qgsmaptoolmovefeature.cpp +++ b/src/app/qgsmaptoolmovefeature.cpp @@ -244,6 +244,7 @@ void QgsMapToolMoveFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e ) } case CopyMove: QgsFeatureRequest request; + qDebug() << mMovedFeatures; request.setFilterFids( mMovedFeatures ); QString errorMsg; QString childrenInfoMsg; diff --git a/src/core/vector/qgsvectorlayertools.cpp b/src/core/vector/qgsvectorlayertools.cpp index 99aba7f309b1..19a5730c07a5 100644 --- a/src/core/vector/qgsvectorlayertools.cpp +++ b/src/core/vector/qgsvectorlayertools.cpp @@ -48,6 +48,13 @@ bool QgsVectorLayerTools::copyMoveFeatures( QgsVectorLayer *layer, QgsFeatureReq { browsedFeatureCount++; + if ( f.hasGeometry() ) + { + QgsGeometry geom = f.geometry(); + geom.translate( dx, dy ); + f.setGeometry( geom ); + } + QgsFeature newFeature; if ( mProject ) { @@ -69,34 +76,25 @@ bool QgsVectorLayerTools::copyMoveFeatures( QgsVectorLayer *layer, QgsFeatureReq else { newFeature = QgsVectorLayerUtils::createFeature( layer, f.geometry(), f.attributes().toMap() ); + if ( !layer->addFeature( newFeature ) ) + { + couldNotWriteCount++; + QgsDebugError( QStringLiteral( "Could not add new feature. Original copied feature id: %1" ).arg( f.id() ) ); + } } // translate if ( newFeature.hasGeometry() ) { QgsGeometry geom = newFeature.geometry(); - geom.translate( dx, dy ); - newFeature.setGeometry( geom ); -#ifdef QGISDEBUG - const QgsFeatureId fid = newFeature.id(); -#endif - // paste feature - if ( !layer->addFeature( newFeature ) ) - { - couldNotWriteCount++; - QgsDebugError( QStringLiteral( "Could not add new feature. Original copied feature id: %1" ).arg( fid ) ); - } - else + fidList.insert( newFeature.id() ); + if ( topologicalEditing ) { - fidList.insert( newFeature.id() ); - if ( topologicalEditing ) + if ( topologicalLayer ) { - if ( topologicalLayer ) - { - topologicalLayer->addTopologicalPoints( geom ); - } - layer->addTopologicalPoints( geom ); + topologicalLayer->addTopologicalPoints( geom ); } + layer->addTopologicalPoints( geom ); } } else