Skip to content

Commit

Permalink
fixes for gdal 2.0 to make sure that OGR drivers and not used as rast…
Browse files Browse the repository at this point in the history
…er data sources
  • Loading branch information
etiennesky committed May 24, 2014
1 parent a168b90 commit b59a01c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 48 deletions.
57 changes: 10 additions & 47 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down
12 changes: 11 additions & 1 deletion src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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( ";;" ) + ";;";
Expand All @@ -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 )
Expand Down

0 comments on commit b59a01c

Please sign in to comment.