@@ -1922,14 +1922,6 @@ void buildSupportedRasterFileFilterAndExtensions( QString &fileFiltersString, QS
1922
1922
1923
1923
GDALDriverH myGdalDriver; // current driver
1924
1924
1925
- char **myGdalDriverMetadata; // driver metadata strings
1926
-
1927
- QString myGdalDriverLongName ( QLatin1String ( " " ) ); // long name for the given driver
1928
- QString myGdalDriverExtension ( QLatin1String ( " " ) ); // file name extension for given driver
1929
- QString myGdalDriverDescription; // QString wrapper of GDAL driver description
1930
-
1931
- QStringList metadataTokens; // essentially the metadata string delimited by '='
1932
-
1933
1925
QStringList catchallFilter; // for Any file(*.*), but also for those
1934
1926
// drivers with no specific file filter
1935
1927
@@ -1943,10 +1935,6 @@ void buildSupportedRasterFileFilterAndExtensions( QString &fileFiltersString, QS
1943
1935
// theoreticaly we can open those files because there exists a
1944
1936
// driver for them, the user will have to use the "All Files" to
1945
1937
// open datasets with no explicitly defined file name extension.
1946
- // Note that file name extension strings are of the form
1947
- // "DMD_EXTENSION=.*". We'll also store the long name of the
1948
- // driver, which will be found in DMD_LONGNAME, which will have the
1949
- // same form.
1950
1938
1951
1939
fileFiltersString.clear ();
1952
1940
@@ -1965,100 +1953,75 @@ void buildSupportedRasterFileFilterAndExtensions( QString &fileFiltersString, QS
1965
1953
}
1966
1954
1967
1955
// in GDAL 2.0 vector and mixed drivers are returned by GDALGetDriver, so filter out non-raster drivers
1968
- // TODO also make sure drivers are not loaded unnecessarily (as GDALAllRegister() and OGRRegisterAll load all drivers)
1969
1956
if ( QString ( GDALGetMetadataItem ( myGdalDriver, GDAL_DCAP_RASTER, nullptr ) ) != QLatin1String ( " YES" ) )
1970
1957
continue ;
1971
1958
1972
1959
// now we need to see if the driver is for something currently
1973
1960
// supported; if not, we give it a miss for the next driver
1974
1961
1975
- myGdalDriverDescription = GDALGetDescription ( myGdalDriver );
1976
- // QgsDebugMsg(QString("got driver string %1").arg(myGdalDriverDescription));
1977
-
1978
- myGdalDriverExtension.clear ();
1979
- myGdalDriverLongName.clear ();
1962
+ QString myGdalDriverDescription = GDALGetDescription ( myGdalDriver );
1963
+ if ( myGdalDriverDescription == QLatin1String ( " BIGGIF" ) )
1964
+ {
1965
+ // BIGGIF is a technical driver. The plain GIF driver will do
1966
+ continue ;
1967
+ }
1980
1968
1981
- myGdalDriverMetadata = GDALGetMetadata ( myGdalDriver, nullptr );
1969
+ // QgsDebugMsg(QString("got driver string %1").arg(myGdalDriverDescription) );
1982
1970
1983
- // presumably we know we've run out of metadta if either the
1984
- // address is 0, or the first character is null
1985
- while ( myGdalDriverMetadata && myGdalDriverMetadata[0 ] )
1971
+ QString myGdalDriverExtensions = GDALGetMetadataItem ( myGdalDriver, GDAL_DMD_EXTENSIONS, " " );
1972
+ QString myGdalDriverLongName = GDALGetMetadataItem ( myGdalDriver, GDAL_DMD_LONGNAME, " " );
1973
+ // remove any superfluous (.*) strings at the end as
1974
+ // they'll confuse QFileDialog::getOpenFileNames()
1975
+ myGdalDriverLongName.remove ( QRegExp ( " \\ (.*\\ )$" ) );
1976
+
1977
+ // if we have both the file name extension and the long name,
1978
+ // then we've all the information we need for the current
1979
+ // driver; therefore emit a file filter string and move to
1980
+ // the next driver
1981
+ if ( !( myGdalDriverExtensions.isEmpty () || myGdalDriverLongName.isEmpty () ) )
1986
1982
{
1987
- metadataTokens = QString ( *myGdalDriverMetadata ).split ( ' =' , QString::SkipEmptyParts );
1988
- // QgsDebugMsg(QString("\t%1").arg(*myGdalDriverMetadata));
1989
-
1990
- // XXX add check for malformed metadataTokens
1983
+ const QStringList splitExtensions = myGdalDriverExtensions.split ( ' ' , QString::SkipEmptyParts );
1991
1984
1992
- // Note that it's oddly possible for there to be a
1993
- // DMD_EXTENSION with no corresponding defined extension
1994
- // string; so we check that there're more than two tokens.
1985
+ // XXX add check for SDTS; in that case we want (*CATD.DDF)
1986
+ QString glob;
1995
1987
1996
- if ( metadataTokens. count () > 1 )
1988
+ for ( const QString &ext : splitExtensions )
1997
1989
{
1998
- if ( " DMD_EXTENSION" == metadataTokens[0 ] )
1999
- {
2000
- myGdalDriverExtension = metadataTokens[1 ];
2001
-
2002
- }
2003
- else if ( " DMD_LONGNAME" == metadataTokens[0 ] )
2004
- {
2005
- myGdalDriverLongName = metadataTokens[1 ];
2006
-
2007
- // remove any superfluous (.*) strings at the end as
2008
- // they'll confuse QFileDialog::getOpenFileNames()
2009
-
2010
- myGdalDriverLongName.remove ( QRegExp ( " \\ (.*\\ )$" ) );
2011
- }
1990
+ // This hacking around that removes '/' is no longer necessary with GDAL 2.3
1991
+ extensions << QString ( ext ).remove ( ' /' ).remove ( ' *' ).remove ( ' .' );
1992
+ if ( !glob.isEmpty () )
1993
+ glob += QLatin1String ( " " );
1994
+ glob += " *." + QString ( ext ).replace ( ' /' , QLatin1String ( " *." ) );
2012
1995
}
2013
1996
2014
- // if we have both the file name extension and the long name,
2015
- // then we've all the information we need for the current
2016
- // driver; therefore emit a file filter string and move to
2017
- // the next driver
2018
- if ( !( myGdalDriverExtension.isEmpty () || myGdalDriverLongName.isEmpty () ) )
1997
+ // Add only the first JP2 driver found to the filter list (it's the one GDAL uses)
1998
+ if ( myGdalDriverDescription == QLatin1String ( " JPEG2000" ) ||
1999
+ myGdalDriverDescription.startsWith ( QLatin1String ( " JP2" ) ) ) // JP2ECW, JP2KAK, JP2MrSID
2019
2000
{
2020
- // XXX add check for SDTS; in that case we want (*CATD.DDF)
2021
- QString glob = " *." + myGdalDriverExtension.replace ( ' /' , QLatin1String ( " *." ) );
2022
- extensions << myGdalDriverExtension.remove ( ' /' ).remove ( ' *' ).remove ( ' .' );
2023
- // Add only the first JP2 driver found to the filter list (it's the one GDAL uses)
2024
- if ( myGdalDriverDescription == QLatin1String ( " JPEG2000" ) ||
2025
- myGdalDriverDescription.startsWith ( QLatin1String ( " JP2" ) ) ) // JP2ECW, JP2KAK, JP2MrSID
2026
- {
2027
- if ( jp2Driver )
2028
- break ; // skip if already found a JP2 driver
2001
+ if ( jp2Driver )
2002
+ continue ; // skip if already found a JP2 driver
2029
2003
2030
- jp2Driver = myGdalDriver; // first JP2 driver found
2004
+ jp2Driver = myGdalDriver; // first JP2 driver found
2005
+ if ( !glob.contains ( " j2k" ) )
2006
+ {
2031
2007
glob += QLatin1String ( " *.j2k" ); // add alternate extension
2032
2008
extensions << QStringLiteral ( " j2k" );
2033
2009
}
2034
- else if ( myGdalDriverDescription == QLatin1String ( " GTiff" ) )
2035
- {
2036
- glob += QLatin1String ( " *.tiff" );
2037
- extensions << QStringLiteral ( " tiff" );
2038
- }
2039
- else if ( myGdalDriverDescription == QLatin1String ( " JPEG" ) )
2040
- {
2041
- glob += QLatin1String ( " *.jpeg" );
2042
- extensions << QStringLiteral ( " jpeg" );
2043
- }
2044
- else if ( myGdalDriverDescription == QLatin1String ( " VRT" ) )
2045
- {
2046
- glob += QLatin1String ( " *.ovr" );
2047
- extensions << QStringLiteral ( " ovr" );
2048
- }
2049
-
2050
- fileFiltersString += createFileFilter_ ( myGdalDriverLongName, glob );
2051
-
2052
- break ; // ... to next driver, if any.
2010
+ }
2011
+ else if ( myGdalDriverDescription == QLatin1String ( " VRT" ) )
2012
+ {
2013
+ glob += QLatin1String ( " *.ovr" );
2014
+ extensions << QStringLiteral ( " ovr" );
2053
2015
}
2054
2016
2055
- ++myGdalDriverMetadata;
2017
+ fileFiltersString += createFileFilter_ ( myGdalDriverLongName, glob );
2018
+
2019
+ }
2056
2020
2057
- } // each metadata item
2058
2021
2059
2022
// QgsDebugMsg(QString("got driver Desc=%1 LongName=%2").arg(myGdalDriverDescription).arg(myGdalDriverLongName));
2060
2023
2061
- if ( myGdalDriverExtension .isEmpty () && !myGdalDriverLongName.isEmpty () )
2024
+ if ( myGdalDriverExtensions .isEmpty () && !myGdalDriverLongName.isEmpty () )
2062
2025
{
2063
2026
// Then what we have here is a driver with no corresponding
2064
2027
// file extension; e.g., GRASS. In which case we append the
@@ -2071,29 +2034,9 @@ void buildSupportedRasterFileFilterAndExtensions( QString &fileFiltersString, QS
2071
2034
// DMD_EXTENSION; so let's check for them here and handle
2072
2035
// them appropriately
2073
2036
2074
- // USGS DEMs use "*.dem"
2075
- if ( myGdalDriverDescription.startsWith ( QLatin1String ( " USGSDEM" ) ) )
2076
- {
2077
- fileFiltersString += createFileFilter_ ( myGdalDriverLongName, QStringLiteral ( " *.dem" ) );
2078
- extensions << QStringLiteral ( " dem" );
2079
- }
2080
- else if ( myGdalDriverDescription.startsWith ( QLatin1String ( " DTED" ) ) )
2081
- {
2082
- // DTED use "*.dt0, *.dt1, *.dt2"
2083
- QString glob = QStringLiteral ( " *.dt0" );
2084
- glob += QLatin1String ( " *.dt1" );
2085
- glob += QLatin1String ( " *.dt2" );
2086
- fileFiltersString += createFileFilter_ ( myGdalDriverLongName, glob );
2087
- extensions << QStringLiteral ( " dt0" ) << QStringLiteral ( " dt1" ) << QStringLiteral ( " dt2" );
2088
- }
2089
- else if ( myGdalDriverDescription.startsWith ( QLatin1String ( " MrSID" ) ) )
2090
- {
2091
- // MrSID use "*.sid"
2092
- fileFiltersString += createFileFilter_ ( myGdalDriverLongName, QStringLiteral ( " *.sid" ) );
2093
- extensions << QStringLiteral ( " sid" );
2094
- }
2095
- else if ( myGdalDriverDescription.startsWith ( QLatin1String ( " EHdr" ) ) )
2037
+ if ( myGdalDriverDescription.startsWith ( QLatin1String ( " EHdr" ) ) )
2096
2038
{
2039
+ // Fixed in GDAL 2.3
2097
2040
fileFiltersString += createFileFilter_ ( myGdalDriverLongName, QStringLiteral ( " *.bil" ) );
2098
2041
extensions << QStringLiteral ( " bil" );
2099
2042
}
@@ -2102,12 +2045,6 @@ void buildSupportedRasterFileFilterAndExtensions( QString &fileFiltersString, QS
2102
2045
fileFiltersString += createFileFilter_ ( myGdalDriverLongName, QStringLiteral ( " hdr.adf" ) );
2103
2046
wildcards << QStringLiteral ( " hdr.adf" );
2104
2047
}
2105
- else if ( myGdalDriverDescription == QLatin1String ( " HDF4" ) )
2106
- {
2107
- // HDF4 extension missing in driver metadata
2108
- fileFiltersString += createFileFilter_ ( myGdalDriverLongName, QStringLiteral ( " *.hdf" ) );
2109
- extensions << QStringLiteral ( " hdf" );
2110
- }
2111
2048
else
2112
2049
{
2113
2050
catchallFilter << QString ( GDALGetDescription ( myGdalDriver ) );
0 commit comments