From 6d769dd10f593d080242ad9a7e1e456a542ddd78 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 4 Dec 2020 10:09:53 +1000 Subject: [PATCH] Fixup messy code for layer duplication, and don't block duplication of mesh, vector tile, point cloud layers (all of which fully support it!) --- src/app/qgisapp.cpp | 46 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 715c5da22d39..4cb144a198f6 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -11772,37 +11772,37 @@ void QgisApp::duplicateLayers( const QList &lyrList ) unSppType.clear(); layerDupName = selectedLyr->name() + ' ' + tr( "copy" ); - if ( selectedLyr->type() == QgsMapLayerType::PluginLayer ) + switch ( selectedLyr->type() ) { - unSppType = tr( "Plugin layer" ); - } - - // duplicate the layer's basic parameters + case QgsMapLayerType::PluginLayer: + unSppType = tr( "Plugin layer" ); + break; - if ( unSppType.isEmpty() ) - { - QgsVectorLayer *vlayer = qobject_cast( selectedLyr ); - // TODO: add other layer types that can be duplicated - // currently memory and plugin layers are skipped - if ( vlayer ) + case QgsMapLayerType::VectorLayer: { - if ( vlayer->auxiliaryLayer() ) - vlayer->auxiliaryLayer()->save(); + if ( QgsVectorLayer *vlayer = qobject_cast( selectedLyr ) ) + { + if ( vlayer->auxiliaryLayer() ) + vlayer->auxiliaryLayer()->save(); - dupLayer = vlayer->clone(); + dupLayer = vlayer->clone(); + } + break; } - } - if ( unSppType.isEmpty() && !dupLayer ) - { - QgsRasterLayer *rlayer = qobject_cast( selectedLyr ); - if ( rlayer ) + case QgsMapLayerType::PointCloudLayer: + case QgsMapLayerType::RasterLayer: + case QgsMapLayerType::VectorTileLayer: + case QgsMapLayerType::MeshLayer: + case QgsMapLayerType::AnnotationLayer: { - dupLayer = rlayer->clone(); + dupLayer = selectedLyr->clone(); + break; } + } - if ( unSppType.isEmpty() && dupLayer && !dupLayer->isValid() ) + if ( dupLayer && !dupLayer->isValid() ) { msgBars.append( new QgsMessageBarItem( tr( "Duplicate layer: " ), @@ -11812,8 +11812,7 @@ void QgisApp::duplicateLayers( const QList &lyrList ) mInfoBar ) ); continue; } - - if ( !unSppType.isEmpty() || !dupLayer ) + else if ( !unSppType.isEmpty() || !dupLayer ) { msgBars.append( new QgsMessageBarItem( tr( "Duplicate layer: " ), @@ -11863,7 +11862,6 @@ void QgisApp::duplicateLayers( const QList &lyrList ) if ( !newSelection ) newSelection = dupLayer; - } dupLayer = nullptr;