Skip to content

Commit a2b80be

Browse files
etienneskyjef-n
authored andcommitted
fixes for browser (GDAL rasters) : skip *.aux.xml files ; add suffix to raster file names in browser ; add HDF4 file suffix (.hdf) in buildSupportedRasterFileFilterAndExtensions()
1 parent 3e0fb86 commit a2b80be

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/core/qgsdataitem.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ bool QgsDataItem::hasChildren()
194194

195195
void QgsDataItem::addChildItem( QgsDataItem * child, bool refresh )
196196
{
197-
QgsDebugMsg( "mName = " + child->mName );
197+
QgsDebugMsg( QString( "add child #%1 - %2" ).arg( mChildren.size() ).arg( child->mName ) );
198+
198199
int i;
199200
for ( i = 0; i < mChildren.size(); i++ )
200201
{

src/providers/gdal/qgsgdaldataitems.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
7979
QgsDebugMsg( "extensions: " + extensions.join( " " ) );
8080
QgsDebugMsg( "wildcards: " + wildcards.join( " " ) );
8181
}
82+
// skip *.aux.xml files (GDAL auxilary metadata files)
83+
// unless that extension is in the list (*.xml might be though)
84+
if ( thePath.right( 8 ) == ".aux.xml" &&
85+
extensions.indexOf( "aux.xml" ) < 0 )
86+
return 0;
87+
8288
if ( extensions.indexOf( info.suffix().toLower() ) < 0 )
8389
{
8490
bool matches = false;
@@ -107,7 +113,8 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
107113

108114
QgsDebugMsg( "GdalDataset opened " + thePath );
109115

110-
QString name = info.completeBaseName();
116+
//extract basename with extension
117+
QString name = info.completeBaseName() + "." + QFileInfo( thePath ).suffix();
111118
QString uri = thePath;
112119

113120
QgsLayerItem * item = new QgsGdalLayerItem( parentItem, name, thePath, uri );
@@ -124,11 +131,10 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
124131
if ( hChildDS )
125132
{
126133
GDALClose( hChildDS );
127-
QgsDebugMsg( QString( "add child #%1 - %2" ).arg( i ).arg( sublayers[i] ) );
128134

129135
QString name = sublayers[i];
130-
name.replace( thePath, QFileInfo( thePath ).completeBaseName() );
131-
136+
//replace full path with basename+extension
137+
name.replace( thePath, QFileInfo( thePath ).completeBaseName() + "." + QFileInfo( thePath ).suffix() );
132138
childItem = new QgsGdalLayerItem( item, name, thePath + "/" + name, sublayers[i] );
133139
if ( childItem )
134140
item->addChildItem( childItem );

src/providers/gdal/qgsgdalprovider.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,10 @@ QStringList QgsGdalProvider::subLayers( GDALDatasetH dataset )
12671267
}
12681268
}
12691269

1270-
QgsDebugMsg( "sublayers:\n " + subLayers.join( "\n " ) );
1270+
if ( subLayers.size() > 0 )
1271+
{
1272+
QgsDebugMsg( "sublayers:\n " + subLayers.join( "\n " ) );
1273+
}
12711274

12721275
return subLayers;
12731276
}
@@ -1801,6 +1804,13 @@ void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString
18011804
theFileFiltersString += ";;[GDAL] " + myGdalDriverLongName + " (" + glob.toLower() + " " + glob.toUpper() + ")";
18021805
theWildcards << "hdr.adf";
18031806
}
1807+
else if ( myGdalDriverDescription == "HDF4" )
1808+
{
1809+
// HDF4 extension missing in driver metadata
1810+
QString glob = "*.hdf";
1811+
theFileFiltersString += ";;[GDAL] " + myGdalDriverLongName + " (" + glob.toLower() + " " + glob.toUpper() + ")";
1812+
theExtensions << "hdf";
1813+
}
18041814
else
18051815
{
18061816
catchallFilter << QString( GDALGetDescription( myGdalDriver ) );

0 commit comments

Comments
 (0)