mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-18 00:06:00 -04:00
Merge pull request #32162 from rouault/fix_29212_followup_revived
Application options: defer disabling of drivers after application restart (relates to #29212)
This commit is contained in:
commit
a491117c88
@ -585,6 +585,32 @@ Apply the skipped drivers list to gdal
|
|||||||
.. seealso:: :py:func:`restoreGdalDriver`
|
.. seealso:: :py:func:`restoreGdalDriver`
|
||||||
|
|
||||||
.. seealso:: :py:func:`skippedGdalDrivers`
|
.. seealso:: :py:func:`skippedGdalDrivers`
|
||||||
|
%End
|
||||||
|
|
||||||
|
static void registerGdalDriversFromSettings();
|
||||||
|
%Docstring
|
||||||
|
Register gdal drivers, excluding the ones mentioned in "gdal/skipList" setting.
|
||||||
|
|
||||||
|
.. versionadded:: 3.10
|
||||||
|
%End
|
||||||
|
|
||||||
|
static QStringList deferredSkippedGdalDrivers();
|
||||||
|
%Docstring
|
||||||
|
Returns the list of gdal drivers that have been disabled in the current session,
|
||||||
|
and thus, for safety, should not be disabled right now, but at the
|
||||||
|
next application restart.
|
||||||
|
|
||||||
|
.. versionadded:: 3.10
|
||||||
|
%End
|
||||||
|
|
||||||
|
static void setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
|
||||||
|
const QStringList &deferredSkippedGdalDrivers );
|
||||||
|
%Docstring
|
||||||
|
Sets the list of gdal drivers that should be disabled (``skippedGdalDrivers``),
|
||||||
|
but excludes for now the ones defines in ``deferredSkippedGdalDrivers``.
|
||||||
|
This writes the "gdal/skipList" setting.
|
||||||
|
|
||||||
|
.. versionadded:: 3.10
|
||||||
%End
|
%End
|
||||||
|
|
||||||
static int maxThreads();
|
static int maxThreads();
|
||||||
|
@ -2194,7 +2194,9 @@ void QgsOptions::optionsStackedWidget_CurrentChanged( int index )
|
|||||||
|
|
||||||
void QgsOptions::loadGdalDriverList()
|
void QgsOptions::loadGdalDriverList()
|
||||||
{
|
{
|
||||||
QStringList mySkippedDrivers = QgsApplication::skippedGdalDrivers();
|
QgsApplication::registerGdalDriversFromSettings();
|
||||||
|
|
||||||
|
const QStringList mySkippedDrivers = QgsApplication::skippedGdalDrivers();
|
||||||
GDALDriverH myGdalDriver; // current driver
|
GDALDriverH myGdalDriver; // current driver
|
||||||
QString myGdalDriverDescription;
|
QString myGdalDriverDescription;
|
||||||
QStringList myDrivers;
|
QStringList myDrivers;
|
||||||
@ -2256,8 +2258,8 @@ void QgsOptions::loadGdalDriverList()
|
|||||||
myDriversLongName[myGdalDriverDescription] = QString( GDALGetMetadataItem( myGdalDriver, "DMD_LONGNAME", "" ) );
|
myDriversLongName[myGdalDriverDescription] = QString( GDALGetMetadataItem( myGdalDriver, "DMD_LONGNAME", "" ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
// restore GDAL_SKIP just in case
|
// restore active drivers
|
||||||
CPLSetConfigOption( "GDAL_SKIP", mySkippedDrivers.join( QStringLiteral( " " ) ).toUtf8() );
|
QgsApplication::applyGdalSkippedDrivers();
|
||||||
|
|
||||||
myDrivers.removeDuplicates();
|
myDrivers.removeDuplicates();
|
||||||
// myDrivers.sort();
|
// myDrivers.sort();
|
||||||
@ -2311,19 +2313,38 @@ void QgsOptions::loadGdalDriverList()
|
|||||||
|
|
||||||
void QgsOptions::saveGdalDriverList()
|
void QgsOptions::saveGdalDriverList()
|
||||||
{
|
{
|
||||||
|
bool driverUnregisterNeeded = false;
|
||||||
|
const auto oldSkippedGdalDrivers = QgsApplication::skippedGdalDrivers();
|
||||||
|
auto deferredSkippedGdalDrivers = QgsApplication::deferredSkippedGdalDrivers();
|
||||||
|
QStringList skippedGdalDrivers;
|
||||||
for ( int i = 0; i < lstGdalDrivers->topLevelItemCount(); i++ )
|
for ( int i = 0; i < lstGdalDrivers->topLevelItemCount(); i++ )
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *mypItem = lstGdalDrivers->topLevelItem( i );
|
QTreeWidgetItem *mypItem = lstGdalDrivers->topLevelItem( i );
|
||||||
|
const auto &driverName( mypItem->text( 0 ) );
|
||||||
if ( mypItem->checkState( 0 ) == Qt::Unchecked )
|
if ( mypItem->checkState( 0 ) == Qt::Unchecked )
|
||||||
{
|
{
|
||||||
QgsApplication::skipGdalDriver( mypItem->text( 0 ) );
|
skippedGdalDrivers << driverName;
|
||||||
|
if ( !deferredSkippedGdalDrivers.contains( driverName ) &&
|
||||||
|
!oldSkippedGdalDrivers.contains( driverName ) )
|
||||||
|
{
|
||||||
|
deferredSkippedGdalDrivers << driverName;
|
||||||
|
driverUnregisterNeeded = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QgsApplication::restoreGdalDriver( mypItem->text( 0 ) );
|
if ( deferredSkippedGdalDrivers.contains( driverName ) )
|
||||||
|
{
|
||||||
|
deferredSkippedGdalDrivers.removeAll( driverName );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mSettings->setValue( QStringLiteral( "gdal/skipList" ), QgsApplication::skippedGdalDrivers().join( QStringLiteral( " " ) ) );
|
if ( driverUnregisterNeeded )
|
||||||
|
{
|
||||||
|
QMessageBox::information( this, tr( "Drivers Disabled" ),
|
||||||
|
tr( "One or more drivers have been disabled. This will only take effect after QGIS is restarted." ) );
|
||||||
|
}
|
||||||
|
QgsApplication::setSkippedGdalDrivers( skippedGdalDrivers, deferredSkippedGdalDrivers );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsOptions::addScale()
|
void QgsOptions::addScale()
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
#include "qgsgdalproviderbase.h"
|
#include "qgsgdalproviderbase.h"
|
||||||
#include "qgssettings.h"
|
#include "qgssettings.h"
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
QgsGdalProviderBase::QgsGdalProviderBase()
|
QgsGdalProviderBase::QgsGdalProviderBase()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -219,18 +221,8 @@ int QgsGdalProviderBase::colorInterpretationFromGdal( const GDALColorInterp gdal
|
|||||||
|
|
||||||
void QgsGdalProviderBase::registerGdalDrivers()
|
void QgsGdalProviderBase::registerGdalDrivers()
|
||||||
{
|
{
|
||||||
GDALAllRegister();
|
static std::once_flag initialized;
|
||||||
QgsSettings mySettings;
|
std::call_once( initialized, QgsApplication::registerGdalDriversFromSettings );
|
||||||
QString myJoinedList = mySettings.value( QStringLiteral( "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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsRectangle QgsGdalProviderBase::extent( GDALDatasetH gdalDataset )const
|
QgsRectangle QgsGdalProviderBase::extent( GDALDatasetH gdalDataset )const
|
||||||
|
@ -128,6 +128,7 @@ QString ABISYM( QgsApplication::mCfgIntDir );
|
|||||||
#endif
|
#endif
|
||||||
QString ABISYM( QgsApplication::mBuildOutputPath );
|
QString ABISYM( QgsApplication::mBuildOutputPath );
|
||||||
QStringList ABISYM( QgsApplication::mGdalSkipList );
|
QStringList ABISYM( QgsApplication::mGdalSkipList );
|
||||||
|
QStringList QgsApplication::sDeferredSkippedGdalDrivers;
|
||||||
int ABISYM( QgsApplication::mMaxThreads );
|
int ABISYM( QgsApplication::mMaxThreads );
|
||||||
QString ABISYM( QgsApplication::mAuthDbDirPath );
|
QString ABISYM( QgsApplication::mAuthDbDirPath );
|
||||||
|
|
||||||
@ -1555,10 +1556,41 @@ void QgsApplication::restoreGdalDriver( const QString &driver )
|
|||||||
applyGdalSkippedDrivers();
|
applyGdalSkippedDrivers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsApplication::setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
|
||||||
|
const QStringList &deferredSkippedGdalDrivers )
|
||||||
|
{
|
||||||
|
ABISYM( mGdalSkipList ) = skippedGdalDrivers;
|
||||||
|
sDeferredSkippedGdalDrivers = deferredSkippedGdalDrivers;
|
||||||
|
|
||||||
|
QgsSettings settings;
|
||||||
|
settings.setValue( QStringLiteral( "gdal/skipList" ), skippedGdalDrivers.join( QStringLiteral( " " ) ) );
|
||||||
|
|
||||||
|
applyGdalSkippedDrivers();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsApplication::registerGdalDriversFromSettings()
|
||||||
|
{
|
||||||
|
QgsSettings settings;
|
||||||
|
QString joinedList = settings.value( QStringLiteral( "gdal/skipList" ), QString() ).toString();
|
||||||
|
QStringList myList;
|
||||||
|
if ( !joinedList.isEmpty() )
|
||||||
|
{
|
||||||
|
myList = joinedList.split( ' ' );
|
||||||
|
}
|
||||||
|
ABISYM( mGdalSkipList ) = myList;
|
||||||
|
applyGdalSkippedDrivers();
|
||||||
|
}
|
||||||
|
|
||||||
void QgsApplication::applyGdalSkippedDrivers()
|
void QgsApplication::applyGdalSkippedDrivers()
|
||||||
{
|
{
|
||||||
ABISYM( mGdalSkipList ).removeDuplicates();
|
ABISYM( mGdalSkipList ).removeDuplicates();
|
||||||
QString myDriverList = ABISYM( mGdalSkipList ).join( QStringLiteral( " " ) );
|
QStringList realDisabledDriverList;
|
||||||
|
for ( const auto &driverName : ABISYM( mGdalSkipList ) )
|
||||||
|
{
|
||||||
|
if ( !sDeferredSkippedGdalDrivers.contains( driverName ) )
|
||||||
|
realDisabledDriverList << driverName;
|
||||||
|
}
|
||||||
|
QString myDriverList = realDisabledDriverList.join( ' ' );
|
||||||
QgsDebugMsg( QStringLiteral( "Gdal Skipped driver list set to:" ) );
|
QgsDebugMsg( QStringLiteral( "Gdal Skipped driver list set to:" ) );
|
||||||
QgsDebugMsg( myDriverList );
|
QgsDebugMsg( myDriverList );
|
||||||
CPLSetConfigOption( "GDAL_SKIP", myDriverList.toUtf8() );
|
CPLSetConfigOption( "GDAL_SKIP", myDriverList.toUtf8() );
|
||||||
|
@ -515,7 +515,7 @@ class CORE_EXPORT QgsApplication : public QApplication
|
|||||||
* Sets the GDAL_SKIP environment variable to exclude the specified driver
|
* Sets the GDAL_SKIP environment variable to exclude the specified driver
|
||||||
* and then calls GDALDriverManager::AutoSkipDrivers() to unregister it. The
|
* and then calls GDALDriverManager::AutoSkipDrivers() to unregister it. The
|
||||||
* driver name should be the short format of the Gdal driver name e.g. GTIFF.
|
* driver name should be the short format of the Gdal driver name e.g. GTIFF.
|
||||||
*/
|
*/
|
||||||
static void restoreGdalDriver( const QString &driver );
|
static void restoreGdalDriver( const QString &driver );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -528,9 +528,33 @@ class CORE_EXPORT QgsApplication : public QApplication
|
|||||||
* Apply the skipped drivers list to gdal
|
* Apply the skipped drivers list to gdal
|
||||||
* \see skipGdalDriver
|
* \see skipGdalDriver
|
||||||
* \see restoreGdalDriver
|
* \see restoreGdalDriver
|
||||||
* \see skippedGdalDrivers */
|
* \see skippedGdalDrivers
|
||||||
|
*/
|
||||||
static void applyGdalSkippedDrivers();
|
static void applyGdalSkippedDrivers();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register gdal drivers, excluding the ones mentioned in "gdal/skipList" setting.
|
||||||
|
* \since QGIS 3.10
|
||||||
|
*/
|
||||||
|
static void registerGdalDriversFromSettings();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of gdal drivers that have been disabled in the current session,
|
||||||
|
* and thus, for safety, should not be disabled right now, but at the
|
||||||
|
* next application restart.
|
||||||
|
* \since QGIS 3.10
|
||||||
|
*/
|
||||||
|
static QStringList deferredSkippedGdalDrivers() { return sDeferredSkippedGdalDrivers; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the list of gdal drivers that should be disabled (\a skippedGdalDrivers),
|
||||||
|
* but excludes for now the ones defines in \a deferredSkippedGdalDrivers.
|
||||||
|
* This writes the "gdal/skipList" setting.
|
||||||
|
* \since QGIS 3.10
|
||||||
|
*/
|
||||||
|
static void setSkippedGdalDrivers( const QStringList &skippedGdalDrivers,
|
||||||
|
const QStringList &deferredSkippedGdalDrivers );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets maximum concurrent thread count
|
* Gets maximum concurrent thread count
|
||||||
* \since QGIS 2.4 */
|
* \since QGIS 2.4 */
|
||||||
@ -858,6 +882,12 @@ class CORE_EXPORT QgsApplication : public QApplication
|
|||||||
* \see skipGdalDriver, restoreGdalDriver */
|
* \see skipGdalDriver, restoreGdalDriver */
|
||||||
static QStringList ABISYM( mGdalSkipList );
|
static QStringList ABISYM( mGdalSkipList );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of gdal drivers that have been disabled in the current session,
|
||||||
|
* and thus, for safety, should not be disabled right now, but at the
|
||||||
|
* next application restart */
|
||||||
|
static QStringList sDeferredSkippedGdalDrivers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \since QGIS 2.4 */
|
* \since QGIS 2.4 */
|
||||||
static int ABISYM( mMaxThreads );
|
static int ABISYM( mMaxThreads );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user