Skip to content

Commit

Permalink
fix #5062 and apply rest of #5041
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 21, 2012
1 parent 7cea2f5 commit 927dcbd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/app/qgisapp.cpp
Expand Up @@ -2258,9 +2258,11 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )

if ( chooseSublayersDialog.exec() )
{
foreach( QString layer, chooseSublayersDialog.getSelection() )
foreach( QString path, chooseSublayersDialog.getSelection() )
{
QgsRasterLayer *rlayer = new QgsRasterLayer( layer, layer );
QString name = path;
name.replace( layer->source(), QFileInfo( layer->source() ).completeBaseName() );
QgsRasterLayer *rlayer = new QgsRasterLayer( path, name );
if ( rlayer && rlayer->isValid() )
{
addRasterLayer( rlayer );
Expand All @@ -2272,11 +2274,11 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
bool QgisApp::shouldAskUserForGDALSublayers( QgsRasterLayer *layer )
{
// return false if layer is empty or raster has no sublayers
if ( !layer || layer->subLayers().size() < 1 )
if ( !layer || layer->providerType() != "gdal" || layer->subLayers().size() < 1 )
return false;

QSettings settings;
int promptLayers = settings.value( "/qgis/promptForRasterSublayers", "if_need" ).toInt();
int promptLayers = settings.value( "/qgis/promptForRasterSublayers", 1 ).toInt();
// 0 = always -> always ask (if there are existing sublayers)
// 1 = if needed -> ask if layer has no bands, but has sublayers
// 2 = never
Expand Down
7 changes: 4 additions & 3 deletions src/app/qgsbrowserdockwidget.cpp
Expand Up @@ -126,10 +126,9 @@ void QgsBrowserDockWidget::itemClicked( const QModelIndex& index )
QString providerKey = layerItem->providerKey();

QgsDebugMsg( providerKey + " : " + uri );
QgsMapLayer* layer = NULL;
if ( type == QgsMapLayer::VectorLayer )
{
layer = QgisApp::instance()->addVectorLayer( uri, layerItem->name(), providerKey );
QgisApp::instance()->addVectorLayer( uri, layerItem->name(), providerKey );
}
if ( type == QgsMapLayer::RasterLayer )
{
Expand Down Expand Up @@ -159,7 +158,7 @@ void QgsBrowserDockWidget::itemClicked( const QModelIndex& index )
QgsDebugMsg( "rasterLayerPath = " + rasterLayerPath );
QgsDebugMsg( "layers = " + layers.join( " " ) );

layer = QgisApp::instance()->addRasterLayer( rasterLayerPath, layerItem->name(), providerKey, layers, styles, format, crs );
QgisApp::instance()->addRasterLayer( rasterLayerPath, layerItem->name(), providerKey, layers, styles, format, crs );
}
}

Expand Down Expand Up @@ -248,7 +247,9 @@ void QgsBrowserDockWidget::removeFavourite()

void QgsBrowserDockWidget::refresh()
{
QApplication::setOverrideCursor( Qt::WaitCursor );
refreshModel( QModelIndex() );
QApplication::restoreOverrideCursor();
}

void QgsBrowserDockWidget::refreshModel( const QModelIndex& index )
Expand Down
6 changes: 5 additions & 1 deletion src/providers/gdal/qgsgdaldataitems.cpp
Expand Up @@ -125,7 +125,11 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
{
GDALClose( hChildDS );
QgsDebugMsg( QString( "add child #%1 - %2" ).arg( i ).arg( sublayers[i] ) );
childItem = new QgsGdalLayerItem( item, sublayers[i], thePath + "/" + sublayers[i], sublayers[i] );

QString name = sublayers[i];
name.replace( thePath, QFileInfo( thePath ).completeBaseName() );

childItem = new QgsGdalLayerItem( item, name, thePath + "/" + name, sublayers[i] );
if ( childItem )
item->addChildItem( childItem );
}
Expand Down

0 comments on commit 927dcbd

Please sign in to comment.