Skip to content
Permalink
Browse files

Use QgsProviderRegistry::decodeUri to obtain the layer name

  • Loading branch information
borysiasty committed Sep 14, 2018
1 parent b08ad82 commit daf7f3e3b9749cf1f2ea2275e091f24ccccee020
Showing with 5 additions and 5 deletions.
  1. +5 −5 src/app/qgisapp.cpp
@@ -12820,17 +12820,17 @@ bool QgisApp::addRasterLayers( QStringList const &fileNameQStringList, bool guiW
{
QFileInfo myFileInfo( *myIterator );

// try to create the layer
// set the layer name to the file base name...
QString layerName = myFileInfo.completeBaseName();

// ...unless the layer uri matches "GPKG:filePath:layerName" and layerName differs from the file base name
const QStringList layerUriSegments = myIterator->split( QLatin1String( ":" ) );
if ( layerUriSegments.count() == 3 && layerUriSegments[ 0 ] == QLatin1String( "GPKG" ) && layerUriSegments[ 2 ] != layerName )
// ...unless provided explicitly
const QVariantMap uriDetails = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "gdal" ), *myIterator );
if ( !uriDetails[ QStringLiteral( "layerName" ) ].toString().isEmpty() )
{
layerName = QStringLiteral( "%1 %2" ).arg( layerName, layerUriSegments[ 2 ] );
layerName = uriDetails[ QStringLiteral( "layerName" ) ].toString();
}

// try to create the layer
QgsRasterLayer *layer = addRasterLayerPrivate( *myIterator, layerName,
QString(), guiWarning, true );
if ( layer && layer->isValid() )

0 comments on commit daf7f3e

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