Skip to content
Permalink
Browse files

Update to duplicate layer(s)

- Duplicate layer always created below source layer, and at same nested group depth
- Duplicate layer is always set to not visible (much faster, canvas refresh not needed when duplicating many layers)
  • Loading branch information
dakcarto committed Nov 2, 2012
1 parent 9df95b1 commit 00b1958dc1987f6356a2941dda6786888cae9d42
Showing with 32 additions and 2 deletions.
  1. +32 −2 src/app/qgisapp.cpp
@@ -5362,12 +5362,20 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )
}

mMapCanvas->freeze();
// int startCount = QgsMapLayerRegistry::instance()->count();
QgsMapLayer *dupLayer;

foreach ( QgsMapLayer * selectedLyr, selectedLyrs )
{
dupLayer = 0;
QString layerDupName = selectedLyr->name() + " " + tr( "copy" );

// setup for placing duplicated layer below source layer, regardless of group depth
mMapLegend->blockSignals( true );
mMapLegend->setCurrentLayer( selectedLyr );
mMapLegend->blockSignals( false );
QTreeWidgetItem *sourceItem = mMapLegend->currentItem();

// duplicate the layer's basic parameters

QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer*>( selectedLyr );
@@ -5389,6 +5397,7 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )

if ( dupLayer && !dupLayer->isValid() )
{
// addMapLayer() also checks layer validity, but do it now to skip canvas refresh
QgsDebugMsg( "Duplicated layer was invalid" );
continue;
}
@@ -5402,16 +5411,37 @@ void QgisApp::duplicateLayers( QList<QgsMapLayer *> lyrList )
}

// add layer to project and layer registry
addMapLayer( dupLayer );
QList<QgsMapLayer *> myList;
myList << dupLayer;
QgsMapLayerRegistry::instance()->addMapLayers( myList );

// duplicate the layer style
copyStyle( selectedLyr );
pasteStyle( dupLayer );

// move layer to just below source layer
QTreeWidgetItem *dupItem = mMapLegend->currentItem();
mMapLegend->moveItem( dupItem, sourceItem );

// always set duplicated layers to not visible
// so layer can be configured before being turned on,
// and no map canvas refresh needed when doing multiple duplications
mMapLegend->setLayerVisible( dupLayer, false );
// OR, set visible property from source layer? (will require canvas refresh)
//mMapLegend->setLayerVisible( dupLayer, mMapLegend->layerCheckState( selectedLyr ) == Qt::Checked );
}

dupLayer = 0;

// update UI
qApp->processEvents();

mMapCanvas->freeze( false );
mMapCanvas->refresh();
// if ( QgsMapLayerRegistry::instance()->count() > startCount )
// {
// statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) );
// mMapCanvas->refresh();
// }
}

void QgisApp::setLayerCRS()

0 comments on commit 00b1958

Please sign in to comment.
You can’t perform that action at this time.