Index: src/app/qgisapp.h =================================================================== --- src/app/qgisapp.h (revision 13817) +++ src/app/qgisapp.h (working copy) @@ -753,10 +753,10 @@ void composerWillBeRemoved( QgsComposerView* v ); private: - /** This method will open a dialog so the user can select the sublayers - * to load + /** This method will open a dialog so the user can select the sublayers to load */ - void askUserForSublayers( QgsVectorLayer *layer ); + void askUserForOGRSublayers( QgsVectorLayer *layer ); + void askUserForGDALSublayers( QgsRasterLayer *layer ); /** Add a raster layer to the map (passed in as a ptr). * It won't force a refresh. */ Index: src/app/qgisapp.cpp =================================================================== --- src/app/qgisapp.cpp (revision 13817) +++ src/app/qgisapp.cpp (working copy) @@ -2620,7 +2620,7 @@ // sublayers selection dialog so the user can select the sublayers to actually load. if ( sublayers.count() > 1 ) { - askUserForSublayers( layer ); + askUserForOGRSublayers( layer ); // The first layer loaded is not useful in that case. The user can select it in // the list if he wants to load it. @@ -2673,18 +2673,49 @@ return true; } // QgisApp::addVectorLayer() +void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer ) +{ + if ( !layer ) + return; + + QStringList sublayers = layer->subLayers(); + + QgsDebugMsg( "sublayers:\n " + sublayers.join( " \n" ) + "\n" ); + + // We initialize a selection dialog and display it. + QgsOGRSublayersDialog chooseSublayersDialog( this ); + chooseSublayersDialog.setWindowTitle( tr( "Select raster layers to add..." ) ); + + QStringList layers; + for ( int i = 0; i < sublayers.size(); i++ ) + { + layers << QString( "%1|%2|1|%3" ).arg( i ).arg( sublayers[i] ).arg( tr( "Raster" ) ); + } + + chooseSublayersDialog.populateLayerTable( layers, "|" ); + + if ( chooseSublayersDialog.exec() ) + { + foreach( QString layer, chooseSublayersDialog.getSelection() ) + { + QgsRasterLayer *rlayer = new QgsRasterLayer( layer, layer ); + if ( rlayer && rlayer->isValid() ) + { + addRasterLayer( rlayer ); + } + } + } +} + // This method is the method that does the real job. If the layer given in // parameter is NULL, then the method tries to act on the activeLayer. -void QgisApp::askUserForSublayers( QgsVectorLayer *layer ) +void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer ) { if ( layer == NULL ) { - if ( activeLayer() == NULL || activeLayer()->type() != QgsMapLayer::VectorLayer ) + layer = qobject_cast( activeLayer() ); + if ( !layer || layer->dataProvider()->name() != "ogr" ) return; - - layer = ( QgsVectorLayer* ) activeLayer(); - if ( layer->dataProvider()->name() != "ogr" ) - return; } QStringList sublayers = layer->dataProvider()->subLayers(); @@ -2692,6 +2723,7 @@ // We initialize a selection dialog and display it. QgsOGRSublayersDialog chooseSublayersDialog( this ); + chooseSublayersDialog.setWindowTitle( tr( "Select vector layers to add..." ) ); chooseSublayersDialog.populateLayerTable( sublayers ); if ( chooseSublayersDialog.exec() ) @@ -6332,16 +6364,28 @@ // create the layer QgsRasterLayer *layer = new QgsRasterLayer( *myIterator, myBaseNameQString ); + QStringList sublayers = layer->subLayers(); - addRasterLayer( layer ); + if ( sublayers.size() > 0 ) + { + askUserForGDALSublayers( layer ); - //only allow one copy of a ai grid file to be loaded at a - //time to prevent the user selecting all adfs in 1 dir which - //actually represent 1 coverate, + // The first layer loaded is not useful in that case. The user can select it in + // the list if he wants to load it. + delete layer; + } + else + { + addRasterLayer( layer ); - if ( myBaseNameQString.toLower().endsWith( ".adf" ) ) - { - break; + //only allow one copy of a ai grid file to be loaded at a + //time to prevent the user selecting all adfs in 1 dir which + //actually represent 1 coverate, + + if ( myBaseNameQString.toLower().endsWith( ".adf" ) ) + { + break; + } } } else Index: src/app/ogr/qgsogrsublayersdialog.h =================================================================== --- src/app/ogr/qgsogrsublayersdialog.h (revision 13817) +++ src/app/ogr/qgsogrsublayersdialog.h (working copy) @@ -19,18 +19,19 @@ #include #include +#include "qgscontexthelp.h" - - class QgsOGRSublayersDialog : public QDialog, private Ui::QgsOGRSublayersDialogBase { Q_OBJECT public: QgsOGRSublayersDialog( QWidget* parent = 0, Qt::WFlags fl = 0 ); ~QgsOGRSublayersDialog(); - void populateLayerTable( QStringList theList ); + void populateLayerTable( QStringList theList, QString delim = ":" ); QStringList getSelection(); + public slots: + void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); } }; #endif Index: src/app/ogr/qgsogrsublayersdialog.cpp =================================================================== --- src/app/ogr/qgsogrsublayersdialog.cpp (revision 13817) +++ src/app/ogr/qgsogrsublayersdialog.cpp (working copy) @@ -42,14 +42,14 @@ return list; } -void QgsOGRSublayersDialog::populateLayerTable( QStringList theList ) +void QgsOGRSublayersDialog::populateLayerTable( QStringList theList, QString delim ) { for ( int i = 0; i < theList.size(); i++ ) { - QString ligne = theList.at( i ); - QStringList elements = ligne.split( ":" ); + QString line = theList.at( i ); + QStringList elements = line.split( delim ); QStringList item = QStringList(); item << elements.at( 0 ) << elements.at( 1 ) << elements.at( 2 ) << elements.at( 3 ); - layersTable -> addTopLevelItem( new QTreeWidgetItem( item ) ); + layersTable->addTopLevelItem( new QTreeWidgetItem( item ) ); } } Index: src/core/raster/qgsrasterlayer.cpp =================================================================== --- src/core/raster/qgsrasterlayer.cpp (revision 13817) +++ src/core/raster/qgsrasterlayer.cpp (working copy) @@ -444,10 +444,8 @@ /** * This helper checks to see whether the file name appears to be a valid raster file name */ -bool QgsRasterLayer::isValidRasterFileName( QString const & theFileNameQString, - QString & retErrMsg ) +bool QgsRasterLayer::isValidRasterFileName( QString const & theFileNameQString, QString & retErrMsg ) { - GDALDatasetH myDataset; registerGdalDrivers(); @@ -463,10 +461,15 @@ } else if ( GDALGetRasterCount( myDataset ) == 0 ) { - GDALClose( myDataset ); - myDataset = NULL; - retErrMsg = "This raster file has no bands and is invalid as a raster layer."; - return false; + QStringList layers = subLayers( myDataset ); + if ( layers.size() == 0 ) + { + GDALClose( myDataset ); + myDataset = NULL; + retErrMsg = tr( "This raster file has no bands and is invalid as a raster layer." ); + return false; + } + return true; } else { @@ -476,10 +479,8 @@ } bool QgsRasterLayer::isValidRasterFileName( QString const & theFileNameQString ) - { QString retErrMsg; - return isValidRasterFileName( theFileNameQString, retErrMsg ); } @@ -2610,7 +2611,7 @@ } else { - QgsDebugMsg( "band " + QString::number( i ) + "has no metadata" ); + QgsDebugMsg( "band " + QString::number( i ) + " has no metadata" ); } char ** GDALcategories = GDALGetRasterCategoryNames( gdalBand ); @@ -3565,18 +3566,40 @@ emit statusChanged( theMessage ); } +QStringList QgsRasterLayer::subLayers( GDALDatasetH dataset ) +{ + QStringList subLayers; + + char **metadata = GDALGetMetadata( dataset, "SUBDATASETS" ); + if ( metadata ) + { + for ( int i = 0; metadata[i] != NULL; i++ ) + { + QString layer = QString::fromUtf8( metadata[i] ); + + int pos = layer.indexOf( "_NAME=" ); + if ( pos >= 0 ) + { + subLayers << layer.mid( pos + 6 ); + } + } + } + + QgsDebugMsg( "sublayers:\n " + subLayers.join( "\n " ) ); + + return subLayers; +} + QStringList QgsRasterLayer::subLayers() const { - if ( mDataProvider ) { return mDataProvider->subLayers(); } else { - return QStringList(); // Empty + return subLayers( mGdalDataset ); } - } void QgsRasterLayer::thumbnailAsPixmap( QPixmap * theQPixmap ) @@ -5219,6 +5242,13 @@ GDALReferenceDataset( mGdalDataset ); } + if ( subLayers().size() > 0 ) + { + // just to get the sublayers + mValid = false; + return true; + } + //check f this file has pyramids GDALRasterBandH myGDALBand = GDALGetRasterBand( mGdalDataset, 1 ); //just use the first band if ( myGDALBand == NULL ) @@ -5231,15 +5261,9 @@ mValid = false; return false; } - if ( GDALGetOverviewCount( myGDALBand ) > 0 ) - { - mHasPyramids = true; - } - else - { - mHasPyramids = false; - } + mHasPyramids = GDALGetOverviewCount( myGDALBand ) > 0; + //populate the list of what pyramids exist buildPyramidList(); Index: src/core/raster/qgsrasterlayer.h =================================================================== --- src/core/raster/qgsrasterlayer.h (revision 13817) +++ src/core/raster/qgsrasterlayer.h (working copy) @@ -284,9 +284,10 @@ * returned in retError. */ static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError ); - static bool isValidRasterFileName( const QString & theFileNameQString ); + static QStringList subLayers( GDALDatasetH dataset ); + /** Return time stamp for given file name */ static QDateTime lastModified( const QString & name ); Index: src/ui/qgsogrsublayersdialogbase.ui =================================================================== --- src/ui/qgsogrsublayersdialogbase.ui (revision 13817) +++ src/ui/qgsogrsublayersdialogbase.ui (working copy) @@ -1,103 +1,45 @@ - + + QgsOGRSublayersDialogBase - - + + 0 0 584 - 535 + 236 - - Select OGR layers to load + + Select layers to load - - ../../../qgis_1.0.0/src/plugins/ogrsublayers - - - + + 9 - - 9 - - - 9 - - - 9 - - + 6 - - 6 - - - - - - 0 - 0 - - - - - Sans Serif - 24 - 75 - false - true - false - false - - - - Sub layers list - - - Qt::AlignCenter - - - - - - + + + Qt::Horizontal - - QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok - - - - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif';">This is the list of all layers available in the datasource of the active layer. You can select the layers to load. The layers will be loaded when you press "OK".</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif';"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif';">The layer name is format dependent. Consult the OGR documentation or the documentation of your data format to determine the nature of the included information.</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif';"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif';"><span style=" font-weight:600;">Be advised: </span>selecting an already opened layer will not generate an error message and the layer will end up loaded twice!</p></body></html> - - - - - - - Qt::NonModal - - + + + QAbstractItemView::ExtendedSelection - + QAbstractItemView::SelectRows - + 1 @@ -105,7 +47,7 @@ - + @@ -114,11 +56,11 @@ QgsOGRSublayersDialogBase accept() - + 446 508 - + 351 473 @@ -130,11 +72,11 @@ QgsOGRSublayersDialogBase reject() - + 541 507 - + 503 434