Skip to content
Permalink
Browse files

more informative layer name when loading OGR datasource with only one…

… sublayer (followup f99ccf0)

Also use more informative raster layer names when loading raster with sublayers
  • Loading branch information
alexbruy committed Jan 6, 2016
1 parent b2cc309 commit 77a0b88a6f6e2c5326b87172350e92db4543183e
Showing with 19 additions and 10 deletions.
  1. +19 −10 src/app/qgisapp.cpp
@@ -3247,16 +3247,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
@@ -3476,9 +3470,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 77a0b88

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