@@ -5362,12 +5362,20 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )
5362
5362
}
5363
5363
5364
5364
mMapCanvas ->freeze ();
5365
+ // int startCount = QgsMapLayerRegistry::instance()->count();
5365
5366
QgsMapLayer *dupLayer;
5367
+
5366
5368
foreach ( QgsMapLayer * selectedLyr, selectedLyrs )
5367
5369
{
5368
5370
dupLayer = 0 ;
5369
5371
QString layerDupName = selectedLyr->name () + " " + tr ( " copy" );
5370
5372
5373
+ // setup for placing duplicated layer below source layer, regardless of group depth
5374
+ mMapLegend ->blockSignals ( true );
5375
+ mMapLegend ->setCurrentLayer ( selectedLyr );
5376
+ mMapLegend ->blockSignals ( false );
5377
+ QTreeWidgetItem *sourceItem = mMapLegend ->currentItem ();
5378
+
5371
5379
// duplicate the layer's basic parameters
5372
5380
5373
5381
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer*>( selectedLyr );
@@ -5389,6 +5397,7 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )
5389
5397
5390
5398
if ( dupLayer && !dupLayer->isValid () )
5391
5399
{
5400
+ // addMapLayer() also checks layer validity, but do it now to skip canvas refresh
5392
5401
QgsDebugMsg ( " Duplicated layer was invalid" );
5393
5402
continue ;
5394
5403
}
@@ -5402,16 +5411,37 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )
5402
5411
}
5403
5412
5404
5413
// add layer to project and layer registry
5405
- addMapLayer ( dupLayer );
5414
+ QList<QgsMapLayer *> myList;
5415
+ myList << dupLayer;
5416
+ QgsMapLayerRegistry::instance ()->addMapLayers ( myList );
5406
5417
5407
5418
// duplicate the layer style
5408
5419
copyStyle ( selectedLyr );
5409
5420
pasteStyle ( dupLayer );
5421
+
5422
+ // move layer to just below source layer
5423
+ QTreeWidgetItem *dupItem = mMapLegend ->currentItem ();
5424
+ mMapLegend ->moveItem ( dupItem, sourceItem );
5425
+
5426
+ // always set duplicated layers to not visible
5427
+ // so layer can be configured before being turned on,
5428
+ // and no map canvas refresh needed when doing multiple duplications
5429
+ mMapLegend ->setLayerVisible ( dupLayer, false );
5430
+ // OR, set visible property from source layer? (will require canvas refresh)
5431
+ // mMapLegend->setLayerVisible( dupLayer, mMapLegend->layerCheckState( selectedLyr ) == Qt::Checked );
5410
5432
}
5411
5433
5412
5434
dupLayer = 0 ;
5435
+
5436
+ // update UI
5437
+ qApp->processEvents ();
5438
+
5413
5439
mMapCanvas ->freeze ( false );
5414
- mMapCanvas ->refresh ();
5440
+ // if ( QgsMapLayerRegistry::instance()->count() > startCount )
5441
+ // {
5442
+ // statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) );
5443
+ // mMapCanvas->refresh();
5444
+ // }
5415
5445
}
5416
5446
5417
5447
void QgisApp::setLayerCRS ()
0 commit comments