Skip to content

Commit

Permalink
[maptools] Fix extra duplicated feature when using the copy+move map …
Browse files Browse the repository at this point in the history
…tool action
  • Loading branch information
nirvn committed Sep 25, 2023
1 parent 657e65d commit d29c219
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/app/qgsmaptoolmovefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ void QgsMapToolMoveFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
}
case CopyMove:
QgsFeatureRequest request;
qDebug() << mMovedFeatures;
request.setFilterFids( mMovedFeatures );
QString errorMsg;
QString childrenInfoMsg;
Expand Down
36 changes: 17 additions & 19 deletions src/core/vector/qgsvectorlayertools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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
Expand Down

0 comments on commit d29c219

Please sign in to comment.