Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 76f856f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 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,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;
Expand All @@ -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 )
Expand Down

0 comments on commit 76f856f

Please sign in to comment.