Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revise logic relating to automatic file name prefix inclusion when
adding vector sub layers

If user has opted to add sublayers to a group, then we don't need
to include the filename in the layer's name, because the group is
already titled with the filename.
But otherwise, we DO include the file name so that users can
differentiate the source when multiple layers are loaded from a GPX
file or similar (refs #37551)
  • Loading branch information
nyalldawson committed Sep 2, 2020
1 parent 43ee924 commit 5432fb2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -6023,6 +6023,8 @@ QList<QgsMapLayer *> QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer, con
if ( !chooseSublayersDialog.exec() )
return result;

const bool addToGroup = chooseSublayersDialog.addToGroupCheckbox();

QString name = layer->name();

auto uriParts = QgsProviderRegistry::instance()->decodeUri(
Expand Down Expand Up @@ -6052,8 +6054,14 @@ QList<QgsMapLayer *> QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer, con
composedURI += "|geometrytype=" + layerGeometryType;
}

QgsDebugMsg( "Creating new vector layer using " + composedURI );
QString name = fileName + " " + def.layerName;
QgsDebugMsgLevel( "Creating new vector layer using " + composedURI, 2 );

// if user has opted to add sublayers to a group, then we don't need to include the
// filename in the layer's name, because the group is already titled with the filename.
// But otherwise, we DO include the file name so that users can differentiate the source
// when multiple layers are loaded from a GPX file or similar (refs https://github.com/qgis/QGIS/issues/37551)
const QString name = addToGroup ? def.layerName : fileName + " " + def.layerName;

QgsVectorLayer::LayerOptions options { QgsProject::instance()->transformContext() };
options.loadDefaultStyle = false;
QgsVectorLayer *layer = new QgsVectorLayer( composedURI, name, QStringLiteral( "ogr" ), options );
Expand All @@ -6072,7 +6080,6 @@ QList<QgsMapLayer *> QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer, con
if ( !result.isEmpty() )
{
QgsSettings settings;
bool addToGroup = settings.value( QStringLiteral( "/qgis/openSublayersInGroup" ), true ).toBool();
bool newLayersVisible = settings.value( QStringLiteral( "/qgis/new_layers_visible" ), true ).toBool();
QgsLayerTreeGroup *group = nullptr;
if ( addToGroup )
Expand Down

0 comments on commit 5432fb2

Please sign in to comment.