@@ -961,6 +961,7 @@ void QgisApp::createActions()
961
961
connect ( mActionLayerSaveAs , SIGNAL ( triggered () ), this , SLOT ( saveAsFile () ) );
962
962
connect ( mActionLayerSelectionSaveAs , SIGNAL ( triggered () ), this , SLOT ( saveSelectionAsVectorFile () ) );
963
963
connect ( mActionRemoveLayer , SIGNAL ( triggered () ), this , SLOT ( removeLayer () ) );
964
+ connect ( mActionDuplicateLayer , SIGNAL ( triggered () ), this , SLOT ( duplicateLayers () ) );
964
965
connect ( mActionSetLayerCRS , SIGNAL ( triggered () ), this , SLOT ( setLayerCRS () ) );
965
966
connect ( mActionSetProjectCRSFromLayer , SIGNAL ( triggered () ), this , SLOT ( setProjectCRSFromLayer () ) );
966
967
connect ( mActionLayerProperties , SIGNAL ( triggered () ), this , SLOT ( layerProperties () ) );
@@ -1630,6 +1631,7 @@ void QgisApp::setTheme( QString theThemeName )
1630
1631
mActionAddMssqlLayer ->setIcon ( QgsApplication::getThemeIcon ( " /mActionAddMssqlLayer.png" ) );
1631
1632
#endif
1632
1633
mActionRemoveLayer ->setIcon ( QgsApplication::getThemeIcon ( " /mActionRemoveLayer.png" ) );
1634
+ mActionDuplicateLayer ->setIcon ( QgsApplication::getThemeIcon ( " /mActionAddMap.png" ) );
1633
1635
mActionSetLayerCRS ->setIcon ( QgsApplication::getThemeIcon ( " /mActionSetLayerCRS.png" ) );
1634
1636
mActionSetProjectCRSFromLayer ->setIcon ( QgsApplication::getThemeIcon ( " /mActionSetProjectCRSFromLayer.png" ) );
1635
1637
mActionNewVectorLayer ->setIcon ( QgsApplication::getThemeIcon ( " /mActionNewVectorLayer.png" ) );
@@ -5341,6 +5343,77 @@ void QgisApp::removeLayer()
5341
5343
mMapCanvas ->refresh ();
5342
5344
}
5343
5345
5346
+ void QgisApp::duplicateLayers ( QList<QgsMapLayer *> lyrList )
5347
+ {
5348
+ if ( mMapCanvas && mMapCanvas ->isDrawing () )
5349
+ {
5350
+ return ;
5351
+ }
5352
+
5353
+ if ( !mMapLegend )
5354
+ {
5355
+ return ;
5356
+ }
5357
+
5358
+ QList<QgsMapLayer *> selectedLyrs = lyrList.empty () ? mMapLegend ->selectedLayers () : lyrList;
5359
+ if ( selectedLyrs.empty () )
5360
+ {
5361
+ return ;
5362
+ }
5363
+
5364
+ mMapCanvas ->freeze ();
5365
+ QgsMapLayer *dupLayer;
5366
+ foreach ( QgsMapLayer * selectedLyr, selectedLyrs )
5367
+ {
5368
+ dupLayer = 0 ;
5369
+ QString layerDupName = selectedLyr->name () + " " + tr ( " copy" );
5370
+
5371
+ // duplicate the layer's basic parameters
5372
+
5373
+ QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer*>( selectedLyr );
5374
+ // TODO: check for other layer types that won't duplicate correctly
5375
+ // currently memory and plugin layers are skipped
5376
+ if ( vlayer && vlayer->storageType () != " Memory storage" )
5377
+ {
5378
+ dupLayer = new QgsVectorLayer ( vlayer->source (), layerDupName, vlayer->providerType () );
5379
+ }
5380
+
5381
+ if ( !dupLayer )
5382
+ {
5383
+ QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer*>( selectedLyr );
5384
+ if ( rlayer )
5385
+ {
5386
+ dupLayer = new QgsRasterLayer ( rlayer->source (), layerDupName );
5387
+ }
5388
+ }
5389
+
5390
+ if ( dupLayer && !dupLayer->isValid () )
5391
+ {
5392
+ QgsDebugMsg ( " Duplicated layer was invalid" );
5393
+ continue ;
5394
+ }
5395
+
5396
+ if ( !dupLayer )
5397
+ {
5398
+ QMessageBox::information ( this ,
5399
+ tr ( " Unsupported Layer" ),
5400
+ tr ( " %1\n\n Duplication of layer type is unsupported." ).arg ( selectedLyr->name () ) );
5401
+ continue ;
5402
+ }
5403
+
5404
+ // add layer to project and layer registry
5405
+ addMapLayer ( dupLayer );
5406
+
5407
+ // duplicate the layer style
5408
+ copyStyle ( selectedLyr );
5409
+ pasteStyle ( dupLayer );
5410
+ }
5411
+
5412
+ dupLayer = 0 ;
5413
+ mMapCanvas ->freeze ( false );
5414
+ mMapCanvas ->refresh ();
5415
+ }
5416
+
5344
5417
void QgisApp::setLayerCRS ()
5345
5418
{
5346
5419
if ( mMapCanvas && mMapCanvas ->isDrawing () )
@@ -6833,6 +6906,7 @@ void QgisApp::selectionChanged( QgsMapLayer *layer )
6833
6906
void QgisApp::legendLayerSelectionChanged ( void )
6834
6907
{
6835
6908
mActionRemoveLayer ->setEnabled ( mMapLegend && mMapLegend ->selectedLayers ().size () > 0 );
6909
+ mActionDuplicateLayer ->setEnabled ( mMapLegend && mMapLegend ->selectedLayers ().size () > 0 );
6836
6910
mActionSetLayerCRS ->setEnabled ( mMapLegend && mMapLegend ->selectedLayers ().size () > 0 );
6837
6911
mActionSetProjectCRSFromLayer ->setEnabled ( mMapLegend && mMapLegend ->selectedLayers ().size () == 1 );
6838
6912
}
0 commit comments