Skip to content
Permalink
Browse files

Fix filename prefix is no longer shown when adding layers from a GPX …

…file to QGIS
  • Loading branch information
github-actions authored and nyalldawson committed Sep 2, 2020
1 parent 16acec7 commit defa16c1bda61d4132e2d3ab1e64e9ea8f322bfa
Showing with 11 additions and 3 deletions.
  1. +11 −3 src/app/qgisapp.cpp
@@ -6004,6 +6004,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(
@@ -6033,10 +6035,17 @@ QList<QgsMapLayer *> QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer, con
composedURI += "|geometrytype=" + layerGeometryType;
}

QgsDebugMsg( "Creating new vector layer using " + composedURI );
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, def.layerName, QStringLiteral( "ogr" ), options );
QgsVectorLayer *layer = new QgsVectorLayer( composedURI, name, QStringLiteral( "ogr" ), options );
if ( layer && layer->isValid() )
{
result << layer;
@@ -6052,7 +6061,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 )

0 comments on commit defa16c

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