Skip to content

Commit

Permalink
Fixup messy code for layer duplication, and don't block duplication
Browse files Browse the repository at this point in the history
of mesh, vector tile, point cloud layers (all of which fully support it!)
  • Loading branch information
nyalldawson committed Dec 4, 2020
1 parent 14a7702 commit 6d769dd
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions src/app/qgisapp.cpp
Expand Up @@ -11772,37 +11772,37 @@ 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::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: " ),
Expand All @@ -11812,8 +11812,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: " ),
Expand Down Expand Up @@ -11863,7 +11862,6 @@ void QgisApp::duplicateLayers( const QList<QgsMapLayer *> &lyrList )

if ( !newSelection )
newSelection = dupLayer;

}

dupLayer = nullptr;
Expand Down

0 comments on commit 6d769dd

Please sign in to comment.