Skip to content
Permalink
Browse files

[FEATURE] implement ability to skip specific drivers (fixes #182)

  • Loading branch information
timlinux committed Sep 12, 2011
1 parent f1d7062 commit c58576e2040e026261758482821554bdb0f16171
@@ -260,5 +260,33 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
@note added in 2.0 */
static QString buildOutputPath();

/** Sets the GDAL_SKIP environment variable to include the specified driver
* and then calls GDALDriverManager::AutoSkipDrivers() to unregister it. The
* driver name should be the short format of the Gdal driver name e.g. GTiff.
* @note added in 2.0
*/
static void skipGdalDriver( QString theDriver );

/** Sets the GDAL_SKIP environment variable to exclude the specified driver
* and then calls GDALDriverManager::AutoSkipDrivers() to unregister it. The
* driver name should be the short format of the Gdal driver name e.g. GTiff.
* @note added in 2.0
*/
static void restoreGdalDriver( QString theDriver );


/** Returns the list of gdal drivers that should be skipped (based on
* GDAL_SKIP environment variable)
* @note added in 2.0
*/
static QStringList skippedGdalDrivers( ) const ;

/** Apply the skipped drivers list to gdal
* @see skipGdalDriver
* @see restoreGdalDriver
* @see skippedGdalDrivers
* @note added in 2.0 */
static void applyGdalSkippedDrivers();

};

@@ -422,6 +422,7 @@ TARGET_LINK_LIBRARIES(${QGIS_APP_NAME}
#should only be needed for win
${QT_QTMAIN_LIBRARY}
${QWTPOLAR_LIBRARY}
${GDAL_LIBRARY}
qgis_core
qgis_gui
qgis_analysis
@@ -4822,6 +4822,9 @@ void QgisApp::options()

//do we need this? TS
mMapCanvas->refresh();

mRasterFileFilter.clear();
QgsRasterLayer::buildSupportedRasterFileFilter( mRasterFileFilter );
}

delete optionsDialog;
@@ -41,6 +41,8 @@
#define ELLIPS_FLAT "NONE"
#define ELLIPS_FLAT_DESC "None / Planimetric"

#define CPL_SUPRESS_CPLUSPLUS
#include <gdal.h>
/**
* \class QgsOptions - Set user options and preferences
* Constructor
@@ -431,6 +433,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :

restoreGeometry( settings.value( "/Windows/Options/geometry" ).toByteArray() );
tabWidget->setCurrentIndex( settings.value( "/Windows/Options/row" ).toInt() );

loadGdalDriverList();

}

//! Destructor
@@ -744,6 +749,10 @@ void QgsOptions::saveOptions()
//
settings.setValue( "locale/userLocale", cboLocale->currentText() );
settings.setValue( "locale/overrideFlag", grpLocale->isChecked() );


// Gdal skip driver list
saveGdalDriverList();
}


@@ -1010,3 +1019,57 @@ void QgsOptions::on_mClearCache_clicked()
QgsNetworkAccessManager::instance()->cache()->clear();
#endif
}

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;
}
QStringListIterator myIterator( myDrivers );
myDrivers.sort();
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 );
}
}

void QgsOptions::saveGdalDriverList()
{
for ( int i=0; i < lstGdalDrivers->count(); i++ )
{
QListWidgetItem * mypItem = lstGdalDrivers->item( i );
if ( mypItem->checkState() == Qt::Unchecked )
{
QgsApplication::skipGdalDriver( mypItem->text() );
}
else
{
QgsApplication::restoreGdalDriver( mypItem->text() );
}
}
}
@@ -120,6 +120,16 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
void on_mBrowseCacheDirectory_clicked();
void on_mClearCache_clicked();

/* Load the list of drivers available in GDAL
* @note added in 2.0
*/
void loadGdalDriverList();

/* Save the list of which gdal drivers should be used.
* @note added in 2.0
*/
void saveGdalDriverList();

protected:
//! Populates combo box with ellipsoids
void getEllipsoidList();
@@ -34,6 +34,7 @@
#include "qgsconfig.h"

#include <ogr_api.h>
#include <gdal_priv.h>
#include <cpl_conv.h> // for setting gdal options

QObject * QgsApplication::mFileOpenEventReceiver;
@@ -49,6 +50,7 @@ QString QgsApplication::mConfigPath = QDir::homePath() + QString( "/.qgis/" );
bool QgsApplication::mRunningFromBuildDir = false;
QString QgsApplication::mBuildSourcePath;
QString QgsApplication::mBuildOutputPath;
QStringList QgsApplication::mGdalSkipList;

/*!
\class QgsApplication
@@ -711,3 +713,43 @@ QString QgsApplication::relativePathToAbsolutePath( QString rpath, QString targe

return targetElems.join( "/" );
}

void QgsApplication::skipGdalDriver( QString theDriver )
{
if ( mGdalSkipList.contains( theDriver ) || theDriver.isEmpty() )
{
return;
}
mGdalSkipList << theDriver;
applyGdalSkippedDrivers();
}

void QgsApplication::restoreGdalDriver( QString theDriver )
{
if ( !mGdalSkipList.contains( theDriver ) )
{
return;
}
int myPos = mGdalSkipList.indexOf( theDriver );
if ( myPos >= 0 )
{
mGdalSkipList.removeAt( myPos );
}
applyGdalSkippedDrivers();
}

void QgsApplication::applyGdalSkippedDrivers()
{
mGdalSkipList.removeDuplicates();
QString myDriverList = mGdalSkipList.join(" ");
QgsDebugMsg( "Gdal Skipped driver list set to:" );
QgsDebugMsg( myDriverList );
#if defined(Q_WS_WIN32) || defined(WIN32)
CPLSetConfigOption("GDAL_SKIP", myDriverList.toUtf8());
#else
int myChangeFlag = 1; //whether we want to force the env var to change
setenv( "GDAL_SKIP", myDriverList.toUtf8(), myChangeFlag );
#endif
GDALDriverManager myDriverManager;
myDriverManager.AutoLoadDrivers();
}
@@ -17,6 +17,7 @@

#include <QApplication>
#include <QEvent>
#include <QStringList>

#include <qgis.h>

@@ -223,6 +224,33 @@ class CORE_EXPORT QgsApplication: public QApplication
@note added in 2.0 */
static QString buildOutputPath() { return mBuildOutputPath; }

/** Sets the GDAL_SKIP environment variable to include the specified driver
* and then calls GDALDriverManager::AutoSkipDrivers() to unregister it. The
* driver name should be the short format of the Gdal driver name e.g. GTIFF.
* @note added in 2.0
*/
static void skipGdalDriver( QString theDriver );

/** Sets the GDAL_SKIP environment variable to exclude the specified driver
* and then calls GDALDriverManager::AutoSkipDrivers() to unregister it. The
* driver name should be the short format of the Gdal driver name e.g. GTIFF.
* @note added in 2.0
*/
static void restoreGdalDriver( QString theDriver );

/** Returns the list of gdal drivers that should be skipped (based on
* GDAL_SKIP environment variable)
* @note added in 2.0
*/
static QStringList skippedGdalDrivers( ){ return mGdalSkipList; };

/** Apply the skipped drivers list to gdal
* @see skipGdalDriver
* @see restoreGdalDriver
* @see skippedGdalDrivers
* @note added in 2.0 */
static void applyGdalSkippedDrivers();

signals:
void preNotify( QObject * receiver, QEvent * event, bool * done );

@@ -246,6 +274,10 @@ class CORE_EXPORT QgsApplication: public QApplication
static QString mBuildSourcePath;
/** path to the output directory of the build. valid only when running from build directory */
static QString mBuildOutputPath;
/** List of gdal drivers to be skipped. Uses GDAL_SKIP to exclude them.
* @see skipGdalDriver, restoreGdalDriver
* @note added in 2.0 */
static QStringList mGdalSkipList;
};

#endif
@@ -1182,7 +1182,11 @@ int QgsGdalProvider::colorInterpretation( int theBandNo ) const
void QgsGdalProvider::registerGdalDrivers()
{
if ( GDALGetDriverCount() == 0 )
{
GDALAllRegister();
}
//call regardless of above
QgsApplication::applyGdalSkippedDrivers();
}


0 comments on commit c58576e

Please sign in to comment.
You can’t perform that action at this time.