@@ -5363,31 +5363,49 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )
53635363 }
53645364
53655365 mMapCanvas ->freeze ();
5366- // int startCount = QgsMapLayerRegistry::instance()->count();
53675366 QgsMapLayer *dupLayer;
5367+ QString layerDupName, unSppType;
53685368
53695369 foreach ( QgsMapLayer * selectedLyr, selectedLyrs )
53705370 {
53715371 dupLayer = 0 ;
5372- QString layerDupName = selectedLyr->name () + " " + tr ( " copy" );
5372+ unSppType = QString ( " " );
5373+ layerDupName = selectedLyr->name () + " " + tr ( " copy" );
53735374
53745375 // setup for placing duplicated layer below source layer, regardless of group depth
53755376 mMapLegend ->blockSignals ( true );
5376- mMapLegend ->setCurrentLayer ( selectedLyr );
5377+ if ( !mMapLegend ->setCurrentLayer ( selectedLyr ) )
5378+ {
5379+ mMapLegend ->blockSignals ( false );
5380+ continue ; // legend item doesn't exist for map layer
5381+ }
53775382 mMapLegend ->blockSignals ( false );
5378- QTreeWidgetItem *sourceItem = mMapLegend ->currentItem ();
5383+ QgsLegendLayer *sourcellayer = mMapLegend ->currentLegendLayer ();
5384+
5385+ if ( selectedLyr->type () == QgsMapLayer::PluginLayer )
5386+ {
5387+ unSppType = tr ( " Plugin layer" );
5388+ }
53795389
53805390 // duplicate the layer's basic parameters
53815391
5382- QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer*>( selectedLyr );
5383- // TODO: check for other layer types that won't duplicate correctly
5384- // currently memory and plugin layers are skipped
5385- if ( vlayer && vlayer->storageType () != " Memory storage" )
5392+ if ( unSppType.isEmpty () )
53865393 {
5387- dupLayer = new QgsVectorLayer ( vlayer->source (), layerDupName, vlayer->providerType () );
5394+ QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer*>( selectedLyr );
5395+ // TODO: check for other layer types that won't duplicate correctly
5396+ // currently memory and plugin layers are skipped
5397+ if ( vlayer && vlayer->storageType () == " Memory storage" )
5398+ {
5399+ unSppType = tr ( " Memory layer" );
5400+ }
5401+ else if ( vlayer )
5402+ {
5403+ dupLayer = new QgsVectorLayer ( vlayer->source (), layerDupName, vlayer->providerType () );
5404+ }
53885405 }
53895406
5390- if ( !dupLayer )
5407+
5408+ if ( unSppType.isEmpty () && !dupLayer )
53915409 {
53925410 QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer*>( selectedLyr );
53935411 if ( rlayer )
@@ -5396,18 +5414,21 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )
53965414 }
53975415 }
53985416
5399- if ( dupLayer && !dupLayer->isValid () )
5417+ if ( unSppType. isEmpty () && dupLayer && !dupLayer->isValid () )
54005418 {
5401- // addMapLayer() also checks layer validity, but do it now to skip canvas refresh
5402- QgsDebugMsg ( " Duplicated layer was invalid" );
5419+ QMessageBox::information ( this ,
5420+ tr ( " Invalid Layer" ),
5421+ tr ( " %1\n\n Duplication resulted in invalid layer." ).arg ( selectedLyr->name () ) );
54035422 continue ;
54045423 }
54055424
5406- if ( !dupLayer )
5425+ if ( !unSppType. isEmpty () || ! dupLayer )
54075426 {
54085427 QMessageBox::information ( this ,
54095428 tr ( " Unsupported Layer" ),
5410- tr ( " %1\n\n Duplication of layer type is unsupported." ).arg ( selectedLyr->name () ) );
5429+ tr ( " %1\n %2\n\n Duplication of layer type is unsupported." )
5430+ .arg ( selectedLyr->name () )
5431+ .arg ( !unSppType.isEmpty () ? QString ( " (" ) + unSppType + QString ( " )" ) : " " ) );
54115432 continue ;
54125433 }
54135434
@@ -5421,15 +5442,13 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )
54215442 pasteStyle ( dupLayer );
54225443
54235444 // move layer to just below source layer
5424- QTreeWidgetItem *dupItem = mMapLegend ->currentItem ();
5425- mMapLegend ->moveItem ( dupItem, sourceItem );
5445+ QgsLegendLayer *dupllayer = mMapLegend ->currentLegendLayer ();
5446+ mMapLegend ->moveItem ( dupllayer, sourcellayer );
54265447
54275448 // always set duplicated layers to not visible
54285449 // so layer can be configured before being turned on,
54295450 // and no map canvas refresh needed when doing multiple duplications
54305451 mMapLegend ->setLayerVisible ( dupLayer, false );
5431- // OR, set visible property from source layer? (will require canvas refresh)
5432- // mMapLegend->setLayerVisible( dupLayer, mMapLegend->layerCheckState( selectedLyr ) == Qt::Checked );
54335452 }
54345453
54355454 dupLayer = 0 ;
@@ -5438,11 +5457,6 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )
54385457 qApp->processEvents ();
54395458
54405459 mMapCanvas ->freeze ( false );
5441- // if ( QgsMapLayerRegistry::instance()->count() > startCount )
5442- // {
5443- // statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) );
5444- // mMapCanvas->refresh();
5445- // }
54465460}
54475461
54485462void QgisApp::setLayerCRS ()
0 commit comments