Skip to content
Permalink
Browse files

Merge pull request #38521 from nyalldawson/fix_37551_gpx_layer_name

Fix filename prefix is no longer shown when adding layers from a GPX file to QGIS
  • Loading branch information
nyalldawson committed Sep 2, 2020
2 parents 682740f + 5432fb2 commit 76f856f2c21d33e995a2cb5e756d5c3bbfa40e37
Showing with 11 additions and 3 deletions.
  1. +11 −3 src/app/qgisapp.cpp
@@ -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(
@@ -6052,10 +6054,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;
@@ -6071,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 )

0 comments on commit 76f856f

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