Skip to content
Permalink
Browse files
fixes for gdal 2.0 to make sure that OGR drivers and not used as rast…
…er data sources
  • Loading branch information
etiennesky committed May 24, 2014
1 parent a168b90 commit b59a01c57b2d1861152aef2659417adf7b9bd79f
Showing with 21 additions and 48 deletions.
  1. +10 −47 src/app/qgsoptions.cpp
  2. +11 −1 src/providers/gdal/qgsgdalprovider.cpp
@@ -1729,53 +1729,6 @@ void QgsOptions::on_mOptionsStackedWidget_currentChanged( int theIndx )
}
}

#if 0
void QgsOptions::loadGdalDriverList()
{
QStringList mySkippedDrivers = QgsApplication::skippedGdalDrivers();
GDALDriverH myGdalDriver; // current driver
QString myGdalDriverDescription;
QStringList myDrivers;
for ( int i = 0; i < GDALGetDriverCount(); ++i )
{
myGdalDriver = GDALGetDriver( i );

Q_CHECK_PTR( myGdalDriver );

if ( !myGdalDriver )
{
QgsLogger::warning( "unable to get driver " + QString::number( i ) );
continue;
}
myGdalDriverDescription = GDALGetDescription( myGdalDriver );
myDrivers << myGdalDriverDescription;
}
// add the skipped drivers to the list too in case their drivers are
// already unloaded...may result in false positive if underlying
// sys config has changed and that driver no longer exists...
myDrivers.append( mySkippedDrivers );
myDrivers.removeDuplicates();
myDrivers.sort();

QStringListIterator myIterator( myDrivers );

while ( myIterator.hasNext() )
{
QString myName = myIterator.next();
QListWidgetItem * mypItem = new QListWidgetItem( myName );
if ( mySkippedDrivers.contains( myName ) )
{
mypItem->setCheckState( Qt::Unchecked );
}
else
{
mypItem->setCheckState( Qt::Checked );
}
lstGdalDrivers->addItem( mypItem );
}
}
#endif

void QgsOptions::loadGdalDriverList()
{
QStringList mySkippedDrivers = QgsApplication::skippedGdalDrivers();
@@ -1804,6 +1757,16 @@ void QgsOptions::loadGdalDriverList()
QgsLogger::warning( "unable to get driver " + QString::number( i ) );
continue;
}

// in GDAL 2.0 vector and mixed drivers are returned by GDALGetDriver, so filter out non-raster drivers
// TODO add same UI for vector drivers
#ifdef GDAL_COMPUTE_VERSION
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,0,0)
if ( QString( GDALGetMetadataItem( myGdalDriver, GDAL_DCAP_RASTER, NULL ) ) != "YES" )
continue;
#endif
#endif

myGdalDriverDescription = GDALGetDescription( myGdalDriver );
myDrivers << myGdalDriverDescription;

@@ -1974,6 +1974,16 @@ void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString
QgsLogger::warning( "unable to get driver " + QString::number( i ) );
continue;
}

// in GDAL 2.0 vector and mixed drivers are returned by GDALGetDriver, so filter out non-raster drivers
// TODO also make sure drivers are not loaded unnecessarily (as GDALAllRegister() and OGRRegisterAll load all drivers)
#ifdef GDAL_COMPUTE_VERSION
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,0,0)
if ( QString( GDALGetMetadataItem( myGdalDriver, GDAL_DCAP_RASTER, NULL ) ) != "YES" )
continue;
#endif
#endif

// now we need to see if the driver is for something currently
// supported; if not, we give it a miss for the next driver

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

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

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

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

0 comments on commit b59a01c

Please sign in to comment.