Skip to content

Commit b59a01c

Browse files
committed
fixes for gdal 2.0 to make sure that OGR drivers and not used as raster data sources
1 parent a168b90 commit b59a01c

File tree

2 files changed

+21
-48
lines changed

2 files changed

+21
-48
lines changed

src/app/qgsoptions.cpp

+10-47
Original file line numberDiff line numberDiff line change
@@ -1729,53 +1729,6 @@ void QgsOptions::on_mOptionsStackedWidget_currentChanged( int theIndx )
17291729
}
17301730
}
17311731

1732-
#if 0
1733-
void QgsOptions::loadGdalDriverList()
1734-
{
1735-
QStringList mySkippedDrivers = QgsApplication::skippedGdalDrivers();
1736-
GDALDriverH myGdalDriver; // current driver
1737-
QString myGdalDriverDescription;
1738-
QStringList myDrivers;
1739-
for ( int i = 0; i < GDALGetDriverCount(); ++i )
1740-
{
1741-
myGdalDriver = GDALGetDriver( i );
1742-
1743-
Q_CHECK_PTR( myGdalDriver );
1744-
1745-
if ( !myGdalDriver )
1746-
{
1747-
QgsLogger::warning( "unable to get driver " + QString::number( i ) );
1748-
continue;
1749-
}
1750-
myGdalDriverDescription = GDALGetDescription( myGdalDriver );
1751-
myDrivers << myGdalDriverDescription;
1752-
}
1753-
// add the skipped drivers to the list too in case their drivers are
1754-
// already unloaded...may result in false positive if underlying
1755-
// sys config has changed and that driver no longer exists...
1756-
myDrivers.append( mySkippedDrivers );
1757-
myDrivers.removeDuplicates();
1758-
myDrivers.sort();
1759-
1760-
QStringListIterator myIterator( myDrivers );
1761-
1762-
while ( myIterator.hasNext() )
1763-
{
1764-
QString myName = myIterator.next();
1765-
QListWidgetItem * mypItem = new QListWidgetItem( myName );
1766-
if ( mySkippedDrivers.contains( myName ) )
1767-
{
1768-
mypItem->setCheckState( Qt::Unchecked );
1769-
}
1770-
else
1771-
{
1772-
mypItem->setCheckState( Qt::Checked );
1773-
}
1774-
lstGdalDrivers->addItem( mypItem );
1775-
}
1776-
}
1777-
#endif
1778-
17791732
void QgsOptions::loadGdalDriverList()
17801733
{
17811734
QStringList mySkippedDrivers = QgsApplication::skippedGdalDrivers();
@@ -1804,6 +1757,16 @@ void QgsOptions::loadGdalDriverList()
18041757
QgsLogger::warning( "unable to get driver " + QString::number( i ) );
18051758
continue;
18061759
}
1760+
1761+
// in GDAL 2.0 vector and mixed drivers are returned by GDALGetDriver, so filter out non-raster drivers
1762+
// TODO add same UI for vector drivers
1763+
#ifdef GDAL_COMPUTE_VERSION
1764+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,0,0)
1765+
if ( QString( GDALGetMetadataItem( myGdalDriver, GDAL_DCAP_RASTER, NULL ) ) != "YES" )
1766+
continue;
1767+
#endif
1768+
#endif
1769+
18071770
myGdalDriverDescription = GDALGetDescription( myGdalDriver );
18081771
myDrivers << myGdalDriverDescription;
18091772

src/providers/gdal/qgsgdalprovider.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,16 @@ void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString
19741974
QgsLogger::warning( "unable to get driver " + QString::number( i ) );
19751975
continue;
19761976
}
1977+
1978+
// in GDAL 2.0 vector and mixed drivers are returned by GDALGetDriver, so filter out non-raster drivers
1979+
// TODO also make sure drivers are not loaded unnecessarily (as GDALAllRegister() and OGRRegisterAll load all drivers)
1980+
#ifdef GDAL_COMPUTE_VERSION
1981+
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,0,0)
1982+
if ( QString( GDALGetMetadataItem( myGdalDriver, GDAL_DCAP_RASTER, NULL ) ) != "YES" )
1983+
continue;
1984+
#endif
1985+
#endif
1986+
19771987
// now we need to see if the driver is for something currently
19781988
// supported; if not, we give it a miss for the next driver
19791989

@@ -2116,7 +2126,6 @@ void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString
21162126
} // each loaded GDAL driver
21172127

21182128
// sort file filters alphabetically
2119-
QgsDebugMsg( "theFileFiltersString: " + theFileFiltersString );
21202129
QStringList filters = theFileFiltersString.split( ";;", QString::SkipEmptyParts );
21212130
filters.sort();
21222131
theFileFiltersString = filters.join( ";;" ) + ";;";
@@ -2138,6 +2147,7 @@ void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString
21382147
if ( theFileFiltersString.endsWith( ";;" ) ) theFileFiltersString.chop( 2 );
21392148

21402149
QgsDebugMsg( "Raster filter list built: " + theFileFiltersString );
2150+
QgsDebugMsg( "Raster extension list built: " + theExtensions.join( " " ) );
21412151
} // buildSupportedRasterFileFilter_()
21422152

21432153
QGISEXTERN bool isValidRasterFileName( QString const & theFileNameQString, QString & retErrMsg )

0 commit comments

Comments
 (0)