Skip to content
Permalink
Browse files

Merge pull request #2643 from alexbruy/sublayers

More informative layer names when loading GDAL/OGR sublayers
  • Loading branch information
alexbruy committed Jan 20, 2016
2 parents 9fda6aa + 77a0b88 commit 1c3f066edf7f148268220ad1b66a505242a641bf
Showing with 19 additions and 10 deletions.
  1. +19 −10 src/app/qgisapp.cpp
@@ -3257,16 +3257,10 @@ bool QgisApp::addVectorLayers( const QStringList &theLayerQStringList, const QSt
//set friendly name for datasources with only one layer
QStringList sublayers = layer->dataProvider()->subLayers();
QStringList elements = sublayers.at( 0 ).split( ':' );
if ( layer->storageType() != "GeoJSON" )
{
while ( elements.size() > 4 )
{
elements[1] += ':' + elements[2];
elements.removeAt( 2 );
}

layer->setLayerName( elements.at( 1 ) );
}
Q_ASSERT( elements.size() >= 4 );
layer->setLayerName( QString( "%1 %2 %3" ).arg( layer->name(), elements.at( 1 ), elements.at( 3 ) ) );

myList << layer;
}
else
@@ -3486,9 +3480,24 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )

if ( chooseSublayersDialog.exec() )
{
// create more informative layer names, containing filename as well as sublayer name
QRegExp rx( "\"(.*)\"" );
QString uri, name;

Q_FOREACH ( int i, chooseSublayersDialog.selectionIndexes() )
{
QgsRasterLayer *rlayer = new QgsRasterLayer( sublayers[i], names[i] );
if ( rx.indexIn( sublayers[i] ) != -1 )
{
uri = rx.cap( 1 );
name = sublayers[i];
name.replace( uri, QFileInfo( uri ).completeBaseName() );
}
else
{
name = names[i];
}

QgsRasterLayer *rlayer = new QgsRasterLayer( sublayers[i], name );
if ( rlayer && rlayer->isValid() )
{
addRasterLayer( rlayer );

0 comments on commit 1c3f066

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