@@ -343,8 +343,8 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
343
343
//
344
344
// Map tools
345
345
//
346
- #include " qgsmaptooladdfeature.h"
347
346
#include " qgsmaptooladdpart.h"
347
+ #include " qgsmaptooladdfeature.h"
348
348
#include " qgsmaptooladdring.h"
349
349
#include " qgsmaptoolfillring.h"
350
350
#include " qgsmaptoolannotation.h"
@@ -1382,6 +1382,7 @@ QgisApp::~QgisApp()
1382
1382
delete mMapTools .mRegularPolygonCenterPoint ;
1383
1383
delete mMapTools .mRegularPolygonCenterCorner ;
1384
1384
delete mMapTools .mAddFeature ;
1385
+ delete mMapTools .mDigitizeFeature ;
1385
1386
delete mpMaptip;
1386
1387
1387
1388
delete mpGpsWidget;
@@ -3298,6 +3299,7 @@ void QgisApp::createCanvasTools()
3298
3299
mMapTools .mAnnotation ->setAction ( mActionAnnotation );
3299
3300
mMapTools .mAddFeature = new QgsMapToolAddFeature ( mMapCanvas , QgsMapToolCapture::CaptureNone );
3300
3301
mMapTools .mAddFeature ->setAction ( mActionAddFeature );
3302
+ mMapTools .mDigitizeFeature = new QgsMapToolDigitizeFeature ( mMapCanvas , QgsMapToolCapture::CaptureNone );
3301
3303
mMapTools .mCircularStringCurvePoint = new QgsMapToolCircularStringCurvePoint ( mMapTools .mAddFeature , mMapCanvas );
3302
3304
mMapTools .mCircularStringCurvePoint ->setAction ( mActionCircularStringCurvePoint );
3303
3305
mMapTools .mCircularStringRadius = new QgsMapToolCircularStringRadius ( mMapTools .mAddFeature , mMapCanvas );
@@ -7621,6 +7623,17 @@ void QgisApp::setupDuplicateFeaturesAction()
7621
7623
duplicateFeatures ( layer, feat );
7622
7624
}
7623
7625
);
7626
+
7627
+ action = new QgsMapLayerAction ( QString ( tr ( " Duplicate feature redigitized" ) ),
7628
+ this , QgsMapLayerAction::AllActions,
7629
+ QgsApplication::getThemeIcon ( QStringLiteral ( " /mIconAms.svg" ) ) );
7630
+
7631
+ QgsGui::mapLayerActionRegistry ()->addMapLayerAction ( action );
7632
+ connect ( action, &QgsMapLayerAction::triggeredForFeature, this , [this ]( QgsMapLayer * layer, const QgsFeature & feat )
7633
+ {
7634
+ duplicateFeatureDigitized ( layer, feat );
7635
+ }
7636
+ );
7624
7637
}
7625
7638
7626
7639
void QgisApp::setupAtlasMapLayerAction ( QgsComposition *composition, bool enableAction )
@@ -13322,31 +13335,88 @@ QgsFeature QgisApp::duplicateFeatures( QgsMapLayer *mlayer, const QgsFeature &fe
13322
13335
{
13323
13336
if ( mlayer->type () != QgsMapLayer::VectorLayer )
13324
13337
return QgsFeature ();
13325
- /*
13326
- QgsVectorLayer *layer=qobject_cast<QgsVectorLayer *>(mlayer);
13327
13338
13328
- layer->startEditing( );
13339
+ QgsVectorLayer * layer = qobject_cast<QgsVectorLayer *>( mlayer );
13329
13340
13330
- QgsFeatureList featureList;
13341
+ layer->startEditing ();
13342
+
13343
+ QgsFeatureList featureList;
13331
13344
13332
- if( feature )
13345
+ if ( feature.isValid () )
13346
+ {
13347
+ featureList.append ( feature );
13348
+ }
13349
+ else
13350
+ {
13351
+ for ( const QgsFeature &f : layer->selectedFeatures () )
13333
13352
{
13334
- featureList.append( feature );
13353
+ featureList.append ( f );
13335
13354
}
13336
- else
13355
+ }
13356
+
13357
+ int featureCount = 0 ;
13358
+
13359
+ QString childrenInfo;
13360
+
13361
+ for ( const QgsFeature &f : featureList )
13362
+ {
13363
+ QgsVectorLayerUtils::QgsDuplicateFeatureContext duplicateFeatureContext;
13364
+
13365
+ QgsVectorLayerUtils::duplicateFeature ( layer, f, QgsProject::instance (), 0 , duplicateFeatureContext );
13366
+ featureCount += 1 ;
13367
+
13368
+ for ( QgsVectorLayer *chl : duplicateFeatureContext.layers () )
13337
13369
{
13338
- for ( const QgsFeature &f : layer->selectedFeatures() )
13339
- {
13340
- featureList.append( f );
13341
- }
13370
+ childrenInfo += ( tr ( " %1 children on layer %2 duplicated" ).arg ( duplicateFeatureContext.duplicatedFeatures ( chl ).size () ).arg ( chl->name () ) );
13342
13371
}
13372
+ }
13373
+
13374
+ messageBar ()->pushMessage ( tr ( " %1 features on layer %2 duplicated\n %3" ).arg ( featureCount ).arg ( layer->name () ).arg ( childrenInfo ), QgsMessageBar::SUCCESS, 5 );
13375
+
13376
+ return QgsFeature ();
13377
+ }
13378
+
13379
+
13380
+ QgsFeature QgisApp::duplicateFeatureDigitized ( QgsMapLayer *mlayer, const QgsFeature &feature )
13381
+ {
13382
+ if ( mlayer->type () != QgsMapLayer::VectorLayer )
13383
+ return QgsFeature ();
13384
+
13385
+ QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mlayer );
13343
13386
13344
- int featureCount=0;
13387
+ layer->startEditing ();
13388
+ mMapCanvas ->setMapTool ( mMapTools .mDigitizeFeature );
13389
+ mMapCanvas ->window ()->raise ();
13390
+ mMapCanvas ->activateWindow ();
13391
+ mMapCanvas ->setFocus ();
13392
+
13393
+ QString msg = tr ( " Digitize the duplicate, please." ).arg ( layer->name () );
13394
+ messageBar ()->pushMessage ( msg, QgsMessageBar::INFO, 3 );
13395
+
13396
+ QMetaObject::Connection *connDigitizingFinished = new QMetaObject::Connection ();
13397
+ *connDigitizingFinished = connect ( mMapTools .mDigitizeFeature , static_cast <void ( QgsMapToolDigitizeFeature::* )( const QgsFeature & )>( &QgsMapToolDigitizeFeature::digitizingFinished ), this , [this , layer, feature, connDigitizingFinished]( const QgsFeature & digitizedFeature )
13398
+ {
13399
+ QString msg = tr ( " Duplicate digitized" );
13400
+ messageBar ()->pushMessage ( msg, QgsMessageBar::INFO, 1 );
13401
+
13402
+ QgsVectorLayerUtils::QgsDuplicateFeatureContext duplicateFeatureContext;
13345
13403
13346
- for ( const QgsFeature &f : featureList )
13404
+ QgsFeature newFeature = feature;
13405
+ newFeature.setGeometry ( digitizedFeature.geometry () );
13406
+ QgsVectorLayerUtils::duplicateFeature ( layer, newFeature, QgsProject::instance (), 0 , duplicateFeatureContext );
13407
+
13408
+ QString childrenInfo;
13409
+ for ( QgsVectorLayer *chl : duplicateFeatureContext.layers () )
13347
13410
{
13348
- //QgsVectorLayerUtils::duplicateFeature( layer, feature, QgsProject::instance(), 0 );
13411
+ childrenInfo += ( tr ( " %1 children on layer %2 duplicated " ). arg ( duplicateFeatureContext. duplicatedFeatures ( chl ). size () ). arg ( chl-> name () ) );
13349
13412
}
13350
- */
13413
+
13414
+ messageBar ()->pushMessage ( tr ( " Feature on layer %2 duplicated\n %3" ).arg ( layer->name () ).arg ( childrenInfo ), QgsMessageBar::SUCCESS, 5 );
13415
+ mMapCanvas ->unsetMapTool ( mMapTools .mDigitizeFeature );
13416
+ disconnect ( *connDigitizingFinished );
13417
+ }
13418
+ );
13419
+
13351
13420
return QgsFeature ();
13352
13421
}
13422
+
0 commit comments