Skip to content
Permalink
Browse files

Fixup messy code for layer duplication, and don't block duplication

of mesh, vector tile, point cloud layers (all of which fully support it!)

(cherry picked from commit 682b5f7)
  • Loading branch information
nyalldawson committed Dec 21, 2020
1 parent 5577ae5 commit d8fe6b33e08b4d475b3b4b1c4293ec0e46fae3d9
Showing with 21 additions and 24 deletions.
  1. +21 −24 src/app/qgisapp.cpp
@@ -11627,37 +11627,36 @@ void QgisApp::duplicateLayers( const QList<QgsMapLayer *> &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<QgsVectorLayer *>( 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<QgsVectorLayer *>( selectedLyr ) )
{
if ( vlayer->auxiliaryLayer() )
vlayer->auxiliaryLayer()->save();

dupLayer = vlayer->clone();
dupLayer = vlayer->clone();
}
break;
}
}

if ( unSppType.isEmpty() && !dupLayer )
{
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( selectedLyr );
if ( rlayer )
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: " ),
@@ -11667,8 +11666,7 @@ void QgisApp::duplicateLayers( const QList<QgsMapLayer *> &lyrList )
mInfoBar ) );
continue;
}

if ( !unSppType.isEmpty() || !dupLayer )
else if ( !unSppType.isEmpty() || !dupLayer )
{
msgBars.append( new QgsMessageBarItem(
tr( "Duplicate layer: " ),
@@ -11718,7 +11716,6 @@ void QgisApp::duplicateLayers( const QList<QgsMapLayer *> &lyrList )

if ( !newSelection )
newSelection = dupLayer;

}

dupLayer = nullptr;

0 comments on commit d8fe6b3

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