From 432224ab9483231a33165ccbb623cdd9ba5a00e8 Mon Sep 17 00:00:00 2001 From: Damiano Date: Thu, 8 Apr 2021 22:01:41 +0200 Subject: [PATCH 01/13] Moved most core settings to SettingsEntry --- .../network/qgsnetworkaccessmanager.sip.in | 5 ++ .../network/qgsnewsfeedparser.sip.in | 8 +++ .../processing/qgsprocessing.sip.in | 8 +++ .../core/auto_generated/qgsapplication.sip.in | 9 +++ .../auto_generated/qgsgeometryoptions.sip.in | 5 ++ .../qgslocalizeddatapathregistry.sip.in | 5 ++ .../auto_generated/qgsmaprendererjob.sip.in | 6 ++ .../settings/qgssettingsregistrycore.sip.in | 12 +++- src/app/main.cpp | 14 ++-- src/app/options/qgsoptions.cpp | 22 +++---- src/app/qgsprojectproperties.cpp | 2 +- src/core/network/qgsnetworkaccessmanager.cpp | 4 +- src/core/network/qgsnetworkaccessmanager.h | 11 ++++ src/core/network/qgsnewsfeedparser.cpp | 17 +++-- src/core/network/qgsnewsfeedparser.h | 17 +++++ src/core/processing/qgsprocessing.h | 17 +++++ src/core/processing/qgsprocessingcontext.cpp | 2 +- src/core/processing/qgsprocessingutils.cpp | 8 +-- src/core/project/qgsproject.cpp | 2 +- src/core/qgsapplication.cpp | 11 ++-- src/core/qgsapplication.h | 19 ++++++ src/core/qgsgeometryoptions.cpp | 2 +- src/core/qgsgeometryoptions.h | 11 ++++ src/core/qgslocalizeddatapathregistry.cpp | 4 +- src/core/qgslocalizeddatapathregistry.h | 11 ++++ src/core/qgsmaprendererjob.cpp | 3 +- src/core/qgsmaprendererjob.h | 12 ++++ src/core/settings/qgssettingsregistrycore.cpp | 64 +++++++++++++++++-- src/core/settings/qgssettingsregistrycore.h | 20 ++++-- src/gui/qgsconfigureshortcutsdialog.cpp | 8 +-- src/gui/qgsgui.cpp | 3 +- src/gui/qgsmapcanvas.cpp | 4 +- tests/src/analysis/testqgsprocessing.cpp | 20 +++--- .../src/core/testqgscompositionconverter.cpp | 3 +- .../src/core/testqgsnetworkaccessmanager.cpp | 2 +- tests/src/core/testqgsnewsfeedparser.cpp | 10 +-- tests/src/core/testqgstranslateproject.cpp | 9 ++- 37 files changed, 294 insertions(+), 96 deletions(-) diff --git a/python/core/auto_generated/network/qgsnetworkaccessmanager.sip.in b/python/core/auto_generated/network/qgsnetworkaccessmanager.sip.in index 207d2594e174..e5f7db3a9f40 100644 --- a/python/core/auto_generated/network/qgsnetworkaccessmanager.sip.in +++ b/python/core/auto_generated/network/qgsnetworkaccessmanager.sip.in @@ -321,6 +321,11 @@ The contents of the reply will be returned after the request is completed or an .. versionadded:: 3.6 %End + struct Settings + { + const QgsSettingsEntryInteger networkTimeout; + }; + signals: void requestAboutToBeCreated( QNetworkAccessManager::Operation, const QNetworkRequest &, QIODevice * ) /Deprecated/; diff --git a/python/core/auto_generated/network/qgsnewsfeedparser.sip.in b/python/core/auto_generated/network/qgsnewsfeedparser.sip.in index f3169fa7c025..a411df070b89 100644 --- a/python/core/auto_generated/network/qgsnewsfeedparser.sip.in +++ b/python/core/auto_generated/network/qgsnewsfeedparser.sip.in @@ -93,6 +93,14 @@ Returns the authentication configuration for the parser. Returns the settings key used for a feed with the given ``baseUrl``. %End + struct Settings + { + const QgsSettingsEntryInteger feedLastFetchTime; + const QgsSettingsEntryString feedLanguage; + const QgsSettingsEntryDouble feedLatitude; + const QgsSettingsEntryDouble feedLongitude; + }; + public slots: void fetch(); diff --git a/python/core/auto_generated/processing/qgsprocessing.sip.in b/python/core/auto_generated/processing/qgsprocessing.sip.in index de33821c12eb..d447f80dfef7 100644 --- a/python/core/auto_generated/processing/qgsprocessing.sip.in +++ b/python/core/auto_generated/processing/qgsprocessing.sip.in @@ -52,6 +52,14 @@ Converts a source ``type`` to a string representation. %End static const QString TEMPORARY_OUTPUT; + + struct Settings + { + const QgsSettingsEntryBool preferFilenameAsLayerName; + const QgsSettingsEntryString tempPath; + const QgsSettingsEntryInteger defaultOutputVectorLayerExt; + const QgsSettingsEntryInteger defaultOutputRasterLayerExt; + }; }; /************************************************************************ diff --git a/python/core/auto_generated/qgsapplication.sip.in b/python/core/auto_generated/qgsapplication.sip.in index 830ac64ea32b..b256b73a69e7 100644 --- a/python/core/auto_generated/qgsapplication.sip.in +++ b/python/core/auto_generated/qgsapplication.sip.in @@ -1004,6 +1004,15 @@ Emits the signal to collect all the strings of .qgs to be included in ts file .. versionadded:: 3.4 %End + struct Settings + { + const QgsSettingsEntryString localeUserLocale; + const QgsSettingsEntryBool localeOverrideFlag; + const QgsSettingsEntryString localeGlobalLocale; + const QgsSettingsEntryBool localeShowGroupSeparator; + const QgsSettingsEntryStringList searchPathsForSVG; + }; + %If (ANDROID) //dummy method to workaround sip generation issue bool x11EventFilter( XEvent *event ); diff --git a/python/core/auto_generated/qgsgeometryoptions.sip.in b/python/core/auto_generated/qgsgeometryoptions.sip.in index 6639f8e6d3e5..dcb9d5971cde 100644 --- a/python/core/auto_generated/qgsgeometryoptions.sip.in +++ b/python/core/auto_generated/qgsgeometryoptions.sip.in @@ -118,6 +118,11 @@ Read the geometry options from ``node``. .. versionadded:: 3.4 %End + struct Settings + { + const QgsSettingsEntryString geometryValidationDefaultChecks; + }; + signals: void checkConfigurationChanged(); diff --git a/python/core/auto_generated/qgslocalizeddatapathregistry.sip.in b/python/core/auto_generated/qgslocalizeddatapathregistry.sip.in index 8d0a62681a73..8185921b73d5 100644 --- a/python/core/auto_generated/qgslocalizeddatapathregistry.sip.in +++ b/python/core/auto_generated/qgslocalizeddatapathregistry.sip.in @@ -60,6 +60,11 @@ Since the paths are stored by order of preference, lower positions in the list t Unregisters a localized path %End + struct Settings + { + const QgsSettingsEntryStringList localizedDataPaths; + }; + private: QgsLocalizedDataPathRegistry( const QgsLocalizedDataPathRegistry &other ); }; diff --git a/python/core/auto_generated/qgsmaprendererjob.sip.in b/python/core/auto_generated/qgsmaprendererjob.sip.in index 49e841509a1d..cd7f15f421e8 100644 --- a/python/core/auto_generated/qgsmaprendererjob.sip.in +++ b/python/core/auto_generated/qgsmaprendererjob.sip.in @@ -157,6 +157,12 @@ Returns map settings with which this job was started. + + struct Settings + { + const QgsSettingsEntryBool logCanvasRefreshEvent; + }; + signals: void renderingLayersFinished(); diff --git a/python/core/auto_generated/settings/qgssettingsregistrycore.sip.in b/python/core/auto_generated/settings/qgssettingsregistrycore.sip.in index 5f77a9252559..9284a092ce8d 100644 --- a/python/core/auto_generated/settings/qgssettingsregistrycore.sip.in +++ b/python/core/auto_generated/settings/qgssettingsregistrycore.sip.in @@ -10,8 +10,6 @@ - - class QgsSettingsRegistryCore { %Docstring(signature="appended") @@ -33,6 +31,16 @@ Constructor for QgsSettingsRegistryCore. virtual ~QgsSettingsRegistryCore(); + const QgsSettingsEntryBase *getSettingsEntry( const QString &key ); +%Docstring +Returns the :py:class:`QgsSettingsEntry` with the given ``key`` or None if not found. +%End + + void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); +%Docstring +Add ``settingsEntry`` to the register. +%End + }; /************************************************************************ diff --git a/src/app/main.cpp b/src/app/main.cpp index 7883dba272d0..f5942d2bc40c 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -966,20 +966,18 @@ int main( int argc, char *argv[] ) delete profile; { - QgsSettings settings; - /* Translation file for QGIS. */ - QString myUserTranslation = settings.value( QStringLiteral( "locale/userLocale" ), "" ).toString(); - QString myGlobalLocale = settings.value( QStringLiteral( "locale/globalLocale" ), "" ).toString(); + QString myUserTranslation = QgsApplication::Settings::localeUserLocale.value(); + QString myGlobalLocale = QgsApplication::Settings::localeGlobalLocale.value(); bool myShowGroupSeparatorFlag = false; // Default to false - bool myLocaleOverrideFlag = settings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool(); + bool myLocaleOverrideFlag = QgsApplication::Settings::localeOverrideFlag.value(); // Override Show Group Separator if the global override flag is set if ( myLocaleOverrideFlag ) { // Default to false again - myShowGroupSeparatorFlag = settings.value( QStringLiteral( "locale/showGroupSeparator" ), false ).toBool(); + myShowGroupSeparatorFlag = QgsApplication::Settings::localeShowGroupSeparator.value(); } // @@ -993,7 +991,7 @@ int main( int argc, char *argv[] ) // if ( !translationCode.isNull() && !translationCode.isEmpty() ) { - settings.setValue( QStringLiteral( "locale/userLocale" ), translationCode ); + QgsApplication::Settings::localeUserLocale.setValue( translationCode ); } else { @@ -1002,7 +1000,7 @@ int main( int argc, char *argv[] ) translationCode = QLocale().name(); //setting the locale/userLocale when the --lang= option is not set will allow third party //plugins to always use the same locale as the QGIS, otherwise they can be out of sync - settings.setValue( QStringLiteral( "locale/userLocale" ), translationCode ); + QgsApplication::Settings::localeUserLocale.setValue( translationCode ); } else { diff --git a/src/app/options/qgsoptions.cpp b/src/app/options/qgsoptions.cpp index 7c5894328731..f5d2d32753b2 100644 --- a/src/app/options/qgsoptions.cpp +++ b/src/app/options/qgsoptions.cpp @@ -24,6 +24,7 @@ #include "qgsgdalutils.h" #include "qgshighlight.h" #include "qgsmapcanvas.h" +#include "qgsmaprendererjob.h" #include "qgsprojectionselectiondialog.h" #include "qgscoordinatereferencesystem.h" #include "qgstolerance.h" @@ -474,7 +475,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QListsetCurrentIndex( index ); // log rendering events, for userspace debugging - mLogCanvasRefreshChkBx->setChecked( mSettings->value( QStringLiteral( "/Map/logCanvasRefreshEvent" ), false ).toBool() ); + mLogCanvasRefreshChkBx->setChecked( QgsMapRendererJob::Settings::logCanvasRefreshEvent.value() ); //set the default projection behavior radio buttons const QgsOptions::UnknownLayerCrsBehavior mode = QgsSettings().enumValue( QStringLiteral( "/projections/unknownCrsBehavior" ), QgsOptions::UnknownLayerCrsBehavior::NoAction, QgsSettings::App ); @@ -1014,9 +1015,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QListsetText( tr( "Detected active locale on your system: %1" ).arg( currentLocale ) ); - QString userLocale = mSettings->value( QStringLiteral( "locale/userLocale" ), QString( ) ).toString(); - bool showGroupSeparator = mSettings->value( QStringLiteral( "locale/showGroupSeparator" ), false ).toBool(); - QString globalLocale = mSettings->value( QStringLiteral( "locale/globalLocale" ), currentLocale ).toString(); + QString userLocale = QgsApplication::Settings::localeUserLocale.value(); + bool showGroupSeparator = QgsApplication::Settings::localeShowGroupSeparator.value(); + QString globalLocale = QgsApplication::Settings::localeGlobalLocale.value(); const QStringList language18nList( i18nList() ); for ( const auto &l : language18nList ) { @@ -1043,8 +1044,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QListsetCurrentIndex( cboTranslation->findData( userLocale ) ); cboGlobalLocale->setCurrentIndex( cboGlobalLocale->findData( globalLocale ) ); - bool localeOverrideFlag = mSettings->value( QStringLiteral( "locale/overrideFlag" ), false ).toBool(); - grpLocale->setChecked( localeOverrideFlag ); + grpLocale->setChecked( QgsApplication::Settings::localeOverrideFlag.value() ); cbShowGroupSeparator->setChecked( showGroupSeparator ); @@ -1673,7 +1673,7 @@ void QgsOptions::saveOptions() mSettings->setValue( QStringLiteral( "/Raster/cumulativeCutUpper" ), mRasterCumulativeCutUpperDoubleSpinBox->value() / 100.0 ); // log rendering events, for userspace debugging - mSettings->setValue( QStringLiteral( "/Map/logCanvasRefreshEvent" ), mLogCanvasRefreshChkBx->isChecked() ); + QgsMapRendererJob::Settings::logCanvasRefreshEvent.setValue( mLogCanvasRefreshChkBx->isChecked() ); //check behavior so default projection when new layer is added with no //projection defined... @@ -1856,12 +1856,12 @@ void QgsOptions::saveOptions() // // Locale settings // - mSettings->setValue( QStringLiteral( "locale/userLocale" ), cboTranslation->currentData().toString() ); - mSettings->setValue( QStringLiteral( "locale/overrideFlag" ), grpLocale->isChecked() ); - mSettings->setValue( QStringLiteral( "locale/globalLocale" ), cboGlobalLocale->currentData( ).toString() ); + QgsApplication::Settings::localeUserLocale.setValue( cboTranslation->currentData().toString() ); + QgsApplication::Settings::localeOverrideFlag.setValue( grpLocale->isChecked() ); + QgsApplication::Settings::localeGlobalLocale.setValue( cboGlobalLocale->currentData( ).toString() ); // Number settings - mSettings->setValue( QStringLiteral( "locale/showGroupSeparator" ), cbShowGroupSeparator->isChecked( ) ); + QgsApplication::Settings::localeShowGroupSeparator.setValue( cbShowGroupSeparator->isChecked( ) ); QgsLocalDefaultSettings::setBearingFormat( mBearingFormat.get() ); diff --git a/src/app/qgsprojectproperties.cpp b/src/app/qgsprojectproperties.cpp index ec04358ad434..6ccc1134eb22 100644 --- a/src/app/qgsprojectproperties.cpp +++ b/src/app/qgsprojectproperties.cpp @@ -983,7 +983,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa } cbtsLocale->addItem( QIcon( QStringLiteral( ":/images/flags/%1.svg" ).arg( QLatin1String( "en_US" ) ) ), QLocale( QStringLiteral( "en_US" ) ).nativeLanguageName(), QStringLiteral( "en_US" ) ); - cbtsLocale->setCurrentIndex( cbtsLocale->findData( settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString() ) ); + cbtsLocale->setCurrentIndex( cbtsLocale->findData( QgsApplication::Settings::localeUserLocale.value() ) ); connect( generateTsFileButton, &QPushButton::clicked, this, &QgsProjectProperties::onGenerateTsFileButton ); diff --git a/src/core/network/qgsnetworkaccessmanager.cpp b/src/core/network/qgsnetworkaccessmanager.cpp index 3c4bc09ca978..aa793d749c98 100644 --- a/src/core/network/qgsnetworkaccessmanager.cpp +++ b/src/core/network/qgsnetworkaccessmanager.cpp @@ -654,12 +654,12 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache( Qt::ConnectionType conn int QgsNetworkAccessManager::timeout() { - return QgsSettings().value( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), 60000 ).toInt(); + return Settings::networkTimeout.value(); } void QgsNetworkAccessManager::setTimeout( const int time ) { - QgsSettings().setValue( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), time ); + Settings::networkTimeout.setValue( time ); } QgsNetworkReplyContent QgsNetworkAccessManager::blockingGet( QNetworkRequest &request, const QString &authCfg, bool forceRefresh, QgsFeedback *feedback ) diff --git a/src/core/network/qgsnetworkaccessmanager.h b/src/core/network/qgsnetworkaccessmanager.h index b14800f9e8b6..5911b787c939 100644 --- a/src/core/network/qgsnetworkaccessmanager.h +++ b/src/core/network/qgsnetworkaccessmanager.h @@ -31,6 +31,7 @@ #include "qgis_core.h" #include "qgis_sip.h" +#include "qgssettingsentry.h" class QgsFeedback; @@ -499,6 +500,16 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager */ static QgsNetworkReplyContent blockingPost( QNetworkRequest &request, const QByteArray &data, const QString &authCfg = QString(), bool forceRefresh = false, QgsFeedback *feedback = nullptr ); + /** + * Contains QgsNetworkAccessManager settings + * \since QGIS 3.20 + */ + struct Settings + { + //! Settings entry network timeout + static const inline QgsSettingsEntryInteger networkTimeout = QgsSettingsEntryInteger( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), QgsSettings::NoSection, 60000, QObject::tr( "Network timeout" ) ); + }; + signals: /** diff --git a/src/core/network/qgsnewsfeedparser.cpp b/src/core/network/qgsnewsfeedparser.cpp index 0489ddfc810f..3c1c63eafe8c 100644 --- a/src/core/network/qgsnewsfeedparser.cpp +++ b/src/core/network/qgsnewsfeedparser.cpp @@ -40,24 +40,23 @@ QgsNewsFeedParser::QgsNewsFeedParser( const QUrl &feedUrl, const QString &authcf QUrlQuery query( feedUrl ); - const qint64 after = QgsSettings().value( QStringLiteral( "%1/lastFetchTime" ).arg( mSettingsKey ), 0, QgsSettings::Core ).toUInt(); + const qint64 after = Settings::feedLastFetchTime.value( mSettingsKey ); if ( after > 0 ) query.addQueryItem( QStringLiteral( "after" ), qgsDoubleToString( after, 0 ) ); - QString feedLanguage = QgsSettings().value( QStringLiteral( "%1/lang" ).arg( mSettingsKey ), QString(), QgsSettings::Core ).toString(); + QString feedLanguage = Settings::feedLanguage.value( mSettingsKey ); if ( feedLanguage.isEmpty() ) { - feedLanguage = QgsSettings().value( QStringLiteral( "locale/userLocale" ), QStringLiteral( "en_US" ) ).toString().left( 2 ); + feedLanguage = QgsSettings().value( QgsApplication::Settings::localeUserLocale.key(), QStringLiteral( "en_US" ) ).toString().left( 2 ); } if ( !feedLanguage.isEmpty() && feedLanguage != QLatin1String( "C" ) ) query.addQueryItem( QStringLiteral( "lang" ), feedLanguage ); - bool latOk = false; - bool longOk = false; - const double feedLat = QgsSettings().value( QStringLiteral( "%1/latitude" ).arg( mSettingsKey ), QString(), QgsSettings::Core ).toDouble( &latOk ); - const double feedLong = QgsSettings().value( QStringLiteral( "%1/longitude" ).arg( mSettingsKey ), QString(), QgsSettings::Core ).toDouble( &longOk ); - if ( latOk && longOk ) + if ( Settings::feedLatitude.exists( mSettingsKey ) && Settings::feedLongitude.exists( mSettingsKey ) ) { + const double feedLat = Settings::feedLatitude.value( mSettingsKey ); + const double feedLong = Settings::feedLongitude.value( mSettingsKey ); + // hack to allow testing using local files if ( feedUrl.isLocalFile() ) { @@ -170,7 +169,7 @@ void QgsNewsFeedParser::fetch() void QgsNewsFeedParser::onFetch( const QString &content ) { - QgsSettings().setValue( mSettingsKey + "/lastFetchTime", mFetchStartTime, QgsSettings::Core ); + Settings::feedLastFetchTime.setValue( mFetchStartTime, mSettingsKey ); const QVariant json = QgsJsonUtils::parseJson( content ); diff --git a/src/core/network/qgsnewsfeedparser.h b/src/core/network/qgsnewsfeedparser.h index 9f6f3268722a..17079296d751 100644 --- a/src/core/network/qgsnewsfeedparser.h +++ b/src/core/network/qgsnewsfeedparser.h @@ -17,6 +17,7 @@ #include "qgis_core.h" #include "qgis_sip.h" +#include "qgssettingsentry.h" #include #include #include @@ -110,6 +111,22 @@ class CORE_EXPORT QgsNewsFeedParser : public QObject */ static QString keyForFeed( const QString &baseUrl ); + /** + * Contains QgsNewsFeedParser settings + * \since QGIS 3.20 + */ + struct Settings + { + //! Settings entry last fetch time + static const inline QgsSettingsEntryInteger feedLastFetchTime = QgsSettingsEntryInteger( QStringLiteral( "%/lastFetchTime" ), QgsSettings::Core, 0, QObject::tr( "Feed last fetch time" ), 0 ); + //! Settings entry feed language + static const inline QgsSettingsEntryString feedLanguage = QgsSettingsEntryString( QStringLiteral( "%/lang" ), QgsSettings::Core, QString(), QObject::tr( "Feed language" ) ); + //! Settings entry feed latitude + static const inline QgsSettingsEntryDouble feedLatitude = QgsSettingsEntryDouble( QStringLiteral( "%/latitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed latitude" ) ); + //! Settings entry feed longitude + static const inline QgsSettingsEntryDouble feedLongitude = QgsSettingsEntryDouble( QStringLiteral( "%/longitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed longitude" ) ); + }; + public slots: /** diff --git a/src/core/processing/qgsprocessing.h b/src/core/processing/qgsprocessing.h index d8424016ff7f..ea26ffee824f 100644 --- a/src/core/processing/qgsprocessing.h +++ b/src/core/processing/qgsprocessing.h @@ -19,6 +19,7 @@ #define QGSPROCESSING_H #include "qgis_core.h" +#include "qgssettingsentry.h" #include // @@ -97,6 +98,22 @@ class CORE_EXPORT QgsProcessing * \since QGIS 3.6 */ static const QString TEMPORARY_OUTPUT; + + /** + * Contains QgsProcessing settings + * \since QGIS 3.20 + */ + struct Settings + { + //! Settings entry prefer filename as layer name + static const inline QgsSettingsEntryBool preferFilenameAsLayerName = QgsSettingsEntryBool( QStringLiteral( "Processing/Configuration/PREFER_FILENAME_AS_LAYER_NAME" ), QgsSettings::NoSection, true, QObject::tr( "Prefer filename as layer name" ) ); + //! Settings entry temp path + static const inline QgsSettingsEntryString tempPath = QgsSettingsEntryString( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ), QgsSettings::NoSection, QString() ); + //! Settings entry default output vector layer ext + static const inline QgsSettingsEntryInteger defaultOutputVectorLayerExt = QgsSettingsEntryInteger( QStringLiteral( "Processing/Configuration/DefaultOutputVectorLayerExt" ), QgsSettings::NoSection, -1 ); + //! Settings entry default output raster layer ext + static const inline QgsSettingsEntryInteger defaultOutputRasterLayerExt = QgsSettingsEntryInteger( QStringLiteral( "Processing/Configuration/DefaultOutputRasterLayerExt" ), QgsSettings::NoSection, -1 ); + }; }; #endif // QGSPROCESSING_H diff --git a/src/core/processing/qgsprocessingcontext.cpp b/src/core/processing/qgsprocessingcontext.cpp index cc07c52d46bc..db0af8d12d7b 100644 --- a/src/core/processing/qgsprocessingcontext.cpp +++ b/src/core/processing/qgsprocessingcontext.cpp @@ -197,7 +197,7 @@ void QgsProcessingContext::LayerDetails::setOutputLayerName( QgsMapLayer *layer if ( !layer ) return; - const bool preferFilenameAsLayerName = QgsSettings().value( QStringLiteral( "Processing/Configuration/PREFER_FILENAME_AS_LAYER_NAME" ), true ).toBool(); + const bool preferFilenameAsLayerName = QgsProcessing::Settings::preferFilenameAsLayerName.value(); // note - for temporary layers, we don't use the filename, regardless of user setting (it will be meaningless!) if ( ( !forceName && preferFilenameAsLayerName && !layer->isTemporary() ) || name.isEmpty() ) diff --git a/src/core/processing/qgsprocessingutils.cpp b/src/core/processing/qgsprocessingutils.cpp index ac72c22fdf2f..1d434d78491b 100644 --- a/src/core/processing/qgsprocessingutils.cpp +++ b/src/core/processing/qgsprocessingutils.cpp @@ -954,7 +954,7 @@ QString QgsProcessingUtils::tempFolder() static QString sFolder; static QMutex sMutex; QMutexLocker locker( &sMutex ); - const QString basePath = QgsSettings().value( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ) ).toString(); + const QString basePath = QgsProcessing::Settings::tempPath.value(); if ( basePath.isEmpty() ) { // default setting -- automatically create a temp folder @@ -1211,8 +1211,7 @@ QgsFields QgsProcessingUtils::indicesToFields( const QList &indices, const QString QgsProcessingUtils::defaultVectorExtension() { - QgsSettings settings; - const int setting = settings.value( QStringLiteral( "Processing/Configuration/DefaultOutputVectorLayerExt" ), -1 ).toInt(); + const int setting = QgsProcessing::Settings::defaultOutputVectorLayerExt.value(); if ( setting == -1 ) return QStringLiteral( "gpkg" ); return QgsVectorFileWriter::supportedFormatExtensions().value( setting, QStringLiteral( "gpkg" ) ); @@ -1220,8 +1219,7 @@ QString QgsProcessingUtils::defaultVectorExtension() QString QgsProcessingUtils::defaultRasterExtension() { - QgsSettings settings; - const int setting = settings.value( QStringLiteral( "Processing/Configuration/DefaultOutputRasterLayerExt" ), -1 ).toInt(); + const int setting = QgsProcessing::Settings::defaultOutputRasterLayerExt.value(); if ( setting == -1 ) return QStringLiteral( "tif" ); return QgsRasterFileWriter::supportedFormatExtensions().value( setting, QStringLiteral( "tif" ) ); diff --git a/src/core/project/qgsproject.cpp b/src/core/project/qgsproject.cpp index 181929095f94..3e63e8fc1479 100644 --- a/src/core/project/qgsproject.cpp +++ b/src/core/project/qgsproject.cpp @@ -1356,7 +1356,7 @@ bool QgsProject::readProjectFile( const QString &filename, QgsProject::ReadFlags QgsApplication::profiler()->clear( QStringLiteral( "projectload" ) ); QgsScopedRuntimeProfile profile( tr( "Setting up translations" ), QStringLiteral( "projectload" ) ); - QString localeFileName = QStringLiteral( "%1_%2" ).arg( QFileInfo( projectFile.fileName() ).baseName(), mSettings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString() ); + QString localeFileName = QStringLiteral( "%1_%2" ).arg( QFileInfo( projectFile.fileName() ).baseName(), QgsApplication::Settings::localeUserLocale.value() ); if ( QFile( QStringLiteral( "%1/%2.qm" ).arg( QFileInfo( projectFile.fileName() ).absolutePath(), localeFileName ) ).exists() ) { diff --git a/src/core/qgsapplication.cpp b/src/core/qgsapplication.cpp index b095dc69dc09..f21dead95843 100644 --- a/src/core/qgsapplication.cpp +++ b/src/core/qgsapplication.cpp @@ -1063,7 +1063,7 @@ QString QgsApplication::srsDatabaseFilePath() void QgsApplication::setSvgPaths( const QStringList &svgPaths ) { - QgsSettings().setValue( QStringLiteral( "svg/searchPathsForSVG" ), svgPaths ); + Settings::searchPathsForSVG.setValue( svgPaths ); members()->mSvgPathCacheValid = false; } @@ -1082,8 +1082,7 @@ QStringList QgsApplication::svgPaths() locker.changeMode( QgsReadWriteLocker::Write ); //local directories to search when looking for an SVG with a given basename //defined by user in options dialog - QgsSettings settings; - const QStringList pathList = settings.value( QStringLiteral( "svg/searchPathsForSVG" ) ).toStringList(); + const QStringList pathList = Settings::searchPathsForSVG.value(); // maintain user set order while stripping duplicates QStringList paths; @@ -1225,11 +1224,9 @@ QString QgsApplication::platform() QString QgsApplication::locale() { - QgsSettings settings; - bool overrideLocale = settings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool(); - if ( overrideLocale ) + if ( Settings::localeOverrideFlag.value() ) { - QString locale = settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString(); + QString locale = Settings::localeUserLocale.value(); // don't differentiate en_US and en_GB if ( locale.startsWith( QLatin1String( "en" ), Qt::CaseInsensitive ) ) { diff --git a/src/core/qgsapplication.h b/src/core/qgsapplication.h index 2ea07b19e720..bb2b2110b9c6 100644 --- a/src/core/qgsapplication.h +++ b/src/core/qgsapplication.h @@ -23,6 +23,7 @@ #include "qgis_sip.h" #include "qgsconfig.h" +#include "qgssettingsentry.h" #include "qgstranslationcontext.h" class QgsSettingsRegistryCore; @@ -944,6 +945,24 @@ class CORE_EXPORT QgsApplication : public QApplication */ void collectTranslatableObjects( QgsTranslationContext *translationContext ); + /** + * Contains QgsApplication settings + * \since QGIS 3.20 + */ + struct Settings + { + //! Settings entry locale user locale + static const inline QgsSettingsEntryString localeUserLocale = QgsSettingsEntryString( QStringLiteral( "locale/userLocale" ), QgsSettings::NoSection, QString() ); + //! Settings entry locale override flag + static const inline QgsSettingsEntryBool localeOverrideFlag = QgsSettingsEntryBool( QStringLiteral( "locale/overrideFlag" ), QgsSettings::NoSection, false ); + //! Settings entry locale global locale + static const inline QgsSettingsEntryString localeGlobalLocale = QgsSettingsEntryString( QStringLiteral( "locale/globalLocale" ), QgsSettings::NoSection, QString() ); + //! Settings entry locale show group separator + static const inline QgsSettingsEntryBool localeShowGroupSeparator = QgsSettingsEntryBool( QStringLiteral( "locale/showGroupSeparator" ), QgsSettings::NoSection, false ); + //! Settings entry search path for SVG + static const inline QgsSettingsEntryStringList searchPathsForSVG = QgsSettingsEntryStringList( QStringLiteral( "svg/searchPathsForSVG" ), QgsSettings::NoSection, QStringList() ); + }; + #ifdef SIP_RUN SIP_IF_FEATURE( ANDROID ) //dummy method to workaround sip generation issue diff --git a/src/core/qgsgeometryoptions.cpp b/src/core/qgsgeometryoptions.cpp index 643ee606f1bc..2c37c7c2f859 100644 --- a/src/core/qgsgeometryoptions.cpp +++ b/src/core/qgsgeometryoptions.cpp @@ -23,7 +23,7 @@ QgsGeometryOptions::QgsGeometryOptions() { - mGeometryChecks = QgsSettings().value( QStringLiteral( "geometry_validation/default_checks" ) ).toString().split( ',' ) ; + mGeometryChecks = Settings::geometryValidationDefaultChecks.value().split( ',' ) ; } bool QgsGeometryOptions::removeDuplicateNodes() const diff --git a/src/core/qgsgeometryoptions.h b/src/core/qgsgeometryoptions.h index bceabf4b9348..4ec9fdb1b626 100644 --- a/src/core/qgsgeometryoptions.h +++ b/src/core/qgsgeometryoptions.h @@ -21,6 +21,7 @@ #include "qgis_core.h" #include "qgis_sip.h" #include "qgsgeometry.h" +#include "qgssettingsentry.h" #include @@ -131,6 +132,16 @@ class CORE_EXPORT QgsGeometryOptions : public QObject */ void readXml( const QDomNode &node ); + /** + * Contains QgsGeometryOptions settings + * \since QGIS 3.20 + */ + struct Settings + { + //! Settings entry search path for templates + static const inline QgsSettingsEntryString geometryValidationDefaultChecks = QgsSettingsEntryString( QStringLiteral( "geometry_validation/default_checks" ), QgsSettings::NoSection, QString() ); + }; + signals: /** diff --git a/src/core/qgslocalizeddatapathregistry.cpp b/src/core/qgslocalizeddatapathregistry.cpp index e2749881f5ed..f5bb8911cc99 100644 --- a/src/core/qgslocalizeddatapathregistry.cpp +++ b/src/core/qgslocalizeddatapathregistry.cpp @@ -105,10 +105,10 @@ void QgsLocalizedDataPathRegistry::unregisterPath( const QString &path ) void QgsLocalizedDataPathRegistry::readFromSettings() { - setPaths( QgsSettings().value( QStringLiteral( "/qgis/localized_data_paths" ) ).toStringList() ); + setPaths( Settings::localizedDataPaths.value() ); } void QgsLocalizedDataPathRegistry::writeToSettings() { - QgsSettings().setValue( QStringLiteral( "/qgis/localized_data_paths" ), paths() ); + Settings::localizedDataPaths.setValue( paths() ); } diff --git a/src/core/qgslocalizeddatapathregistry.h b/src/core/qgslocalizeddatapathregistry.h index fc150d8b10da..a686638026fb 100644 --- a/src/core/qgslocalizeddatapathregistry.h +++ b/src/core/qgslocalizeddatapathregistry.h @@ -24,6 +24,7 @@ #include "qgis_core.h" #include "qgis_sip.h" +#include "qgssettingsentry.h" /** * \ingroup core @@ -65,6 +66,16 @@ class CORE_EXPORT QgsLocalizedDataPathRegistry //! Unregisters a localized path void unregisterPath( const QString &path ); + /** + * Contains QgsLocalizedDataPathRegistry settings + * \since QGIS 3.20 + */ + struct Settings + { + //! Settings entry localized data paths + static const inline QgsSettingsEntryStringList localizedDataPaths = QgsSettingsEntryStringList( QStringLiteral( "/qgis/localized_data_paths" ), QgsSettings::NoSection, QStringList() ); + }; + private: #ifdef SIP_RUN QgsLocalizedDataPathRegistry( const QgsLocalizedDataPathRegistry &other ) diff --git a/src/core/qgsmaprendererjob.cpp b/src/core/qgsmaprendererjob.cpp index b1f8ac90dd6a..24667c51d015 100644 --- a/src/core/qgsmaprendererjob.cpp +++ b/src/core/qgsmaprendererjob.cpp @@ -977,8 +977,7 @@ void QgsMapRendererJob::composeSecondPass( LayerRenderJobs &secondPassJobs, Labe void QgsMapRendererJob::logRenderingTime( const LayerRenderJobs &jobs, const LayerRenderJobs &secondPassJobs, const LabelRenderJob &labelJob ) { - QgsSettings settings; - if ( !settings.value( QStringLiteral( "Map/logCanvasRefreshEvent" ), false ).toBool() ) + if ( !Settings::logCanvasRefreshEvent.value() ) return; QMultiMap elapsed; diff --git a/src/core/qgsmaprendererjob.h b/src/core/qgsmaprendererjob.h index 4534a4020059..305bdfdd24c0 100644 --- a/src/core/qgsmaprendererjob.h +++ b/src/core/qgsmaprendererjob.h @@ -29,6 +29,7 @@ #include "qgsmapsettings.h" #include "qgsmaskidprovider.h" +#include "qgssettingsentry.h" class QgsLabelingEngine; @@ -343,6 +344,17 @@ class CORE_EXPORT QgsMapRendererJob : public QObject */ static const QString LABEL_PREVIEW_CACHE_ID SIP_SKIP; + + /** + * Contains QgsMapRendererJob settings + * \since QGIS 3.20 + */ + struct Settings + { + //! Settings entry log canvas refresh event + static const inline QgsSettingsEntryBool logCanvasRefreshEvent = QgsSettingsEntryBool( QStringLiteral( "Map/logCanvasRefreshEvent" ), QgsSettings::NoSection, false ); + }; + signals: /** diff --git a/src/core/settings/qgssettingsregistrycore.cpp b/src/core/settings/qgssettingsregistrycore.cpp index 188028a23f8d..d8bb0274bf58 100644 --- a/src/core/settings/qgssettingsregistrycore.cpp +++ b/src/core/settings/qgssettingsregistrycore.cpp @@ -17,19 +17,73 @@ #include "qgslayout.h" #include "qgslocator.h" +#include "qgsnetworkaccessmanager.h" +#include "qgsnewsfeedparser.h" +#include "qgsprocessing.h" +#include "qgsapplication.h" +#include "qgsgeometryoptions.h" +#include "qgslocalizeddatapathregistry.h" +#include "qgsmaprendererjob.h" QgsSettingsRegistryCore::QgsSettingsRegistryCore() - : mSettingsEntries() + : mSettingsEntriesMap() { - mSettingsEntries.append( &QgsLayout::settingsSearchPathForTemplates ); + addSettingsEntry( &QgsLayout::settingsSearchPathForTemplates ); - mSettingsEntries.append( &QgsLocator::settingsLocatorFilterEnabled ); - mSettingsEntries.append( &QgsLocator::settingsLocatorFilterDefault ); - mSettingsEntries.append( &QgsLocator::settingsLocatorFilterPrefix ); + addSettingsEntry( &QgsLocator::settingsLocatorFilterEnabled ); + addSettingsEntry( &QgsLocator::settingsLocatorFilterDefault ); + addSettingsEntry( &QgsLocator::settingsLocatorFilterPrefix ); + + addSettingsEntry( &QgsNetworkAccessManager::Settings::networkTimeout ); + + addSettingsEntry( &QgsNewsFeedParser::Settings::feedLastFetchTime ); + addSettingsEntry( &QgsNewsFeedParser::Settings::feedLanguage ); + addSettingsEntry( &QgsNewsFeedParser::Settings::feedLatitude ); + addSettingsEntry( &QgsNewsFeedParser::Settings::feedLongitude ); + + addSettingsEntry( &QgsProcessing::Settings::preferFilenameAsLayerName ); + addSettingsEntry( &QgsProcessing::Settings::tempPath ); + addSettingsEntry( &QgsProcessing::Settings::defaultOutputVectorLayerExt ); + addSettingsEntry( &QgsProcessing::Settings::defaultOutputRasterLayerExt ); + + addSettingsEntry( &QgsApplication::Settings::localeUserLocale ); + addSettingsEntry( &QgsApplication::Settings::localeOverrideFlag ); + addSettingsEntry( &QgsApplication::Settings::localeGlobalLocale ); + addSettingsEntry( &QgsApplication::Settings::localeShowGroupSeparator ); + addSettingsEntry( &QgsApplication::Settings::searchPathsForSVG ); + + addSettingsEntry( &QgsGeometryOptions::Settings::geometryValidationDefaultChecks ); + + addSettingsEntry( &QgsLocalizedDataPathRegistry::Settings::localizedDataPaths ); + + addSettingsEntry( &QgsMapRendererJob::Settings::logCanvasRefreshEvent ); } QgsSettingsRegistryCore::~QgsSettingsRegistryCore() { } +const QgsSettingsEntryBase *QgsSettingsRegistryCore::getSettingsEntry( const QString &key ) +{ + if ( mSettingsEntriesMap.contains( key ) ) + return mSettingsEntriesMap.value( key ); + + const QMap dynamicSettingsEntriesMap = mDynamicSettingsEntriesMap; + for ( const QgsSettingsEntryBase *settingsEntry : dynamicSettingsEntriesMap ) + { + QRegularExpression regularExpression( settingsEntry->key( ".*" ) ); + QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( key ); + if ( regularExpresisonMatch.hasMatch() ) + return settingsEntry; + } + + return nullptr; +} +void QgsSettingsRegistryCore::addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ) +{ + if ( settingsEntry->hasDynamicKey() ) + mDynamicSettingsEntriesMap.insert( settingsEntry->key(), settingsEntry ); + else + mSettingsEntriesMap.insert( settingsEntry->key(), settingsEntry ); +} diff --git a/src/core/settings/qgssettingsregistrycore.h b/src/core/settings/qgssettingsregistrycore.h index 933b5d4bfc8c..03398cf7268e 100644 --- a/src/core/settings/qgssettingsregistrycore.h +++ b/src/core/settings/qgssettingsregistrycore.h @@ -21,12 +21,7 @@ #include "qgis_sip.h" #include "qgssettingsentry.h" -#include "qgslayout.h" -#include "qgslocator.h" - -#include - -class QgsSettingsEntryStringList; +#include /** * \ingroup core @@ -50,9 +45,20 @@ class CORE_EXPORT QgsSettingsRegistryCore */ virtual ~QgsSettingsRegistryCore(); + /** + * Returns the QgsSettingsEntry with the given \a key or nullptr if not found. + */ + const QgsSettingsEntryBase *getSettingsEntry( const QString &key ); + + /** + * Add \a settingsEntry to the register. + */ + void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); + private: - QList mSettingsEntries; + QMap mSettingsEntriesMap; + QMap mDynamicSettingsEntriesMap; }; diff --git a/src/gui/qgsconfigureshortcutsdialog.cpp b/src/gui/qgsconfigureshortcutsdialog.cpp index fc514c19e436..5daa3a82d158 100644 --- a/src/gui/qgsconfigureshortcutsdialog.cpp +++ b/src/gui/qgsconfigureshortcutsdialog.cpp @@ -16,6 +16,7 @@ #include "qgsconfigureshortcutsdialog.h" #include "qgsshortcutsmanager.h" +#include "qgsapplication.h" #include "qgslogger.h" #include "qgssettings.h" #include "qgsgui.h" @@ -135,7 +136,7 @@ void QgsConfigureShortcutsDialog::saveShortcuts() QDomDocument doc( QStringLiteral( "shortcuts" ) ); QDomElement root = doc.createElement( QStringLiteral( "qgsshortcuts" ) ); root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) ); - root.setAttribute( QStringLiteral( "locale" ), settings.value( QStringLiteral( "locale/userLocale" ), "en_US" ).toString() ); + root.setAttribute( QStringLiteral( "locale" ), settings.value( QgsApplication::Settings::localeUserLocale.key(), "en_US" ).toString() ); doc.appendChild( root ); settings.beginGroup( mManager->settingsPath() ); @@ -202,13 +203,12 @@ void QgsConfigureShortcutsDialog::loadShortcuts() return; } - QgsSettings settings; QString currentLocale; - bool localeOverrideFlag = settings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool(); + bool localeOverrideFlag = QgsApplication::Settings::localeOverrideFlag.value(); if ( localeOverrideFlag ) { - currentLocale = settings.value( QStringLiteral( "locale/userLocale" ), "en_US" ).toString(); + currentLocale = QgsSettings().value( QgsApplication::Settings::localeUserLocale.key(), "en_US" ).toString(); } else // use QGIS locale { diff --git a/src/gui/qgsgui.cpp b/src/gui/qgsgui.cpp index 5db19edc2fad..1c6636ae11e0 100644 --- a/src/gui/qgsgui.cpp +++ b/src/gui/qgsgui.cpp @@ -174,8 +174,7 @@ void QgsGui::setWindowManager( QgsWindowManagerInterface *manager ) QgsGui::HigFlags QgsGui::higFlags() { - QgsSettings settings; - if ( settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString().startsWith( QLatin1String( "en" ) ) ) + if ( QgsApplication::Settings::localeUserLocale.value().startsWith( QLatin1String( "en" ) ) ) { return HigMenuTextIsTitleCase | HigDialogTitleIsTitleCase; } diff --git a/src/gui/qgsmapcanvas.cpp b/src/gui/qgsmapcanvas.cpp index 0740cfb86e5e..b53df96806f5 100644 --- a/src/gui/qgsmapcanvas.cpp +++ b/src/gui/qgsmapcanvas.cpp @@ -61,6 +61,7 @@ email : sherman at mrcc.com #include "qgsmapoverviewcanvas.h" #include "qgsmaprenderercache.h" #include "qgsmaprenderercustompainterjob.h" +#include "qgsmaprendererjob.h" #include "qgsmaprendererparalleljob.h" #include "qgsmaprenderersequentialjob.h" #include "qgsmapsettingsutils.h" @@ -705,8 +706,7 @@ void QgsMapCanvas::rendererJobFinished() QPainter p( &img ); emit renderComplete( &p ); - QgsSettings settings; - if ( settings.value( QStringLiteral( "Map/logCanvasRefreshEvent" ), false ).toBool() ) + if ( QgsMapRendererJob::Settings::logCanvasRefreshEvent.value() ) { QString logMsg = tr( "Canvas refresh: %1 ms" ).arg( mJob->renderingTime() ); QgsMessageLog::logMessage( logMsg, tr( "Rendering" ) ); diff --git a/tests/src/analysis/testqgsprocessing.cpp b/tests/src/analysis/testqgsprocessing.cpp index f47a4f061fc1..bb0122329060 100644 --- a/tests/src/analysis/testqgsprocessing.cpp +++ b/tests/src/analysis/testqgsprocessing.cpp @@ -2303,11 +2303,11 @@ void TestQgsProcessing::parameters() context2.layersToLoadOnCompletion().values().at( 0 ).setOutputLayerName( rl.get() ); QCOMPARE( rl->name(), QStringLiteral( "landsat" ) ); // unless setting prohibits it... - QgsSettings().setValue( QStringLiteral( "Processing/Configuration/PREFER_FILENAME_AS_LAYER_NAME" ), false ); + QgsProcessing::Settings::preferFilenameAsLayerName.setValue( false ); context2.layersToLoadOnCompletion().values().at( 0 ).setOutputLayerName( rl.get() ); QCOMPARE( rl->name(), QStringLiteral( "my_dest" ) ); // if layer has a layername, we should use that instead of the base file name... - QgsSettings().setValue( QStringLiteral( "Processing/Configuration/PREFER_FILENAME_AS_LAYER_NAME" ), true ); + QgsProcessing::Settings::preferFilenameAsLayerName.setValue( true ); vl = std::make_unique< QgsVectorLayer >( QStringLiteral( TEST_DATA_DIR ) + "/points_gpkg.gpkg|layername=points_small", QString() ); context2.layersToLoadOnCompletion().values().at( 0 ).setOutputLayerName( vl.get() ); QCOMPARE( vl->name(), QStringLiteral( "points_small" ) ); @@ -11042,7 +11042,7 @@ void TestQgsProcessing::tempUtils() QgsSettings settings; QString alternative_tempFolder1 = tempDirPath + QStringLiteral( "/alternative_temp_test_one" ); - settings.setValue( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ), alternative_tempFolder1 ); + QgsProcessing::Settings::tempPath.setValue( alternative_tempFolder1 ); // check folder and if it's constant with alternative temp folder 1 tempFolder = QgsProcessingUtils::tempFolder(); QCOMPARE( tempFolder.left( alternative_tempFolder1.length() ), alternative_tempFolder1 ); @@ -11054,7 +11054,7 @@ void TestQgsProcessing::tempUtils() QVERIFY( alternativeTempFile1.startsWith( alternative_tempFolder1 ) ); // change temp folder in the settings again QString alternative_tempFolder2 = tempDirPath + QStringLiteral( "/alternative_temp_test_two" ); - settings.setValue( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ), alternative_tempFolder2 ); + QgsProcessing::Settings::tempPath.setValue( alternative_tempFolder2 ); // check folder and if it's constant constant with alternative temp folder 2 tempFolder = QgsProcessingUtils::tempFolder(); QCOMPARE( tempFolder.left( alternative_tempFolder2.length() ), alternative_tempFolder2 ); @@ -11064,7 +11064,7 @@ void TestQgsProcessing::tempUtils() QVERIFY( alternativeTempFile2.endsWith( "alternative_temptest.txt" ) ); QVERIFY( alternativeTempFile2.startsWith( tempFolder ) ); QVERIFY( alternativeTempFile2.startsWith( alternative_tempFolder2 ) ); - settings.setValue( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ), QString() ); + QgsProcessing::Settings::tempPath.setValue( QString() ); } @@ -11529,10 +11529,8 @@ void TestQgsProcessing::defaultExtensionsForProvider() QCOMPARE( context.preferredRasterFormat(), QStringLiteral( "tif" ) ); // unless the user has set a default format, which IS supported by that provider - QgsSettings settings; - - settings.setValue( QStringLiteral( "Processing/Configuration/DefaultOutputVectorLayerExt" ), QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "tab" ) ) ); - settings.setValue( QStringLiteral( "Processing/Configuration/DefaultOutputRasterLayerExt" ), QgsRasterFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "sdat" ) ) ); + QgsProcessing::Settings::defaultOutputVectorLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "tab" ) ) ); + QgsProcessing::Settings::defaultOutputRasterLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "sdat" ) ) ); QCOMPARE( provider.defaultVectorFileExtension( true ), QStringLiteral( "tab" ) ); QCOMPARE( provider.defaultRasterFileExtension(), QStringLiteral( "sdat" ) ); @@ -11543,8 +11541,8 @@ void TestQgsProcessing::defaultExtensionsForProvider() QCOMPARE( context2.preferredRasterFormat(), QStringLiteral( "sdat" ) ); // but if default is not supported by provider, we use a supported format - settings.setValue( QStringLiteral( "Processing/Configuration/DefaultOutputVectorLayerExt" ), QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "gpkg" ) ) ); - settings.setValue( QStringLiteral( "Processing/Configuration/DefaultOutputRasterLayerExt" ), QgsRasterFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "ecw" ) ) ); + QgsProcessing::Settings::defaultOutputVectorLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "gpkg" ) ) ); + QgsProcessing::Settings::defaultOutputRasterLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "ecw" ) ) ); QCOMPARE( provider.defaultVectorFileExtension( true ), QStringLiteral( "mif" ) ); QCOMPARE( provider.defaultRasterFileExtension(), QStringLiteral( "mig" ) ); } diff --git a/tests/src/core/testqgscompositionconverter.cpp b/tests/src/core/testqgscompositionconverter.cpp index 3a1ab011ef26..b973c7165c16 100644 --- a/tests/src/core/testqgscompositionconverter.cpp +++ b/tests/src/core/testqgscompositionconverter.cpp @@ -163,8 +163,7 @@ void TestQgsCompositionConverter::initTestCase() QgsApplication::init(); QgsApplication::initQgis(); mReport = QStringLiteral( "

Layout Tests

\n" ); - QgsSettings settings; - settings.setValue( QStringLiteral( "svg/searchPathsForSVG" ), QStringLiteral( TEST_DATA_DIR ) ) ; + QgsApplication::Settings::searchPathsForSVG.setValue( QStringLiteral( TEST_DATA_DIR ) ); } void TestQgsCompositionConverter::cleanupTestCase() diff --git a/tests/src/core/testqgsnetworkaccessmanager.cpp b/tests/src/core/testqgsnetworkaccessmanager.cpp index d96627ffa4f2..e38294750b31 100644 --- a/tests/src/core/testqgsnetworkaccessmanager.cpp +++ b/tests/src/core/testqgsnetworkaccessmanager.cpp @@ -175,7 +175,7 @@ void TestQgsNetworkAccessManager::initTestCase() QgsApplication::init(); QgsApplication::initQgis(); - QgsSettings().setValue( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), 5000 ); + QgsNetworkAccessManager::Settings::networkTimeout.setValue( 5000 ); mHttpBinHost = QStringLiteral( "httpbin.org" ); QString overrideHost = qgetenv( "QGIS_HTTPBIN_HOST" ); diff --git a/tests/src/core/testqgsnewsfeedparser.cpp b/tests/src/core/testqgsnewsfeedparser.cpp index b8369ad5368b..9601ad9b84f9 100644 --- a/tests/src/core/testqgsnewsfeedparser.cpp +++ b/tests/src/core/testqgsnewsfeedparser.cpp @@ -111,12 +111,12 @@ void TestQgsNewsFeedParser::testFetch() entries.clear(); // after a fetch, the current timestamp should be saved to avoid refetching these - uint after = QgsSettings().value( feedKey + "/lastFetchTime", 0, QgsSettings::Core ).toUInt(); + uint after = QgsNewsFeedParser::Settings::feedLastFetchTime.value( feedKey ); QVERIFY( after >= beforeTime ); // reset to a standard known last time QgsSettings().remove( feedKey, QgsSettings::Core ); - QgsSettings().setValue( feedKey + "/lastFetchTime", 1457360008, QgsSettings::Core ); + QgsNewsFeedParser::Settings::feedLastFetchTime.setValue( 1457360008, feedKey ); // refetch, only new items should be fetched QgsNewsFeedParser parser2( url ); @@ -230,7 +230,7 @@ void TestQgsNewsFeedParser::testLang() const QString feedKey = QgsNewsFeedParser::keyForFeed( url.toString() ); QgsSettings().remove( feedKey, QgsSettings::Core ); // force to Spanish language - QgsSettings().setValue( QStringLiteral( "%1/lang" ).arg( feedKey ), QStringLiteral( "es" ), QgsSettings::Core ); + QgsNewsFeedParser::Settings::feedLanguage.setValue( QStringLiteral( "es" ), feedKey ); QgsNewsFeedParser parser( url ); QSignalSpy spy( &parser, &QgsNewsFeedParser::entryAdded ); @@ -256,8 +256,8 @@ void TestQgsNewsFeedParser::testGeoFencing() const QUrl url( QUrl::fromLocalFile( QStringLiteral( TEST_DATA_DIR ) + "/newsfeed/feed" ) ); const QString feedKey = QgsNewsFeedParser::keyForFeed( url.toString() ); QgsSettings().remove( feedKey, QgsSettings::Core ); - QgsSettings().setValue( QStringLiteral( "%1/latitude" ).arg( feedKey ), 37.2343, QgsSettings::Core ); - QgsSettings().setValue( QStringLiteral( "%1/longitude" ).arg( feedKey ), -115.8067, QgsSettings::Core ); + QgsNewsFeedParser::Settings::feedLatitude.setValue( 37.2343, feedKey ); + QgsNewsFeedParser::Settings::feedLongitude.setValue( -115.8067, feedKey ); QgsNewsFeedParser parser( url ); QSignalSpy spy( &parser, &QgsNewsFeedParser::entryAdded ); diff --git a/tests/src/core/testqgstranslateproject.cpp b/tests/src/core/testqgstranslateproject.cpp index f1be8ab0ba68..5c1cf04339fe 100644 --- a/tests/src/core/testqgstranslateproject.cpp +++ b/tests/src/core/testqgstranslateproject.cpp @@ -47,7 +47,6 @@ class TestQgsTranslateProject : public QObject void translateProject(); private: - QgsSettings settings; QString original_locale; }; @@ -58,12 +57,12 @@ void TestQgsTranslateProject::initTestCase() QgsApplication::init(); QgsApplication::initQgis(); - original_locale = settings.value( QStringLiteral( "locale/userLocale" ), "" ).toString() ; + original_locale = QgsApplication::Settings::localeUserLocale.value(); } void TestQgsTranslateProject::cleanupTestCase() { - settings.setValue( QStringLiteral( "locale/userLocale" ), original_locale ); + QgsApplication::Settings::localeUserLocale.setValue( original_locale ); QgsApplication::exitQgis(); //delete translated project file @@ -92,7 +91,7 @@ void TestQgsTranslateProject::cleanup() void TestQgsTranslateProject::createTsFile() { //open project in english - settings.setValue( QStringLiteral( "locale/userLocale" ), "en" ); + QgsApplication::Settings::localeUserLocale.setValue( "en" ); QString projectFileName( TEST_DATA_DIR ); projectFileName = projectFileName + "/project_translation/points_translation.qgs"; QgsProject::instance()->read( projectFileName ); @@ -164,7 +163,7 @@ void TestQgsTranslateProject::createTsFile() void TestQgsTranslateProject::translateProject() { //open project in german - settings.setValue( QStringLiteral( "locale/userLocale" ), "de" ); + QgsApplication::Settings::localeUserLocale.setValue( "de" ); QString projectFileName( TEST_DATA_DIR ); projectFileName = projectFileName + "/project_translation/points_translation.qgs"; QgsProject::instance()->read( projectFileName ); From 65163814ff15f58c46eadb33985360a241baed02 Mon Sep 17 00:00:00 2001 From: Damiano Date: Thu, 8 Apr 2021 23:41:05 +0200 Subject: [PATCH 02/13] Added QgsSettingsRegistry base class --- .../settings/qgssettingsentry.sip.in | 217 ++---------------- .../settings/qgssettingsregistrycore.sip.in | 12 +- src/core/CMakeLists.txt | 2 + src/core/settings/qgssettingsentry.cpp | 12 + src/core/settings/qgssettingsentry.h | 7 + src/core/settings/qgssettingsregistry.cpp | 61 +++++ src/core/settings/qgssettingsregistry.h | 65 ++++++ src/core/settings/qgssettingsregistrycore.cpp | 27 +-- src/core/settings/qgssettingsregistrycore.h | 19 +- tests/src/core/CMakeLists.txt | 1 + tests/src/core/testqgssettings.cpp | 2 +- tests/src/core/testqgssettingsentry.cpp | 3 +- tests/src/core/testqgssettingsregistry.cpp | 76 ++++++ 13 files changed, 256 insertions(+), 248 deletions(-) create mode 100644 src/core/settings/qgssettingsregistry.cpp create mode 100644 src/core/settings/qgssettingsregistry.h create mode 100644 tests/src/core/testqgssettingsregistry.cpp diff --git a/python/core/auto_generated/settings/qgssettingsentry.sip.in b/python/core/auto_generated/settings/qgssettingsentry.sip.in index 617bcd4cf5a5..5decd372b97f 100644 --- a/python/core/auto_generated/settings/qgssettingsentry.sip.in +++ b/python/core/auto_generated/settings/qgssettingsentry.sip.in @@ -75,13 +75,6 @@ The ``description`` argument specifies a description for the settings entry. Get settings entry key. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -%End - - QString key( const QStringList &dynamicKeyPartList ) const; -%Docstring -Get settings entry key. - -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. %End bool hasDynamicKey() const; @@ -94,13 +87,6 @@ Returns true if a part of the settings key is built dynamically. Returns true if the settings is contained in the underlying QSettings. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -%End - - bool exists( const QStringList &dynamicKeyPartList ) const; -%Docstring -Returns true if the settings is contained in the underlying QSettings. - -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. %End void remove( const QString &dynamicKeyPart = QString() ) const; @@ -108,13 +94,6 @@ The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the sett Removes the settings from the underlying QSettings. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -%End - - void remove( const QStringList &dynamicKeyPartList ) const; -%Docstring -Removes the settings from the underlying QSettings. - -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. %End QgsSettings::Section section() const; @@ -122,38 +101,18 @@ The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the sett Get settings section. The settings section of the parent group is returned if available. %End - virtual bool setVariantValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; + virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; %Docstring Set settings value. -The ``value`` to set. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. %End - virtual bool setVariantValue( const QVariant &value, const QStringList &dynamicKeyPartList ) const; -%Docstring -Set settings value. - -The ``value`` to set. -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. -%End - - QVariant valueAsVariant( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, const QVariant &defaultValueOverride = QVariant() ) const; + QVariant valueAsVariant( const QString &dynamicKeyPart = QString() ) const; %Docstring Get settings value. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. -The ``defaultValueOverride`` argument if valid is used instead of the normal default value. -%End - - QVariant valueAsVariant( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, const QVariant &defaultValueOverride = QVariant() ) const; -%Docstring -Get settings value. - -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. -The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. -The ``defaultValueOverride`` argument if valid is used instead of the normal default value. %End QVariant defaultValueAsVariant() const; @@ -202,38 +161,18 @@ The ``default`` value argument specifies the default value for the settings entr The ``description`` argument specifies a description for the settings entry. %End - bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; -%Docstring -Set settings value. -The ``value`` to set. -The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -%End + virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; - bool setValue( const QVariant &value, const QStringList &dynamicKeyPartList ) const; %Docstring -Set settings value. - -The ``value`` to set. -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +\copydoc :py:class:`QgsSettingsEntryBase`.setValue %End - QVariant value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, const QVariant &defaultValueOverride = QVariant() ) const; + QVariant value( const QString &dynamicKeyPart = QString() ) const; %Docstring Get settings value. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. -The ``defaultValueOverride`` argument if valid is used instead of the normal default value. -%End - - QVariant value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, const QVariant &defaultValueOverride = QVariant() ) const; -%Docstring -Get settings value. - -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. -The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. -The ``defaultValueOverride`` argument if valid is used instead of the normal default value. %End QVariant defaultValue() const; @@ -264,7 +203,7 @@ A string settings entry. QgsSettingsEntryString( const QString &key, const QString &pluginName, - const QString &defaultValue = QString(), + const QVariant &defaultValue = QVariant(), const QString &description = QString() ); %Docstring Constructor for QgsSettingsEntryString. @@ -276,38 +215,17 @@ The ``default`` value argument specifies the default value for the settings entr The ``description`` argument specifies a description for the settings entry. %End - bool setValue( const QString &value, const QString &dynamicKeyPart = QString() ) const; -%Docstring -Set settings value. + virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; -The ``value`` to set. -The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -%End - - bool setValue( const QString &value, const QStringList &dynamicKeyPartList ) const; %Docstring -Set settings value. - -The ``value`` to set. -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +\copydoc :py:class:`QgsSettingsEntryBase`.setValue %End - QString value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, const QString &defaultValueOverride = QString() ) const; + QString value( const QString &dynamicKeyPart = QString() ) const; %Docstring Get settings value. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. -The ``defaultValueOverride`` argument if valid is used instead of the normal default value. -%End - - QString value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, const QString &defaultValueOverride = QString() ) const; -%Docstring -Get settings value. - -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. -The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. -The ``defaultValueOverride`` argument if valid is used instead of the normal default value. %End QString defaultValue() const; @@ -363,7 +281,7 @@ A string list settings entry. QgsSettingsEntryStringList( const QString &key, const QString &pluginName, - const QStringList &defaultValue = QStringList(), + const QVariant &defaultValue = QVariant(), const QString &description = QString() ); %Docstring Constructor for QgsSettingsEntryStringList. @@ -375,38 +293,17 @@ The ``default`` value argument specifies the default value for the settings entr The ``description`` argument specifies a description for the settings entry. %End - bool setValue( const QStringList &value, const QString &dynamicKeyPart = QString() ) const; -%Docstring -Set settings value. + virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; -The ``value`` to set. -The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -%End - - bool setValue( const QStringList &value, const QStringList &dynamicKeyPartList ) const; %Docstring -Set settings value. - -The ``value`` to set. -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +\copydoc :py:class:`QgsSettingsEntryBase`.setValue %End - QStringList value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, const QStringList &defaultValueOverride = QStringList() ) const; + QStringList value( const QString &dynamicKeyPart = QString() ) const; %Docstring Get settings value. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. -The ``defaultValueOverride`` argument if valid is used instead of the normal default value. -%End - - QStringList value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, const QStringList &defaultValueOverride = QStringList() ) const; -%Docstring -Get settings value. - -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. -The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. -The ``defaultValueOverride`` argument if valid is used instead of the normal default value. %End QStringList defaultValue() const; @@ -438,7 +335,7 @@ A boolean settings entry. QgsSettingsEntryBool( const QString &key, const QString &pluginName, - bool defaultValue = false, + const QVariant &defaultValue = QVariant(), const QString &description = QString() ); %Docstring Constructor for QgsSettingsEntryBool. @@ -450,38 +347,17 @@ The ``default`` value argument specifies the default value for the settings entr The ``description`` argument specifies a description for the settings entry. %End - bool setValue( bool value, const QString &dynamicKeyPart = QString() ) const; -%Docstring -Set settings value. + virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; -The ``value`` to set. -The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -%End - - bool setValue( bool value, const QStringList &dynamicKeyPartList ) const; %Docstring -Set settings value. - -The ``value`` to set. -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +\copydoc :py:class:`QgsSettingsEntryBase`.setValue %End - bool value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, bool defaultValueOverride = false ) const; + bool value( const QString &dynamicKeyPart = QString() ) const; %Docstring Get settings value. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. -The ``defaultValueOverride`` argument if valid is used instead of the normal default value. -%End - - bool value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, bool defaultValueOverride = false ) const; -%Docstring -Get settings value. - -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. -The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. -The ``defaultValueOverride`` argument if valid is used instead of the normal default value. %End bool defaultValue() const; @@ -513,7 +389,7 @@ An integer settings entry. QgsSettingsEntryInteger( const QString &key, const QString &pluginName, - qlonglong defaultValue = 0, + const QVariant &defaultValue = QVariant(), const QString &description = QString() ); %Docstring Constructor for QgsSettingsEntryInteger. @@ -525,38 +401,18 @@ The ``default`` value argument specifies the default value for the settings entr The ``description`` argument specifies a description for the settings entry. %End - bool setValue( qlonglong value, const QString &dynamicKeyPart = QString() ) const; -%Docstring -Set settings value. -The ``value`` to set. -The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -%End + virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; - bool setValue( qlonglong value, const QStringList &dynamicKeyPartList ) const; %Docstring -Set settings value. - -The ``value`` to set. -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +\copydoc :py:class:`QgsSettingsEntryBase`.setValue %End - qlonglong value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, qlonglong defaultValueOverride = 0 ) const; + qlonglong value( const QString &dynamicKeyPart = QString() ) const; %Docstring Get settings value. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. -The ``defaultValueOverride`` argument if valid is used instead of the normal default value. -%End - - qlonglong value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, qlonglong defaultValueOverride = 0 ) const; -%Docstring -Get settings value. - -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. -The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. -The ``defaultValueOverride`` argument if valid is used instead of the normal default value. %End qlonglong defaultValue() const; @@ -612,7 +468,7 @@ A double settings entry. QgsSettingsEntryDouble( const QString &key, const QString &pluginName, - double defaultValue, + const QVariant &defaultValue = QVariant(), const QString &description = QString() ); %Docstring Constructor for QgsSettingsEntryDouble. @@ -624,38 +480,17 @@ The ``default`` value argument specifies the default value for the settings entr The ``description`` argument specifies a description for the settings entry. %End - bool setValue( double value, const QString &dynamicKeyPart = QString() ) const; -%Docstring -Set settings value. - -The ``value`` to set. -The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -%End + virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; - bool setValue( double value, const QStringList &dynamicKeyPartList ) const; %Docstring -Set settings value. - -The ``value`` to set. -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +\copydoc :py:class:`QgsSettingsEntryBase`.setValue %End - double value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, double defaultValueOverride = 0.0 ) const; + double value( const QString &dynamicKeyPart = QString() ) const; %Docstring Get settings value. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. -The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. -The ``defaultValueOverride`` argument if valid is used instead of the normal default value. -%End - - double value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, double defaultValueOverride = 0.0 ) const; -%Docstring -Get settings value. - -The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. -The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. -The ``defaultValueOverride`` argument if valid is used instead of the normal default value. %End double defaultValue() const; @@ -710,8 +545,6 @@ Returns how much decimals should be shown in the Gui. - - /************************************************************************ * This file has been generated automatically from * * * diff --git a/python/core/auto_generated/settings/qgssettingsregistrycore.sip.in b/python/core/auto_generated/settings/qgssettingsregistrycore.sip.in index 9284a092ce8d..5517cc40cb71 100644 --- a/python/core/auto_generated/settings/qgssettingsregistrycore.sip.in +++ b/python/core/auto_generated/settings/qgssettingsregistrycore.sip.in @@ -10,7 +10,7 @@ -class QgsSettingsRegistryCore +class QgsSettingsRegistryCore : QgsSettingsRegistry { %Docstring(signature="appended") :py:class:`QgsSettingsRegistryCore` is used for settings introspection and collects all @@ -31,16 +31,6 @@ Constructor for QgsSettingsRegistryCore. virtual ~QgsSettingsRegistryCore(); - const QgsSettingsEntryBase *getSettingsEntry( const QString &key ); -%Docstring -Returns the :py:class:`QgsSettingsEntry` with the given ``key`` or None if not found. -%End - - void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); -%Docstring -Add ``settingsEntry`` to the register. -%End - }; /************************************************************************ diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 5e2aa49f9f65..23196cc59e27 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -718,6 +718,7 @@ set(QGIS_CORE_SRCS geocms/geonode/qgsgeonoderequest.cpp settings/qgssettingsentry.cpp + settings/qgssettingsregistry.cpp settings/qgssettingsregistrycore.cpp validity/qgsabstractvaliditycheck.cpp @@ -1562,6 +1563,7 @@ set(QGIS_CORE_HDRS textrenderer/qgstextshadowsettings.h settings/qgssettingsentry.h + settings/qgssettingsregistry.h settings/qgssettingsregistrycore.h validity/qgsabstractvaliditycheck.h diff --git a/src/core/settings/qgssettingsentry.cpp b/src/core/settings/qgssettingsentry.cpp index 0f6510d33631..f1de37748007 100644 --- a/src/core/settings/qgssettingsentry.cpp +++ b/src/core/settings/qgssettingsentry.cpp @@ -80,6 +80,18 @@ QString QgsSettingsEntryBase::key( const QStringList &dynamicKeyPartList ) const completeKey.replace( QString( "%%1" ).arg( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) ); } } +} + +QString QgsSettingsEntryBase::definitionKey() const +{ + QString completeKey = mKey; + if ( !mPluginName.isEmpty() ) + { + if ( completeKey.startsWith( '/' ) ) + completeKey.remove( 0, 1 ); + completeKey.prepend( mPluginName + "/" ); + } + return completeKey; } diff --git a/src/core/settings/qgssettingsentry.h b/src/core/settings/qgssettingsentry.h index 2b11e0d712c6..caa46eab9156 100644 --- a/src/core/settings/qgssettingsentry.h +++ b/src/core/settings/qgssettingsentry.h @@ -119,6 +119,13 @@ class CORE_EXPORT QgsSettingsEntryBase */ QString key( const QStringList &dynamicKeyPartList ) const; + /** + * Returns settings entry defining key. + * For dynamic settings it return the key with the placeholder for dynamic part + * included. For non-dynamic settings returns the same as key(). + */ + QString definitionKey() const; + /** * Returns true if a part of the settings key is built dynamically. */ diff --git a/src/core/settings/qgssettingsregistry.cpp b/src/core/settings/qgssettingsregistry.cpp new file mode 100644 index 000000000000..cd96408a51a6 --- /dev/null +++ b/src/core/settings/qgssettingsregistry.cpp @@ -0,0 +1,61 @@ +/*************************************************************************** + qgssettingsregistry.cpp + -------------------------------------- + Date : February 2021 + Copyright : (C) 2021 by Damiano Lombardi + Email : damiano at opengis dot ch + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgssettingsregistry.h" + +#include "qgslayout.h" +#include "qgslocator.h" +#include "qgsnetworkaccessmanager.h" +#include "qgsnewsfeedparser.h" +#include "qgsprocessing.h" +#include "qgsapplication.h" +#include "qgsgeometryoptions.h" +#include "qgslocalizeddatapathregistry.h" +#include "qgsmaprendererjob.h" + +QgsSettingsRegistry::QgsSettingsRegistry() + : mSettingsEntriesMap() + , mDynamicSettingsEntriesMap() +{ +} + +QgsSettingsRegistry::~QgsSettingsRegistry() +{ +} + +const QgsSettingsEntryBase *QgsSettingsRegistry::getSettingsEntry( const QString &key ) +{ + if ( mSettingsEntriesMap.contains( key ) ) + return mSettingsEntriesMap.value( key ); + + const QMap dynamicSettingsEntriesMap = mDynamicSettingsEntriesMap; + for ( const QgsSettingsEntryBase *settingsEntry : dynamicSettingsEntriesMap ) + { + QRegularExpression regularExpression( settingsEntry->key( ".*" ) ); + QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( key ); + if ( regularExpresisonMatch.hasMatch() ) + return settingsEntry; + } + + return nullptr; +} + +void QgsSettingsRegistry::addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ) +{ + if ( settingsEntry->hasDynamicKey() ) + mDynamicSettingsEntriesMap.insert( settingsEntry->definitionKey(), settingsEntry ); + else + mSettingsEntriesMap.insert( settingsEntry->key(), settingsEntry ); +} diff --git a/src/core/settings/qgssettingsregistry.h b/src/core/settings/qgssettingsregistry.h new file mode 100644 index 000000000000..77d96daf6d52 --- /dev/null +++ b/src/core/settings/qgssettingsregistry.h @@ -0,0 +1,65 @@ +/*************************************************************************** + qgssettingsregistry.h + -------------------------------------- + Date : February 2021 + Copyright : (C) 2021 by Damiano Lombardi + Email : damiano at opengis dot ch + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + + +#ifndef QGSSETTINGSREGISTRY_H +#define QGSSETTINGSREGISTRY_H + +#include "qgis_core.h" +#include "qgis_sip.h" +#include "qgssettingsentry.h" + +#include + +/** + * \ingroup core + * \class QgsSettingsRegistry + * QgsSettingsRegistry is used for settings introspection and collects a + * list of child QgsSettingsRegistry and a list of child QgsSettingsRegistry + * + * \since QGIS 3.20 + */ +class CORE_EXPORT QgsSettingsRegistry +{ + public: + + /** + * Constructor for QgsSettingsRegistry. + */ + QgsSettingsRegistry(); + + /** + * Destructor for QgsSettingsRegistry. + */ + virtual ~QgsSettingsRegistry(); + + /** + * Returns the QgsSettingsEntry with the given \a key or nullptr if not found. + */ + const QgsSettingsEntryBase *getSettingsEntry( const QString &key ); + + /** + * Add \a settingsEntry to the register. + */ + void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); + + private: + + QMap mSettingsEntriesMap; + QMap mDynamicSettingsEntriesMap; + +}; + +#endif // QGSSETTINGSREGISTRY_H diff --git a/src/core/settings/qgssettingsregistrycore.cpp b/src/core/settings/qgssettingsregistrycore.cpp index d8bb0274bf58..e163f8e2dbcb 100644 --- a/src/core/settings/qgssettingsregistrycore.cpp +++ b/src/core/settings/qgssettingsregistrycore.cpp @@ -26,7 +26,7 @@ #include "qgsmaprendererjob.h" QgsSettingsRegistryCore::QgsSettingsRegistryCore() - : mSettingsEntriesMap() + : QgsSettingsRegistry() { addSettingsEntry( &QgsLayout::settingsSearchPathForTemplates ); @@ -62,28 +62,3 @@ QgsSettingsRegistryCore::QgsSettingsRegistryCore() QgsSettingsRegistryCore::~QgsSettingsRegistryCore() { } - -const QgsSettingsEntryBase *QgsSettingsRegistryCore::getSettingsEntry( const QString &key ) -{ - if ( mSettingsEntriesMap.contains( key ) ) - return mSettingsEntriesMap.value( key ); - - const QMap dynamicSettingsEntriesMap = mDynamicSettingsEntriesMap; - for ( const QgsSettingsEntryBase *settingsEntry : dynamicSettingsEntriesMap ) - { - QRegularExpression regularExpression( settingsEntry->key( ".*" ) ); - QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( key ); - if ( regularExpresisonMatch.hasMatch() ) - return settingsEntry; - } - - return nullptr; -} - -void QgsSettingsRegistryCore::addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ) -{ - if ( settingsEntry->hasDynamicKey() ) - mDynamicSettingsEntriesMap.insert( settingsEntry->key(), settingsEntry ); - else - mSettingsEntriesMap.insert( settingsEntry->key(), settingsEntry ); -} diff --git a/src/core/settings/qgssettingsregistrycore.h b/src/core/settings/qgssettingsregistrycore.h index 03398cf7268e..0f435cc5c257 100644 --- a/src/core/settings/qgssettingsregistrycore.h +++ b/src/core/settings/qgssettingsregistrycore.h @@ -19,7 +19,7 @@ #include "qgis_core.h" #include "qgis_sip.h" -#include "qgssettingsentry.h" +#include "qgssettingsregistry.h" #include @@ -31,7 +31,7 @@ * * \since QGIS 3.20 */ -class CORE_EXPORT QgsSettingsRegistryCore +class CORE_EXPORT QgsSettingsRegistryCore : public QgsSettingsRegistry { public: @@ -45,21 +45,6 @@ class CORE_EXPORT QgsSettingsRegistryCore */ virtual ~QgsSettingsRegistryCore(); - /** - * Returns the QgsSettingsEntry with the given \a key or nullptr if not found. - */ - const QgsSettingsEntryBase *getSettingsEntry( const QString &key ); - - /** - * Add \a settingsEntry to the register. - */ - void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); - - private: - - QMap mSettingsEntriesMap; - QMap mDynamicSettingsEntriesMap; - }; #endif // QGSSETTINGSREGISTRYCORE_H diff --git a/tests/src/core/CMakeLists.txt b/tests/src/core/CMakeLists.txt index 61acef4e54f0..a574b1601a7d 100644 --- a/tests/src/core/CMakeLists.txt +++ b/tests/src/core/CMakeLists.txt @@ -189,6 +189,7 @@ set(TESTS testqgsruntimeprofiler.cpp testqgssettings.cpp testqgssettingsentry.cpp + testqgssettingsregistry.cpp testqgsshapeburst.cpp testqgssimplemarker.cpp testqgssnappingutils.cpp diff --git a/tests/src/core/testqgssettings.cpp b/tests/src/core/testqgssettings.cpp index 3da66e690e2e..cb467869443a 100644 --- a/tests/src/core/testqgssettings.cpp +++ b/tests/src/core/testqgssettings.cpp @@ -23,7 +23,7 @@ /** * \ingroup UnitTests - * This is a unit test for the operations on curve geometries + * This is a unit test for the enum and flag functions of QgsSettings */ class TestQgsSettings : public QObject { diff --git a/tests/src/core/testqgssettingsentry.cpp b/tests/src/core/testqgssettingsentry.cpp index f060258a02c0..eb50321c88bb 100644 --- a/tests/src/core/testqgssettingsentry.cpp +++ b/tests/src/core/testqgssettingsentry.cpp @@ -24,7 +24,8 @@ /** * \ingroup UnitTests - * This is a unit test for the operations on curve geometries + * This is a unit test for QgsSettingsEntry classes + * \note Most functions are covered in the python test */ class TestQgsSettingsEntry : public QObject { diff --git a/tests/src/core/testqgssettingsregistry.cpp b/tests/src/core/testqgssettingsregistry.cpp new file mode 100644 index 000000000000..6139dd948c2b --- /dev/null +++ b/tests/src/core/testqgssettingsregistry.cpp @@ -0,0 +1,76 @@ +/*************************************************************************** + testqgssettingregistry.cpp + -------------------------------------- + Date : 08.04.2021 + Copyright : (C) 2021 by Damiano Lombardi + Email : damiano@opengis.ch + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#include + +#include "qgssettingsentry.h" +#include "qgssettingsregistry.h" +#include "qgsunittypes.h" +#include "qgsmaplayerproxymodel.h" +#include "qgstest.h" + + +/** + * \ingroup UnitTests + * This is a unit test for the QgsSettingsRegistry classes + */ +class TestQgsSettingsRegistry : public QObject +{ + Q_OBJECT + + private slots: + void getSettingsEntries(); + void getSettingsEntriesWithDynamicKeys(); +}; + +void TestQgsSettingsRegistry::getSettingsEntries() +{ + QString settingsEntryBoolKey( "/qgis/testing/settingsEntryBool" ); + QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false ); + QString settingsEntryIntegerKey( "/qgis/testing/settingsEntryInteger" ); + QgsSettingsEntryBool settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 ); + + QString settingsEntryInexisting( "/qgis/testing/settingsEntryInexisting" ); + + QgsSettingsRegistry settingsRegistry; + settingsRegistry.addSettingsEntry( &settingsEntryBool ); + settingsRegistry.addSettingsEntry( &settingsEntryInteger ); + + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey ), &settingsEntryBool ); + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey ), &settingsEntryInteger ); + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryInexisting ), nullptr ); +} + +void TestQgsSettingsRegistry::getSettingsEntriesWithDynamicKeys() +{ + QString settingsEntryBoolKey( "/qgis/testing/%_settingsEntryBool" ); + QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false ); + QString settingsEntryIntegerKey( "/qgis/testing/%/settingsEntryInteger" ); + QgsSettingsEntryBool settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 ); + + QString settingsEntryInexisting( "/qgis/testing/settingsEntryInexisting%" ); + + QgsSettingsRegistry settingsRegistry; + settingsRegistry.addSettingsEntry( &settingsEntryBool ); + settingsRegistry.addSettingsEntry( &settingsEntryInteger ); + + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey ), &settingsEntryBool ); + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey.replace( "%", "1st" ) ), &settingsEntryBool ); + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey.replace( "%", "Second" ) ), &settingsEntryInteger ); + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey ), &settingsEntryInteger ); + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryInexisting ), nullptr ); +} + +QGSTEST_MAIN( TestQgsSettingsRegistry ) +#include "testqgssettingsregistry.moc" From 2087a7f4f81771f202ea3eb2c9f3881aa678d247 Mon Sep 17 00:00:00 2001 From: Damiano Date: Thu, 15 Apr 2021 17:32:59 +0200 Subject: [PATCH 03/13] Removed settings struct --- .../network/qgsnetworkaccessmanager.sip.in | 5 +- .../network/qgsnewsfeedparser.sip.in | 11 +- .../processing/qgsprocessing.sip.in | 11 +- .../core/auto_generated/qgsapplication.sip.in | 13 +- .../auto_generated/qgsgeometryoptions.sip.in | 5 +- .../qgslocalizeddatapathregistry.sip.in | 5 +- .../auto_generated/qgsmaprendererjob.sip.in | 6 +- .../settings/qgssettingsentry.sip.in | 224 ++++++++++++++++-- .../settings/qgssettingsregistry.sip.in | 52 ++++ python/core/core_auto.sip | 1 + src/app/main.cpp | 12 +- src/app/options/qgsoptions.cpp | 20 +- src/app/qgsprojectproperties.cpp | 2 +- src/core/network/qgsnetworkaccessmanager.cpp | 4 +- src/core/network/qgsnetworkaccessmanager.h | 11 +- src/core/network/qgsnewsfeedparser.cpp | 14 +- src/core/network/qgsnewsfeedparser.h | 23 +- src/core/processing/qgsprocessing.h | 23 +- src/core/processing/qgsprocessingcontext.cpp | 2 +- src/core/processing/qgsprocessingutils.cpp | 6 +- src/core/project/qgsproject.cpp | 2 +- src/core/qgsapplication.cpp | 8 +- src/core/qgsapplication.h | 27 +-- src/core/qgsgeometryoptions.cpp | 2 +- src/core/qgsgeometryoptions.h | 11 +- src/core/qgslocalizeddatapathregistry.cpp | 4 +- src/core/qgslocalizeddatapathregistry.h | 11 +- src/core/qgsmaprendererjob.cpp | 2 +- src/core/qgsmaprendererjob.h | 12 +- src/core/settings/qgssettingsentry.cpp | 1 + src/core/settings/qgssettingsregistrycore.cpp | 34 +-- src/gui/qgsconfigureshortcutsdialog.cpp | 6 +- src/gui/qgsgui.cpp | 2 +- src/gui/qgsmapcanvas.cpp | 2 +- tests/src/analysis/testqgsprocessing.cpp | 18 +- .../src/core/testqgscompositionconverter.cpp | 2 +- .../src/core/testqgsnetworkaccessmanager.cpp | 2 +- tests/src/core/testqgsnewsfeedparser.cpp | 10 +- tests/src/core/testqgstranslateproject.cpp | 8 +- 39 files changed, 385 insertions(+), 229 deletions(-) create mode 100644 python/core/auto_generated/settings/qgssettingsregistry.sip.in diff --git a/python/core/auto_generated/network/qgsnetworkaccessmanager.sip.in b/python/core/auto_generated/network/qgsnetworkaccessmanager.sip.in index e5f7db3a9f40..654750605e5f 100644 --- a/python/core/auto_generated/network/qgsnetworkaccessmanager.sip.in +++ b/python/core/auto_generated/network/qgsnetworkaccessmanager.sip.in @@ -321,10 +321,7 @@ The contents of the reply will be returned after the request is completed or an .. versionadded:: 3.6 %End - struct Settings - { - const QgsSettingsEntryInteger networkTimeout; - }; + const QgsSettingsEntryInteger settingsNetworkTimeout; signals: diff --git a/python/core/auto_generated/network/qgsnewsfeedparser.sip.in b/python/core/auto_generated/network/qgsnewsfeedparser.sip.in index a411df070b89..b6643c4629da 100644 --- a/python/core/auto_generated/network/qgsnewsfeedparser.sip.in +++ b/python/core/auto_generated/network/qgsnewsfeedparser.sip.in @@ -93,13 +93,10 @@ Returns the authentication configuration for the parser. Returns the settings key used for a feed with the given ``baseUrl``. %End - struct Settings - { - const QgsSettingsEntryInteger feedLastFetchTime; - const QgsSettingsEntryString feedLanguage; - const QgsSettingsEntryDouble feedLatitude; - const QgsSettingsEntryDouble feedLongitude; - }; + const QgsSettingsEntryInteger settingsFeedLastFetchTime; + const QgsSettingsEntryString settingsFeedLanguage; + const QgsSettingsEntryDouble settingsFeedLatitude; + const QgsSettingsEntryDouble settingsFeedLongitude; public slots: diff --git a/python/core/auto_generated/processing/qgsprocessing.sip.in b/python/core/auto_generated/processing/qgsprocessing.sip.in index d447f80dfef7..c14aec992082 100644 --- a/python/core/auto_generated/processing/qgsprocessing.sip.in +++ b/python/core/auto_generated/processing/qgsprocessing.sip.in @@ -53,13 +53,10 @@ Converts a source ``type`` to a string representation. static const QString TEMPORARY_OUTPUT; - struct Settings - { - const QgsSettingsEntryBool preferFilenameAsLayerName; - const QgsSettingsEntryString tempPath; - const QgsSettingsEntryInteger defaultOutputVectorLayerExt; - const QgsSettingsEntryInteger defaultOutputRasterLayerExt; - }; + const QgsSettingsEntryBool settingsPreferFilenameAsLayerName; + const QgsSettingsEntryString settingsTempPath; + const QgsSettingsEntryInteger settingsDefaultOutputVectorLayerExt; + const QgsSettingsEntryInteger settingsDefaultOutputRasterLayerExt; }; /************************************************************************ diff --git a/python/core/auto_generated/qgsapplication.sip.in b/python/core/auto_generated/qgsapplication.sip.in index b256b73a69e7..79411a972da2 100644 --- a/python/core/auto_generated/qgsapplication.sip.in +++ b/python/core/auto_generated/qgsapplication.sip.in @@ -1004,14 +1004,11 @@ Emits the signal to collect all the strings of .qgs to be included in ts file .. versionadded:: 3.4 %End - struct Settings - { - const QgsSettingsEntryString localeUserLocale; - const QgsSettingsEntryBool localeOverrideFlag; - const QgsSettingsEntryString localeGlobalLocale; - const QgsSettingsEntryBool localeShowGroupSeparator; - const QgsSettingsEntryStringList searchPathsForSVG; - }; + const QgsSettingsEntryString settingsLocaleUserLocale; + const QgsSettingsEntryBool settingsLocaleOverrideFlag; + const QgsSettingsEntryString settingsLocaleGlobalLocale; + const QgsSettingsEntryBool settingsLocaleShowGroupSeparator; + const QgsSettingsEntryStringList settingsSearchPathsForSVG; %If (ANDROID) //dummy method to workaround sip generation issue diff --git a/python/core/auto_generated/qgsgeometryoptions.sip.in b/python/core/auto_generated/qgsgeometryoptions.sip.in index dcb9d5971cde..28da763994c7 100644 --- a/python/core/auto_generated/qgsgeometryoptions.sip.in +++ b/python/core/auto_generated/qgsgeometryoptions.sip.in @@ -118,10 +118,7 @@ Read the geometry options from ``node``. .. versionadded:: 3.4 %End - struct Settings - { - const QgsSettingsEntryString geometryValidationDefaultChecks; - }; + const QgsSettingsEntryString settingsGeometryValidationDefaultChecks; signals: diff --git a/python/core/auto_generated/qgslocalizeddatapathregistry.sip.in b/python/core/auto_generated/qgslocalizeddatapathregistry.sip.in index 8185921b73d5..92873da33fe9 100644 --- a/python/core/auto_generated/qgslocalizeddatapathregistry.sip.in +++ b/python/core/auto_generated/qgslocalizeddatapathregistry.sip.in @@ -60,10 +60,7 @@ Since the paths are stored by order of preference, lower positions in the list t Unregisters a localized path %End - struct Settings - { - const QgsSettingsEntryStringList localizedDataPaths; - }; + const QgsSettingsEntryStringList settingsLocalizedDataPaths; private: QgsLocalizedDataPathRegistry( const QgsLocalizedDataPathRegistry &other ); diff --git a/python/core/auto_generated/qgsmaprendererjob.sip.in b/python/core/auto_generated/qgsmaprendererjob.sip.in index cd7f15f421e8..9fc86cd56436 100644 --- a/python/core/auto_generated/qgsmaprendererjob.sip.in +++ b/python/core/auto_generated/qgsmaprendererjob.sip.in @@ -157,11 +157,7 @@ Returns map settings with which this job was started. - - struct Settings - { - const QgsSettingsEntryBool logCanvasRefreshEvent; - }; + const QgsSettingsEntryBool settingsLogCanvasRefreshEvent; signals: diff --git a/python/core/auto_generated/settings/qgssettingsentry.sip.in b/python/core/auto_generated/settings/qgssettingsentry.sip.in index 5decd372b97f..95a11fa3aa3b 100644 --- a/python/core/auto_generated/settings/qgssettingsentry.sip.in +++ b/python/core/auto_generated/settings/qgssettingsentry.sip.in @@ -75,6 +75,20 @@ The ``description`` argument specifies a description for the settings entry. Get settings entry key. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +%End + + QString key( const QStringList &dynamicKeyPartList ) const; +%Docstring +Get settings entry key. + +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +%End + + QString definitionKey() const; +%Docstring +Returns settings entry defining key. +For dynamic settings it return the key with the placeholder for dynamic part +included. For non-dynamic settings returns the same as :py:func:`~QgsSettingsEntryBase.key`. %End bool hasDynamicKey() const; @@ -87,6 +101,13 @@ Returns true if a part of the settings key is built dynamically. Returns true if the settings is contained in the underlying QSettings. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +%End + + bool exists( const QStringList &dynamicKeyPartList ) const; +%Docstring +Returns true if the settings is contained in the underlying QSettings. + +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. %End void remove( const QString &dynamicKeyPart = QString() ) const; @@ -94,6 +115,13 @@ The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. Removes the settings from the underlying QSettings. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +%End + + void remove( const QStringList &dynamicKeyPartList ) const; +%Docstring +Removes the settings from the underlying QSettings. + +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. %End QgsSettings::Section section() const; @@ -101,18 +129,38 @@ The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. Get settings section. The settings section of the parent group is returned if available. %End - virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; + virtual bool setVariantValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; %Docstring Set settings value. +The ``value`` to set. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. %End - QVariant valueAsVariant( const QString &dynamicKeyPart = QString() ) const; + virtual bool setVariantValue( const QVariant &value, const QStringList &dynamicKeyPartList ) const; +%Docstring +Set settings value. + +The ``value`` to set. +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +%End + + QVariant valueAsVariant( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, const QVariant &defaultValueOverride = QVariant() ) const; %Docstring Get settings value. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. +The ``defaultValueOverride`` argument if valid is used instead of the normal default value. +%End + + QVariant valueAsVariant( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, const QVariant &defaultValueOverride = QVariant() ) const; +%Docstring +Get settings value. + +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. +The ``defaultValueOverride`` argument if valid is used instead of the normal default value. %End QVariant defaultValueAsVariant() const; @@ -161,18 +209,38 @@ The ``default`` value argument specifies the default value for the settings entr The ``description`` argument specifies a description for the settings entry. %End + bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; +%Docstring +Set settings value. - virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; +The ``value`` to set. +The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +%End + bool setValue( const QVariant &value, const QStringList &dynamicKeyPartList ) const; %Docstring -\copydoc :py:class:`QgsSettingsEntryBase`.setValue +Set settings value. + +The ``value`` to set. +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. %End - QVariant value( const QString &dynamicKeyPart = QString() ) const; + QVariant value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, const QVariant &defaultValueOverride = QVariant() ) const; %Docstring Get settings value. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. +The ``defaultValueOverride`` argument if valid is used instead of the normal default value. +%End + + QVariant value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, const QVariant &defaultValueOverride = QVariant() ) const; +%Docstring +Get settings value. + +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. +The ``defaultValueOverride`` argument if valid is used instead of the normal default value. %End QVariant defaultValue() const; @@ -203,7 +271,7 @@ A string settings entry. QgsSettingsEntryString( const QString &key, const QString &pluginName, - const QVariant &defaultValue = QVariant(), + const QString &defaultValue = QString(), const QString &description = QString() ); %Docstring Constructor for QgsSettingsEntryString. @@ -215,17 +283,38 @@ The ``default`` value argument specifies the default value for the settings entr The ``description`` argument specifies a description for the settings entry. %End - virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; + bool setValue( const QString &value, const QString &dynamicKeyPart = QString() ) const; +%Docstring +Set settings value. + +The ``value`` to set. +The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +%End + bool setValue( const QString &value, const QStringList &dynamicKeyPartList ) const; %Docstring -\copydoc :py:class:`QgsSettingsEntryBase`.setValue +Set settings value. + +The ``value`` to set. +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. %End - QString value( const QString &dynamicKeyPart = QString() ) const; + QString value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, const QString &defaultValueOverride = QString() ) const; %Docstring Get settings value. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. +The ``defaultValueOverride`` argument if valid is used instead of the normal default value. +%End + + QString value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, const QString &defaultValueOverride = QString() ) const; +%Docstring +Get settings value. + +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. +The ``defaultValueOverride`` argument if valid is used instead of the normal default value. %End QString defaultValue() const; @@ -281,7 +370,7 @@ A string list settings entry. QgsSettingsEntryStringList( const QString &key, const QString &pluginName, - const QVariant &defaultValue = QVariant(), + const QStringList &defaultValue = QStringList(), const QString &description = QString() ); %Docstring Constructor for QgsSettingsEntryStringList. @@ -293,17 +382,38 @@ The ``default`` value argument specifies the default value for the settings entr The ``description`` argument specifies a description for the settings entry. %End - virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; + bool setValue( const QStringList &value, const QString &dynamicKeyPart = QString() ) const; +%Docstring +Set settings value. +The ``value`` to set. +The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +%End + + bool setValue( const QStringList &value, const QStringList &dynamicKeyPartList ) const; %Docstring -\copydoc :py:class:`QgsSettingsEntryBase`.setValue +Set settings value. + +The ``value`` to set. +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. %End - QStringList value( const QString &dynamicKeyPart = QString() ) const; + QStringList value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, const QStringList &defaultValueOverride = QStringList() ) const; %Docstring Get settings value. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. +The ``defaultValueOverride`` argument if valid is used instead of the normal default value. +%End + + QStringList value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, const QStringList &defaultValueOverride = QStringList() ) const; +%Docstring +Get settings value. + +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. +The ``defaultValueOverride`` argument if valid is used instead of the normal default value. %End QStringList defaultValue() const; @@ -335,7 +445,7 @@ A boolean settings entry. QgsSettingsEntryBool( const QString &key, const QString &pluginName, - const QVariant &defaultValue = QVariant(), + bool defaultValue = false, const QString &description = QString() ); %Docstring Constructor for QgsSettingsEntryBool. @@ -347,17 +457,38 @@ The ``default`` value argument specifies the default value for the settings entr The ``description`` argument specifies a description for the settings entry. %End - virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; + bool setValue( bool value, const QString &dynamicKeyPart = QString() ) const; +%Docstring +Set settings value. +The ``value`` to set. +The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +%End + + bool setValue( bool value, const QStringList &dynamicKeyPartList ) const; %Docstring -\copydoc :py:class:`QgsSettingsEntryBase`.setValue +Set settings value. + +The ``value`` to set. +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. %End - bool value( const QString &dynamicKeyPart = QString() ) const; + bool value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, bool defaultValueOverride = false ) const; %Docstring Get settings value. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. +The ``defaultValueOverride`` argument if valid is used instead of the normal default value. +%End + + bool value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, bool defaultValueOverride = false ) const; +%Docstring +Get settings value. + +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. +The ``defaultValueOverride`` argument if valid is used instead of the normal default value. %End bool defaultValue() const; @@ -389,7 +520,7 @@ An integer settings entry. QgsSettingsEntryInteger( const QString &key, const QString &pluginName, - const QVariant &defaultValue = QVariant(), + qlonglong defaultValue = 0, const QString &description = QString() ); %Docstring Constructor for QgsSettingsEntryInteger. @@ -401,18 +532,38 @@ The ``default`` value argument specifies the default value for the settings entr The ``description`` argument specifies a description for the settings entry. %End + bool setValue( qlonglong value, const QString &dynamicKeyPart = QString() ) const; +%Docstring +Set settings value. - virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; +The ``value`` to set. +The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +%End + bool setValue( qlonglong value, const QStringList &dynamicKeyPartList ) const; %Docstring -\copydoc :py:class:`QgsSettingsEntryBase`.setValue +Set settings value. + +The ``value`` to set. +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. %End - qlonglong value( const QString &dynamicKeyPart = QString() ) const; + qlonglong value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, qlonglong defaultValueOverride = 0 ) const; %Docstring Get settings value. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. +The ``defaultValueOverride`` argument if valid is used instead of the normal default value. +%End + + qlonglong value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, qlonglong defaultValueOverride = 0 ) const; +%Docstring +Get settings value. + +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. +The ``defaultValueOverride`` argument if valid is used instead of the normal default value. %End qlonglong defaultValue() const; @@ -468,7 +619,7 @@ A double settings entry. QgsSettingsEntryDouble( const QString &key, const QString &pluginName, - const QVariant &defaultValue = QVariant(), + double defaultValue, const QString &description = QString() ); %Docstring Constructor for QgsSettingsEntryDouble. @@ -480,17 +631,38 @@ The ``default`` value argument specifies the default value for the settings entr The ``description`` argument specifies a description for the settings entry. %End - virtual bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const; + bool setValue( double value, const QString &dynamicKeyPart = QString() ) const; +%Docstring +Set settings value. +The ``value`` to set. +The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +%End + + bool setValue( double value, const QStringList &dynamicKeyPartList ) const; %Docstring -\copydoc :py:class:`QgsSettingsEntryBase`.setValue +Set settings value. + +The ``value`` to set. +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. %End - double value( const QString &dynamicKeyPart = QString() ) const; + double value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, double defaultValueOverride = 0.0 ) const; %Docstring Get settings value. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. +The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. +The ``defaultValueOverride`` argument if valid is used instead of the normal default value. +%End + + double value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, double defaultValueOverride = 0.0 ) const; +%Docstring +Get settings value. + +The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used. +The ``defaultValueOverride`` argument if valid is used instead of the normal default value. %End double defaultValue() const; @@ -545,6 +717,8 @@ Returns how much decimals should be shown in the Gui. + + /************************************************************************ * This file has been generated automatically from * * * diff --git a/python/core/auto_generated/settings/qgssettingsregistry.sip.in b/python/core/auto_generated/settings/qgssettingsregistry.sip.in new file mode 100644 index 000000000000..05809aaf9391 --- /dev/null +++ b/python/core/auto_generated/settings/qgssettingsregistry.sip.in @@ -0,0 +1,52 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/settings/qgssettingsregistry.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + + +class QgsSettingsRegistry +{ +%Docstring(signature="appended") +:py:class:`QgsSettingsRegistry` is used for settings introspection and collects a +list of child :py:class:`QgsSettingsRegistry` and a list of child :py:class:`QgsSettingsRegistry` + +.. versionadded:: 3.20 +%End + +%TypeHeaderCode +#include "qgssettingsregistry.h" +%End + public: + + QgsSettingsRegistry(); +%Docstring +Constructor for QgsSettingsRegistry. +%End + + virtual ~QgsSettingsRegistry(); + + const QgsSettingsEntryBase *getSettingsEntry( const QString &key ); +%Docstring +Returns the :py:class:`QgsSettingsEntry` with the given ``key`` or None if not found. +%End + + void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); +%Docstring +Add ``settingsEntry`` to the register. +%End + +}; + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/settings/qgssettingsregistry.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/core/core_auto.sip b/python/core/core_auto.sip index f318b2fbe541..1b4553fc13cd 100644 --- a/python/core/core_auto.sip +++ b/python/core/core_auto.sip @@ -603,6 +603,7 @@ %Include auto_generated/textrenderer/qgstextrendererutils.sip %Include auto_generated/textrenderer/qgstextshadowsettings.sip %Include auto_generated/settings/qgssettingsentry.sip +%Include auto_generated/settings/qgssettingsregistry.sip %Include auto_generated/settings/qgssettingsregistrycore.sip %Include auto_generated/validity/qgsabstractvaliditycheck.sip %Include auto_generated/validity/qgsvaliditycheckcontext.sip diff --git a/src/app/main.cpp b/src/app/main.cpp index f5942d2bc40c..85ae09e399fe 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -968,16 +968,16 @@ int main( int argc, char *argv[] ) { /* Translation file for QGIS. */ - QString myUserTranslation = QgsApplication::Settings::localeUserLocale.value(); - QString myGlobalLocale = QgsApplication::Settings::localeGlobalLocale.value(); + QString myUserTranslation = QgsApplication::settingsLocaleUserLocale.value(); + QString myGlobalLocale = QgsApplication::settingsLocaleGlobalLocale.value(); bool myShowGroupSeparatorFlag = false; // Default to false - bool myLocaleOverrideFlag = QgsApplication::Settings::localeOverrideFlag.value(); + bool myLocaleOverrideFlag = QgsApplication::settingsLocaleOverrideFlag.value(); // Override Show Group Separator if the global override flag is set if ( myLocaleOverrideFlag ) { // Default to false again - myShowGroupSeparatorFlag = QgsApplication::Settings::localeShowGroupSeparator.value(); + myShowGroupSeparatorFlag = QgsApplication::settingsLocaleShowGroupSeparator.value(); } // @@ -991,7 +991,7 @@ int main( int argc, char *argv[] ) // if ( !translationCode.isNull() && !translationCode.isEmpty() ) { - QgsApplication::Settings::localeUserLocale.setValue( translationCode ); + QgsApplication::settingsLocaleUserLocale.setValue( translationCode ); } else { @@ -1000,7 +1000,7 @@ int main( int argc, char *argv[] ) translationCode = QLocale().name(); //setting the locale/userLocale when the --lang= option is not set will allow third party //plugins to always use the same locale as the QGIS, otherwise they can be out of sync - QgsApplication::Settings::localeUserLocale.setValue( translationCode ); + QgsApplication::settingsLocaleUserLocale.setValue( translationCode ); } else { diff --git a/src/app/options/qgsoptions.cpp b/src/app/options/qgsoptions.cpp index f5d2d32753b2..cf88ec414238 100644 --- a/src/app/options/qgsoptions.cpp +++ b/src/app/options/qgsoptions.cpp @@ -475,7 +475,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QListsetCurrentIndex( index ); // log rendering events, for userspace debugging - mLogCanvasRefreshChkBx->setChecked( QgsMapRendererJob::Settings::logCanvasRefreshEvent.value() ); + mLogCanvasRefreshChkBx->setChecked( QgsMapRendererJob::settingsLogCanvasRefreshEvent.value() ); //set the default projection behavior radio buttons const QgsOptions::UnknownLayerCrsBehavior mode = QgsSettings().enumValue( QStringLiteral( "/projections/unknownCrsBehavior" ), QgsOptions::UnknownLayerCrsBehavior::NoAction, QgsSettings::App ); @@ -1015,9 +1015,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QListsetText( tr( "Detected active locale on your system: %1" ).arg( currentLocale ) ); - QString userLocale = QgsApplication::Settings::localeUserLocale.value(); - bool showGroupSeparator = QgsApplication::Settings::localeShowGroupSeparator.value(); - QString globalLocale = QgsApplication::Settings::localeGlobalLocale.value(); + QString userLocale = QgsApplication::settingsLocaleUserLocale.value(); + bool showGroupSeparator = QgsApplication::settingsLocaleShowGroupSeparator.value(); + QString globalLocale = QgsApplication::settingsLocaleGlobalLocale.value(); const QStringList language18nList( i18nList() ); for ( const auto &l : language18nList ) { @@ -1044,7 +1044,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QListsetCurrentIndex( cboTranslation->findData( userLocale ) ); cboGlobalLocale->setCurrentIndex( cboGlobalLocale->findData( globalLocale ) ); - grpLocale->setChecked( QgsApplication::Settings::localeOverrideFlag.value() ); + grpLocale->setChecked( QgsApplication::settingsLocaleOverrideFlag.value() ); cbShowGroupSeparator->setChecked( showGroupSeparator ); @@ -1673,7 +1673,7 @@ void QgsOptions::saveOptions() mSettings->setValue( QStringLiteral( "/Raster/cumulativeCutUpper" ), mRasterCumulativeCutUpperDoubleSpinBox->value() / 100.0 ); // log rendering events, for userspace debugging - QgsMapRendererJob::Settings::logCanvasRefreshEvent.setValue( mLogCanvasRefreshChkBx->isChecked() ); + QgsMapRendererJob::settingsLogCanvasRefreshEvent.setValue( mLogCanvasRefreshChkBx->isChecked() ); //check behavior so default projection when new layer is added with no //projection defined... @@ -1856,12 +1856,12 @@ void QgsOptions::saveOptions() // // Locale settings // - QgsApplication::Settings::localeUserLocale.setValue( cboTranslation->currentData().toString() ); - QgsApplication::Settings::localeOverrideFlag.setValue( grpLocale->isChecked() ); - QgsApplication::Settings::localeGlobalLocale.setValue( cboGlobalLocale->currentData( ).toString() ); + QgsApplication::settingsLocaleUserLocale.setValue( cboTranslation->currentData().toString() ); + QgsApplication::settingsLocaleOverrideFlag.setValue( grpLocale->isChecked() ); + QgsApplication::settingsLocaleGlobalLocale.setValue( cboGlobalLocale->currentData( ).toString() ); // Number settings - QgsApplication::Settings::localeShowGroupSeparator.setValue( cbShowGroupSeparator->isChecked( ) ); + QgsApplication::settingsLocaleShowGroupSeparator.setValue( cbShowGroupSeparator->isChecked( ) ); QgsLocalDefaultSettings::setBearingFormat( mBearingFormat.get() ); diff --git a/src/app/qgsprojectproperties.cpp b/src/app/qgsprojectproperties.cpp index 6ccc1134eb22..f729cd48bbae 100644 --- a/src/app/qgsprojectproperties.cpp +++ b/src/app/qgsprojectproperties.cpp @@ -983,7 +983,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa } cbtsLocale->addItem( QIcon( QStringLiteral( ":/images/flags/%1.svg" ).arg( QLatin1String( "en_US" ) ) ), QLocale( QStringLiteral( "en_US" ) ).nativeLanguageName(), QStringLiteral( "en_US" ) ); - cbtsLocale->setCurrentIndex( cbtsLocale->findData( QgsApplication::Settings::localeUserLocale.value() ) ); + cbtsLocale->setCurrentIndex( cbtsLocale->findData( QgsApplication::settingsLocaleUserLocale.value() ) ); connect( generateTsFileButton, &QPushButton::clicked, this, &QgsProjectProperties::onGenerateTsFileButton ); diff --git a/src/core/network/qgsnetworkaccessmanager.cpp b/src/core/network/qgsnetworkaccessmanager.cpp index aa793d749c98..75c9b0b27aaf 100644 --- a/src/core/network/qgsnetworkaccessmanager.cpp +++ b/src/core/network/qgsnetworkaccessmanager.cpp @@ -654,12 +654,12 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache( Qt::ConnectionType conn int QgsNetworkAccessManager::timeout() { - return Settings::networkTimeout.value(); + return settingsNetworkTimeout.value(); } void QgsNetworkAccessManager::setTimeout( const int time ) { - Settings::networkTimeout.setValue( time ); + settingsNetworkTimeout.setValue( time ); } QgsNetworkReplyContent QgsNetworkAccessManager::blockingGet( QNetworkRequest &request, const QString &authCfg, bool forceRefresh, QgsFeedback *feedback ) diff --git a/src/core/network/qgsnetworkaccessmanager.h b/src/core/network/qgsnetworkaccessmanager.h index 5911b787c939..b6b643e1d384 100644 --- a/src/core/network/qgsnetworkaccessmanager.h +++ b/src/core/network/qgsnetworkaccessmanager.h @@ -500,15 +500,8 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager */ static QgsNetworkReplyContent blockingPost( QNetworkRequest &request, const QByteArray &data, const QString &authCfg = QString(), bool forceRefresh = false, QgsFeedback *feedback = nullptr ); - /** - * Contains QgsNetworkAccessManager settings - * \since QGIS 3.20 - */ - struct Settings - { - //! Settings entry network timeout - static const inline QgsSettingsEntryInteger networkTimeout = QgsSettingsEntryInteger( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), QgsSettings::NoSection, 60000, QObject::tr( "Network timeout" ) ); - }; + //! Settings entry network timeout + static const inline QgsSettingsEntryInteger settingsNetworkTimeout = QgsSettingsEntryInteger( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), QgsSettings::NoSection, 60000, QObject::tr( "Network timeout" ) ); signals: diff --git a/src/core/network/qgsnewsfeedparser.cpp b/src/core/network/qgsnewsfeedparser.cpp index 3c1c63eafe8c..183c0bc91aa7 100644 --- a/src/core/network/qgsnewsfeedparser.cpp +++ b/src/core/network/qgsnewsfeedparser.cpp @@ -40,22 +40,22 @@ QgsNewsFeedParser::QgsNewsFeedParser( const QUrl &feedUrl, const QString &authcf QUrlQuery query( feedUrl ); - const qint64 after = Settings::feedLastFetchTime.value( mSettingsKey ); + const qint64 after = settingsFeedLastFetchTime.value( mSettingsKey ); if ( after > 0 ) query.addQueryItem( QStringLiteral( "after" ), qgsDoubleToString( after, 0 ) ); - QString feedLanguage = Settings::feedLanguage.value( mSettingsKey ); + QString feedLanguage = settingsFeedLanguage.value( mSettingsKey ); if ( feedLanguage.isEmpty() ) { - feedLanguage = QgsSettings().value( QgsApplication::Settings::localeUserLocale.key(), QStringLiteral( "en_US" ) ).toString().left( 2 ); + feedLanguage = QgsSettings().value( QgsApplication::settingsLocaleUserLocale.key(), QStringLiteral( "en_US" ) ).toString().left( 2 ); } if ( !feedLanguage.isEmpty() && feedLanguage != QLatin1String( "C" ) ) query.addQueryItem( QStringLiteral( "lang" ), feedLanguage ); - if ( Settings::feedLatitude.exists( mSettingsKey ) && Settings::feedLongitude.exists( mSettingsKey ) ) + if ( settingsFeedLatitude.exists( mSettingsKey ) && settingsFeedLongitude.exists( mSettingsKey ) ) { - const double feedLat = Settings::feedLatitude.value( mSettingsKey ); - const double feedLong = Settings::feedLongitude.value( mSettingsKey ); + const double feedLat = settingsFeedLatitude.value( mSettingsKey ); + const double feedLong = settingsFeedLongitude.value( mSettingsKey ); // hack to allow testing using local files if ( feedUrl.isLocalFile() ) @@ -169,7 +169,7 @@ void QgsNewsFeedParser::fetch() void QgsNewsFeedParser::onFetch( const QString &content ) { - Settings::feedLastFetchTime.setValue( mFetchStartTime, mSettingsKey ); + settingsFeedLastFetchTime.setValue( mFetchStartTime, mSettingsKey ); const QVariant json = QgsJsonUtils::parseJson( content ); diff --git a/src/core/network/qgsnewsfeedparser.h b/src/core/network/qgsnewsfeedparser.h index 17079296d751..fb06c0824307 100644 --- a/src/core/network/qgsnewsfeedparser.h +++ b/src/core/network/qgsnewsfeedparser.h @@ -111,21 +111,14 @@ class CORE_EXPORT QgsNewsFeedParser : public QObject */ static QString keyForFeed( const QString &baseUrl ); - /** - * Contains QgsNewsFeedParser settings - * \since QGIS 3.20 - */ - struct Settings - { - //! Settings entry last fetch time - static const inline QgsSettingsEntryInteger feedLastFetchTime = QgsSettingsEntryInteger( QStringLiteral( "%/lastFetchTime" ), QgsSettings::Core, 0, QObject::tr( "Feed last fetch time" ), 0 ); - //! Settings entry feed language - static const inline QgsSettingsEntryString feedLanguage = QgsSettingsEntryString( QStringLiteral( "%/lang" ), QgsSettings::Core, QString(), QObject::tr( "Feed language" ) ); - //! Settings entry feed latitude - static const inline QgsSettingsEntryDouble feedLatitude = QgsSettingsEntryDouble( QStringLiteral( "%/latitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed latitude" ) ); - //! Settings entry feed longitude - static const inline QgsSettingsEntryDouble feedLongitude = QgsSettingsEntryDouble( QStringLiteral( "%/longitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed longitude" ) ); - }; + //! Settings entry last fetch time + static const inline QgsSettingsEntryInteger settingsFeedLastFetchTime = QgsSettingsEntryInteger( QStringLiteral( "%/lastFetchTime" ), QgsSettings::Core, 0, QObject::tr( "Feed last fetch time" ), 0 ); + //! Settings entry feed language + static const inline QgsSettingsEntryString settingsFeedLanguage = QgsSettingsEntryString( QStringLiteral( "%/lang" ), QgsSettings::Core, QString(), QObject::tr( "Feed language" ) ); + //! Settings entry feed latitude + static const inline QgsSettingsEntryDouble settingsFeedLatitude = QgsSettingsEntryDouble( QStringLiteral( "%/latitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed latitude" ) ); + //! Settings entry feed longitude + static const inline QgsSettingsEntryDouble settingsFeedLongitude = QgsSettingsEntryDouble( QStringLiteral( "%/longitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed longitude" ) ); public slots: diff --git a/src/core/processing/qgsprocessing.h b/src/core/processing/qgsprocessing.h index ea26ffee824f..53eee28fdcf5 100644 --- a/src/core/processing/qgsprocessing.h +++ b/src/core/processing/qgsprocessing.h @@ -99,21 +99,14 @@ class CORE_EXPORT QgsProcessing */ static const QString TEMPORARY_OUTPUT; - /** - * Contains QgsProcessing settings - * \since QGIS 3.20 - */ - struct Settings - { - //! Settings entry prefer filename as layer name - static const inline QgsSettingsEntryBool preferFilenameAsLayerName = QgsSettingsEntryBool( QStringLiteral( "Processing/Configuration/PREFER_FILENAME_AS_LAYER_NAME" ), QgsSettings::NoSection, true, QObject::tr( "Prefer filename as layer name" ) ); - //! Settings entry temp path - static const inline QgsSettingsEntryString tempPath = QgsSettingsEntryString( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ), QgsSettings::NoSection, QString() ); - //! Settings entry default output vector layer ext - static const inline QgsSettingsEntryInteger defaultOutputVectorLayerExt = QgsSettingsEntryInteger( QStringLiteral( "Processing/Configuration/DefaultOutputVectorLayerExt" ), QgsSettings::NoSection, -1 ); - //! Settings entry default output raster layer ext - static const inline QgsSettingsEntryInteger defaultOutputRasterLayerExt = QgsSettingsEntryInteger( QStringLiteral( "Processing/Configuration/DefaultOutputRasterLayerExt" ), QgsSettings::NoSection, -1 ); - }; + //! Settings entry prefer filename as layer name + static const inline QgsSettingsEntryBool settingsPreferFilenameAsLayerName = QgsSettingsEntryBool( QStringLiteral( "Processing/Configuration/PREFER_FILENAME_AS_LAYER_NAME" ), QgsSettings::NoSection, true, QObject::tr( "Prefer filename as layer name" ) ); + //! Settings entry temp path + static const inline QgsSettingsEntryString settingsTempPath = QgsSettingsEntryString( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ), QgsSettings::NoSection, QString() ); + //! Settings entry default output vector layer ext + static const inline QgsSettingsEntryInteger settingsDefaultOutputVectorLayerExt = QgsSettingsEntryInteger( QStringLiteral( "Processing/Configuration/DefaultOutputVectorLayerExt" ), QgsSettings::NoSection, -1 ); + //! Settings entry default output raster layer ext + static const inline QgsSettingsEntryInteger settingsDefaultOutputRasterLayerExt = QgsSettingsEntryInteger( QStringLiteral( "Processing/Configuration/DefaultOutputRasterLayerExt" ), QgsSettings::NoSection, -1 ); }; #endif // QGSPROCESSING_H diff --git a/src/core/processing/qgsprocessingcontext.cpp b/src/core/processing/qgsprocessingcontext.cpp index db0af8d12d7b..4c52a4c46a06 100644 --- a/src/core/processing/qgsprocessingcontext.cpp +++ b/src/core/processing/qgsprocessingcontext.cpp @@ -197,7 +197,7 @@ void QgsProcessingContext::LayerDetails::setOutputLayerName( QgsMapLayer *layer if ( !layer ) return; - const bool preferFilenameAsLayerName = QgsProcessing::Settings::preferFilenameAsLayerName.value(); + const bool preferFilenameAsLayerName = QgsProcessing::settingsPreferFilenameAsLayerName.value(); // note - for temporary layers, we don't use the filename, regardless of user setting (it will be meaningless!) if ( ( !forceName && preferFilenameAsLayerName && !layer->isTemporary() ) || name.isEmpty() ) diff --git a/src/core/processing/qgsprocessingutils.cpp b/src/core/processing/qgsprocessingutils.cpp index 1d434d78491b..fc19b2094dc1 100644 --- a/src/core/processing/qgsprocessingutils.cpp +++ b/src/core/processing/qgsprocessingutils.cpp @@ -954,7 +954,7 @@ QString QgsProcessingUtils::tempFolder() static QString sFolder; static QMutex sMutex; QMutexLocker locker( &sMutex ); - const QString basePath = QgsProcessing::Settings::tempPath.value(); + const QString basePath = QgsProcessing::settingsTempPath.value(); if ( basePath.isEmpty() ) { // default setting -- automatically create a temp folder @@ -1211,7 +1211,7 @@ QgsFields QgsProcessingUtils::indicesToFields( const QList &indices, const QString QgsProcessingUtils::defaultVectorExtension() { - const int setting = QgsProcessing::Settings::defaultOutputVectorLayerExt.value(); + const int setting = QgsProcessing::settingsDefaultOutputVectorLayerExt.value(); if ( setting == -1 ) return QStringLiteral( "gpkg" ); return QgsVectorFileWriter::supportedFormatExtensions().value( setting, QStringLiteral( "gpkg" ) ); @@ -1219,7 +1219,7 @@ QString QgsProcessingUtils::defaultVectorExtension() QString QgsProcessingUtils::defaultRasterExtension() { - const int setting = QgsProcessing::Settings::defaultOutputRasterLayerExt.value(); + const int setting = QgsProcessing::settingsDefaultOutputRasterLayerExt.value(); if ( setting == -1 ) return QStringLiteral( "tif" ); return QgsRasterFileWriter::supportedFormatExtensions().value( setting, QStringLiteral( "tif" ) ); diff --git a/src/core/project/qgsproject.cpp b/src/core/project/qgsproject.cpp index 3e63e8fc1479..60ac90cbf8e7 100644 --- a/src/core/project/qgsproject.cpp +++ b/src/core/project/qgsproject.cpp @@ -1356,7 +1356,7 @@ bool QgsProject::readProjectFile( const QString &filename, QgsProject::ReadFlags QgsApplication::profiler()->clear( QStringLiteral( "projectload" ) ); QgsScopedRuntimeProfile profile( tr( "Setting up translations" ), QStringLiteral( "projectload" ) ); - QString localeFileName = QStringLiteral( "%1_%2" ).arg( QFileInfo( projectFile.fileName() ).baseName(), QgsApplication::Settings::localeUserLocale.value() ); + QString localeFileName = QStringLiteral( "%1_%2" ).arg( QFileInfo( projectFile.fileName() ).baseName(), QgsApplication::settingsLocaleUserLocale.value() ); if ( QFile( QStringLiteral( "%1/%2.qm" ).arg( QFileInfo( projectFile.fileName() ).absolutePath(), localeFileName ) ).exists() ) { diff --git a/src/core/qgsapplication.cpp b/src/core/qgsapplication.cpp index f21dead95843..f5ceba1b250c 100644 --- a/src/core/qgsapplication.cpp +++ b/src/core/qgsapplication.cpp @@ -1063,7 +1063,7 @@ QString QgsApplication::srsDatabaseFilePath() void QgsApplication::setSvgPaths( const QStringList &svgPaths ) { - Settings::searchPathsForSVG.setValue( svgPaths ); + settingsSearchPathsForSVG.setValue( svgPaths ); members()->mSvgPathCacheValid = false; } @@ -1082,7 +1082,7 @@ QStringList QgsApplication::svgPaths() locker.changeMode( QgsReadWriteLocker::Write ); //local directories to search when looking for an SVG with a given basename //defined by user in options dialog - const QStringList pathList = Settings::searchPathsForSVG.value(); + const QStringList pathList = settingsSearchPathsForSVG.value(); // maintain user set order while stripping duplicates QStringList paths; @@ -1224,9 +1224,9 @@ QString QgsApplication::platform() QString QgsApplication::locale() { - if ( Settings::localeOverrideFlag.value() ) + if ( settingsLocaleOverrideFlag.value() ) { - QString locale = Settings::localeUserLocale.value(); + QString locale = settingsLocaleUserLocale.value(); // don't differentiate en_US and en_GB if ( locale.startsWith( QLatin1String( "en" ), Qt::CaseInsensitive ) ) { diff --git a/src/core/qgsapplication.h b/src/core/qgsapplication.h index bb2b2110b9c6..937e4175f225 100644 --- a/src/core/qgsapplication.h +++ b/src/core/qgsapplication.h @@ -945,23 +945,16 @@ class CORE_EXPORT QgsApplication : public QApplication */ void collectTranslatableObjects( QgsTranslationContext *translationContext ); - /** - * Contains QgsApplication settings - * \since QGIS 3.20 - */ - struct Settings - { - //! Settings entry locale user locale - static const inline QgsSettingsEntryString localeUserLocale = QgsSettingsEntryString( QStringLiteral( "locale/userLocale" ), QgsSettings::NoSection, QString() ); - //! Settings entry locale override flag - static const inline QgsSettingsEntryBool localeOverrideFlag = QgsSettingsEntryBool( QStringLiteral( "locale/overrideFlag" ), QgsSettings::NoSection, false ); - //! Settings entry locale global locale - static const inline QgsSettingsEntryString localeGlobalLocale = QgsSettingsEntryString( QStringLiteral( "locale/globalLocale" ), QgsSettings::NoSection, QString() ); - //! Settings entry locale show group separator - static const inline QgsSettingsEntryBool localeShowGroupSeparator = QgsSettingsEntryBool( QStringLiteral( "locale/showGroupSeparator" ), QgsSettings::NoSection, false ); - //! Settings entry search path for SVG - static const inline QgsSettingsEntryStringList searchPathsForSVG = QgsSettingsEntryStringList( QStringLiteral( "svg/searchPathsForSVG" ), QgsSettings::NoSection, QStringList() ); - }; + //! Settings entry locale user locale + static const inline QgsSettingsEntryString settingsLocaleUserLocale = QgsSettingsEntryString( QStringLiteral( "locale/userLocale" ), QgsSettings::NoSection, QString() ); + //! Settings entry locale override flag + static const inline QgsSettingsEntryBool settingsLocaleOverrideFlag = QgsSettingsEntryBool( QStringLiteral( "locale/overrideFlag" ), QgsSettings::NoSection, false ); + //! Settings entry locale global locale + static const inline QgsSettingsEntryString settingsLocaleGlobalLocale = QgsSettingsEntryString( QStringLiteral( "locale/globalLocale" ), QgsSettings::NoSection, QString() ); + //! Settings entry locale show group separator + static const inline QgsSettingsEntryBool settingsLocaleShowGroupSeparator = QgsSettingsEntryBool( QStringLiteral( "locale/showGroupSeparator" ), QgsSettings::NoSection, false ); + //! Settings entry search path for SVG + static const inline QgsSettingsEntryStringList settingsSearchPathsForSVG = QgsSettingsEntryStringList( QStringLiteral( "svg/searchPathsForSVG" ), QgsSettings::NoSection, QStringList() ); #ifdef SIP_RUN SIP_IF_FEATURE( ANDROID ) diff --git a/src/core/qgsgeometryoptions.cpp b/src/core/qgsgeometryoptions.cpp index 2c37c7c2f859..750ce7744845 100644 --- a/src/core/qgsgeometryoptions.cpp +++ b/src/core/qgsgeometryoptions.cpp @@ -23,7 +23,7 @@ QgsGeometryOptions::QgsGeometryOptions() { - mGeometryChecks = Settings::geometryValidationDefaultChecks.value().split( ',' ) ; + mGeometryChecks = settingsGeometryValidationDefaultChecks.value().split( ',' ) ; } bool QgsGeometryOptions::removeDuplicateNodes() const diff --git a/src/core/qgsgeometryoptions.h b/src/core/qgsgeometryoptions.h index 4ec9fdb1b626..8fae89986ef4 100644 --- a/src/core/qgsgeometryoptions.h +++ b/src/core/qgsgeometryoptions.h @@ -132,15 +132,8 @@ class CORE_EXPORT QgsGeometryOptions : public QObject */ void readXml( const QDomNode &node ); - /** - * Contains QgsGeometryOptions settings - * \since QGIS 3.20 - */ - struct Settings - { - //! Settings entry search path for templates - static const inline QgsSettingsEntryString geometryValidationDefaultChecks = QgsSettingsEntryString( QStringLiteral( "geometry_validation/default_checks" ), QgsSettings::NoSection, QString() ); - }; + //! Settings entry search path for templates + static const inline QgsSettingsEntryString settingsGeometryValidationDefaultChecks = QgsSettingsEntryString( QStringLiteral( "geometry_validation/default_checks" ), QgsSettings::NoSection, QString() ); signals: diff --git a/src/core/qgslocalizeddatapathregistry.cpp b/src/core/qgslocalizeddatapathregistry.cpp index f5bb8911cc99..7c148b05d576 100644 --- a/src/core/qgslocalizeddatapathregistry.cpp +++ b/src/core/qgslocalizeddatapathregistry.cpp @@ -105,10 +105,10 @@ void QgsLocalizedDataPathRegistry::unregisterPath( const QString &path ) void QgsLocalizedDataPathRegistry::readFromSettings() { - setPaths( Settings::localizedDataPaths.value() ); + setPaths( settingsLocalizedDataPaths.value() ); } void QgsLocalizedDataPathRegistry::writeToSettings() { - Settings::localizedDataPaths.setValue( paths() ); + settingsLocalizedDataPaths.setValue( paths() ); } diff --git a/src/core/qgslocalizeddatapathregistry.h b/src/core/qgslocalizeddatapathregistry.h index a686638026fb..b1e222c5efee 100644 --- a/src/core/qgslocalizeddatapathregistry.h +++ b/src/core/qgslocalizeddatapathregistry.h @@ -66,15 +66,8 @@ class CORE_EXPORT QgsLocalizedDataPathRegistry //! Unregisters a localized path void unregisterPath( const QString &path ); - /** - * Contains QgsLocalizedDataPathRegistry settings - * \since QGIS 3.20 - */ - struct Settings - { - //! Settings entry localized data paths - static const inline QgsSettingsEntryStringList localizedDataPaths = QgsSettingsEntryStringList( QStringLiteral( "/qgis/localized_data_paths" ), QgsSettings::NoSection, QStringList() ); - }; + //! Settings entry localized data paths + static const inline QgsSettingsEntryStringList settingsLocalizedDataPaths = QgsSettingsEntryStringList( QStringLiteral( "/qgis/localized_data_paths" ), QgsSettings::NoSection, QStringList() ); private: #ifdef SIP_RUN diff --git a/src/core/qgsmaprendererjob.cpp b/src/core/qgsmaprendererjob.cpp index 24667c51d015..2128ac38d2ca 100644 --- a/src/core/qgsmaprendererjob.cpp +++ b/src/core/qgsmaprendererjob.cpp @@ -977,7 +977,7 @@ void QgsMapRendererJob::composeSecondPass( LayerRenderJobs &secondPassJobs, Labe void QgsMapRendererJob::logRenderingTime( const LayerRenderJobs &jobs, const LayerRenderJobs &secondPassJobs, const LabelRenderJob &labelJob ) { - if ( !Settings::logCanvasRefreshEvent.value() ) + if ( !settingsLogCanvasRefreshEvent.value() ) return; QMultiMap elapsed; diff --git a/src/core/qgsmaprendererjob.h b/src/core/qgsmaprendererjob.h index 305bdfdd24c0..cc382738a866 100644 --- a/src/core/qgsmaprendererjob.h +++ b/src/core/qgsmaprendererjob.h @@ -344,16 +344,8 @@ class CORE_EXPORT QgsMapRendererJob : public QObject */ static const QString LABEL_PREVIEW_CACHE_ID SIP_SKIP; - - /** - * Contains QgsMapRendererJob settings - * \since QGIS 3.20 - */ - struct Settings - { - //! Settings entry log canvas refresh event - static const inline QgsSettingsEntryBool logCanvasRefreshEvent = QgsSettingsEntryBool( QStringLiteral( "Map/logCanvasRefreshEvent" ), QgsSettings::NoSection, false ); - }; + //! Settings entry log canvas refresh event + static const inline QgsSettingsEntryBool settingsLogCanvasRefreshEvent = QgsSettingsEntryBool( QStringLiteral( "Map/logCanvasRefreshEvent" ), QgsSettings::NoSection, false ); signals: diff --git a/src/core/settings/qgssettingsentry.cpp b/src/core/settings/qgssettingsentry.cpp index f1de37748007..0c90ee8ac10d 100644 --- a/src/core/settings/qgssettingsentry.cpp +++ b/src/core/settings/qgssettingsentry.cpp @@ -80,6 +80,7 @@ QString QgsSettingsEntryBase::key( const QStringList &dynamicKeyPartList ) const completeKey.replace( QString( "%%1" ).arg( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) ); } } + return completeKey; } QString QgsSettingsEntryBase::definitionKey() const diff --git a/src/core/settings/qgssettingsregistrycore.cpp b/src/core/settings/qgssettingsregistrycore.cpp index e163f8e2dbcb..2e94674c5fbd 100644 --- a/src/core/settings/qgssettingsregistrycore.cpp +++ b/src/core/settings/qgssettingsregistrycore.cpp @@ -34,29 +34,29 @@ QgsSettingsRegistryCore::QgsSettingsRegistryCore() addSettingsEntry( &QgsLocator::settingsLocatorFilterDefault ); addSettingsEntry( &QgsLocator::settingsLocatorFilterPrefix ); - addSettingsEntry( &QgsNetworkAccessManager::Settings::networkTimeout ); + addSettingsEntry( &QgsNetworkAccessManager::settingsNetworkTimeout ); - addSettingsEntry( &QgsNewsFeedParser::Settings::feedLastFetchTime ); - addSettingsEntry( &QgsNewsFeedParser::Settings::feedLanguage ); - addSettingsEntry( &QgsNewsFeedParser::Settings::feedLatitude ); - addSettingsEntry( &QgsNewsFeedParser::Settings::feedLongitude ); + addSettingsEntry( &QgsNewsFeedParser::settingsFeedLastFetchTime ); + addSettingsEntry( &QgsNewsFeedParser::settingsFeedLanguage ); + addSettingsEntry( &QgsNewsFeedParser::settingsFeedLatitude ); + addSettingsEntry( &QgsNewsFeedParser::settingsFeedLongitude ); - addSettingsEntry( &QgsProcessing::Settings::preferFilenameAsLayerName ); - addSettingsEntry( &QgsProcessing::Settings::tempPath ); - addSettingsEntry( &QgsProcessing::Settings::defaultOutputVectorLayerExt ); - addSettingsEntry( &QgsProcessing::Settings::defaultOutputRasterLayerExt ); + addSettingsEntry( &QgsProcessing::settingsPreferFilenameAsLayerName ); + addSettingsEntry( &QgsProcessing::settingsTempPath ); + addSettingsEntry( &QgsProcessing::settingsDefaultOutputVectorLayerExt ); + addSettingsEntry( &QgsProcessing::settingsDefaultOutputRasterLayerExt ); - addSettingsEntry( &QgsApplication::Settings::localeUserLocale ); - addSettingsEntry( &QgsApplication::Settings::localeOverrideFlag ); - addSettingsEntry( &QgsApplication::Settings::localeGlobalLocale ); - addSettingsEntry( &QgsApplication::Settings::localeShowGroupSeparator ); - addSettingsEntry( &QgsApplication::Settings::searchPathsForSVG ); + addSettingsEntry( &QgsApplication::settingsLocaleUserLocale ); + addSettingsEntry( &QgsApplication::settingsLocaleOverrideFlag ); + addSettingsEntry( &QgsApplication::settingsLocaleGlobalLocale ); + addSettingsEntry( &QgsApplication::settingsLocaleShowGroupSeparator ); + addSettingsEntry( &QgsApplication::settingsSearchPathsForSVG ); - addSettingsEntry( &QgsGeometryOptions::Settings::geometryValidationDefaultChecks ); + addSettingsEntry( &QgsGeometryOptions::settingsGeometryValidationDefaultChecks ); - addSettingsEntry( &QgsLocalizedDataPathRegistry::Settings::localizedDataPaths ); + addSettingsEntry( &QgsLocalizedDataPathRegistry::settingsLocalizedDataPaths ); - addSettingsEntry( &QgsMapRendererJob::Settings::logCanvasRefreshEvent ); + addSettingsEntry( &QgsMapRendererJob::settingsLogCanvasRefreshEvent ); } QgsSettingsRegistryCore::~QgsSettingsRegistryCore() diff --git a/src/gui/qgsconfigureshortcutsdialog.cpp b/src/gui/qgsconfigureshortcutsdialog.cpp index 5daa3a82d158..e5dd2a4c0d47 100644 --- a/src/gui/qgsconfigureshortcutsdialog.cpp +++ b/src/gui/qgsconfigureshortcutsdialog.cpp @@ -136,7 +136,7 @@ void QgsConfigureShortcutsDialog::saveShortcuts() QDomDocument doc( QStringLiteral( "shortcuts" ) ); QDomElement root = doc.createElement( QStringLiteral( "qgsshortcuts" ) ); root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) ); - root.setAttribute( QStringLiteral( "locale" ), settings.value( QgsApplication::Settings::localeUserLocale.key(), "en_US" ).toString() ); + root.setAttribute( QStringLiteral( "locale" ), settings.value( QgsApplication::settingsLocaleUserLocale.key(), "en_US" ).toString() ); doc.appendChild( root ); settings.beginGroup( mManager->settingsPath() ); @@ -205,10 +205,10 @@ void QgsConfigureShortcutsDialog::loadShortcuts() QString currentLocale; - bool localeOverrideFlag = QgsApplication::Settings::localeOverrideFlag.value(); + bool localeOverrideFlag = QgsApplication::settingsLocaleOverrideFlag.value(); if ( localeOverrideFlag ) { - currentLocale = QgsSettings().value( QgsApplication::Settings::localeUserLocale.key(), "en_US" ).toString(); + currentLocale = QgsApplication::settingsLocaleUserLocale.value( QString(), true, "en_US" ); } else // use QGIS locale { diff --git a/src/gui/qgsgui.cpp b/src/gui/qgsgui.cpp index 1c6636ae11e0..4fcf9bdc7004 100644 --- a/src/gui/qgsgui.cpp +++ b/src/gui/qgsgui.cpp @@ -174,7 +174,7 @@ void QgsGui::setWindowManager( QgsWindowManagerInterface *manager ) QgsGui::HigFlags QgsGui::higFlags() { - if ( QgsApplication::Settings::localeUserLocale.value().startsWith( QLatin1String( "en" ) ) ) + if ( QgsApplication::settingsLocaleUserLocale.value().startsWith( QLatin1String( "en" ) ) ) { return HigMenuTextIsTitleCase | HigDialogTitleIsTitleCase; } diff --git a/src/gui/qgsmapcanvas.cpp b/src/gui/qgsmapcanvas.cpp index b53df96806f5..0b9e56a6e44e 100644 --- a/src/gui/qgsmapcanvas.cpp +++ b/src/gui/qgsmapcanvas.cpp @@ -706,7 +706,7 @@ void QgsMapCanvas::rendererJobFinished() QPainter p( &img ); emit renderComplete( &p ); - if ( QgsMapRendererJob::Settings::logCanvasRefreshEvent.value() ) + if ( QgsMapRendererJob::settingsLogCanvasRefreshEvent.value() ) { QString logMsg = tr( "Canvas refresh: %1 ms" ).arg( mJob->renderingTime() ); QgsMessageLog::logMessage( logMsg, tr( "Rendering" ) ); diff --git a/tests/src/analysis/testqgsprocessing.cpp b/tests/src/analysis/testqgsprocessing.cpp index bb0122329060..0f688306fa65 100644 --- a/tests/src/analysis/testqgsprocessing.cpp +++ b/tests/src/analysis/testqgsprocessing.cpp @@ -2303,11 +2303,11 @@ void TestQgsProcessing::parameters() context2.layersToLoadOnCompletion().values().at( 0 ).setOutputLayerName( rl.get() ); QCOMPARE( rl->name(), QStringLiteral( "landsat" ) ); // unless setting prohibits it... - QgsProcessing::Settings::preferFilenameAsLayerName.setValue( false ); + QgsProcessing::settingsPreferFilenameAsLayerName.setValue( false ); context2.layersToLoadOnCompletion().values().at( 0 ).setOutputLayerName( rl.get() ); QCOMPARE( rl->name(), QStringLiteral( "my_dest" ) ); // if layer has a layername, we should use that instead of the base file name... - QgsProcessing::Settings::preferFilenameAsLayerName.setValue( true ); + QgsProcessing::settingsPreferFilenameAsLayerName.setValue( true ); vl = std::make_unique< QgsVectorLayer >( QStringLiteral( TEST_DATA_DIR ) + "/points_gpkg.gpkg|layername=points_small", QString() ); context2.layersToLoadOnCompletion().values().at( 0 ).setOutputLayerName( vl.get() ); QCOMPARE( vl->name(), QStringLiteral( "points_small" ) ); @@ -11042,7 +11042,7 @@ void TestQgsProcessing::tempUtils() QgsSettings settings; QString alternative_tempFolder1 = tempDirPath + QStringLiteral( "/alternative_temp_test_one" ); - QgsProcessing::Settings::tempPath.setValue( alternative_tempFolder1 ); + QgsProcessing::settingsTempPath.setValue( alternative_tempFolder1 ); // check folder and if it's constant with alternative temp folder 1 tempFolder = QgsProcessingUtils::tempFolder(); QCOMPARE( tempFolder.left( alternative_tempFolder1.length() ), alternative_tempFolder1 ); @@ -11054,7 +11054,7 @@ void TestQgsProcessing::tempUtils() QVERIFY( alternativeTempFile1.startsWith( alternative_tempFolder1 ) ); // change temp folder in the settings again QString alternative_tempFolder2 = tempDirPath + QStringLiteral( "/alternative_temp_test_two" ); - QgsProcessing::Settings::tempPath.setValue( alternative_tempFolder2 ); + QgsProcessing::settingsTempPath.setValue( alternative_tempFolder2 ); // check folder and if it's constant constant with alternative temp folder 2 tempFolder = QgsProcessingUtils::tempFolder(); QCOMPARE( tempFolder.left( alternative_tempFolder2.length() ), alternative_tempFolder2 ); @@ -11064,7 +11064,7 @@ void TestQgsProcessing::tempUtils() QVERIFY( alternativeTempFile2.endsWith( "alternative_temptest.txt" ) ); QVERIFY( alternativeTempFile2.startsWith( tempFolder ) ); QVERIFY( alternativeTempFile2.startsWith( alternative_tempFolder2 ) ); - QgsProcessing::Settings::tempPath.setValue( QString() ); + QgsProcessing::settingsTempPath.setValue( QString() ); } @@ -11529,8 +11529,8 @@ void TestQgsProcessing::defaultExtensionsForProvider() QCOMPARE( context.preferredRasterFormat(), QStringLiteral( "tif" ) ); // unless the user has set a default format, which IS supported by that provider - QgsProcessing::Settings::defaultOutputVectorLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "tab" ) ) ); - QgsProcessing::Settings::defaultOutputRasterLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "sdat" ) ) ); + QgsProcessing::settingsDefaultOutputVectorLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "tab" ) ) ); + QgsProcessing::settingsDefaultOutputRasterLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "sdat" ) ) ); QCOMPARE( provider.defaultVectorFileExtension( true ), QStringLiteral( "tab" ) ); QCOMPARE( provider.defaultRasterFileExtension(), QStringLiteral( "sdat" ) ); @@ -11541,8 +11541,8 @@ void TestQgsProcessing::defaultExtensionsForProvider() QCOMPARE( context2.preferredRasterFormat(), QStringLiteral( "sdat" ) ); // but if default is not supported by provider, we use a supported format - QgsProcessing::Settings::defaultOutputVectorLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "gpkg" ) ) ); - QgsProcessing::Settings::defaultOutputRasterLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "ecw" ) ) ); + QgsProcessing::settingsDefaultOutputVectorLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "gpkg" ) ) ); + QgsProcessing::settingsDefaultOutputRasterLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "ecw" ) ) ); QCOMPARE( provider.defaultVectorFileExtension( true ), QStringLiteral( "mif" ) ); QCOMPARE( provider.defaultRasterFileExtension(), QStringLiteral( "mig" ) ); } diff --git a/tests/src/core/testqgscompositionconverter.cpp b/tests/src/core/testqgscompositionconverter.cpp index b973c7165c16..346c211410c7 100644 --- a/tests/src/core/testqgscompositionconverter.cpp +++ b/tests/src/core/testqgscompositionconverter.cpp @@ -163,7 +163,7 @@ void TestQgsCompositionConverter::initTestCase() QgsApplication::init(); QgsApplication::initQgis(); mReport = QStringLiteral( "

Layout Tests

\n" ); - QgsApplication::Settings::searchPathsForSVG.setValue( QStringLiteral( TEST_DATA_DIR ) ); + QgsApplication::settingsSearchPathsForSVG.setValue( QStringList() << QStringLiteral( TEST_DATA_DIR ) ); } void TestQgsCompositionConverter::cleanupTestCase() diff --git a/tests/src/core/testqgsnetworkaccessmanager.cpp b/tests/src/core/testqgsnetworkaccessmanager.cpp index e38294750b31..f8b51c6cd43a 100644 --- a/tests/src/core/testqgsnetworkaccessmanager.cpp +++ b/tests/src/core/testqgsnetworkaccessmanager.cpp @@ -175,7 +175,7 @@ void TestQgsNetworkAccessManager::initTestCase() QgsApplication::init(); QgsApplication::initQgis(); - QgsNetworkAccessManager::Settings::networkTimeout.setValue( 5000 ); + QgsNetworkAccessManager::settingsNetworkTimeout.setValue( 5000 ); mHttpBinHost = QStringLiteral( "httpbin.org" ); QString overrideHost = qgetenv( "QGIS_HTTPBIN_HOST" ); diff --git a/tests/src/core/testqgsnewsfeedparser.cpp b/tests/src/core/testqgsnewsfeedparser.cpp index 9601ad9b84f9..28ba11ad1817 100644 --- a/tests/src/core/testqgsnewsfeedparser.cpp +++ b/tests/src/core/testqgsnewsfeedparser.cpp @@ -111,12 +111,12 @@ void TestQgsNewsFeedParser::testFetch() entries.clear(); // after a fetch, the current timestamp should be saved to avoid refetching these - uint after = QgsNewsFeedParser::Settings::feedLastFetchTime.value( feedKey ); + uint after = QgsNewsFeedParser::settingsFeedLastFetchTime.value( feedKey ); QVERIFY( after >= beforeTime ); // reset to a standard known last time QgsSettings().remove( feedKey, QgsSettings::Core ); - QgsNewsFeedParser::Settings::feedLastFetchTime.setValue( 1457360008, feedKey ); + QgsNewsFeedParser::settingsFeedLastFetchTime.setValue( 1457360008, feedKey ); // refetch, only new items should be fetched QgsNewsFeedParser parser2( url ); @@ -230,7 +230,7 @@ void TestQgsNewsFeedParser::testLang() const QString feedKey = QgsNewsFeedParser::keyForFeed( url.toString() ); QgsSettings().remove( feedKey, QgsSettings::Core ); // force to Spanish language - QgsNewsFeedParser::Settings::feedLanguage.setValue( QStringLiteral( "es" ), feedKey ); + QgsNewsFeedParser::settingsFeedLanguage.setValue( QStringLiteral( "es" ), feedKey ); QgsNewsFeedParser parser( url ); QSignalSpy spy( &parser, &QgsNewsFeedParser::entryAdded ); @@ -256,8 +256,8 @@ void TestQgsNewsFeedParser::testGeoFencing() const QUrl url( QUrl::fromLocalFile( QStringLiteral( TEST_DATA_DIR ) + "/newsfeed/feed" ) ); const QString feedKey = QgsNewsFeedParser::keyForFeed( url.toString() ); QgsSettings().remove( feedKey, QgsSettings::Core ); - QgsNewsFeedParser::Settings::feedLatitude.setValue( 37.2343, feedKey ); - QgsNewsFeedParser::Settings::feedLongitude.setValue( -115.8067, feedKey ); + QgsNewsFeedParser::settingsFeedLatitude.setValue( 37.2343, feedKey ); + QgsNewsFeedParser::settingsFeedLongitude.setValue( -115.8067, feedKey ); QgsNewsFeedParser parser( url ); QSignalSpy spy( &parser, &QgsNewsFeedParser::entryAdded ); diff --git a/tests/src/core/testqgstranslateproject.cpp b/tests/src/core/testqgstranslateproject.cpp index 5c1cf04339fe..aa5f674f81ad 100644 --- a/tests/src/core/testqgstranslateproject.cpp +++ b/tests/src/core/testqgstranslateproject.cpp @@ -57,12 +57,12 @@ void TestQgsTranslateProject::initTestCase() QgsApplication::init(); QgsApplication::initQgis(); - original_locale = QgsApplication::Settings::localeUserLocale.value(); + original_locale = QgsApplication::settingsLocaleUserLocale.value(); } void TestQgsTranslateProject::cleanupTestCase() { - QgsApplication::Settings::localeUserLocale.setValue( original_locale ); + QgsApplication::settingsLocaleUserLocale.setValue( original_locale ); QgsApplication::exitQgis(); //delete translated project file @@ -91,7 +91,7 @@ void TestQgsTranslateProject::cleanup() void TestQgsTranslateProject::createTsFile() { //open project in english - QgsApplication::Settings::localeUserLocale.setValue( "en" ); + QgsApplication::settingsLocaleUserLocale.setValue( "en" ); QString projectFileName( TEST_DATA_DIR ); projectFileName = projectFileName + "/project_translation/points_translation.qgs"; QgsProject::instance()->read( projectFileName ); @@ -163,7 +163,7 @@ void TestQgsTranslateProject::createTsFile() void TestQgsTranslateProject::translateProject() { //open project in german - QgsApplication::Settings::localeUserLocale.setValue( "de" ); + QgsApplication::settingsLocaleUserLocale.setValue( "de" ); QString projectFileName( TEST_DATA_DIR ); projectFileName = projectFileName + "/project_translation/points_translation.qgs"; QgsProject::instance()->read( projectFileName ); From 6e1ef0e988a91f1945b58f1db123ec9fe3989aa1 Mon Sep 17 00:00:00 2001 From: Damiano Date: Fri, 16 Apr 2021 11:14:02 +0200 Subject: [PATCH 04/13] testqgssettingsregistry --- .../settings/qgssettingsentry.sip.in | 7 +++++++ src/core/settings/qgssettingsentry.cpp | 16 +++++++++++++--- src/core/settings/qgssettingsentry.h | 7 +++++++ src/core/settings/qgssettingsregistry.cpp | 4 +--- tests/src/core/testqgssettingsregistry.cpp | 15 ++++++++++----- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/python/core/auto_generated/settings/qgssettingsentry.sip.in b/python/core/auto_generated/settings/qgssettingsentry.sip.in index 95a11fa3aa3b..54e7b4e4d328 100644 --- a/python/core/auto_generated/settings/qgssettingsentry.sip.in +++ b/python/core/auto_generated/settings/qgssettingsentry.sip.in @@ -82,6 +82,13 @@ The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. Get settings entry key. The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. +%End + + bool checkKey( const QString &key ) const; +%Docstring +Returns true if the provided key match the settings entry + +The ``key`` to check %End QString definitionKey() const; diff --git a/src/core/settings/qgssettingsentry.cpp b/src/core/settings/qgssettingsentry.cpp index 0c90ee8ac10d..5cd187992b03 100644 --- a/src/core/settings/qgssettingsentry.cpp +++ b/src/core/settings/qgssettingsentry.cpp @@ -83,14 +83,24 @@ QString QgsSettingsEntryBase::key( const QStringList &dynamicKeyPartList ) const return completeKey; } +bool QgsSettingsEntryBase::checkKey( const QString &key ) const +{ + if ( !hasDynamicKey() ) + return key == QgsSettingsEntryBase::key(); + + QRegularExpression regularExpression( definitionKey().replace( QRegularExpression( "%\\d+" ), ".*" ) ); + QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( key ); + return regularExpresisonMatch.hasMatch(); +} + QString QgsSettingsEntryBase::definitionKey() const { QString completeKey = mKey; if ( !mPluginName.isEmpty() ) { - if ( completeKey.startsWith( '/' ) ) - completeKey.remove( 0, 1 ); - completeKey.prepend( mPluginName + "/" ); + if ( !completeKey.startsWith( "/" ) ) + completeKey.prepend( "/" ); + completeKey.prepend( mPluginName ); } return completeKey; diff --git a/src/core/settings/qgssettingsentry.h b/src/core/settings/qgssettingsentry.h index caa46eab9156..bf2b59ed5781 100644 --- a/src/core/settings/qgssettingsentry.h +++ b/src/core/settings/qgssettingsentry.h @@ -119,6 +119,13 @@ class CORE_EXPORT QgsSettingsEntryBase */ QString key( const QStringList &dynamicKeyPartList ) const; + /** + * Returns true if the provided key match the settings entry + * + * The \a key to check + */ + bool checkKey( const QString &key ) const; + /** * Returns settings entry defining key. * For dynamic settings it return the key with the placeholder for dynamic part diff --git a/src/core/settings/qgssettingsregistry.cpp b/src/core/settings/qgssettingsregistry.cpp index cd96408a51a6..1eeb4692d72d 100644 --- a/src/core/settings/qgssettingsregistry.cpp +++ b/src/core/settings/qgssettingsregistry.cpp @@ -43,9 +43,7 @@ const QgsSettingsEntryBase *QgsSettingsRegistry::getSettingsEntry( const QString const QMap dynamicSettingsEntriesMap = mDynamicSettingsEntriesMap; for ( const QgsSettingsEntryBase *settingsEntry : dynamicSettingsEntriesMap ) { - QRegularExpression regularExpression( settingsEntry->key( ".*" ) ); - QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( key ); - if ( regularExpresisonMatch.hasMatch() ) + if ( settingsEntry->checkKey( key ) ) return settingsEntry; } diff --git a/tests/src/core/testqgssettingsregistry.cpp b/tests/src/core/testqgssettingsregistry.cpp index 6139dd948c2b..534391b0ff73 100644 --- a/tests/src/core/testqgssettingsregistry.cpp +++ b/tests/src/core/testqgssettingsregistry.cpp @@ -54,21 +54,26 @@ void TestQgsSettingsRegistry::getSettingsEntries() void TestQgsSettingsRegistry::getSettingsEntriesWithDynamicKeys() { - QString settingsEntryBoolKey( "/qgis/testing/%_settingsEntryBool" ); + QString settingsEntryBoolKey( "/qgis/testing/%1_settingsEntryBool" ); QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false ); - QString settingsEntryIntegerKey( "/qgis/testing/%/settingsEntryInteger" ); + QString settingsEntryIntegerKey( "/qgis/testing/%1/settingsEntryInteger" ); QgsSettingsEntryBool settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 ); + QString settingsEntryDoubleKey( "/qgis/testing/%1/settingsEntryDouble_%2" ); + QgsSettingsEntryBool settingsEntryDouble( settingsEntryDoubleKey, QgsSettings::NoSection, 1.23 ); - QString settingsEntryInexisting( "/qgis/testing/settingsEntryInexisting%" ); + QString settingsEntryInexisting( "/qgis/testing/settingsEntryInexisting%1" ); QgsSettingsRegistry settingsRegistry; settingsRegistry.addSettingsEntry( &settingsEntryBool ); settingsRegistry.addSettingsEntry( &settingsEntryInteger ); + settingsRegistry.addSettingsEntry( &settingsEntryDouble ); QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey ), &settingsEntryBool ); - QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey.replace( "%", "1st" ) ), &settingsEntryBool ); - QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey.replace( "%", "Second" ) ), &settingsEntryInteger ); + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey.replace( "%1", "1st" ) ), &settingsEntryBool ); QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey ), &settingsEntryInteger ); + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey.replace( "%1", "Second" ) ), &settingsEntryInteger ); + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryDoubleKey ), &settingsEntryDouble ); + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryDoubleKey.replace( "%1", "1st" ).replace( "%2", "2nd" ) ), &settingsEntryDouble ); QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryInexisting ), nullptr ); } From 68ee4442ca1803dd0fa27017c024896bb0440591 Mon Sep 17 00:00:00 2001 From: Damiano Date: Sun, 18 Apr 2021 23:22:40 +0200 Subject: [PATCH 05/13] Added api to add child settings registries to settings registry --- .../settings/qgssettingsregistry.sip.in | 23 ++++++- src/core/settings/qgssettingsregistry.cpp | 67 ++++++++++++++++--- src/core/settings/qgssettingsregistry.h | 26 +++++-- tests/src/core/testqgssettingsregistry.cpp | 24 +++++++ tests/src/python/CMakeLists.txt | 1 + tests/src/python/test_qgssettingsentry.py | 4 -- tests/src/python/test_qgssettingsregistry.py | 52 ++++++++++++++ 7 files changed, 175 insertions(+), 22 deletions(-) create mode 100644 tests/src/python/test_qgssettingsregistry.py diff --git a/python/core/auto_generated/settings/qgssettingsregistry.sip.in b/python/core/auto_generated/settings/qgssettingsregistry.sip.in index 05809aaf9391..b3f3b34d2d83 100644 --- a/python/core/auto_generated/settings/qgssettingsregistry.sip.in +++ b/python/core/auto_generated/settings/qgssettingsregistry.sip.in @@ -31,14 +31,31 @@ Constructor for QgsSettingsRegistry. virtual ~QgsSettingsRegistry(); - const QgsSettingsEntryBase *getSettingsEntry( const QString &key ); + void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); +%Docstring +Add ``settingsEntry`` to the register. +%End + + QList getChildSettingsEntries() const; +%Docstring +Returns the list of registered :py:class:`QgsSettingsEntryBase`. +%End + + const QgsSettingsEntryBase *getSettingsEntry( const QString &key, bool searchChildRegistries = true ) const; %Docstring Returns the :py:class:`QgsSettingsEntry` with the given ``key`` or None if not found. + +The ``searchChildRegistries`` parameter specifies if child registries should be included in the search %End - void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); + void addChildSettingsRegistry( const QgsSettingsRegistry *settingsRegistry ); %Docstring -Add ``settingsEntry`` to the register. +Add a child ``settingsRegistry`` to the register. +%End + + QList getChildSettingsRegistries() const; +%Docstring +Returns the list of registered child QgsSettingsRegistry. %End }; diff --git a/src/core/settings/qgssettingsregistry.cpp b/src/core/settings/qgssettingsregistry.cpp index 1eeb4692d72d..c1e265d25160 100644 --- a/src/core/settings/qgssettingsregistry.cpp +++ b/src/core/settings/qgssettingsregistry.cpp @@ -27,7 +27,7 @@ QgsSettingsRegistry::QgsSettingsRegistry() : mSettingsEntriesMap() - , mDynamicSettingsEntriesMap() + , mSettingsRegistryChildList() { } @@ -35,25 +35,70 @@ QgsSettingsRegistry::~QgsSettingsRegistry() { } -const QgsSettingsEntryBase *QgsSettingsRegistry::getSettingsEntry( const QString &key ) +void QgsSettingsRegistry::addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ) { - if ( mSettingsEntriesMap.contains( key ) ) - return mSettingsEntriesMap.value( key ); + if ( settingsEntry == nullptr ) + { + QgsLogger::warning( QStringLiteral( "Trying to register a nullptr settings entry." ) ); + return; + } - const QMap dynamicSettingsEntriesMap = mDynamicSettingsEntriesMap; - for ( const QgsSettingsEntryBase *settingsEntry : dynamicSettingsEntriesMap ) + if ( mSettingsEntriesMap.contains( settingsEntry->definitionKey() ) ) + { + QgsLogger::warning( QStringLiteral( "Settings with key '%1' is already registered." ).arg( settingsEntry->definitionKey() ) ); + return; + } + + mSettingsEntriesMap.insert( settingsEntry->definitionKey(), settingsEntry ); +} + +QList QgsSettingsRegistry::getChildSettingsEntries() const +{ + return mSettingsEntriesMap.values(); +} + +const QgsSettingsEntryBase *QgsSettingsRegistry::getSettingsEntry( const QString &key, bool searchChildRegistries ) const +{ + // Search in this registry + const QMap settingsEntriesMap = mSettingsEntriesMap; + for ( const QgsSettingsEntryBase *settingsEntry : settingsEntriesMap ) { if ( settingsEntry->checkKey( key ) ) return settingsEntry; } + // Search in child registries + if ( searchChildRegistries ) + { + for ( const QgsSettingsRegistry *settingsRegistry : mSettingsRegistryChildList ) + { + const QgsSettingsEntryBase *settingsEntry = settingsRegistry->getSettingsEntry( key, true ); + if ( settingsEntry != nullptr ) + return settingsEntry; + } + } + return nullptr; } -void QgsSettingsRegistry::addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ) +void QgsSettingsRegistry::addChildSettingsRegistry( const QgsSettingsRegistry *settingsRegistry ) +{ + if ( settingsRegistry == nullptr ) + { + QgsLogger::warning( QStringLiteral( "Trying to register a nullptr child settings registry." ) ); + return; + } + + if ( mSettingsRegistryChildList.contains( settingsRegistry ) ) + { + QgsLogger::warning( QStringLiteral( "Child register is already registered." ) ); + return; + } + + mSettingsRegistryChildList.append( settingsRegistry ); +} + +QList QgsSettingsRegistry::getChildSettingsRegistries() const { - if ( settingsEntry->hasDynamicKey() ) - mDynamicSettingsEntriesMap.insert( settingsEntry->definitionKey(), settingsEntry ); - else - mSettingsEntriesMap.insert( settingsEntry->key(), settingsEntry ); + return mSettingsRegistryChildList; } diff --git a/src/core/settings/qgssettingsregistry.h b/src/core/settings/qgssettingsregistry.h index 77d96daf6d52..6d2ee9fb5531 100644 --- a/src/core/settings/qgssettingsregistry.h +++ b/src/core/settings/qgssettingsregistry.h @@ -45,20 +45,38 @@ class CORE_EXPORT QgsSettingsRegistry */ virtual ~QgsSettingsRegistry(); + /** + * Add \a settingsEntry to the register. + */ + void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); + + /** + * Returns the list of registered QgsSettingsEntryBase. + */ + QList getChildSettingsEntries() const; + /** * Returns the QgsSettingsEntry with the given \a key or nullptr if not found. + * + * The \a searchChildRegistries parameter specifies if child registries should be included in the search */ - const QgsSettingsEntryBase *getSettingsEntry( const QString &key ); + const QgsSettingsEntryBase *getSettingsEntry( const QString &key, bool searchChildRegistries = true ) const; /** - * Add \a settingsEntry to the register. + * Add a child \a settingsRegistry to the register. */ - void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); + void addChildSettingsRegistry( const QgsSettingsRegistry *settingsRegistry ); + + /** + * Returns the list of registered child QgsSettingsRegistry. + */ + QList getChildSettingsRegistries() const; private: QMap mSettingsEntriesMap; - QMap mDynamicSettingsEntriesMap; + + QList mSettingsRegistryChildList; }; diff --git a/tests/src/core/testqgssettingsregistry.cpp b/tests/src/core/testqgssettingsregistry.cpp index 534391b0ff73..25f8cfcf7e1a 100644 --- a/tests/src/core/testqgssettingsregistry.cpp +++ b/tests/src/core/testqgssettingsregistry.cpp @@ -32,6 +32,7 @@ class TestQgsSettingsRegistry : public QObject private slots: void getSettingsEntries(); void getSettingsEntriesWithDynamicKeys(); + void childRegistry(); }; void TestQgsSettingsRegistry::getSettingsEntries() @@ -44,6 +45,7 @@ void TestQgsSettingsRegistry::getSettingsEntries() QString settingsEntryInexisting( "/qgis/testing/settingsEntryInexisting" ); QgsSettingsRegistry settingsRegistry; + settingsRegistry.addSettingsEntry( nullptr ); // should not crash settingsRegistry.addSettingsEntry( &settingsEntryBool ); settingsRegistry.addSettingsEntry( &settingsEntryInteger ); @@ -77,5 +79,27 @@ void TestQgsSettingsRegistry::getSettingsEntriesWithDynamicKeys() QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryInexisting ), nullptr ); } +void TestQgsSettingsRegistry::childRegistry() +{ + QString settingsEntryBoolKey( "/qgis/testing/settingsEntryBool" ); + QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false ); + QString settingsEntryIntegerKey( "/qgis/testing/settingsEntryInteger" ); + QgsSettingsEntryBool settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 ); + + QgsSettingsRegistry settingsRegistryChild; + settingsRegistryChild.addSettingsEntry( &settingsEntryInteger ); + + QgsSettingsRegistry settingsRegistry; + settingsRegistry.addSettingsEntry( &settingsEntryBool ); + settingsRegistry.addChildSettingsRegistry( nullptr ); // should not crash + settingsRegistry.addChildSettingsRegistry( &settingsRegistryChild ); + + // Search only in parent + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey, false ), nullptr ); + + // Search including child registries + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey, true ), &settingsEntryInteger ); +} + QGSTEST_MAIN( TestQgsSettingsRegistry ) #include "testqgssettingsregistry.moc" diff --git a/tests/src/python/CMakeLists.txt b/tests/src/python/CMakeLists.txt index f8745a40fc60..5f2098d84a66 100644 --- a/tests/src/python/CMakeLists.txt +++ b/tests/src/python/CMakeLists.txt @@ -341,6 +341,7 @@ ADD_PYTHON_TEST(PyQgsDBManagerSpatialite test_db_manager_spatialite.py) ADD_PYTHON_TEST(PyQgsFileDownloader test_qgsfiledownloader.py) ADD_PYTHON_TEST(PyQgsSettings test_qgssettings.py) ADD_PYTHON_TEST(PyQgsSettingsEntry test_qgssettingsentry.py) +ADD_PYTHON_TEST(PyQgsSettingsRegistry test_qgssettingsregistry.py) ADD_PYTHON_TEST(PyQgsZipUtils test_qgsziputils.py) ADD_PYTHON_TEST(PyQgsSourceSelectProvider test_qgssourceselectprovider.py) ADD_PYTHON_TEST(PyQgsAuthManagerProxy test_authmanager_proxy.py) diff --git a/tests/src/python/test_qgssettingsentry.py b/tests/src/python/test_qgssettingsentry.py index 547002e02508..161220f9e08f 100644 --- a/tests/src/python/test_qgssettingsentry.py +++ b/tests/src/python/test_qgssettingsentry.py @@ -10,12 +10,8 @@ (at your option) any later version. """ -import os -import tempfile from qgis.core import QgsSettings, QgsSettingsEntryBase, QgsSettingsEntryVariant, QgsSettingsEntryString, QgsSettingsEntryStringList, QgsSettingsEntryBool, QgsSettingsEntryInteger, QgsSettingsEntryDouble, QgsSettingsEntryEnum, QgsSettingsEntryFlag, QgsUnitTypes, QgsMapLayerProxyModel from qgis.testing import start_app, unittest -from qgis.PyQt.QtCore import QSettings, QVariant, QMetaEnum -from pathlib import Path __author__ = 'Damiano Lombardi' __date__ = '02/04/2021' diff --git a/tests/src/python/test_qgssettingsregistry.py b/tests/src/python/test_qgssettingsregistry.py new file mode 100644 index 000000000000..1bddef78d2c2 --- /dev/null +++ b/tests/src/python/test_qgssettingsregistry.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +""" +Test the PyQgsSettingsRegistry classes + +Run with: ctest -V -R PyQgsSettingsRegistry + +.. note:: This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. +""" + +from qgis.core import QgsSettingsRegistry, QgsSettingsEntryBase, QgsSettingsEntryInteger, QgsApplication +from qgis.testing import start_app, unittest + +__author__ = 'Damiano Lombardi' +__date__ = '18/04/2021' +__copyright__ = 'Copyright 2021, The QGIS Project' + + +start_app() + + +class PyQgsSettingsRegistry(unittest.TestCase): + + cnt = 0 + + def setUp(self): + self.pluginName = "UnitTestSettingsRegistry" + + def tearDown(self): + pass + + def test_settings_registry(self): + + settingsEntryKey = "settingsRegistry/integerValue" + settingsEntry = QgsSettingsEntryInteger(settingsEntryKey, self.pluginName, 123) + + settingsRegistry = QgsSettingsRegistry() + settingsRegistry.addSettingsEntry(settingsEntry) + + # check get settings entry + self.assertEqual(settingsRegistry.getSettingsEntry(settingsEntry.key(), False), settingsEntry) + + # add registry to core registry + QgsApplication.settingsRegistryCore().addChildSettingsRegistry(settingsRegistry) + + self.assertEqual(QgsApplication.settingsRegistryCore().getSettingsEntry(settingsEntry.key(), True), settingsEntry) + + +if __name__ == '__main__': + unittest.main() From 598f6c73f00d57f895996d91e31fdd9f6d16b243 Mon Sep 17 00:00:00 2001 From: Damiano Date: Mon, 19 Apr 2021 10:22:04 +0200 Subject: [PATCH 06/13] Moved QgsSettings class in subdir settings --- .../{ => settings}/qgssettings.sip.in | 4 ++-- python/core/core_auto.sip | 2 +- src/core/CMakeLists.txt | 4 ++-- src/core/network/qgsnewsfeedparser.h | 8 ++++---- src/core/{ => settings}/qgssettings.cpp | 0 src/core/{ => settings}/qgssettings.h | 0 src/core/settings/qgssettingsentry.cpp | 13 +++++++++++-- tests/src/python/test_qgssettingsregistry.py | 5 ----- 8 files changed, 20 insertions(+), 16 deletions(-) rename python/core/auto_generated/{ => settings}/qgssettings.sip.in (98%) rename src/core/{ => settings}/qgssettings.cpp (100%) rename src/core/{ => settings}/qgssettings.h (100%) diff --git a/python/core/auto_generated/qgssettings.sip.in b/python/core/auto_generated/settings/qgssettings.sip.in similarity index 98% rename from python/core/auto_generated/qgssettings.sip.in rename to python/core/auto_generated/settings/qgssettings.sip.in index e738507e6e41..0eed4368140e 100644 --- a/python/core/auto_generated/qgssettings.sip.in +++ b/python/core/auto_generated/settings/qgssettings.sip.in @@ -1,7 +1,7 @@ /************************************************************************ * This file has been generated automatically from * * * - * src/core/qgssettings.h * + * src/core/settings/qgssettings.h * * * * Do not edit manually ! Edit header and run scripts/sipify.pl again * ************************************************************************/ @@ -279,7 +279,7 @@ Removes all entries in the user settings /************************************************************************ * This file has been generated automatically from * * * - * src/core/qgssettings.h * + * src/core/settings/qgssettings.h * * * * Do not edit manually ! Edit header and run scripts/sipify.pl again * ************************************************************************/ diff --git a/python/core/core_auto.sip b/python/core/core_auto.sip index 1b4553fc13cd..3c52aca54bec 100644 --- a/python/core/core_auto.sip +++ b/python/core/core_auto.sip @@ -174,7 +174,6 @@ %Include auto_generated/qgsruntimeprofiler.sip %Include auto_generated/qgsscalecalculator.sip %Include auto_generated/qgsscaleutils.sip -%Include auto_generated/qgssettings.sip %Include auto_generated/qgssimplifymethod.sip %Include auto_generated/qgssnappingconfig.sip %Include auto_generated/qgssnappingutils.sip @@ -602,6 +601,7 @@ %Include auto_generated/textrenderer/qgstextrenderer.sip %Include auto_generated/textrenderer/qgstextrendererutils.sip %Include auto_generated/textrenderer/qgstextshadowsettings.sip +%Include auto_generated/settings/qgssettings.sip %Include auto_generated/settings/qgssettingsentry.sip %Include auto_generated/settings/qgssettingsregistry.sip %Include auto_generated/settings/qgssettingsregistrycore.sip diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 23196cc59e27..cb4bc93cd033 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -471,7 +471,6 @@ set(QGIS_CORE_SRCS qgsvirtuallayerdefinitionutils.cpp qgsmapthemecollection.cpp qgsxmlutils.cpp - qgssettings.cpp qgsarchive.cpp qgstestutils.cpp qgsziputils.cpp @@ -717,6 +716,7 @@ set(QGIS_CORE_SRCS geocms/geonode/qgsgeonodeconnection.cpp geocms/geonode/qgsgeonoderequest.cpp + settings/qgssettings.cpp settings/qgssettingsentry.cpp settings/qgssettingsregistry.cpp settings/qgssettingsregistrycore.cpp @@ -1036,7 +1036,6 @@ set(QGIS_CORE_HDRS qgsruntimeprofiler.h qgsscalecalculator.h qgsscaleutils.h - qgssettings.h qgsshapegenerator.h qgssimplifymethod.h qgssnappingconfig.h @@ -1562,6 +1561,7 @@ set(QGIS_CORE_HDRS textrenderer/qgstextrendererutils.h textrenderer/qgstextshadowsettings.h + settings/qgssettings.h settings/qgssettingsentry.h settings/qgssettingsregistry.h settings/qgssettingsregistrycore.h diff --git a/src/core/network/qgsnewsfeedparser.h b/src/core/network/qgsnewsfeedparser.h index fb06c0824307..a1d44444626e 100644 --- a/src/core/network/qgsnewsfeedparser.h +++ b/src/core/network/qgsnewsfeedparser.h @@ -112,13 +112,13 @@ class CORE_EXPORT QgsNewsFeedParser : public QObject static QString keyForFeed( const QString &baseUrl ); //! Settings entry last fetch time - static const inline QgsSettingsEntryInteger settingsFeedLastFetchTime = QgsSettingsEntryInteger( QStringLiteral( "%/lastFetchTime" ), QgsSettings::Core, 0, QObject::tr( "Feed last fetch time" ), 0 ); + static const inline QgsSettingsEntryInteger settingsFeedLastFetchTime = QgsSettingsEntryInteger( QStringLiteral( "%1/lastFetchTime" ), QgsSettings::Core, 0, QObject::tr( "Feed last fetch time" ), 0 ); //! Settings entry feed language - static const inline QgsSettingsEntryString settingsFeedLanguage = QgsSettingsEntryString( QStringLiteral( "%/lang" ), QgsSettings::Core, QString(), QObject::tr( "Feed language" ) ); + static const inline QgsSettingsEntryString settingsFeedLanguage = QgsSettingsEntryString( QStringLiteral( "%1/lang" ), QgsSettings::Core, QString(), QObject::tr( "Feed language" ) ); //! Settings entry feed latitude - static const inline QgsSettingsEntryDouble settingsFeedLatitude = QgsSettingsEntryDouble( QStringLiteral( "%/latitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed latitude" ) ); + static const inline QgsSettingsEntryDouble settingsFeedLatitude = QgsSettingsEntryDouble( QStringLiteral( "%1/latitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed latitude" ) ); //! Settings entry feed longitude - static const inline QgsSettingsEntryDouble settingsFeedLongitude = QgsSettingsEntryDouble( QStringLiteral( "%/longitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed longitude" ) ); + static const inline QgsSettingsEntryDouble settingsFeedLongitude = QgsSettingsEntryDouble( QStringLiteral( "%1/longitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed longitude" ) ); public slots: diff --git a/src/core/qgssettings.cpp b/src/core/settings/qgssettings.cpp similarity index 100% rename from src/core/qgssettings.cpp rename to src/core/settings/qgssettings.cpp diff --git a/src/core/qgssettings.h b/src/core/settings/qgssettings.h similarity index 100% rename from src/core/qgssettings.h rename to src/core/settings/qgssettings.h diff --git a/src/core/settings/qgssettingsentry.cpp b/src/core/settings/qgssettingsentry.cpp index 5cd187992b03..29fd986128ab 100644 --- a/src/core/settings/qgssettingsentry.cpp +++ b/src/core/settings/qgssettingsentry.cpp @@ -85,11 +85,20 @@ QString QgsSettingsEntryBase::key( const QStringList &dynamicKeyPartList ) const bool QgsSettingsEntryBase::checkKey( const QString &key ) const { + QString completeKey = key; + if ( !mPluginName.isEmpty() + && !completeKey.startsWith( mPluginName ) ) + { + if ( !completeKey.startsWith( "/" ) ) + completeKey.prepend( "/" ); + completeKey.prepend( mPluginName ); + } + if ( !hasDynamicKey() ) - return key == QgsSettingsEntryBase::key(); + return completeKey == QgsSettingsEntryBase::key(); QRegularExpression regularExpression( definitionKey().replace( QRegularExpression( "%\\d+" ), ".*" ) ); - QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( key ); + QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( completeKey ); return regularExpresisonMatch.hasMatch(); } diff --git a/tests/src/python/test_qgssettingsregistry.py b/tests/src/python/test_qgssettingsregistry.py index 1bddef78d2c2..a613ac96cba8 100644 --- a/tests/src/python/test_qgssettingsregistry.py +++ b/tests/src/python/test_qgssettingsregistry.py @@ -23,14 +23,9 @@ class PyQgsSettingsRegistry(unittest.TestCase): - cnt = 0 - def setUp(self): self.pluginName = "UnitTestSettingsRegistry" - def tearDown(self): - pass - def test_settings_registry(self): settingsEntryKey = "settingsRegistry/integerValue" From fc558661558e62f0d5299d3c573baf103bfe93f4 Mon Sep 17 00:00:00 2001 From: Damiano Date: Mon, 19 Apr 2021 13:05:15 +0200 Subject: [PATCH 07/13] Removed move of settings for a separate pr --- .../network/qgsnetworkaccessmanager.sip.in | 2 -- .../network/qgsnewsfeedparser.sip.in | 5 --- .../processing/qgsprocessing.sip.in | 5 --- .../core/auto_generated/qgsapplication.sip.in | 6 ---- .../auto_generated/qgsgeometryoptions.sip.in | 2 -- .../qgslocalizeddatapathregistry.sip.in | 2 -- .../auto_generated/qgsmaprendererjob.sip.in | 2 -- .../settings/qgssettingsregistrycore.sip.in | 1 - src/app/main.cpp | 14 ++++---- src/app/options/qgsoptions.cpp | 22 ++++++------- src/app/qgsprojectproperties.cpp | 2 +- src/core/network/qgsnetworkaccessmanager.cpp | 4 +-- src/core/network/qgsnetworkaccessmanager.h | 4 --- src/core/network/qgsnewsfeedparser.cpp | 17 +++++----- src/core/network/qgsnewsfeedparser.h | 10 ------ src/core/processing/qgsprocessing.h | 10 ------ src/core/processing/qgsprocessingcontext.cpp | 2 +- src/core/processing/qgsprocessingutils.cpp | 8 +++-- src/core/project/qgsproject.cpp | 2 +- src/core/qgsapplication.cpp | 11 ++++--- src/core/qgsapplication.h | 12 ------- src/core/qgsgeometryoptions.cpp | 2 +- src/core/qgsgeometryoptions.h | 4 --- src/core/qgslocalizeddatapathregistry.cpp | 4 +-- src/core/qgslocalizeddatapathregistry.h | 4 --- src/core/qgsmaprendererjob.cpp | 3 +- src/core/qgsmaprendererjob.h | 4 --- src/core/settings/qgssettingsregistrycore.cpp | 32 +------------------ src/core/settings/qgssettingsregistrycore.h | 2 -- src/gui/qgsconfigureshortcutsdialog.cpp | 8 ++--- src/gui/qgsgui.cpp | 3 +- src/gui/qgsmapcanvas.cpp | 4 +-- tests/src/analysis/testqgsprocessing.cpp | 20 ++++++------ .../src/core/testqgscompositionconverter.cpp | 3 +- .../src/core/testqgsnetworkaccessmanager.cpp | 2 +- tests/src/core/testqgsnewsfeedparser.cpp | 10 +++--- tests/src/core/testqgstranslateproject.cpp | 9 +++--- 37 files changed, 83 insertions(+), 174 deletions(-) diff --git a/python/core/auto_generated/network/qgsnetworkaccessmanager.sip.in b/python/core/auto_generated/network/qgsnetworkaccessmanager.sip.in index 654750605e5f..207d2594e174 100644 --- a/python/core/auto_generated/network/qgsnetworkaccessmanager.sip.in +++ b/python/core/auto_generated/network/qgsnetworkaccessmanager.sip.in @@ -321,8 +321,6 @@ The contents of the reply will be returned after the request is completed or an .. versionadded:: 3.6 %End - const QgsSettingsEntryInteger settingsNetworkTimeout; - signals: void requestAboutToBeCreated( QNetworkAccessManager::Operation, const QNetworkRequest &, QIODevice * ) /Deprecated/; diff --git a/python/core/auto_generated/network/qgsnewsfeedparser.sip.in b/python/core/auto_generated/network/qgsnewsfeedparser.sip.in index b6643c4629da..f3169fa7c025 100644 --- a/python/core/auto_generated/network/qgsnewsfeedparser.sip.in +++ b/python/core/auto_generated/network/qgsnewsfeedparser.sip.in @@ -93,11 +93,6 @@ Returns the authentication configuration for the parser. Returns the settings key used for a feed with the given ``baseUrl``. %End - const QgsSettingsEntryInteger settingsFeedLastFetchTime; - const QgsSettingsEntryString settingsFeedLanguage; - const QgsSettingsEntryDouble settingsFeedLatitude; - const QgsSettingsEntryDouble settingsFeedLongitude; - public slots: void fetch(); diff --git a/python/core/auto_generated/processing/qgsprocessing.sip.in b/python/core/auto_generated/processing/qgsprocessing.sip.in index c14aec992082..de33821c12eb 100644 --- a/python/core/auto_generated/processing/qgsprocessing.sip.in +++ b/python/core/auto_generated/processing/qgsprocessing.sip.in @@ -52,11 +52,6 @@ Converts a source ``type`` to a string representation. %End static const QString TEMPORARY_OUTPUT; - - const QgsSettingsEntryBool settingsPreferFilenameAsLayerName; - const QgsSettingsEntryString settingsTempPath; - const QgsSettingsEntryInteger settingsDefaultOutputVectorLayerExt; - const QgsSettingsEntryInteger settingsDefaultOutputRasterLayerExt; }; /************************************************************************ diff --git a/python/core/auto_generated/qgsapplication.sip.in b/python/core/auto_generated/qgsapplication.sip.in index 79411a972da2..830ac64ea32b 100644 --- a/python/core/auto_generated/qgsapplication.sip.in +++ b/python/core/auto_generated/qgsapplication.sip.in @@ -1004,12 +1004,6 @@ Emits the signal to collect all the strings of .qgs to be included in ts file .. versionadded:: 3.4 %End - const QgsSettingsEntryString settingsLocaleUserLocale; - const QgsSettingsEntryBool settingsLocaleOverrideFlag; - const QgsSettingsEntryString settingsLocaleGlobalLocale; - const QgsSettingsEntryBool settingsLocaleShowGroupSeparator; - const QgsSettingsEntryStringList settingsSearchPathsForSVG; - %If (ANDROID) //dummy method to workaround sip generation issue bool x11EventFilter( XEvent *event ); diff --git a/python/core/auto_generated/qgsgeometryoptions.sip.in b/python/core/auto_generated/qgsgeometryoptions.sip.in index 28da763994c7..6639f8e6d3e5 100644 --- a/python/core/auto_generated/qgsgeometryoptions.sip.in +++ b/python/core/auto_generated/qgsgeometryoptions.sip.in @@ -118,8 +118,6 @@ Read the geometry options from ``node``. .. versionadded:: 3.4 %End - const QgsSettingsEntryString settingsGeometryValidationDefaultChecks; - signals: void checkConfigurationChanged(); diff --git a/python/core/auto_generated/qgslocalizeddatapathregistry.sip.in b/python/core/auto_generated/qgslocalizeddatapathregistry.sip.in index 92873da33fe9..8d0a62681a73 100644 --- a/python/core/auto_generated/qgslocalizeddatapathregistry.sip.in +++ b/python/core/auto_generated/qgslocalizeddatapathregistry.sip.in @@ -60,8 +60,6 @@ Since the paths are stored by order of preference, lower positions in the list t Unregisters a localized path %End - const QgsSettingsEntryStringList settingsLocalizedDataPaths; - private: QgsLocalizedDataPathRegistry( const QgsLocalizedDataPathRegistry &other ); }; diff --git a/python/core/auto_generated/qgsmaprendererjob.sip.in b/python/core/auto_generated/qgsmaprendererjob.sip.in index 9fc86cd56436..49e841509a1d 100644 --- a/python/core/auto_generated/qgsmaprendererjob.sip.in +++ b/python/core/auto_generated/qgsmaprendererjob.sip.in @@ -157,8 +157,6 @@ Returns map settings with which this job was started. - const QgsSettingsEntryBool settingsLogCanvasRefreshEvent; - signals: void renderingLayersFinished(); diff --git a/python/core/auto_generated/settings/qgssettingsregistrycore.sip.in b/python/core/auto_generated/settings/qgssettingsregistrycore.sip.in index 5517cc40cb71..570a37f175d1 100644 --- a/python/core/auto_generated/settings/qgssettingsregistrycore.sip.in +++ b/python/core/auto_generated/settings/qgssettingsregistrycore.sip.in @@ -9,7 +9,6 @@ - class QgsSettingsRegistryCore : QgsSettingsRegistry { %Docstring(signature="appended") diff --git a/src/app/main.cpp b/src/app/main.cpp index 85ae09e399fe..7883dba272d0 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -966,18 +966,20 @@ int main( int argc, char *argv[] ) delete profile; { + QgsSettings settings; + /* Translation file for QGIS. */ - QString myUserTranslation = QgsApplication::settingsLocaleUserLocale.value(); - QString myGlobalLocale = QgsApplication::settingsLocaleGlobalLocale.value(); + QString myUserTranslation = settings.value( QStringLiteral( "locale/userLocale" ), "" ).toString(); + QString myGlobalLocale = settings.value( QStringLiteral( "locale/globalLocale" ), "" ).toString(); bool myShowGroupSeparatorFlag = false; // Default to false - bool myLocaleOverrideFlag = QgsApplication::settingsLocaleOverrideFlag.value(); + bool myLocaleOverrideFlag = settings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool(); // Override Show Group Separator if the global override flag is set if ( myLocaleOverrideFlag ) { // Default to false again - myShowGroupSeparatorFlag = QgsApplication::settingsLocaleShowGroupSeparator.value(); + myShowGroupSeparatorFlag = settings.value( QStringLiteral( "locale/showGroupSeparator" ), false ).toBool(); } // @@ -991,7 +993,7 @@ int main( int argc, char *argv[] ) // if ( !translationCode.isNull() && !translationCode.isEmpty() ) { - QgsApplication::settingsLocaleUserLocale.setValue( translationCode ); + settings.setValue( QStringLiteral( "locale/userLocale" ), translationCode ); } else { @@ -1000,7 +1002,7 @@ int main( int argc, char *argv[] ) translationCode = QLocale().name(); //setting the locale/userLocale when the --lang= option is not set will allow third party //plugins to always use the same locale as the QGIS, otherwise they can be out of sync - QgsApplication::settingsLocaleUserLocale.setValue( translationCode ); + settings.setValue( QStringLiteral( "locale/userLocale" ), translationCode ); } else { diff --git a/src/app/options/qgsoptions.cpp b/src/app/options/qgsoptions.cpp index cf88ec414238..7c5894328731 100644 --- a/src/app/options/qgsoptions.cpp +++ b/src/app/options/qgsoptions.cpp @@ -24,7 +24,6 @@ #include "qgsgdalutils.h" #include "qgshighlight.h" #include "qgsmapcanvas.h" -#include "qgsmaprendererjob.h" #include "qgsprojectionselectiondialog.h" #include "qgscoordinatereferencesystem.h" #include "qgstolerance.h" @@ -475,7 +474,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QListsetCurrentIndex( index ); // log rendering events, for userspace debugging - mLogCanvasRefreshChkBx->setChecked( QgsMapRendererJob::settingsLogCanvasRefreshEvent.value() ); + mLogCanvasRefreshChkBx->setChecked( mSettings->value( QStringLiteral( "/Map/logCanvasRefreshEvent" ), false ).toBool() ); //set the default projection behavior radio buttons const QgsOptions::UnknownLayerCrsBehavior mode = QgsSettings().enumValue( QStringLiteral( "/projections/unknownCrsBehavior" ), QgsOptions::UnknownLayerCrsBehavior::NoAction, QgsSettings::App ); @@ -1015,9 +1014,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QListsetText( tr( "Detected active locale on your system: %1" ).arg( currentLocale ) ); - QString userLocale = QgsApplication::settingsLocaleUserLocale.value(); - bool showGroupSeparator = QgsApplication::settingsLocaleShowGroupSeparator.value(); - QString globalLocale = QgsApplication::settingsLocaleGlobalLocale.value(); + QString userLocale = mSettings->value( QStringLiteral( "locale/userLocale" ), QString( ) ).toString(); + bool showGroupSeparator = mSettings->value( QStringLiteral( "locale/showGroupSeparator" ), false ).toBool(); + QString globalLocale = mSettings->value( QStringLiteral( "locale/globalLocale" ), currentLocale ).toString(); const QStringList language18nList( i18nList() ); for ( const auto &l : language18nList ) { @@ -1044,7 +1043,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QListsetCurrentIndex( cboTranslation->findData( userLocale ) ); cboGlobalLocale->setCurrentIndex( cboGlobalLocale->findData( globalLocale ) ); - grpLocale->setChecked( QgsApplication::settingsLocaleOverrideFlag.value() ); + bool localeOverrideFlag = mSettings->value( QStringLiteral( "locale/overrideFlag" ), false ).toBool(); + grpLocale->setChecked( localeOverrideFlag ); cbShowGroupSeparator->setChecked( showGroupSeparator ); @@ -1673,7 +1673,7 @@ void QgsOptions::saveOptions() mSettings->setValue( QStringLiteral( "/Raster/cumulativeCutUpper" ), mRasterCumulativeCutUpperDoubleSpinBox->value() / 100.0 ); // log rendering events, for userspace debugging - QgsMapRendererJob::settingsLogCanvasRefreshEvent.setValue( mLogCanvasRefreshChkBx->isChecked() ); + mSettings->setValue( QStringLiteral( "/Map/logCanvasRefreshEvent" ), mLogCanvasRefreshChkBx->isChecked() ); //check behavior so default projection when new layer is added with no //projection defined... @@ -1856,12 +1856,12 @@ void QgsOptions::saveOptions() // // Locale settings // - QgsApplication::settingsLocaleUserLocale.setValue( cboTranslation->currentData().toString() ); - QgsApplication::settingsLocaleOverrideFlag.setValue( grpLocale->isChecked() ); - QgsApplication::settingsLocaleGlobalLocale.setValue( cboGlobalLocale->currentData( ).toString() ); + mSettings->setValue( QStringLiteral( "locale/userLocale" ), cboTranslation->currentData().toString() ); + mSettings->setValue( QStringLiteral( "locale/overrideFlag" ), grpLocale->isChecked() ); + mSettings->setValue( QStringLiteral( "locale/globalLocale" ), cboGlobalLocale->currentData( ).toString() ); // Number settings - QgsApplication::settingsLocaleShowGroupSeparator.setValue( cbShowGroupSeparator->isChecked( ) ); + mSettings->setValue( QStringLiteral( "locale/showGroupSeparator" ), cbShowGroupSeparator->isChecked( ) ); QgsLocalDefaultSettings::setBearingFormat( mBearingFormat.get() ); diff --git a/src/app/qgsprojectproperties.cpp b/src/app/qgsprojectproperties.cpp index f729cd48bbae..ec04358ad434 100644 --- a/src/app/qgsprojectproperties.cpp +++ b/src/app/qgsprojectproperties.cpp @@ -983,7 +983,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa } cbtsLocale->addItem( QIcon( QStringLiteral( ":/images/flags/%1.svg" ).arg( QLatin1String( "en_US" ) ) ), QLocale( QStringLiteral( "en_US" ) ).nativeLanguageName(), QStringLiteral( "en_US" ) ); - cbtsLocale->setCurrentIndex( cbtsLocale->findData( QgsApplication::settingsLocaleUserLocale.value() ) ); + cbtsLocale->setCurrentIndex( cbtsLocale->findData( settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString() ) ); connect( generateTsFileButton, &QPushButton::clicked, this, &QgsProjectProperties::onGenerateTsFileButton ); diff --git a/src/core/network/qgsnetworkaccessmanager.cpp b/src/core/network/qgsnetworkaccessmanager.cpp index 75c9b0b27aaf..3c4bc09ca978 100644 --- a/src/core/network/qgsnetworkaccessmanager.cpp +++ b/src/core/network/qgsnetworkaccessmanager.cpp @@ -654,12 +654,12 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache( Qt::ConnectionType conn int QgsNetworkAccessManager::timeout() { - return settingsNetworkTimeout.value(); + return QgsSettings().value( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), 60000 ).toInt(); } void QgsNetworkAccessManager::setTimeout( const int time ) { - settingsNetworkTimeout.setValue( time ); + QgsSettings().setValue( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), time ); } QgsNetworkReplyContent QgsNetworkAccessManager::blockingGet( QNetworkRequest &request, const QString &authCfg, bool forceRefresh, QgsFeedback *feedback ) diff --git a/src/core/network/qgsnetworkaccessmanager.h b/src/core/network/qgsnetworkaccessmanager.h index b6b643e1d384..b14800f9e8b6 100644 --- a/src/core/network/qgsnetworkaccessmanager.h +++ b/src/core/network/qgsnetworkaccessmanager.h @@ -31,7 +31,6 @@ #include "qgis_core.h" #include "qgis_sip.h" -#include "qgssettingsentry.h" class QgsFeedback; @@ -500,9 +499,6 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager */ static QgsNetworkReplyContent blockingPost( QNetworkRequest &request, const QByteArray &data, const QString &authCfg = QString(), bool forceRefresh = false, QgsFeedback *feedback = nullptr ); - //! Settings entry network timeout - static const inline QgsSettingsEntryInteger settingsNetworkTimeout = QgsSettingsEntryInteger( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), QgsSettings::NoSection, 60000, QObject::tr( "Network timeout" ) ); - signals: /** diff --git a/src/core/network/qgsnewsfeedparser.cpp b/src/core/network/qgsnewsfeedparser.cpp index 183c0bc91aa7..0489ddfc810f 100644 --- a/src/core/network/qgsnewsfeedparser.cpp +++ b/src/core/network/qgsnewsfeedparser.cpp @@ -40,23 +40,24 @@ QgsNewsFeedParser::QgsNewsFeedParser( const QUrl &feedUrl, const QString &authcf QUrlQuery query( feedUrl ); - const qint64 after = settingsFeedLastFetchTime.value( mSettingsKey ); + const qint64 after = QgsSettings().value( QStringLiteral( "%1/lastFetchTime" ).arg( mSettingsKey ), 0, QgsSettings::Core ).toUInt(); if ( after > 0 ) query.addQueryItem( QStringLiteral( "after" ), qgsDoubleToString( after, 0 ) ); - QString feedLanguage = settingsFeedLanguage.value( mSettingsKey ); + QString feedLanguage = QgsSettings().value( QStringLiteral( "%1/lang" ).arg( mSettingsKey ), QString(), QgsSettings::Core ).toString(); if ( feedLanguage.isEmpty() ) { - feedLanguage = QgsSettings().value( QgsApplication::settingsLocaleUserLocale.key(), QStringLiteral( "en_US" ) ).toString().left( 2 ); + feedLanguage = QgsSettings().value( QStringLiteral( "locale/userLocale" ), QStringLiteral( "en_US" ) ).toString().left( 2 ); } if ( !feedLanguage.isEmpty() && feedLanguage != QLatin1String( "C" ) ) query.addQueryItem( QStringLiteral( "lang" ), feedLanguage ); - if ( settingsFeedLatitude.exists( mSettingsKey ) && settingsFeedLongitude.exists( mSettingsKey ) ) + bool latOk = false; + bool longOk = false; + const double feedLat = QgsSettings().value( QStringLiteral( "%1/latitude" ).arg( mSettingsKey ), QString(), QgsSettings::Core ).toDouble( &latOk ); + const double feedLong = QgsSettings().value( QStringLiteral( "%1/longitude" ).arg( mSettingsKey ), QString(), QgsSettings::Core ).toDouble( &longOk ); + if ( latOk && longOk ) { - const double feedLat = settingsFeedLatitude.value( mSettingsKey ); - const double feedLong = settingsFeedLongitude.value( mSettingsKey ); - // hack to allow testing using local files if ( feedUrl.isLocalFile() ) { @@ -169,7 +170,7 @@ void QgsNewsFeedParser::fetch() void QgsNewsFeedParser::onFetch( const QString &content ) { - settingsFeedLastFetchTime.setValue( mFetchStartTime, mSettingsKey ); + QgsSettings().setValue( mSettingsKey + "/lastFetchTime", mFetchStartTime, QgsSettings::Core ); const QVariant json = QgsJsonUtils::parseJson( content ); diff --git a/src/core/network/qgsnewsfeedparser.h b/src/core/network/qgsnewsfeedparser.h index a1d44444626e..9f6f3268722a 100644 --- a/src/core/network/qgsnewsfeedparser.h +++ b/src/core/network/qgsnewsfeedparser.h @@ -17,7 +17,6 @@ #include "qgis_core.h" #include "qgis_sip.h" -#include "qgssettingsentry.h" #include #include #include @@ -111,15 +110,6 @@ class CORE_EXPORT QgsNewsFeedParser : public QObject */ static QString keyForFeed( const QString &baseUrl ); - //! Settings entry last fetch time - static const inline QgsSettingsEntryInteger settingsFeedLastFetchTime = QgsSettingsEntryInteger( QStringLiteral( "%1/lastFetchTime" ), QgsSettings::Core, 0, QObject::tr( "Feed last fetch time" ), 0 ); - //! Settings entry feed language - static const inline QgsSettingsEntryString settingsFeedLanguage = QgsSettingsEntryString( QStringLiteral( "%1/lang" ), QgsSettings::Core, QString(), QObject::tr( "Feed language" ) ); - //! Settings entry feed latitude - static const inline QgsSettingsEntryDouble settingsFeedLatitude = QgsSettingsEntryDouble( QStringLiteral( "%1/latitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed latitude" ) ); - //! Settings entry feed longitude - static const inline QgsSettingsEntryDouble settingsFeedLongitude = QgsSettingsEntryDouble( QStringLiteral( "%1/longitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed longitude" ) ); - public slots: /** diff --git a/src/core/processing/qgsprocessing.h b/src/core/processing/qgsprocessing.h index 53eee28fdcf5..d8424016ff7f 100644 --- a/src/core/processing/qgsprocessing.h +++ b/src/core/processing/qgsprocessing.h @@ -19,7 +19,6 @@ #define QGSPROCESSING_H #include "qgis_core.h" -#include "qgssettingsentry.h" #include // @@ -98,15 +97,6 @@ class CORE_EXPORT QgsProcessing * \since QGIS 3.6 */ static const QString TEMPORARY_OUTPUT; - - //! Settings entry prefer filename as layer name - static const inline QgsSettingsEntryBool settingsPreferFilenameAsLayerName = QgsSettingsEntryBool( QStringLiteral( "Processing/Configuration/PREFER_FILENAME_AS_LAYER_NAME" ), QgsSettings::NoSection, true, QObject::tr( "Prefer filename as layer name" ) ); - //! Settings entry temp path - static const inline QgsSettingsEntryString settingsTempPath = QgsSettingsEntryString( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ), QgsSettings::NoSection, QString() ); - //! Settings entry default output vector layer ext - static const inline QgsSettingsEntryInteger settingsDefaultOutputVectorLayerExt = QgsSettingsEntryInteger( QStringLiteral( "Processing/Configuration/DefaultOutputVectorLayerExt" ), QgsSettings::NoSection, -1 ); - //! Settings entry default output raster layer ext - static const inline QgsSettingsEntryInteger settingsDefaultOutputRasterLayerExt = QgsSettingsEntryInteger( QStringLiteral( "Processing/Configuration/DefaultOutputRasterLayerExt" ), QgsSettings::NoSection, -1 ); }; #endif // QGSPROCESSING_H diff --git a/src/core/processing/qgsprocessingcontext.cpp b/src/core/processing/qgsprocessingcontext.cpp index 4c52a4c46a06..cc07c52d46bc 100644 --- a/src/core/processing/qgsprocessingcontext.cpp +++ b/src/core/processing/qgsprocessingcontext.cpp @@ -197,7 +197,7 @@ void QgsProcessingContext::LayerDetails::setOutputLayerName( QgsMapLayer *layer if ( !layer ) return; - const bool preferFilenameAsLayerName = QgsProcessing::settingsPreferFilenameAsLayerName.value(); + const bool preferFilenameAsLayerName = QgsSettings().value( QStringLiteral( "Processing/Configuration/PREFER_FILENAME_AS_LAYER_NAME" ), true ).toBool(); // note - for temporary layers, we don't use the filename, regardless of user setting (it will be meaningless!) if ( ( !forceName && preferFilenameAsLayerName && !layer->isTemporary() ) || name.isEmpty() ) diff --git a/src/core/processing/qgsprocessingutils.cpp b/src/core/processing/qgsprocessingutils.cpp index fc19b2094dc1..ac72c22fdf2f 100644 --- a/src/core/processing/qgsprocessingutils.cpp +++ b/src/core/processing/qgsprocessingutils.cpp @@ -954,7 +954,7 @@ QString QgsProcessingUtils::tempFolder() static QString sFolder; static QMutex sMutex; QMutexLocker locker( &sMutex ); - const QString basePath = QgsProcessing::settingsTempPath.value(); + const QString basePath = QgsSettings().value( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ) ).toString(); if ( basePath.isEmpty() ) { // default setting -- automatically create a temp folder @@ -1211,7 +1211,8 @@ QgsFields QgsProcessingUtils::indicesToFields( const QList &indices, const QString QgsProcessingUtils::defaultVectorExtension() { - const int setting = QgsProcessing::settingsDefaultOutputVectorLayerExt.value(); + QgsSettings settings; + const int setting = settings.value( QStringLiteral( "Processing/Configuration/DefaultOutputVectorLayerExt" ), -1 ).toInt(); if ( setting == -1 ) return QStringLiteral( "gpkg" ); return QgsVectorFileWriter::supportedFormatExtensions().value( setting, QStringLiteral( "gpkg" ) ); @@ -1219,7 +1220,8 @@ QString QgsProcessingUtils::defaultVectorExtension() QString QgsProcessingUtils::defaultRasterExtension() { - const int setting = QgsProcessing::settingsDefaultOutputRasterLayerExt.value(); + QgsSettings settings; + const int setting = settings.value( QStringLiteral( "Processing/Configuration/DefaultOutputRasterLayerExt" ), -1 ).toInt(); if ( setting == -1 ) return QStringLiteral( "tif" ); return QgsRasterFileWriter::supportedFormatExtensions().value( setting, QStringLiteral( "tif" ) ); diff --git a/src/core/project/qgsproject.cpp b/src/core/project/qgsproject.cpp index 60ac90cbf8e7..181929095f94 100644 --- a/src/core/project/qgsproject.cpp +++ b/src/core/project/qgsproject.cpp @@ -1356,7 +1356,7 @@ bool QgsProject::readProjectFile( const QString &filename, QgsProject::ReadFlags QgsApplication::profiler()->clear( QStringLiteral( "projectload" ) ); QgsScopedRuntimeProfile profile( tr( "Setting up translations" ), QStringLiteral( "projectload" ) ); - QString localeFileName = QStringLiteral( "%1_%2" ).arg( QFileInfo( projectFile.fileName() ).baseName(), QgsApplication::settingsLocaleUserLocale.value() ); + QString localeFileName = QStringLiteral( "%1_%2" ).arg( QFileInfo( projectFile.fileName() ).baseName(), mSettings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString() ); if ( QFile( QStringLiteral( "%1/%2.qm" ).arg( QFileInfo( projectFile.fileName() ).absolutePath(), localeFileName ) ).exists() ) { diff --git a/src/core/qgsapplication.cpp b/src/core/qgsapplication.cpp index f5ceba1b250c..b095dc69dc09 100644 --- a/src/core/qgsapplication.cpp +++ b/src/core/qgsapplication.cpp @@ -1063,7 +1063,7 @@ QString QgsApplication::srsDatabaseFilePath() void QgsApplication::setSvgPaths( const QStringList &svgPaths ) { - settingsSearchPathsForSVG.setValue( svgPaths ); + QgsSettings().setValue( QStringLiteral( "svg/searchPathsForSVG" ), svgPaths ); members()->mSvgPathCacheValid = false; } @@ -1082,7 +1082,8 @@ QStringList QgsApplication::svgPaths() locker.changeMode( QgsReadWriteLocker::Write ); //local directories to search when looking for an SVG with a given basename //defined by user in options dialog - const QStringList pathList = settingsSearchPathsForSVG.value(); + QgsSettings settings; + const QStringList pathList = settings.value( QStringLiteral( "svg/searchPathsForSVG" ) ).toStringList(); // maintain user set order while stripping duplicates QStringList paths; @@ -1224,9 +1225,11 @@ QString QgsApplication::platform() QString QgsApplication::locale() { - if ( settingsLocaleOverrideFlag.value() ) + QgsSettings settings; + bool overrideLocale = settings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool(); + if ( overrideLocale ) { - QString locale = settingsLocaleUserLocale.value(); + QString locale = settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString(); // don't differentiate en_US and en_GB if ( locale.startsWith( QLatin1String( "en" ), Qt::CaseInsensitive ) ) { diff --git a/src/core/qgsapplication.h b/src/core/qgsapplication.h index 937e4175f225..2ea07b19e720 100644 --- a/src/core/qgsapplication.h +++ b/src/core/qgsapplication.h @@ -23,7 +23,6 @@ #include "qgis_sip.h" #include "qgsconfig.h" -#include "qgssettingsentry.h" #include "qgstranslationcontext.h" class QgsSettingsRegistryCore; @@ -945,17 +944,6 @@ class CORE_EXPORT QgsApplication : public QApplication */ void collectTranslatableObjects( QgsTranslationContext *translationContext ); - //! Settings entry locale user locale - static const inline QgsSettingsEntryString settingsLocaleUserLocale = QgsSettingsEntryString( QStringLiteral( "locale/userLocale" ), QgsSettings::NoSection, QString() ); - //! Settings entry locale override flag - static const inline QgsSettingsEntryBool settingsLocaleOverrideFlag = QgsSettingsEntryBool( QStringLiteral( "locale/overrideFlag" ), QgsSettings::NoSection, false ); - //! Settings entry locale global locale - static const inline QgsSettingsEntryString settingsLocaleGlobalLocale = QgsSettingsEntryString( QStringLiteral( "locale/globalLocale" ), QgsSettings::NoSection, QString() ); - //! Settings entry locale show group separator - static const inline QgsSettingsEntryBool settingsLocaleShowGroupSeparator = QgsSettingsEntryBool( QStringLiteral( "locale/showGroupSeparator" ), QgsSettings::NoSection, false ); - //! Settings entry search path for SVG - static const inline QgsSettingsEntryStringList settingsSearchPathsForSVG = QgsSettingsEntryStringList( QStringLiteral( "svg/searchPathsForSVG" ), QgsSettings::NoSection, QStringList() ); - #ifdef SIP_RUN SIP_IF_FEATURE( ANDROID ) //dummy method to workaround sip generation issue diff --git a/src/core/qgsgeometryoptions.cpp b/src/core/qgsgeometryoptions.cpp index 750ce7744845..643ee606f1bc 100644 --- a/src/core/qgsgeometryoptions.cpp +++ b/src/core/qgsgeometryoptions.cpp @@ -23,7 +23,7 @@ QgsGeometryOptions::QgsGeometryOptions() { - mGeometryChecks = settingsGeometryValidationDefaultChecks.value().split( ',' ) ; + mGeometryChecks = QgsSettings().value( QStringLiteral( "geometry_validation/default_checks" ) ).toString().split( ',' ) ; } bool QgsGeometryOptions::removeDuplicateNodes() const diff --git a/src/core/qgsgeometryoptions.h b/src/core/qgsgeometryoptions.h index 8fae89986ef4..bceabf4b9348 100644 --- a/src/core/qgsgeometryoptions.h +++ b/src/core/qgsgeometryoptions.h @@ -21,7 +21,6 @@ #include "qgis_core.h" #include "qgis_sip.h" #include "qgsgeometry.h" -#include "qgssettingsentry.h" #include @@ -132,9 +131,6 @@ class CORE_EXPORT QgsGeometryOptions : public QObject */ void readXml( const QDomNode &node ); - //! Settings entry search path for templates - static const inline QgsSettingsEntryString settingsGeometryValidationDefaultChecks = QgsSettingsEntryString( QStringLiteral( "geometry_validation/default_checks" ), QgsSettings::NoSection, QString() ); - signals: /** diff --git a/src/core/qgslocalizeddatapathregistry.cpp b/src/core/qgslocalizeddatapathregistry.cpp index 7c148b05d576..e2749881f5ed 100644 --- a/src/core/qgslocalizeddatapathregistry.cpp +++ b/src/core/qgslocalizeddatapathregistry.cpp @@ -105,10 +105,10 @@ void QgsLocalizedDataPathRegistry::unregisterPath( const QString &path ) void QgsLocalizedDataPathRegistry::readFromSettings() { - setPaths( settingsLocalizedDataPaths.value() ); + setPaths( QgsSettings().value( QStringLiteral( "/qgis/localized_data_paths" ) ).toStringList() ); } void QgsLocalizedDataPathRegistry::writeToSettings() { - settingsLocalizedDataPaths.setValue( paths() ); + QgsSettings().setValue( QStringLiteral( "/qgis/localized_data_paths" ), paths() ); } diff --git a/src/core/qgslocalizeddatapathregistry.h b/src/core/qgslocalizeddatapathregistry.h index b1e222c5efee..fc150d8b10da 100644 --- a/src/core/qgslocalizeddatapathregistry.h +++ b/src/core/qgslocalizeddatapathregistry.h @@ -24,7 +24,6 @@ #include "qgis_core.h" #include "qgis_sip.h" -#include "qgssettingsentry.h" /** * \ingroup core @@ -66,9 +65,6 @@ class CORE_EXPORT QgsLocalizedDataPathRegistry //! Unregisters a localized path void unregisterPath( const QString &path ); - //! Settings entry localized data paths - static const inline QgsSettingsEntryStringList settingsLocalizedDataPaths = QgsSettingsEntryStringList( QStringLiteral( "/qgis/localized_data_paths" ), QgsSettings::NoSection, QStringList() ); - private: #ifdef SIP_RUN QgsLocalizedDataPathRegistry( const QgsLocalizedDataPathRegistry &other ) diff --git a/src/core/qgsmaprendererjob.cpp b/src/core/qgsmaprendererjob.cpp index 2128ac38d2ca..b1f8ac90dd6a 100644 --- a/src/core/qgsmaprendererjob.cpp +++ b/src/core/qgsmaprendererjob.cpp @@ -977,7 +977,8 @@ void QgsMapRendererJob::composeSecondPass( LayerRenderJobs &secondPassJobs, Labe void QgsMapRendererJob::logRenderingTime( const LayerRenderJobs &jobs, const LayerRenderJobs &secondPassJobs, const LabelRenderJob &labelJob ) { - if ( !settingsLogCanvasRefreshEvent.value() ) + QgsSettings settings; + if ( !settings.value( QStringLiteral( "Map/logCanvasRefreshEvent" ), false ).toBool() ) return; QMultiMap elapsed; diff --git a/src/core/qgsmaprendererjob.h b/src/core/qgsmaprendererjob.h index cc382738a866..4534a4020059 100644 --- a/src/core/qgsmaprendererjob.h +++ b/src/core/qgsmaprendererjob.h @@ -29,7 +29,6 @@ #include "qgsmapsettings.h" #include "qgsmaskidprovider.h" -#include "qgssettingsentry.h" class QgsLabelingEngine; @@ -344,9 +343,6 @@ class CORE_EXPORT QgsMapRendererJob : public QObject */ static const QString LABEL_PREVIEW_CACHE_ID SIP_SKIP; - //! Settings entry log canvas refresh event - static const inline QgsSettingsEntryBool settingsLogCanvasRefreshEvent = QgsSettingsEntryBool( QStringLiteral( "Map/logCanvasRefreshEvent" ), QgsSettings::NoSection, false ); - signals: /** diff --git a/src/core/settings/qgssettingsregistrycore.cpp b/src/core/settings/qgssettingsregistrycore.cpp index 2e94674c5fbd..1f5a58f3fb76 100644 --- a/src/core/settings/qgssettingsregistrycore.cpp +++ b/src/core/settings/qgssettingsregistrycore.cpp @@ -17,13 +17,6 @@ #include "qgslayout.h" #include "qgslocator.h" -#include "qgsnetworkaccessmanager.h" -#include "qgsnewsfeedparser.h" -#include "qgsprocessing.h" -#include "qgsapplication.h" -#include "qgsgeometryoptions.h" -#include "qgslocalizeddatapathregistry.h" -#include "qgsmaprendererjob.h" QgsSettingsRegistryCore::QgsSettingsRegistryCore() : QgsSettingsRegistry() @@ -33,32 +26,9 @@ QgsSettingsRegistryCore::QgsSettingsRegistryCore() addSettingsEntry( &QgsLocator::settingsLocatorFilterEnabled ); addSettingsEntry( &QgsLocator::settingsLocatorFilterDefault ); addSettingsEntry( &QgsLocator::settingsLocatorFilterPrefix ); - - addSettingsEntry( &QgsNetworkAccessManager::settingsNetworkTimeout ); - - addSettingsEntry( &QgsNewsFeedParser::settingsFeedLastFetchTime ); - addSettingsEntry( &QgsNewsFeedParser::settingsFeedLanguage ); - addSettingsEntry( &QgsNewsFeedParser::settingsFeedLatitude ); - addSettingsEntry( &QgsNewsFeedParser::settingsFeedLongitude ); - - addSettingsEntry( &QgsProcessing::settingsPreferFilenameAsLayerName ); - addSettingsEntry( &QgsProcessing::settingsTempPath ); - addSettingsEntry( &QgsProcessing::settingsDefaultOutputVectorLayerExt ); - addSettingsEntry( &QgsProcessing::settingsDefaultOutputRasterLayerExt ); - - addSettingsEntry( &QgsApplication::settingsLocaleUserLocale ); - addSettingsEntry( &QgsApplication::settingsLocaleOverrideFlag ); - addSettingsEntry( &QgsApplication::settingsLocaleGlobalLocale ); - addSettingsEntry( &QgsApplication::settingsLocaleShowGroupSeparator ); - addSettingsEntry( &QgsApplication::settingsSearchPathsForSVG ); - - addSettingsEntry( &QgsGeometryOptions::settingsGeometryValidationDefaultChecks ); - - addSettingsEntry( &QgsLocalizedDataPathRegistry::settingsLocalizedDataPaths ); - - addSettingsEntry( &QgsMapRendererJob::settingsLogCanvasRefreshEvent ); } QgsSettingsRegistryCore::~QgsSettingsRegistryCore() { } + diff --git a/src/core/settings/qgssettingsregistrycore.h b/src/core/settings/qgssettingsregistrycore.h index 0f435cc5c257..b85dfe80ee02 100644 --- a/src/core/settings/qgssettingsregistrycore.h +++ b/src/core/settings/qgssettingsregistrycore.h @@ -21,8 +21,6 @@ #include "qgis_sip.h" #include "qgssettingsregistry.h" -#include - /** * \ingroup core * \class QgsSettingsRegistryCore diff --git a/src/gui/qgsconfigureshortcutsdialog.cpp b/src/gui/qgsconfigureshortcutsdialog.cpp index e5dd2a4c0d47..fc514c19e436 100644 --- a/src/gui/qgsconfigureshortcutsdialog.cpp +++ b/src/gui/qgsconfigureshortcutsdialog.cpp @@ -16,7 +16,6 @@ #include "qgsconfigureshortcutsdialog.h" #include "qgsshortcutsmanager.h" -#include "qgsapplication.h" #include "qgslogger.h" #include "qgssettings.h" #include "qgsgui.h" @@ -136,7 +135,7 @@ void QgsConfigureShortcutsDialog::saveShortcuts() QDomDocument doc( QStringLiteral( "shortcuts" ) ); QDomElement root = doc.createElement( QStringLiteral( "qgsshortcuts" ) ); root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0" ) ); - root.setAttribute( QStringLiteral( "locale" ), settings.value( QgsApplication::settingsLocaleUserLocale.key(), "en_US" ).toString() ); + root.setAttribute( QStringLiteral( "locale" ), settings.value( QStringLiteral( "locale/userLocale" ), "en_US" ).toString() ); doc.appendChild( root ); settings.beginGroup( mManager->settingsPath() ); @@ -203,12 +202,13 @@ void QgsConfigureShortcutsDialog::loadShortcuts() return; } + QgsSettings settings; QString currentLocale; - bool localeOverrideFlag = QgsApplication::settingsLocaleOverrideFlag.value(); + bool localeOverrideFlag = settings.value( QStringLiteral( "locale/overrideFlag" ), false ).toBool(); if ( localeOverrideFlag ) { - currentLocale = QgsApplication::settingsLocaleUserLocale.value( QString(), true, "en_US" ); + currentLocale = settings.value( QStringLiteral( "locale/userLocale" ), "en_US" ).toString(); } else // use QGIS locale { diff --git a/src/gui/qgsgui.cpp b/src/gui/qgsgui.cpp index 4fcf9bdc7004..5db19edc2fad 100644 --- a/src/gui/qgsgui.cpp +++ b/src/gui/qgsgui.cpp @@ -174,7 +174,8 @@ void QgsGui::setWindowManager( QgsWindowManagerInterface *manager ) QgsGui::HigFlags QgsGui::higFlags() { - if ( QgsApplication::settingsLocaleUserLocale.value().startsWith( QLatin1String( "en" ) ) ) + QgsSettings settings; + if ( settings.value( QStringLiteral( "locale/userLocale" ), QString() ).toString().startsWith( QLatin1String( "en" ) ) ) { return HigMenuTextIsTitleCase | HigDialogTitleIsTitleCase; } diff --git a/src/gui/qgsmapcanvas.cpp b/src/gui/qgsmapcanvas.cpp index 0b9e56a6e44e..0740cfb86e5e 100644 --- a/src/gui/qgsmapcanvas.cpp +++ b/src/gui/qgsmapcanvas.cpp @@ -61,7 +61,6 @@ email : sherman at mrcc.com #include "qgsmapoverviewcanvas.h" #include "qgsmaprenderercache.h" #include "qgsmaprenderercustompainterjob.h" -#include "qgsmaprendererjob.h" #include "qgsmaprendererparalleljob.h" #include "qgsmaprenderersequentialjob.h" #include "qgsmapsettingsutils.h" @@ -706,7 +705,8 @@ void QgsMapCanvas::rendererJobFinished() QPainter p( &img ); emit renderComplete( &p ); - if ( QgsMapRendererJob::settingsLogCanvasRefreshEvent.value() ) + QgsSettings settings; + if ( settings.value( QStringLiteral( "Map/logCanvasRefreshEvent" ), false ).toBool() ) { QString logMsg = tr( "Canvas refresh: %1 ms" ).arg( mJob->renderingTime() ); QgsMessageLog::logMessage( logMsg, tr( "Rendering" ) ); diff --git a/tests/src/analysis/testqgsprocessing.cpp b/tests/src/analysis/testqgsprocessing.cpp index 0f688306fa65..f47a4f061fc1 100644 --- a/tests/src/analysis/testqgsprocessing.cpp +++ b/tests/src/analysis/testqgsprocessing.cpp @@ -2303,11 +2303,11 @@ void TestQgsProcessing::parameters() context2.layersToLoadOnCompletion().values().at( 0 ).setOutputLayerName( rl.get() ); QCOMPARE( rl->name(), QStringLiteral( "landsat" ) ); // unless setting prohibits it... - QgsProcessing::settingsPreferFilenameAsLayerName.setValue( false ); + QgsSettings().setValue( QStringLiteral( "Processing/Configuration/PREFER_FILENAME_AS_LAYER_NAME" ), false ); context2.layersToLoadOnCompletion().values().at( 0 ).setOutputLayerName( rl.get() ); QCOMPARE( rl->name(), QStringLiteral( "my_dest" ) ); // if layer has a layername, we should use that instead of the base file name... - QgsProcessing::settingsPreferFilenameAsLayerName.setValue( true ); + QgsSettings().setValue( QStringLiteral( "Processing/Configuration/PREFER_FILENAME_AS_LAYER_NAME" ), true ); vl = std::make_unique< QgsVectorLayer >( QStringLiteral( TEST_DATA_DIR ) + "/points_gpkg.gpkg|layername=points_small", QString() ); context2.layersToLoadOnCompletion().values().at( 0 ).setOutputLayerName( vl.get() ); QCOMPARE( vl->name(), QStringLiteral( "points_small" ) ); @@ -11042,7 +11042,7 @@ void TestQgsProcessing::tempUtils() QgsSettings settings; QString alternative_tempFolder1 = tempDirPath + QStringLiteral( "/alternative_temp_test_one" ); - QgsProcessing::settingsTempPath.setValue( alternative_tempFolder1 ); + settings.setValue( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ), alternative_tempFolder1 ); // check folder and if it's constant with alternative temp folder 1 tempFolder = QgsProcessingUtils::tempFolder(); QCOMPARE( tempFolder.left( alternative_tempFolder1.length() ), alternative_tempFolder1 ); @@ -11054,7 +11054,7 @@ void TestQgsProcessing::tempUtils() QVERIFY( alternativeTempFile1.startsWith( alternative_tempFolder1 ) ); // change temp folder in the settings again QString alternative_tempFolder2 = tempDirPath + QStringLiteral( "/alternative_temp_test_two" ); - QgsProcessing::settingsTempPath.setValue( alternative_tempFolder2 ); + settings.setValue( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ), alternative_tempFolder2 ); // check folder and if it's constant constant with alternative temp folder 2 tempFolder = QgsProcessingUtils::tempFolder(); QCOMPARE( tempFolder.left( alternative_tempFolder2.length() ), alternative_tempFolder2 ); @@ -11064,7 +11064,7 @@ void TestQgsProcessing::tempUtils() QVERIFY( alternativeTempFile2.endsWith( "alternative_temptest.txt" ) ); QVERIFY( alternativeTempFile2.startsWith( tempFolder ) ); QVERIFY( alternativeTempFile2.startsWith( alternative_tempFolder2 ) ); - QgsProcessing::settingsTempPath.setValue( QString() ); + settings.setValue( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ), QString() ); } @@ -11529,8 +11529,10 @@ void TestQgsProcessing::defaultExtensionsForProvider() QCOMPARE( context.preferredRasterFormat(), QStringLiteral( "tif" ) ); // unless the user has set a default format, which IS supported by that provider - QgsProcessing::settingsDefaultOutputVectorLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "tab" ) ) ); - QgsProcessing::settingsDefaultOutputRasterLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "sdat" ) ) ); + QgsSettings settings; + + settings.setValue( QStringLiteral( "Processing/Configuration/DefaultOutputVectorLayerExt" ), QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "tab" ) ) ); + settings.setValue( QStringLiteral( "Processing/Configuration/DefaultOutputRasterLayerExt" ), QgsRasterFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "sdat" ) ) ); QCOMPARE( provider.defaultVectorFileExtension( true ), QStringLiteral( "tab" ) ); QCOMPARE( provider.defaultRasterFileExtension(), QStringLiteral( "sdat" ) ); @@ -11541,8 +11543,8 @@ void TestQgsProcessing::defaultExtensionsForProvider() QCOMPARE( context2.preferredRasterFormat(), QStringLiteral( "sdat" ) ); // but if default is not supported by provider, we use a supported format - QgsProcessing::settingsDefaultOutputVectorLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "gpkg" ) ) ); - QgsProcessing::settingsDefaultOutputRasterLayerExt.setValue( QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "ecw" ) ) ); + settings.setValue( QStringLiteral( "Processing/Configuration/DefaultOutputVectorLayerExt" ), QgsVectorFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "gpkg" ) ) ); + settings.setValue( QStringLiteral( "Processing/Configuration/DefaultOutputRasterLayerExt" ), QgsRasterFileWriter::supportedFormatExtensions().indexOf( QLatin1String( "ecw" ) ) ); QCOMPARE( provider.defaultVectorFileExtension( true ), QStringLiteral( "mif" ) ); QCOMPARE( provider.defaultRasterFileExtension(), QStringLiteral( "mig" ) ); } diff --git a/tests/src/core/testqgscompositionconverter.cpp b/tests/src/core/testqgscompositionconverter.cpp index 346c211410c7..3a1ab011ef26 100644 --- a/tests/src/core/testqgscompositionconverter.cpp +++ b/tests/src/core/testqgscompositionconverter.cpp @@ -163,7 +163,8 @@ void TestQgsCompositionConverter::initTestCase() QgsApplication::init(); QgsApplication::initQgis(); mReport = QStringLiteral( "

Layout Tests

\n" ); - QgsApplication::settingsSearchPathsForSVG.setValue( QStringList() << QStringLiteral( TEST_DATA_DIR ) ); + QgsSettings settings; + settings.setValue( QStringLiteral( "svg/searchPathsForSVG" ), QStringLiteral( TEST_DATA_DIR ) ) ; } void TestQgsCompositionConverter::cleanupTestCase() diff --git a/tests/src/core/testqgsnetworkaccessmanager.cpp b/tests/src/core/testqgsnetworkaccessmanager.cpp index f8b51c6cd43a..d96627ffa4f2 100644 --- a/tests/src/core/testqgsnetworkaccessmanager.cpp +++ b/tests/src/core/testqgsnetworkaccessmanager.cpp @@ -175,7 +175,7 @@ void TestQgsNetworkAccessManager::initTestCase() QgsApplication::init(); QgsApplication::initQgis(); - QgsNetworkAccessManager::settingsNetworkTimeout.setValue( 5000 ); + QgsSettings().setValue( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), 5000 ); mHttpBinHost = QStringLiteral( "httpbin.org" ); QString overrideHost = qgetenv( "QGIS_HTTPBIN_HOST" ); diff --git a/tests/src/core/testqgsnewsfeedparser.cpp b/tests/src/core/testqgsnewsfeedparser.cpp index 28ba11ad1817..b8369ad5368b 100644 --- a/tests/src/core/testqgsnewsfeedparser.cpp +++ b/tests/src/core/testqgsnewsfeedparser.cpp @@ -111,12 +111,12 @@ void TestQgsNewsFeedParser::testFetch() entries.clear(); // after a fetch, the current timestamp should be saved to avoid refetching these - uint after = QgsNewsFeedParser::settingsFeedLastFetchTime.value( feedKey ); + uint after = QgsSettings().value( feedKey + "/lastFetchTime", 0, QgsSettings::Core ).toUInt(); QVERIFY( after >= beforeTime ); // reset to a standard known last time QgsSettings().remove( feedKey, QgsSettings::Core ); - QgsNewsFeedParser::settingsFeedLastFetchTime.setValue( 1457360008, feedKey ); + QgsSettings().setValue( feedKey + "/lastFetchTime", 1457360008, QgsSettings::Core ); // refetch, only new items should be fetched QgsNewsFeedParser parser2( url ); @@ -230,7 +230,7 @@ void TestQgsNewsFeedParser::testLang() const QString feedKey = QgsNewsFeedParser::keyForFeed( url.toString() ); QgsSettings().remove( feedKey, QgsSettings::Core ); // force to Spanish language - QgsNewsFeedParser::settingsFeedLanguage.setValue( QStringLiteral( "es" ), feedKey ); + QgsSettings().setValue( QStringLiteral( "%1/lang" ).arg( feedKey ), QStringLiteral( "es" ), QgsSettings::Core ); QgsNewsFeedParser parser( url ); QSignalSpy spy( &parser, &QgsNewsFeedParser::entryAdded ); @@ -256,8 +256,8 @@ void TestQgsNewsFeedParser::testGeoFencing() const QUrl url( QUrl::fromLocalFile( QStringLiteral( TEST_DATA_DIR ) + "/newsfeed/feed" ) ); const QString feedKey = QgsNewsFeedParser::keyForFeed( url.toString() ); QgsSettings().remove( feedKey, QgsSettings::Core ); - QgsNewsFeedParser::settingsFeedLatitude.setValue( 37.2343, feedKey ); - QgsNewsFeedParser::settingsFeedLongitude.setValue( -115.8067, feedKey ); + QgsSettings().setValue( QStringLiteral( "%1/latitude" ).arg( feedKey ), 37.2343, QgsSettings::Core ); + QgsSettings().setValue( QStringLiteral( "%1/longitude" ).arg( feedKey ), -115.8067, QgsSettings::Core ); QgsNewsFeedParser parser( url ); QSignalSpy spy( &parser, &QgsNewsFeedParser::entryAdded ); diff --git a/tests/src/core/testqgstranslateproject.cpp b/tests/src/core/testqgstranslateproject.cpp index aa5f674f81ad..f1be8ab0ba68 100644 --- a/tests/src/core/testqgstranslateproject.cpp +++ b/tests/src/core/testqgstranslateproject.cpp @@ -47,6 +47,7 @@ class TestQgsTranslateProject : public QObject void translateProject(); private: + QgsSettings settings; QString original_locale; }; @@ -57,12 +58,12 @@ void TestQgsTranslateProject::initTestCase() QgsApplication::init(); QgsApplication::initQgis(); - original_locale = QgsApplication::settingsLocaleUserLocale.value(); + original_locale = settings.value( QStringLiteral( "locale/userLocale" ), "" ).toString() ; } void TestQgsTranslateProject::cleanupTestCase() { - QgsApplication::settingsLocaleUserLocale.setValue( original_locale ); + settings.setValue( QStringLiteral( "locale/userLocale" ), original_locale ); QgsApplication::exitQgis(); //delete translated project file @@ -91,7 +92,7 @@ void TestQgsTranslateProject::cleanup() void TestQgsTranslateProject::createTsFile() { //open project in english - QgsApplication::settingsLocaleUserLocale.setValue( "en" ); + settings.setValue( QStringLiteral( "locale/userLocale" ), "en" ); QString projectFileName( TEST_DATA_DIR ); projectFileName = projectFileName + "/project_translation/points_translation.qgs"; QgsProject::instance()->read( projectFileName ); @@ -163,7 +164,7 @@ void TestQgsTranslateProject::createTsFile() void TestQgsTranslateProject::translateProject() { //open project in german - QgsApplication::settingsLocaleUserLocale.setValue( "de" ); + settings.setValue( QStringLiteral( "locale/userLocale" ), "de" ); QString projectFileName( TEST_DATA_DIR ); projectFileName = projectFileName + "/project_translation/points_translation.qgs"; QgsProject::instance()->read( projectFileName ); From a693ebc8d5be3f1aeacc9bdf7e399304d2fef407 Mon Sep 17 00:00:00 2001 From: Damiano Date: Mon, 19 Apr 2021 15:01:42 +0200 Subject: [PATCH 08/13] Advanced settings editor show description for registered settings --- src/app/qgssettingstree.cpp | 16 +++++++-- src/core/settings/qgssettingsentry.cpp | 38 +++++++++++++++++----- tests/src/core/testqgssettingsregistry.cpp | 6 ++-- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/app/qgssettingstree.cpp b/src/app/qgssettingstree.cpp index eae9154a0534..be9a1b420717 100644 --- a/src/app/qgssettingstree.cpp +++ b/src/app/qgssettingstree.cpp @@ -45,6 +45,8 @@ #include "qgsvariantdelegate.h" #include "qgslogger.h" #include "qgssettings.h" +#include "qgssettingsentry.h" +#include "qgssettingsregistrycore.h" #include "qgsapplication.h" #include @@ -319,7 +321,17 @@ QTreeWidgetItem *QgsSettingsTree::createItem( const QString &text, item->setFlags( item->flags() | Qt::ItemIsEditable ); item->setData( 0, TypeRole, isGroup ? Group : Setting ); - item->setData( 0, PathRole, mSettings->group().isEmpty() ? text : mSettings->group() + '/' + text ); + + QString completeSettingsPath = mSettings->group().isEmpty() ? text : mSettings->group() + '/' + text; + item->setData( 0, PathRole, completeSettingsPath ); + + // If settings registered add description + if ( !isGroup ) + { + const QgsSettingsEntryBase *settingsEntry = QgsApplication::settingsRegistryCore()->getSettingsEntry( completeSettingsPath, true ); + if ( settingsEntry != nullptr ) + item->setText( 3, settingsEntry->description() ); + } QString key = itemKey( item ); QgsDebugMsgLevel( key, 4 ); @@ -332,8 +344,6 @@ QTreeWidgetItem *QgsSettingsTree::createItem( const QString &text, item->setToolTip( 2, values.at( 1 ) ); } - // if ( settingsMap.contains( - return item; } diff --git a/src/core/settings/qgssettingsentry.cpp b/src/core/settings/qgssettingsentry.cpp index 29fd986128ab..577684df6470 100644 --- a/src/core/settings/qgssettingsentry.cpp +++ b/src/core/settings/qgssettingsentry.cpp @@ -85,20 +85,40 @@ QString QgsSettingsEntryBase::key( const QStringList &dynamicKeyPartList ) const bool QgsSettingsEntryBase::checkKey( const QString &key ) const { - QString completeKey = key; - if ( !mPluginName.isEmpty() - && !completeKey.startsWith( mPluginName ) ) + // Key to check + QString completeKeyToCheck = key; + + QString settingsPrefix = QgsSettings().prefixedKey( "", section() ); + settingsPrefix.chop( 1 ); + if ( !completeKeyToCheck.startsWith( settingsPrefix ) ) { - if ( !completeKey.startsWith( "/" ) ) - completeKey.prepend( "/" ); - completeKey.prepend( mPluginName ); + if ( !mPluginName.isEmpty() + && !completeKeyToCheck.startsWith( mPluginName ) ) + { + if ( !completeKeyToCheck.startsWith( "/" ) ) + completeKeyToCheck.prepend( "/" ); + completeKeyToCheck.prepend( mPluginName ); + } + + if ( !completeKeyToCheck.startsWith( "/" ) ) + completeKeyToCheck.prepend( "/" ); + completeKeyToCheck.prepend( settingsPrefix ); + } + + // Prefixed settings key + QString prefixedSettingsKey = definitionKey(); + if ( !prefixedSettingsKey.startsWith( settingsPrefix ) ) + { + if ( !prefixedSettingsKey.startsWith( "/" ) ) + prefixedSettingsKey.prepend( "/" ); + prefixedSettingsKey.prepend( settingsPrefix ); } if ( !hasDynamicKey() ) - return completeKey == QgsSettingsEntryBase::key(); + return completeKeyToCheck == prefixedSettingsKey; - QRegularExpression regularExpression( definitionKey().replace( QRegularExpression( "%\\d+" ), ".*" ) ); - QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( completeKey ); + QRegularExpression regularExpression( prefixedSettingsKey.replace( QRegularExpression( "%\\d+" ), ".*" ) ); + QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( completeKeyToCheck ); return regularExpresisonMatch.hasMatch(); } diff --git a/tests/src/core/testqgssettingsregistry.cpp b/tests/src/core/testqgssettingsregistry.cpp index 25f8cfcf7e1a..5b6cc1cf149a 100644 --- a/tests/src/core/testqgssettingsregistry.cpp +++ b/tests/src/core/testqgssettingsregistry.cpp @@ -59,9 +59,9 @@ void TestQgsSettingsRegistry::getSettingsEntriesWithDynamicKeys() QString settingsEntryBoolKey( "/qgis/testing/%1_settingsEntryBool" ); QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false ); QString settingsEntryIntegerKey( "/qgis/testing/%1/settingsEntryInteger" ); - QgsSettingsEntryBool settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 ); + QgsSettingsEntryInteger settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 ); QString settingsEntryDoubleKey( "/qgis/testing/%1/settingsEntryDouble_%2" ); - QgsSettingsEntryBool settingsEntryDouble( settingsEntryDoubleKey, QgsSettings::NoSection, 1.23 ); + QgsSettingsEntryDouble settingsEntryDouble( settingsEntryDoubleKey, QgsSettings::NoSection, 1.23 ); QString settingsEntryInexisting( "/qgis/testing/settingsEntryInexisting%1" ); @@ -84,7 +84,7 @@ void TestQgsSettingsRegistry::childRegistry() QString settingsEntryBoolKey( "/qgis/testing/settingsEntryBool" ); QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false ); QString settingsEntryIntegerKey( "/qgis/testing/settingsEntryInteger" ); - QgsSettingsEntryBool settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 ); + QgsSettingsEntryInteger settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 ); QgsSettingsRegistry settingsRegistryChild; settingsRegistryChild.addSettingsEntry( &settingsEntryInteger ); From e99b92a92cb2194ef90e2e115cedf6c78793cc09 Mon Sep 17 00:00:00 2001 From: Damiano Date: Tue, 20 Apr 2021 14:41:47 +0200 Subject: [PATCH 09/13] Applied suggestions from code review --- .../settings/qgssettingsentry.sip.in | 14 +++++--- .../settings/qgssettingsregistry.sip.in | 12 ++++--- src/core/settings/qgssettingsentry.cpp | 34 +++++++++---------- src/core/settings/qgssettingsentry.h | 14 +++++--- src/core/settings/qgssettingsregistry.cpp | 16 ++++----- src/core/settings/qgssettingsregistry.h | 12 ++++--- tests/src/core/testqgssettingsregistry.cpp | 20 ++++++++--- 7 files changed, 73 insertions(+), 49 deletions(-) diff --git a/python/core/auto_generated/settings/qgssettingsentry.sip.in b/python/core/auto_generated/settings/qgssettingsentry.sip.in index 54e7b4e4d328..7dd9b8a4731f 100644 --- a/python/core/auto_generated/settings/qgssettingsentry.sip.in +++ b/python/core/auto_generated/settings/qgssettingsentry.sip.in @@ -84,9 +84,13 @@ Get settings entry key. The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. %End - bool checkKey( const QString &key ) const; + bool keyIsValid( const QString &key ) const; %Docstring -Returns true if the provided key match the settings entry +Returns ``True`` if the provided key match the settings entry. + +This is useful for settings with dynamic keys. For example this permits to check that +the settings key "NewsFeed/httpsfeedqgisorg/27/content" is valid for the settings entry +defined with the key "NewsFeed/%1/%2/content" The ``key`` to check %End @@ -100,19 +104,19 @@ included. For non-dynamic settings returns the same as :py:func:`~QgsSettingsEnt bool hasDynamicKey() const; %Docstring -Returns true if a part of the settings key is built dynamically. +Returns ``True`` if a part of the settings key is built dynamically. %End bool exists( const QString &dynamicKeyPart = QString() ) const; %Docstring -Returns true if the settings is contained in the underlying QSettings. +Returns ``True`` if the settings is contained in the underlying QSettings. The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key. %End bool exists( const QStringList &dynamicKeyPartList ) const; %Docstring -Returns true if the settings is contained in the underlying QSettings. +Returns ``True`` if the settings is contained in the underlying QSettings. The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key. %End diff --git a/python/core/auto_generated/settings/qgssettingsregistry.sip.in b/python/core/auto_generated/settings/qgssettingsregistry.sip.in index b3f3b34d2d83..f173cba19cfd 100644 --- a/python/core/auto_generated/settings/qgssettingsregistry.sip.in +++ b/python/core/auto_generated/settings/qgssettingsregistry.sip.in @@ -31,11 +31,6 @@ Constructor for QgsSettingsRegistry. virtual ~QgsSettingsRegistry(); - void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); -%Docstring -Add ``settingsEntry`` to the register. -%End - QList getChildSettingsEntries() const; %Docstring Returns the list of registered :py:class:`QgsSettingsEntryBase`. @@ -56,6 +51,13 @@ Add a child ``settingsRegistry`` to the register. QList getChildSettingsRegistries() const; %Docstring Returns the list of registered child QgsSettingsRegistry. +%End + + protected: + + void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); +%Docstring +Add ``settingsEntry`` to the register. %End }; diff --git a/src/core/settings/qgssettingsentry.cpp b/src/core/settings/qgssettingsentry.cpp index 577684df6470..8e78b2f9f4f9 100644 --- a/src/core/settings/qgssettingsentry.cpp +++ b/src/core/settings/qgssettingsentry.cpp @@ -55,15 +55,15 @@ QString QgsSettingsEntryBase::key( const QStringList &dynamicKeyPartList ) const QString completeKey = mKey; if ( !mPluginName.isEmpty() ) { - if ( !completeKey.startsWith( "/" ) ) - completeKey.prepend( "/" ); + if ( !completeKey.startsWith( '/' ) ) + completeKey.prepend( '/' ); completeKey.prepend( mPluginName ); } if ( dynamicKeyPartList.isEmpty() ) { if ( hasDynamicKey() ) - QgsLogger::warning( QStringLiteral( "Settings '%1' have a dynamic key but the dynamic key part was not provided" ).arg( completeKey ) ); + QgsDebugMsg( QStringLiteral( "Settings '%1' have a dynamic key but the dynamic key part was not provided" ).arg( completeKey ) ); return completeKey; } @@ -71,37 +71,37 @@ QString QgsSettingsEntryBase::key( const QStringList &dynamicKeyPartList ) const { if ( !hasDynamicKey() ) { - QgsLogger::warning( QStringLiteral( "Settings '%1' don't have a dynamic key, the provided dynamic key part will be ignored" ).arg( completeKey ) ); + QgsDebugMsg( QStringLiteral( "Settings '%1' don't have a dynamic key, the provided dynamic key part will be ignored" ).arg( completeKey ) ); return completeKey; } for ( int i = 0; i < dynamicKeyPartList.size(); i++ ) { - completeKey.replace( QString( "%%1" ).arg( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) ); + completeKey.replace( QStringLiteral( "%%1" ).arg( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) ); } } return completeKey; } -bool QgsSettingsEntryBase::checkKey( const QString &key ) const +bool QgsSettingsEntryBase::keyIsValid( const QString &key ) const { // Key to check QString completeKeyToCheck = key; - QString settingsPrefix = QgsSettings().prefixedKey( "", section() ); + QString settingsPrefix = QgsSettings().prefixedKey( QString(), section() ); settingsPrefix.chop( 1 ); if ( !completeKeyToCheck.startsWith( settingsPrefix ) ) { if ( !mPluginName.isEmpty() && !completeKeyToCheck.startsWith( mPluginName ) ) { - if ( !completeKeyToCheck.startsWith( "/" ) ) - completeKeyToCheck.prepend( "/" ); + if ( !completeKeyToCheck.startsWith( '/' ) ) + completeKeyToCheck.prepend( '/' ); completeKeyToCheck.prepend( mPluginName ); } - if ( !completeKeyToCheck.startsWith( "/" ) ) - completeKeyToCheck.prepend( "/" ); + if ( !completeKeyToCheck.startsWith( '/' ) ) + completeKeyToCheck.prepend( '/' ); completeKeyToCheck.prepend( settingsPrefix ); } @@ -109,15 +109,15 @@ bool QgsSettingsEntryBase::checkKey( const QString &key ) const QString prefixedSettingsKey = definitionKey(); if ( !prefixedSettingsKey.startsWith( settingsPrefix ) ) { - if ( !prefixedSettingsKey.startsWith( "/" ) ) - prefixedSettingsKey.prepend( "/" ); + if ( !prefixedSettingsKey.startsWith( '/' ) ) + prefixedSettingsKey.prepend( '/' ); prefixedSettingsKey.prepend( settingsPrefix ); } if ( !hasDynamicKey() ) return completeKeyToCheck == prefixedSettingsKey; - QRegularExpression regularExpression( prefixedSettingsKey.replace( QRegularExpression( "%\\d+" ), ".*" ) ); + QRegularExpression regularExpression( prefixedSettingsKey.replace( QRegularExpression( QStringLiteral( "%\\d+" ) ), QStringLiteral( ".*" ) ) ); QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( completeKeyToCheck ); return regularExpresisonMatch.hasMatch(); } @@ -127,8 +127,8 @@ QString QgsSettingsEntryBase::definitionKey() const QString completeKey = mKey; if ( !mPluginName.isEmpty() ) { - if ( !completeKey.startsWith( "/" ) ) - completeKey.prepend( "/" ); + if ( !completeKey.startsWith( '/' ) ) + completeKey.prepend( '/' ); completeKey.prepend( mPluginName ); } @@ -137,7 +137,7 @@ QString QgsSettingsEntryBase::definitionKey() const bool QgsSettingsEntryBase::hasDynamicKey() const { - static const QRegularExpression regularExpression( "%\\d+" ); + static const QRegularExpression regularExpression( QStringLiteral( "%\\d+" ) ); return mKey.contains( regularExpression ); } diff --git a/src/core/settings/qgssettingsentry.h b/src/core/settings/qgssettingsentry.h index bf2b59ed5781..7142ff80de31 100644 --- a/src/core/settings/qgssettingsentry.h +++ b/src/core/settings/qgssettingsentry.h @@ -120,11 +120,15 @@ class CORE_EXPORT QgsSettingsEntryBase QString key( const QStringList &dynamicKeyPartList ) const; /** - * Returns true if the provided key match the settings entry + * Returns TRUE if the provided key match the settings entry. + * + * This is useful for settings with dynamic keys. For example this permits to check that + * the settings key "NewsFeed/httpsfeedqgisorg/27/content" is valid for the settings entry + * defined with the key "NewsFeed/%1/%2/content" * * The \a key to check */ - bool checkKey( const QString &key ) const; + bool keyIsValid( const QString &key ) const; /** * Returns settings entry defining key. @@ -134,19 +138,19 @@ class CORE_EXPORT QgsSettingsEntryBase QString definitionKey() const; /** - * Returns true if a part of the settings key is built dynamically. + * Returns TRUE if a part of the settings key is built dynamically. */ bool hasDynamicKey() const; /** - * Returns true if the settings is contained in the underlying QSettings. + * Returns TRUE if the settings is contained in the underlying QSettings. * * The \a dynamicKeyPart argument specifies the dynamic part of the settings key. */ bool exists( const QString &dynamicKeyPart = QString() ) const; /** - * Returns true if the settings is contained in the underlying QSettings. + * Returns TRUE if the settings is contained in the underlying QSettings. * * The \a dynamicKeyParts argument specifies the list of dynamic parts of the settings key. */ diff --git a/src/core/settings/qgssettingsregistry.cpp b/src/core/settings/qgssettingsregistry.cpp index c1e265d25160..28cdad60aa32 100644 --- a/src/core/settings/qgssettingsregistry.cpp +++ b/src/core/settings/qgssettingsregistry.cpp @@ -37,15 +37,15 @@ QgsSettingsRegistry::~QgsSettingsRegistry() void QgsSettingsRegistry::addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ) { - if ( settingsEntry == nullptr ) + if ( !settingsEntry ) { - QgsLogger::warning( QStringLiteral( "Trying to register a nullptr settings entry." ) ); + QgsDebugMsg( QStringLiteral( "Trying to register a nullptr settings entry." ) ); return; } if ( mSettingsEntriesMap.contains( settingsEntry->definitionKey() ) ) { - QgsLogger::warning( QStringLiteral( "Settings with key '%1' is already registered." ).arg( settingsEntry->definitionKey() ) ); + QgsDebugMsg( QStringLiteral( "Settings with key '%1' is already registered." ).arg( settingsEntry->definitionKey() ) ); return; } @@ -63,14 +63,14 @@ const QgsSettingsEntryBase *QgsSettingsRegistry::getSettingsEntry( const QString const QMap settingsEntriesMap = mSettingsEntriesMap; for ( const QgsSettingsEntryBase *settingsEntry : settingsEntriesMap ) { - if ( settingsEntry->checkKey( key ) ) + if ( settingsEntry->keyIsValid( key ) ) return settingsEntry; } // Search in child registries if ( searchChildRegistries ) { - for ( const QgsSettingsRegistry *settingsRegistry : mSettingsRegistryChildList ) + for ( const QgsSettingsRegistry *settingsRegistry : std::as_const( mSettingsRegistryChildList ) ) { const QgsSettingsEntryBase *settingsEntry = settingsRegistry->getSettingsEntry( key, true ); if ( settingsEntry != nullptr ) @@ -83,15 +83,15 @@ const QgsSettingsEntryBase *QgsSettingsRegistry::getSettingsEntry( const QString void QgsSettingsRegistry::addChildSettingsRegistry( const QgsSettingsRegistry *settingsRegistry ) { - if ( settingsRegistry == nullptr ) + if ( !settingsRegistry ) { - QgsLogger::warning( QStringLiteral( "Trying to register a nullptr child settings registry." ) ); + QgsDebugMsg( QStringLiteral( "Trying to register a nullptr child settings registry." ) ); return; } if ( mSettingsRegistryChildList.contains( settingsRegistry ) ) { - QgsLogger::warning( QStringLiteral( "Child register is already registered." ) ); + QgsDebugMsg( QStringLiteral( "Child register is already registered." ) ); return; } diff --git a/src/core/settings/qgssettingsregistry.h b/src/core/settings/qgssettingsregistry.h index 6d2ee9fb5531..bdac2c6ac397 100644 --- a/src/core/settings/qgssettingsregistry.h +++ b/src/core/settings/qgssettingsregistry.h @@ -45,11 +45,6 @@ class CORE_EXPORT QgsSettingsRegistry */ virtual ~QgsSettingsRegistry(); - /** - * Add \a settingsEntry to the register. - */ - void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); - /** * Returns the list of registered QgsSettingsEntryBase. */ @@ -72,6 +67,13 @@ class CORE_EXPORT QgsSettingsRegistry */ QList getChildSettingsRegistries() const; + protected: + + /** + * Add \a settingsEntry to the register. + */ + void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); + private: QMap mSettingsEntriesMap; diff --git a/tests/src/core/testqgssettingsregistry.cpp b/tests/src/core/testqgssettingsregistry.cpp index 5b6cc1cf149a..49821ec35e3b 100644 --- a/tests/src/core/testqgssettingsregistry.cpp +++ b/tests/src/core/testqgssettingsregistry.cpp @@ -20,6 +20,18 @@ #include "qgsmaplayerproxymodel.h" #include "qgstest.h" +/** + * This is a helper class to test protected methods of QgsSettingsRegistry + */ +class SettingsRegistryTest : public QgsSettingsRegistry +{ + public: + + void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ) + { + QgsSettingsRegistry::addSettingsEntry( settingsEntry ); + } +}; /** * \ingroup UnitTests @@ -44,7 +56,7 @@ void TestQgsSettingsRegistry::getSettingsEntries() QString settingsEntryInexisting( "/qgis/testing/settingsEntryInexisting" ); - QgsSettingsRegistry settingsRegistry; + SettingsRegistryTest settingsRegistry; settingsRegistry.addSettingsEntry( nullptr ); // should not crash settingsRegistry.addSettingsEntry( &settingsEntryBool ); settingsRegistry.addSettingsEntry( &settingsEntryInteger ); @@ -65,7 +77,7 @@ void TestQgsSettingsRegistry::getSettingsEntriesWithDynamicKeys() QString settingsEntryInexisting( "/qgis/testing/settingsEntryInexisting%1" ); - QgsSettingsRegistry settingsRegistry; + SettingsRegistryTest settingsRegistry; settingsRegistry.addSettingsEntry( &settingsEntryBool ); settingsRegistry.addSettingsEntry( &settingsEntryInteger ); settingsRegistry.addSettingsEntry( &settingsEntryDouble ); @@ -86,10 +98,10 @@ void TestQgsSettingsRegistry::childRegistry() QString settingsEntryIntegerKey( "/qgis/testing/settingsEntryInteger" ); QgsSettingsEntryInteger settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 ); - QgsSettingsRegistry settingsRegistryChild; + SettingsRegistryTest settingsRegistryChild; settingsRegistryChild.addSettingsEntry( &settingsEntryInteger ); - QgsSettingsRegistry settingsRegistry; + SettingsRegistryTest settingsRegistry; settingsRegistry.addSettingsEntry( &settingsEntryBool ); settingsRegistry.addChildSettingsRegistry( nullptr ); // should not crash settingsRegistry.addChildSettingsRegistry( &settingsRegistryChild ); From d320a184473e7589ab0b59a45e8a5ba4368e5a57 Mon Sep 17 00:00:00 2001 From: Damiano Date: Tue, 20 Apr 2021 14:50:40 +0200 Subject: [PATCH 10/13] Added missing QStringLiteral in tests --- tests/src/core/testqgssettingsentry.cpp | 8 ++++---- tests/src/core/testqgssettingsregistry.cpp | 24 +++++++++++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/src/core/testqgssettingsentry.cpp b/tests/src/core/testqgssettingsentry.cpp index eb50321c88bb..52962fe3e7d8 100644 --- a/tests/src/core/testqgssettingsentry.cpp +++ b/tests/src/core/testqgssettingsentry.cpp @@ -96,12 +96,12 @@ void TestQgsSettingsEntry::settingsKey() void TestQgsSettingsEntry::enumValue() { - QString settingsKey( "qgis/testing/my_enum_value_for_units" ); + QString settingsKey( QStringLiteral( "qgis/testing/my_enum_value_for_units" ) ); // Make sure the setting is not existing QgsSettings().remove( settingsKey, QgsSettings::NoSection ); - QgsSettingsEntryEnum settingsEntryEnum( settingsKey, QgsSettings::NoSection, QgsUnitTypes::LayoutMeters, "Layout unit" ); + QgsSettingsEntryEnum settingsEntryEnum( settingsKey, QgsSettings::NoSection, QgsUnitTypes::LayoutMeters, QStringLiteral( "Layout unit" ) ); // Check default value QCOMPARE( settingsEntryEnum.defaultValue(), QgsUnitTypes::LayoutMeters ); @@ -142,7 +142,7 @@ void TestQgsSettingsEntry::enumValue() void TestQgsSettingsEntry::flagValue() { - QString settingsKey( "qgis/testing/my_flag_value_for_units" ); + QString settingsKey( QStringLiteral( "qgis/testing/my_flag_value_for_units" ) ); QgsMapLayerProxyModel::Filters pointAndLine = QgsMapLayerProxyModel::Filters( QgsMapLayerProxyModel::PointLayer | QgsMapLayerProxyModel::LineLayer ); QgsMapLayerProxyModel::Filters pointAndPolygon = QgsMapLayerProxyModel::Filters( QgsMapLayerProxyModel::PointLayer | QgsMapLayerProxyModel::PolygonLayer ); QgsMapLayerProxyModel::Filters hasGeometry = QgsMapLayerProxyModel::Filters( QgsMapLayerProxyModel::HasGeometry ); @@ -150,7 +150,7 @@ void TestQgsSettingsEntry::flagValue() // Make sure the setting is not existing QgsSettings().remove( settingsKey, QgsSettings::NoSection ); - QgsSettingsEntryFlag settingsEntryFlag( settingsKey, QgsSettings::NoSection, pointAndLine, "Filters" ); + QgsSettingsEntryFlag settingsEntryFlag( settingsKey, QgsSettings::NoSection, pointAndLine, QStringLiteral( "Filters" ) ); // Check default value QCOMPARE( settingsEntryFlag.defaultValue(), pointAndLine ); diff --git a/tests/src/core/testqgssettingsregistry.cpp b/tests/src/core/testqgssettingsregistry.cpp index 49821ec35e3b..aacc3f5c9ee0 100644 --- a/tests/src/core/testqgssettingsregistry.cpp +++ b/tests/src/core/testqgssettingsregistry.cpp @@ -49,12 +49,12 @@ class TestQgsSettingsRegistry : public QObject void TestQgsSettingsRegistry::getSettingsEntries() { - QString settingsEntryBoolKey( "/qgis/testing/settingsEntryBool" ); + QString settingsEntryBoolKey( QStringLiteral( "/qgis/testing/settingsEntryBool" ) ); QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false ); - QString settingsEntryIntegerKey( "/qgis/testing/settingsEntryInteger" ); + QString settingsEntryIntegerKey( QStringLiteral( "/qgis/testing/settingsEntryInteger" ) ); QgsSettingsEntryBool settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 ); - QString settingsEntryInexisting( "/qgis/testing/settingsEntryInexisting" ); + QString settingsEntryInexisting( QStringLiteral( "/qgis/testing/settingsEntryInexisting" ) ); SettingsRegistryTest settingsRegistry; settingsRegistry.addSettingsEntry( nullptr ); // should not crash @@ -68,14 +68,14 @@ void TestQgsSettingsRegistry::getSettingsEntries() void TestQgsSettingsRegistry::getSettingsEntriesWithDynamicKeys() { - QString settingsEntryBoolKey( "/qgis/testing/%1_settingsEntryBool" ); + QString settingsEntryBoolKey( QStringLiteral( "/qgis/testing/%1_settingsEntryBool" ) ); QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false ); - QString settingsEntryIntegerKey( "/qgis/testing/%1/settingsEntryInteger" ); + QString settingsEntryIntegerKey( QStringLiteral( "/qgis/testing/%1/settingsEntryInteger" ) ); QgsSettingsEntryInteger settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 ); - QString settingsEntryDoubleKey( "/qgis/testing/%1/settingsEntryDouble_%2" ); + QString settingsEntryDoubleKey( QStringLiteral( "/qgis/testing/%1/settingsEntryDouble_%2" ) ); QgsSettingsEntryDouble settingsEntryDouble( settingsEntryDoubleKey, QgsSettings::NoSection, 1.23 ); - QString settingsEntryInexisting( "/qgis/testing/settingsEntryInexisting%1" ); + QString settingsEntryInexisting( QStringLiteral( "/qgis/testing/settingsEntryInexisting%1" ) ); SettingsRegistryTest settingsRegistry; settingsRegistry.addSettingsEntry( &settingsEntryBool ); @@ -83,19 +83,19 @@ void TestQgsSettingsRegistry::getSettingsEntriesWithDynamicKeys() settingsRegistry.addSettingsEntry( &settingsEntryDouble ); QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey ), &settingsEntryBool ); - QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey.replace( "%1", "1st" ) ), &settingsEntryBool ); + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey.replace( QStringLiteral( "%1" ), QStringLiteral( "1st" ) ) ), &settingsEntryBool ); QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey ), &settingsEntryInteger ); - QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey.replace( "%1", "Second" ) ), &settingsEntryInteger ); + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey.replace( QStringLiteral( "%1" ), QStringLiteral( "Second" ) ) ), &settingsEntryInteger ); QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryDoubleKey ), &settingsEntryDouble ); - QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryDoubleKey.replace( "%1", "1st" ).replace( "%2", "2nd" ) ), &settingsEntryDouble ); + QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryDoubleKey.replace( QStringLiteral( "%1" ), QStringLiteral( "1st" ) ).replace( QStringLiteral( "%2" ), QStringLiteral( "2nd" ) ) ), &settingsEntryDouble ); QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryInexisting ), nullptr ); } void TestQgsSettingsRegistry::childRegistry() { - QString settingsEntryBoolKey( "/qgis/testing/settingsEntryBool" ); + QString settingsEntryBoolKey( QStringLiteral( "/qgis/testing/settingsEntryBool" ) ); QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false ); - QString settingsEntryIntegerKey( "/qgis/testing/settingsEntryInteger" ); + QString settingsEntryIntegerKey( QStringLiteral( "/qgis/testing/settingsEntryInteger" ) ); QgsSettingsEntryInteger settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 ); SettingsRegistryTest settingsRegistryChild; From 1b10f18a5064e638740073c04d82f4ef854e01d7 Mon Sep 17 00:00:00 2001 From: Damiano Lombardi Date: Wed, 21 Apr 2021 12:57:00 +0200 Subject: [PATCH 11/13] Applied suggestions from code review --- src/app/qgssettingstree.cpp | 62 +++++++++++++------------- src/app/qgssettingstree.h | 9 ++++ src/core/settings/qgssettingsentry.cpp | 8 ++-- 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/app/qgssettingstree.cpp b/src/app/qgssettingstree.cpp index be9a1b420717..2e0d83968086 100644 --- a/src/app/qgssettingstree.cpp +++ b/src/app/qgssettingstree.cpp @@ -60,11 +60,9 @@ QgsSettingsTree::QgsSettingsTree( QWidget *parent ) QStringList labels; labels << tr( "Setting" ) << tr( "Type" ) << tr( "Value" ) << tr( "Description" ); setHeaderLabels( labels ); - // header()->setResizeMode( 0, QHeaderView::Stretch ); - // header()->setResizeMode( 2, QHeaderView::Stretch ); - header()->resizeSection( 0, 250 ); - header()->resizeSection( 1, 100 ); - header()->resizeSection( 2, 250 ); + header()->resizeSection( ColumnSettings, 250 ); + header()->resizeSection( ColumnType, 100 ); + header()->resizeSection( ColumnValue, 250 ); mRefreshTimer.setInterval( 2000 ); @@ -170,7 +168,7 @@ void QgsSettingsTree::updateSetting( QTreeWidgetItem *item ) if ( key.isNull() ) return; - mSettings->setValue( key, item->data( 2, Qt::UserRole ) ); + mSettings->setValue( key, item->data( ColumnValue, Qt::UserRole ) ); if ( mAutoRefresh ) refresh(); } @@ -181,9 +179,9 @@ void QgsSettingsTree::showContextMenu( QPoint pos ) if ( !item ) return; - Type itemType = item->data( 0, TypeRole ).value< Type >(); - const QString itemText = item->data( 0, Qt::DisplayRole ).toString(); - const QString itemPath = item->data( 0, PathRole ).toString(); + Type itemType = item->data( ColumnSettings, TypeRole ).value< Type >(); + const QString itemText = item->data( ColumnSettings, Qt::DisplayRole ).toString(); + const QString itemPath = item->data( ColumnSettings, PathRole ).toString(); mContextMenu->clear(); switch ( itemType ) @@ -242,16 +240,16 @@ void QgsSettingsTree::updateChildItems( QTreeWidgetItem *parent ) if ( childIndex != -1 ) { child = childAt( parent, childIndex ); - child->setText( 1, QString() ); - child->setText( 2, QString() ); - child->setData( 2, Qt::UserRole, QVariant() ); + child->setText( ColumnType, QString() ); + child->setText( ColumnValue, QString() ); + child->setData( ColumnValue, Qt::UserRole, QVariant() ); moveItemForward( parent, childIndex, dividerIndex ); } else { child = createItem( group, parent, dividerIndex, true ); } - child->setIcon( 0, mGroupIcon ); + child->setIcon( ColumnSettings, mGroupIcon ); ++dividerIndex; mSettings->beginGroup( group ); @@ -278,7 +276,7 @@ void QgsSettingsTree::updateChildItems( QTreeWidgetItem *parent ) { child = createItem( key, parent, dividerIndex, false ); } - child->setIcon( 0, mKeyIcon ); + child->setIcon( ColumnSettings, mKeyIcon ); ++dividerIndex; } else @@ -289,14 +287,14 @@ void QgsSettingsTree::updateChildItems( QTreeWidgetItem *parent ) QVariant value = mSettings->value( key ); if ( value.type() == QVariant::Invalid ) { - child->setText( 1, QStringLiteral( "Invalid" ) ); + child->setText( ColumnType, QStringLiteral( "Invalid" ) ); } else { - child->setText( 1, QVariant::typeToName( QgsVariantDelegate::type( value ) ) ); + child->setText( ColumnType, QVariant::typeToName( QgsVariantDelegate::type( value ) ) ); } - child->setText( 2, QgsVariantDelegate::displayText( value ) ); - child->setData( 2, Qt::UserRole, value ); + child->setText( ColumnValue, QgsVariantDelegate::displayText( value ) ); + child->setData( ColumnValue, Qt::UserRole, value ); } while ( dividerIndex < childCount( parent ) ) @@ -316,21 +314,24 @@ QTreeWidgetItem *QgsSettingsTree::createItem( const QString &text, else item = new QTreeWidgetItem( this, after ); - item->setText( 0, text ); + item->setText( ColumnSettings, text ); if ( !isGroup ) item->setFlags( item->flags() | Qt::ItemIsEditable ); - item->setData( 0, TypeRole, isGroup ? Group : Setting ); + item->setData( ColumnSettings, TypeRole, isGroup ? Group : Setting ); - QString completeSettingsPath = mSettings->group().isEmpty() ? text : mSettings->group() + '/' + text; - item->setData( 0, PathRole, completeSettingsPath ); + const QString completeSettingsPath = mSettings->group().isEmpty() ? text : mSettings->group() + '/' + text; + item->setData( ColumnSettings, PathRole, completeSettingsPath ); // If settings registered add description if ( !isGroup ) { const QgsSettingsEntryBase *settingsEntry = QgsApplication::settingsRegistryCore()->getSettingsEntry( completeSettingsPath, true ); - if ( settingsEntry != nullptr ) - item->setText( 3, settingsEntry->description() ); + if ( settingsEntry ) + { + item->setText( ColumnDescription, settingsEntry->description() ); + item->setToolTip( ColumnDescription, settingsEntry->description() ); + } } QString key = itemKey( item ); @@ -339,9 +340,10 @@ QTreeWidgetItem *QgsSettingsTree::createItem( const QString &text, { QgsDebugMsgLevel( QStringLiteral( "contains!!!!" ), 4 ); QStringList values = mSettingsMap[ key ]; - item->setText( 3, values.at( 0 ) ); - item->setToolTip( 0, values.at( 1 ) ); - item->setToolTip( 2, values.at( 1 ) ); + item->setText( ColumnDescription, values.at( 0 ) ); + item->setToolTip( ColumnDescription, values.at( 0 ) ); + item->setToolTip( ColumnSettings, values.at( 1 ) ); + item->setToolTip( ColumnValue, values.at( 1 ) ); } return item; @@ -352,11 +354,11 @@ QString QgsSettingsTree::itemKey( QTreeWidgetItem *item ) if ( ! item ) return QString(); - QString key = item->text( 0 ); + QString key = item->text( ColumnSettings ); QTreeWidgetItem *ancestor = item->parent(); while ( ancestor ) { - key.prepend( ancestor->text( 0 ) + '/' ); + key.prepend( ancestor->text( ColumnSettings ) + '/' ); ancestor = ancestor->parent(); } @@ -384,7 +386,7 @@ int QgsSettingsTree::findChild( QTreeWidgetItem *parent, const QString &text, { for ( int i = startIndex; i < childCount( parent ); ++i ) { - if ( childAt( parent, i )->text( 0 ) == text ) + if ( childAt( parent, i )->text( ColumnSettings ) == text ) return i; } return -1; diff --git a/src/app/qgssettingstree.h b/src/app/qgssettingstree.h index 7dbc1c06b127..4253b7a73627 100644 --- a/src/app/qgssettingstree.h +++ b/src/app/qgssettingstree.h @@ -89,6 +89,15 @@ class QgsSettingsTree : public QTreeWidget void showContextMenu( QPoint pos ); private: + + enum Columns + { + ColumnSettings = 0, + ColumnType, + ColumnValue, + ColumnDescription + }; + void updateChildItems( QTreeWidgetItem *parent ); QTreeWidgetItem *createItem( const QString &text, QTreeWidgetItem *parent, int index, bool isGroup ); diff --git a/src/core/settings/qgssettingsentry.cpp b/src/core/settings/qgssettingsentry.cpp index 8e78b2f9f4f9..9d8a6fa8441c 100644 --- a/src/core/settings/qgssettingsentry.cpp +++ b/src/core/settings/qgssettingsentry.cpp @@ -77,7 +77,7 @@ QString QgsSettingsEntryBase::key( const QStringList &dynamicKeyPartList ) const for ( int i = 0; i < dynamicKeyPartList.size(); i++ ) { - completeKey.replace( QStringLiteral( "%%1" ).arg( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) ); + completeKey.replace( QStringLiteral( "%" ).append( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) ); } } return completeKey; @@ -118,8 +118,8 @@ bool QgsSettingsEntryBase::keyIsValid( const QString &key ) const return completeKeyToCheck == prefixedSettingsKey; QRegularExpression regularExpression( prefixedSettingsKey.replace( QRegularExpression( QStringLiteral( "%\\d+" ) ), QStringLiteral( ".*" ) ) ); - QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( completeKeyToCheck ); - return regularExpresisonMatch.hasMatch(); + QRegularExpressionMatch regularExpressionMatch = regularExpression.match( completeKeyToCheck ); + return regularExpressionMatch.hasMatch(); } QString QgsSettingsEntryBase::definitionKey() const @@ -137,7 +137,7 @@ QString QgsSettingsEntryBase::definitionKey() const bool QgsSettingsEntryBase::hasDynamicKey() const { - static const QRegularExpression regularExpression( QStringLiteral( "%\\d+" ) ); + const thread_local QRegularExpression regularExpression( QStringLiteral( "%\\d+" ) ); return mKey.contains( regularExpression ); } From 95e7360f7933b03b6ad257878689230ce6b7eafe Mon Sep 17 00:00:00 2001 From: Damiano Date: Mon, 26 Apr 2021 10:18:21 +0200 Subject: [PATCH 12/13] Apply suggestions from code review Co-authored-by: Paul Blottiere --- src/core/settings/qgssettingsentry.cpp | 5 ++--- src/core/settings/qgssettingsregistry.cpp | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/settings/qgssettingsentry.cpp b/src/core/settings/qgssettingsentry.cpp index 9d8a6fa8441c..3d2e84560476 100644 --- a/src/core/settings/qgssettingsentry.cpp +++ b/src/core/settings/qgssettingsentry.cpp @@ -117,8 +117,8 @@ bool QgsSettingsEntryBase::keyIsValid( const QString &key ) const if ( !hasDynamicKey() ) return completeKeyToCheck == prefixedSettingsKey; - QRegularExpression regularExpression( prefixedSettingsKey.replace( QRegularExpression( QStringLiteral( "%\\d+" ) ), QStringLiteral( ".*" ) ) ); - QRegularExpressionMatch regularExpressionMatch = regularExpression.match( completeKeyToCheck ); + const QRegularExpression regularExpression( prefixedSettingsKey.replace( QRegularExpression( QStringLiteral( "%\\d+" ) ), QStringLiteral( ".*" ) ) ); + const QRegularExpressionMatch regularExpressionMatch = regularExpression.match( completeKeyToCheck ); return regularExpressionMatch.hasMatch(); } @@ -643,4 +643,3 @@ int QgsSettingsEntryDouble::displayHintDecimals() const } - diff --git a/src/core/settings/qgssettingsregistry.cpp b/src/core/settings/qgssettingsregistry.cpp index 28cdad60aa32..74f59c561ab0 100644 --- a/src/core/settings/qgssettingsregistry.cpp +++ b/src/core/settings/qgssettingsregistry.cpp @@ -73,7 +73,7 @@ const QgsSettingsEntryBase *QgsSettingsRegistry::getSettingsEntry( const QString for ( const QgsSettingsRegistry *settingsRegistry : std::as_const( mSettingsRegistryChildList ) ) { const QgsSettingsEntryBase *settingsEntry = settingsRegistry->getSettingsEntry( key, true ); - if ( settingsEntry != nullptr ) + if ( settingsEntry ) return settingsEntry; } } From 8a7bfa18e15fb0bdd9c1660f9754b987c46c2594 Mon Sep 17 00:00:00 2001 From: Damiano Date: Mon, 26 Apr 2021 11:44:48 +0200 Subject: [PATCH 13/13] Renamed method addChildSettingsRegistry to appendRegistry --- .../core/auto_generated/settings/qgssettingsregistry.sip.in | 4 ++-- src/core/settings/qgssettingsregistry.cpp | 2 +- src/core/settings/qgssettingsregistry.h | 4 ++-- tests/src/core/testqgssettingsregistry.cpp | 4 ++-- tests/src/python/test_qgssettingsregistry.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/python/core/auto_generated/settings/qgssettingsregistry.sip.in b/python/core/auto_generated/settings/qgssettingsregistry.sip.in index f173cba19cfd..1ddb3d0d201e 100644 --- a/python/core/auto_generated/settings/qgssettingsregistry.sip.in +++ b/python/core/auto_generated/settings/qgssettingsregistry.sip.in @@ -43,9 +43,9 @@ Returns the :py:class:`QgsSettingsEntry` with the given ``key`` or None if not f The ``searchChildRegistries`` parameter specifies if child registries should be included in the search %End - void addChildSettingsRegistry( const QgsSettingsRegistry *settingsRegistry ); + void appendRegistry( const QgsSettingsRegistry *settingsRegistry ); %Docstring -Add a child ``settingsRegistry`` to the register. +Append a child ``settingsRegistry`` to the register. %End QList getChildSettingsRegistries() const; diff --git a/src/core/settings/qgssettingsregistry.cpp b/src/core/settings/qgssettingsregistry.cpp index 74f59c561ab0..7e7d810ae52a 100644 --- a/src/core/settings/qgssettingsregistry.cpp +++ b/src/core/settings/qgssettingsregistry.cpp @@ -81,7 +81,7 @@ const QgsSettingsEntryBase *QgsSettingsRegistry::getSettingsEntry( const QString return nullptr; } -void QgsSettingsRegistry::addChildSettingsRegistry( const QgsSettingsRegistry *settingsRegistry ) +void QgsSettingsRegistry::appendRegistry( const QgsSettingsRegistry *settingsRegistry ) { if ( !settingsRegistry ) { diff --git a/src/core/settings/qgssettingsregistry.h b/src/core/settings/qgssettingsregistry.h index bdac2c6ac397..eb32b0502358 100644 --- a/src/core/settings/qgssettingsregistry.h +++ b/src/core/settings/qgssettingsregistry.h @@ -58,9 +58,9 @@ class CORE_EXPORT QgsSettingsRegistry const QgsSettingsEntryBase *getSettingsEntry( const QString &key, bool searchChildRegistries = true ) const; /** - * Add a child \a settingsRegistry to the register. + * Append a child \a settingsRegistry to the register. */ - void addChildSettingsRegistry( const QgsSettingsRegistry *settingsRegistry ); + void appendRegistry( const QgsSettingsRegistry *settingsRegistry ); /** * Returns the list of registered child QgsSettingsRegistry. diff --git a/tests/src/core/testqgssettingsregistry.cpp b/tests/src/core/testqgssettingsregistry.cpp index aacc3f5c9ee0..34171cc50c46 100644 --- a/tests/src/core/testqgssettingsregistry.cpp +++ b/tests/src/core/testqgssettingsregistry.cpp @@ -103,8 +103,8 @@ void TestQgsSettingsRegistry::childRegistry() SettingsRegistryTest settingsRegistry; settingsRegistry.addSettingsEntry( &settingsEntryBool ); - settingsRegistry.addChildSettingsRegistry( nullptr ); // should not crash - settingsRegistry.addChildSettingsRegistry( &settingsRegistryChild ); + settingsRegistry.appendRegistry( nullptr ); // should not crash + settingsRegistry.appendRegistry( &settingsRegistryChild ); // Search only in parent QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey, false ), nullptr ); diff --git a/tests/src/python/test_qgssettingsregistry.py b/tests/src/python/test_qgssettingsregistry.py index a613ac96cba8..2ac468c03ebe 100644 --- a/tests/src/python/test_qgssettingsregistry.py +++ b/tests/src/python/test_qgssettingsregistry.py @@ -38,7 +38,7 @@ def test_settings_registry(self): self.assertEqual(settingsRegistry.getSettingsEntry(settingsEntry.key(), False), settingsEntry) # add registry to core registry - QgsApplication.settingsRegistryCore().addChildSettingsRegistry(settingsRegistry) + QgsApplication.settingsRegistryCore().appendRegistry(settingsRegistry) self.assertEqual(QgsApplication.settingsRegistryCore().getSettingsEntry(settingsEntry.key(), True), settingsEntry)