mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[FEATURE] implement ability to skip specific drivers (fixes #182)
This commit is contained in:
parent
f1d7062c3e
commit
c58576e204
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,8 +50,14 @@
|
||||
<string>General</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_7">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QScrollArea" name="scrollArea_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -60,8 +66,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>780</width>
|
||||
<height>755</height>
|
||||
<width>979</width>
|
||||
<height>1135</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_12">
|
||||
@ -425,6 +431,32 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_13">
|
||||
<property name="title">
|
||||
<string>GDAL Drivers</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QListWidget" name="lstGdalDrivers">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>141</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_17">
|
||||
<property name="text">
|
||||
<string>In some cases more than one GDAL driver can be used to load the same raster format. Use the list below to specify which to use.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_4">
|
||||
<property name="title">
|
||||
@ -489,8 +521,14 @@
|
||||
<string>Rendering</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_9">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QScrollArea" name="scrollArea_3">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -499,8 +537,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>780</width>
|
||||
<height>433</height>
|
||||
<width>641</width>
|
||||
<height>512</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_8">
|
||||
@ -657,8 +695,14 @@
|
||||
<string>Map tools</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_6">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -667,8 +711,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>780</width>
|
||||
<height>456</height>
|
||||
<width>567</width>
|
||||
<height>532</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
@ -937,8 +981,14 @@
|
||||
<string>Overlays</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_11">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QScrollArea" name="scrollArea_4">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -947,8 +997,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>795</width>
|
||||
<height>415</height>
|
||||
<width>289</width>
|
||||
<height>94</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_10">
|
||||
@ -1022,8 +1072,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>795</width>
|
||||
<height>415</height>
|
||||
<width>797</width>
|
||||
<height>490</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_13">
|
||||
@ -1342,8 +1392,14 @@
|
||||
<string>CRS</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_16">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QScrollArea" name="scrollArea_6">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -1352,8 +1408,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>795</width>
|
||||
<height>415</height>
|
||||
<width>446</width>
|
||||
<height>420</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_15">
|
||||
@ -1510,8 +1566,14 @@
|
||||
<string>Locale</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_18">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QScrollArea" name="scrollArea_7">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -1520,8 +1582,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>780</width>
|
||||
<height>527</height>
|
||||
<width>519</width>
|
||||
<height>583</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_17">
|
||||
@ -1601,8 +1663,14 @@
|
||||
<string>Network</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_19">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QScrollArea" name="scrollArea_8">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -1611,8 +1679,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>780</width>
|
||||
<height>461</height>
|
||||
<width>384</width>
|
||||
<height>573</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_20">
|
||||
|
Loading…
x
Reference in New Issue
Block a user