28 changes: 28 additions & 0 deletions python/core/qgsapplication.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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();

};

1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,12 @@ int main( int argc, char *argv[] )
QApplication::setStyle( new QPlastiqueStyle );
#endif

QString i18nPath = QgsApplication::i18nPath();
QSettings mySettings;


/* Translation file for QGIS.
*/
QSettings mySettings;
QString i18nPath = QgsApplication::i18nPath();
QString myUserLocale = mySettings.value( "locale/userLocale", "" ).toString();
bool myLocaleOverrideFlag = mySettings.value( "locale/overrideFlag", false ).toBool();
QString myLocale;
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
qApp->processEvents();
// now build vector file filter
mVectorFileFilter = QgsProviderRegistry::instance()->fileVectorFilters();

// now build raster file filter
QgsRasterLayer::buildSupportedRasterFileFilter( mRasterFileFilter );

Expand Down Expand Up @@ -4822,6 +4823,9 @@ void QgisApp::options()

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

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

delete optionsDialog;
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgscustomization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ void QgsCustomization::customizeWidget( QString thePath, QWidget * theWidget )
QString p = myPath + "/" + w->objectName();

bool on = mySettings.value( p, true ).toBool();
QgsDebugMsg( QString( "p = %1 on = %2" ).arg( p ).arg( on ) );
//QgsDebugMsg( QString( "p = %1 on = %2" ).arg( p ).arg( on ) );
if ( on )
{
QgsCustomization::customizeWidget( myPath, w );
Expand Down Expand Up @@ -854,7 +854,7 @@ void QgsCustomization::preNotify( QObject * receiver, QEvent * event, bool * don
}
else if ( widget && event->type() == QEvent::MouseButtonPress )
{
QgsDebugMsg( "click" );
//QgsDebugMsg( "click" );
if ( pDialog && pDialog->isVisible() )
{
QMouseEvent *e = static_cast<QMouseEvent*>( event );
Expand All @@ -870,7 +870,7 @@ void QgsCustomization::preNotify( QObject * receiver, QEvent * event, bool * don
if ( pDialog && pDialog->isVisible() )
{
QKeyEvent *e = static_cast<QKeyEvent*>( event );
QgsDebugMsg( QString( "key = %1 modifiers = %2" ).arg( e->key() ).arg( e->modifiers() ) ) ;
//QgsDebugMsg( QString( "key = %1 modifiers = %2" ).arg( e->key() ).arg( e->modifiers() ) ) ;
if ( e->key() == Qt::Key_M && e->modifiers() == Qt::ControlModifier )
{
pDialog->setCatch( !pDialog->catchOn() );
Expand Down
72 changes: 72 additions & 0 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -744,6 +749,10 @@ void QgsOptions::saveOptions()
//
settings.setValue( "locale/userLocale", cboLocale->currentText() );
settings.setValue( "locale/overrideFlag", grpLocale->isChecked() );


// Gdal skip driver list
saveGdalDriverList();
}


Expand Down Expand Up @@ -1010,3 +1019,66 @@ 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;
}
// 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 );
}
}

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() );
}
}
QSettings mySettings;
mySettings.setValue( "gdal/skipList", QgsApplication::skippedGdalDrivers().join(" ") );
}
10 changes: 10 additions & 0 deletions src/app/qgsoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
36 changes: 36 additions & 0 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -711,3 +713,37 @@ 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 );
CPLSetConfigOption("GDAL_SKIP", myDriverList.toUtf8());
GetGDALDriverManager()->AutoSkipDrivers();
}
32 changes: 32 additions & 0 deletions src/core/qgsapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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

#include <qgis.h>

Expand Down Expand Up @@ -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 );

Expand All @@ -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
15 changes: 13 additions & 2 deletions src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1181,8 +1181,19 @@ int QgsGdalProvider::colorInterpretation( int theBandNo ) const

void QgsGdalProvider::registerGdalDrivers()
{
if ( GDALGetDriverCount() == 0 )
GDALAllRegister();
//GDALDestroyDriverManager();
GDALAllRegister();
QSettings mySettings;
QString myJoinedList = mySettings.value( "gdal/skipList", "" ).toString();
if ( !myJoinedList.isEmpty() )
{
QStringList myList = myJoinedList.split(" ");
for ( int i = 0; i < myList.size(); ++i )
{
QgsApplication::skipGdalDriver( myList.at( i ) );
}
QgsApplication::applyGdalSkippedDrivers();
}
}


Expand Down
Loading