Merge pull request #47633 from 3nids/settings-sections

Explicit declaration of sections/prefixes for settings
This commit is contained in:
Denis Rouzaud 2022-03-08 21:03:37 +01:00 committed by GitHub
commit ede7f35a86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 563 additions and 484 deletions

View File

@ -49,28 +49,28 @@ class PyQgsSettingsEntryEnumFlag(QgsSettingsEntryBase):
defaultValueStr = self.__metaEnum.valueToKey(defaultValue)
self.__enumFlagClass = defaultValue.__class__
super().__init__(key, pluginName, defaultValueStr, description)
super().__init__(key, 'plugins/{}'.format(pluginName), defaultValueStr, description)
def value(self, dynamicKeyPart=None, useDefaultValueOverride=False, defaultValueOverride=None):
def value(self, dynamicKeyPart=None):
"""
Get settings value.
:param dynamicKeyPart: argument specifies the dynamic part of the settings key.
:param useDefaultValueOverride: argument specifies if defaultValueOverride should be used.
:param defaultValueOverride: argument if valid is used instead of the normal default value.
"""
defaultValue = self.defaultValue()
if useDefaultValueOverride:
defaultValue = defaultValueOverride
if self.__metaEnum.isFlag():
return QgsSettings().flagValue(self.key(dynamicKeyPart),
defaultValue,
self.section())
return QgsSettings().flagValue(self.key(dynamicKeyPart), self.defaultValue())
else:
return QgsSettings().enumValue(self.key(dynamicKeyPart),
defaultValue,
self.section())
return QgsSettings().enumValue(self.key(dynamicKeyPart), self.defaultValue())
def valueWithDefaultOverride(self, defaultValueOverride, dynamicKeyPart=None):
"""
Get settings value with a default value override.
:param defaultValueOverride: argument if valid is used instead of the normal default value.
:param dynamicKeyPart: argument specifies the dynamic part of the settings key.
"""
if self.__metaEnum.isFlag():
return QgsSettings().flagValue(self.key(dynamicKeyPart), defaultValueOverride)
else:
return QgsSettings().enumValue(self.key(dynamicKeyPart), defaultValueOverride)
def defaultValue(self):
"""

View File

@ -65,6 +65,7 @@ static bool setGlobalSettingsPath( QString path );
Gps,
};
explicit QgsSettings( const QString &organization,
const QString &application = QString(), QObject *parent = 0 );
%Docstring

View File

@ -45,19 +45,18 @@ to validate set values and provide more accurate settings description for the gu
QgsSettingsEntryBase( const QString &key,
const QString &pluginName,
const QString &section,
const QVariant &defaultValue = QVariant(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
%Docstring
Constructor for QgsSettingsEntryBase.
This constructor is intended to be used from plugins.
The ``key`` argument specifies the key of the settings.
The ``pluginName`` argument is inserted in the key after the section.
The ``section`` argument specifies the section.
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
The ``options`` argument specifies the options for the settings entry.
%End
virtual ~QgsSettingsEntryBase();
@ -127,9 +126,12 @@ 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;
QgsSettings::Section section() const;
%Docstring
Returns settings section. The settings section of the parent group is returned if available.
.. deprecated:: QGIS 3.26
the key is entirely self-defined
%End
virtual bool setVariantValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const /Deprecated/;
@ -268,23 +270,21 @@ Base abstract class for settings entry which are passed by reference
%End
public:
QgsSettingsEntryByReference( const QString &key,
const QString &pluginName,
const QString &section,
const T &defaultValue,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
%Docstring
Constructor for QgsSettingsEntryByReference.
This constructor is intended to be used from plugins.
The ``key`` argument specifies the key of the settings.
The ``pluginName`` argument is inserted in the key after the section.
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
%End
virtual Qgis::SettingsType settingsType() const = 0;
T value( const QString &dynamicKeyPart = QString() ) const;
@ -405,17 +405,12 @@ Base abstract class for settings entry which are passed by value
public:
QgsSettingsEntryByValue( const QString &key,
const QString &pluginName,
T defaultValue,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
QgsSettingsEntryByValue( const QString &key, const QString &section, QVariant defaultValue, const QString &description = QString(), Qgis::SettingsOptions options = Qgis::SettingsOptions() );
%Docstring
Constructor for QgsSettingsEntryByValue.
This constructor is intended to be used from plugins.
The ``key`` argument specifies the key of the settings.
The ``pluginName`` argument is inserted in the key after the section.
The ``section`` argument specifies the section.
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.

View File

@ -29,6 +29,23 @@ typedef QgsSettingsEntryByReference<QVariant> QgsSettingsEntryByReferenceQVarian
public:
private:
QgsSettingsEntryVariant( const QString &key,
const QString &section,
const QVariant &defaultValue = QVariant(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
%Docstring
Constructor for QgsSettingsEntryVariant.
The ``key`` argument specifies the final part of the settings key.
The ``section`` argument specifies the section.
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` argument specifies the options for the settings entry.
%End
public:
QgsSettingsEntryVariant( const QString &key,
const QString &pluginName,
const QVariant &defaultValue = QVariant(),
@ -44,6 +61,9 @@ The ``defaultValue`` argument specifies the default value for the settings entry
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
%End
%MethodCode
sipCpp = new sipQgsSettingsEntryVariant( QgsSettingsEntryVariant( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), *a2, *a3, *a4 ) );
%End
virtual Qgis::SettingsType settingsType() const;
@ -72,12 +92,34 @@ typedef QgsSettingsEntryByReference<QString> QgsSettingsEntryByReferenceQStringB
%End
public:
private:
QgsSettingsEntryString( const QString &key,
const QString &section,
const QString &defaultValue = QString(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions(),
int minLength = 0,
int maxLength = -1 );
%Docstring
Constructor for QgsSettingsEntryString.
The ``key`` argument specifies the final part of the settings key.
The ``section`` argument specifies the section.
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
The ``minLength`` argument specifies the minimal length of the string value. 0 means no limit.
The ``maxLength`` argument specifies the maximal length of the string value. -1 means no limit.
%End
public:
QgsSettingsEntryString( const QString &key,
const QString &pluginName,
const QString &defaultValue = QString(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
Qgis::SettingsOptions options = Qgis::SettingsOptions(),
int minLength = 0,
int maxLength = -1 );
%Docstring
Constructor for QgsSettingsEntryString.
This constructor is intended to be used from plugins.
@ -87,6 +129,9 @@ The ``pluginName`` argument is inserted in the key after the section.
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
%End
%MethodCode
sipCpp = new sipQgsSettingsEntryString( QgsSettingsEntryString( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), *a2, *a3, *a4 ) );
%End
virtual Qgis::SettingsType settingsType() const;
@ -142,6 +187,22 @@ typedef QgsSettingsEntryByReference<QStringList> QgsSettingsEntryByReferenceQStr
%End
public:
private:
QgsSettingsEntryStringList( const QString &key,
const QString &section,
const QStringList &defaultValue = QStringList(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
%Docstring
Constructor for QgsSettingsEntryStringList.
The ``key`` argument specifies the final part of the settings key.
The ``section`` argument specifies the section.
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
%End
public:
QgsSettingsEntryStringList( const QString &key,
const QString &pluginName,
@ -157,6 +218,9 @@ The ``pluginName`` argument is inserted in the key after the section.
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
%End
%MethodCode
sipCpp = new sipQgsSettingsEntryStringList( QgsSettingsEntryStringList( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), *a2, *a3, *a4 ) );
%End
virtual Qgis::SettingsType settingsType() const;
@ -186,8 +250,28 @@ typedef QgsSettingsEntryByValue<bool> QgsSettingsEntryByValueboolBase;
%End
public:
private:
QgsSettingsEntryBool( const QString &key,
const QString &section,
bool defaultValue = false,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
%Docstring
Constructor for QgsSettingsEntryBool.
QgsSettingsEntryBool( const QString &key, const QString &pluginName, bool defaultValue = false, const QString &description = QString(), Qgis::SettingsOptions options = Qgis::SettingsOptions() );
The ``key`` argument specifies the final part of the settings key.
The ``section`` argument specifies the section.
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
%End
public:
QgsSettingsEntryBool( const QString &key,
const QString &pluginName,
bool defaultValue = false,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
%Docstring
Constructor for QgsSettingsEntryBool.
This constructor is intended to be used from plugins.
@ -198,6 +282,10 @@ The ``defaultValue`` argument specifies the default value for the settings entry
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
%End
%MethodCode
sipCpp = new sipQgsSettingsEntryBool( QgsSettingsEntryBool( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), a2, *a3, *a4 ) );
%End
virtual Qgis::SettingsType settingsType() const;
@ -226,23 +314,50 @@ typedef QgsSettingsEntryByValue<qlonglong> QgsSettingsEntryByValueqlonglongBase;
%End
public:
private:
QgsSettingsEntryInteger( const QString &key,
const QString &section,
qlonglong defaultValue = 0,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions(),
qlonglong minValue = LLONG_MIN,
qlonglong maxValue = LLONG_MAX );
%Docstring
Constructor for QgsSettingsEntryInteger.
The ``key`` argument specifies the final part of the settings key.
The ``section`` argument specifies the section.
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
The ``minValue`` argument specifies the minimal value.
The ``maxValue`` argument specifies the maximal value.
%End
public:
QgsSettingsEntryInteger( const QString &key,
const QString &pluginName,
qlonglong defaultValue = 0,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
Qgis::SettingsOptions options = Qgis::SettingsOptions(),
qlonglong minValue = LLONG_MIN,
qlonglong maxValue = LLONG_MAX );
%Docstring
Constructor for QgsSettingsEntryInteger.
This constructor is intended to be used from plugins.
The ``key`` argument specifies the key of the settings.
The ``pluginName`` argument is inserted in the key after the section.
The ``pluginName`` argument is used to define the key of the setting
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
The ``minValue`` argument specifies the minimal value.
The ``maxValue`` argument specifies the maximal value.
%End
%MethodCode
sipCpp = new sipQgsSettingsEntryInteger( QgsSettingsEntryInteger( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), a2, *a3, *a4, a5, a6 ) );
%End
virtual Qgis::SettingsType settingsType() const;
void setMinValue( qlonglong minValue );
@ -296,22 +411,55 @@ typedef QgsSettingsEntryByValue<double> QgsSettingsEntryByValuedoubleBase;
%End
public:
private:
QgsSettingsEntryDouble( const QString &key,
const QString &section,
double defaultValue = 0.0,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions(),
double minValue = -DBL_MAX,
double maxValue = DBL_MAX,
int displayDecimals = 1 );
%Docstring
Constructor for QgsSettingsEntryDouble.
The ``key`` argument specifies the final part of the settings key.
The ``section`` argument specifies the section.
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
The ``minValue`` argument specifies the minimal value.
The ``maxValue`` argument specifies the maximal value.
The ``displayDecimals`` specifies an hint for the gui about how much decimals to show
for example for a QDoubleSpinBox.
%End
public:
QgsSettingsEntryDouble( const QString &key,
const QString &pluginName,
double defaultValue,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
Qgis::SettingsOptions options = Qgis::SettingsOptions(),
double minValue = -DBL_MAX,
double maxValue = DBL_MAX,
int displayDecimals = 1 );
%Docstring
Constructor for QgsSettingsEntryDouble.
This constructor is intended to be used from plugins.
The ``key`` argument specifies the key of the settings.
The ``pluginName`` argument is inserted in the key after the section.
The ``pluginName`` argument is used to define the key of the setting
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``minValue`` argument specifies the minimal value.
The ``maxValue`` argument specifies the maximal value.
The ``displayDecimals`` specifies an hint for the gui about how much decimals to show
%End
%MethodCode
sipCpp = new sipQgsSettingsEntryDouble( QgsSettingsEntryDouble( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), a2, *a3, *a4, a5, a6, a7 ) );
%End
virtual Qgis::SettingsType settingsType() const;
@ -379,6 +527,22 @@ typedef QgsSettingsEntryByReference<QColor> QgsSettingsEntryByReferenceQColorBas
%End
public:
private:
QgsSettingsEntryColor( const QString &key,
const QString &section,
const QColor &defaultValue = QColor(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
%Docstring
Constructor for QgsSettingsEntryColor.
The ``key`` argument specifies the final part of the settings key.
The ``section`` argument specifies the section.
The ``defaultValue`` argument specifies the default value for the settings entry.
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
%End
public:
QgsSettingsEntryColor( const QString &key,
const QString &pluginName,
@ -395,6 +559,10 @@ The ``defaultValue`` argument specifies the default value for the settings entry
The ``description`` argument specifies a description for the settings entry.
The ``options`` arguments specifies the options for the settings entry.
%End
%MethodCode
sipCpp = new sipQgsSettingsEntryColor( QgsSettingsEntryColor( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), *a2, *a3, *a4 ) );
%End
virtual Qgis::SettingsType settingsType() const;
private:

View File

@ -12,6 +12,7 @@
class QgsSettingsRegistryCore : QgsSettingsRegistry
{
%Docstring(signature="appended")

View File

@ -62,14 +62,14 @@ class QgsGeoreferencerMainWindow : public QMainWindow, private Ui::QgsGeorefPlug
public:
static const inline QgsSettingsEntryEnumFlag<QgsImageWarper::ResamplingMethod> settingResamplingMethod = QgsSettingsEntryEnumFlag<QgsImageWarper::ResamplingMethod>( QStringLiteral( "/georeferencer/resampling-method" ), QgsSettings::App, QgsImageWarper::ResamplingMethod::NearestNeighbour, QObject::tr( "Last used georeferencer resampling method" ) );
static const inline QgsSettingsEntryString settingCompressionMethod = QgsSettingsEntryString( QStringLiteral( "/georeferencer/compression-method" ), QgsSettings::App, QStringLiteral( "NONE" ), QObject::tr( "Last used georeferencer compression method" ) );
static const inline QgsSettingsEntryBool settingUseZeroForTransparent = QgsSettingsEntryBool( QStringLiteral( "/georeferencer/use-zero-for-transparent" ), QgsSettings::App, false, QObject::tr( "Last used georeferencer use-zero-as-transparent option" ) );
static const inline QgsSettingsEntryEnumFlag<QgsGcpTransformerInterface::TransformMethod> settingTransformMethod = QgsSettingsEntryEnumFlag<QgsGcpTransformerInterface::TransformMethod>( QStringLiteral( "/georeferencer/transform-method" ), QgsSettings::App, QgsGcpTransformerInterface::TransformMethod::Linear, QObject::tr( "Last used georeferencer transform method" ) );
static const inline QgsSettingsEntryBool settingSaveGcps = QgsSettingsEntryBool( QStringLiteral( "/georeferencer/save-gcp-points" ), QgsSettings::App, false, QObject::tr( "Whether georeferencer should automatically save .points files" ) );
static const inline QgsSettingsEntryBool settingLoadInProject = QgsSettingsEntryBool( QStringLiteral( "/georeferencer/load-result-in-project" ), QgsSettings::App, true, QObject::tr( "Whether georeferencer should automatically load results into the current project" ) );
static const inline QgsSettingsEntryString settingLastSourceFolder = QgsSettingsEntryString( QStringLiteral( "/georeferencer/last-source-folder" ), QgsSettings::App, QString(), QObject::tr( "Last used folder for georeferencer source files" ) );
static const inline QgsSettingsEntryString settingLastRasterFileFilter = QgsSettingsEntryString( QStringLiteral( "/georeferencer/last-raster-file-filter" ), QgsSettings::App, QString(), QObject::tr( "Last used raster file filter for georeferencer source files" ) );
static const inline QgsSettingsEntryEnumFlag<QgsImageWarper::ResamplingMethod> settingResamplingMethod = QgsSettingsEntryEnumFlag<QgsImageWarper::ResamplingMethod>( QStringLiteral( "resampling-method" ), QgsSettings::Prefix::APP_GEOREFERENCER, QgsImageWarper::ResamplingMethod::NearestNeighbour, QObject::tr( "Last used georeferencer resampling method" ) );
static const inline QgsSettingsEntryString settingCompressionMethod = QgsSettingsEntryString( QStringLiteral( "compression-method" ), QgsSettings::Prefix::APP_GEOREFERENCER, QStringLiteral( "NONE" ), QObject::tr( "Last used georeferencer compression method" ) );
static const inline QgsSettingsEntryBool settingUseZeroForTransparent = QgsSettingsEntryBool( QStringLiteral( "use-zero-for-transparent" ), QgsSettings::Prefix::APP_GEOREFERENCER, false, QObject::tr( "Last used georeferencer use-zero-as-transparent option" ) );
static const inline QgsSettingsEntryEnumFlag<QgsGcpTransformerInterface::TransformMethod> settingTransformMethod = QgsSettingsEntryEnumFlag<QgsGcpTransformerInterface::TransformMethod>( QStringLiteral( "transform-method" ), QgsSettings::Prefix::APP_GEOREFERENCER, QgsGcpTransformerInterface::TransformMethod::Linear, QObject::tr( "Last used georeferencer transform method" ) );
static const inline QgsSettingsEntryBool settingSaveGcps = QgsSettingsEntryBool( QStringLiteral( "save-gcp-points" ), QgsSettings::Prefix::APP_GEOREFERENCER, false, QObject::tr( "Whether georeferencer should automatically save .points files" ) );
static const inline QgsSettingsEntryBool settingLoadInProject = QgsSettingsEntryBool( QStringLiteral( "load-result-in-project" ), QgsSettings::Prefix::APP_GEOREFERENCER, true, QObject::tr( "Whether georeferencer should automatically load results into the current project" ) );
static const inline QgsSettingsEntryString settingLastSourceFolder = QgsSettingsEntryString( QStringLiteral( "last-source-folder" ), QgsSettings::Prefix::APP_GEOREFERENCER, QString(), QObject::tr( "Last used folder for georeferencer source files" ) );
static const inline QgsSettingsEntryString settingLastRasterFileFilter = QgsSettingsEntryString( QStringLiteral( "last-raster-file-filter" ), QgsSettings::Prefix::APP_GEOREFERENCER, QString(), QObject::tr( "Last used raster file filter for georeferencer source files" ) );
QgsGeoreferencerMainWindow( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags() );
~QgsGeoreferencerMainWindow() override;

View File

@ -28,8 +28,8 @@ class QgsTransformSettingsDialog : public QDialog, private Ui::QgsTransformSetti
public:
static const inline QgsSettingsEntryString settingLastDestinationFolder = QgsSettingsEntryString( QStringLiteral( "/georeferencer/last-destination-folder" ), QgsSettings::App, QString(), QObject::tr( "Last used folder for georeferencer destination files" ) );
static const inline QgsSettingsEntryString settingLastPdfFolder = QgsSettingsEntryString( QStringLiteral( "/georeferencer/last-pdf-folder" ), QgsSettings::App, QString(), QObject::tr( "Last used folder for georeferencer PDF report files" ) );
static const inline QgsSettingsEntryString settingLastDestinationFolder = QgsSettingsEntryString( QStringLiteral( "last-destination-folder" ), QgsSettings::Prefix::APP_GEOREFERENCER, QString(), QObject::tr( "Last used folder for georeferencer destination files" ) );
static const inline QgsSettingsEntryString settingLastPdfFolder = QgsSettingsEntryString( QStringLiteral( "last-pdf-folder" ), QgsSettings::Prefix::APP_GEOREFERENCER, QString(), QObject::tr( "Last used folder for georeferencer PDF report files" ) );
QgsTransformSettingsDialog( QgsMapLayerType type, const QString &source, const QString &output, QWidget *parent = nullptr );

View File

@ -53,10 +53,10 @@ class APP_EXPORT QgsMapToolsDigitizingTechniqueManager : public QObject
{
Q_OBJECT
public:
static const inline QgsSettingsEntryEnumFlag<QgsMapToolCapture::CaptureTechnique> settingsDigitizingTechnique = QgsSettingsEntryEnumFlag<QgsMapToolCapture::CaptureTechnique>( QStringLiteral( "/qgis/digitizing/technique" ), QgsSettings::NoSection, QgsMapToolCapture::CaptureTechnique::StraightSegments, QObject::tr( "Current digitizing technique" ), Qgis::SettingsOption::SaveFormerValue ) SIP_SKIP;
static const inline QgsSettingsEntryEnumFlag<QgsMapToolCapture::CaptureTechnique> settingsDigitizingTechnique = QgsSettingsEntryEnumFlag<QgsMapToolCapture::CaptureTechnique>( QStringLiteral( "technique" ), QgsSettings::Prefix::QGIS_DIGITIZING, QgsMapToolCapture::CaptureTechnique::StraightSegments, QObject::tr( "Current digitizing technique" ), Qgis::SettingsOption::SaveFormerValue ) SIP_SKIP;
static const inline QgsSettingsEntryString settingMapToolShapeDefaultForShape = QgsSettingsEntryString( QStringLiteral( "/qgis/digitizing/shape-map-tools/%1/default" ), QgsSettings::NoSection, QString(), QObject::tr( "Default map tool for given shape category" ) ) SIP_SKIP;
static const inline QgsSettingsEntryString settingMapToolShapeCurrent = QgsSettingsEntryString( QStringLiteral( "/qgis/digitizing/shape-map-tools/current" ), QgsSettings::NoSection, QString(), QObject::tr( "Current shape map tool" ) ) SIP_SKIP;
static const inline QgsSettingsEntryString settingMapToolShapeDefaultForShape = QgsSettingsEntryString( QStringLiteral( "%1/default" ), QgsSettings::Prefix::QGIS_DIGITIZING_SHAPEMAPTOOLS, QString(), QObject::tr( "Default map tool for given shape category" ) ) SIP_SKIP;
static const inline QgsSettingsEntryString settingMapToolShapeCurrent = QgsSettingsEntryString( QStringLiteral( "current" ), QgsSettings::Prefix::QGIS_DIGITIZING_SHAPEMAPTOOLS, QString(), QObject::tr( "Current shape map tool" ) ) SIP_SKIP;
QgsMapToolsDigitizingTechniqueManager( QObject *parent );
~QgsMapToolsDigitizingTechniqueManager();

View File

@ -660,7 +660,7 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
#ifndef SIP_RUN
//! Settings entry search path for templates
static const inline QgsSettingsEntryStringList settingsSearchPathForTemplates = QgsSettingsEntryStringList( QStringLiteral( "Layout/searchPathsForTemplates" ), QgsSettings::Core, QStringList(), QObject::tr( "Search path for templates" ) );
static const inline QgsSettingsEntryStringList settingsSearchPathForTemplates = QgsSettingsEntryStringList( QStringLiteral( "searchPathsForTemplates" ), QgsSettings::Prefix::CORE_LAYOUT, QStringList(), QObject::tr( "Search path for templates" ) );
#endif
public slots:

View File

@ -155,11 +155,11 @@ class CORE_EXPORT QgsLocator : public QObject
#ifndef SIP_RUN
//! Settings entry locator filter enabled
static const inline QgsSettingsEntryBool settingsLocatorFilterEnabled = QgsSettingsEntryBool( QStringLiteral( "locator_filters/enabled_%1" ), QgsSettings::Gui, true, QObject::tr( "Locator filter enabled" ) );
static const inline QgsSettingsEntryBool settingsLocatorFilterEnabled = QgsSettingsEntryBool( QStringLiteral( "enabled_%1" ), QgsSettings::Prefix::GUI_LOCATORFILTERS, true, QObject::tr( "Locator filter enabled" ) );
//! Settings entry locator filter default value
static const inline QgsSettingsEntryBool settingsLocatorFilterDefault = QgsSettingsEntryBool( QStringLiteral( "locator_filters/default_%1" ), QgsSettings::Gui, false, QObject::tr( "Locator filter default value" ) );
static const inline QgsSettingsEntryBool settingsLocatorFilterDefault = QgsSettingsEntryBool( QStringLiteral( "default_%1" ), QgsSettings::Prefix::GUI_LOCATORFILTERS, false, QObject::tr( "Locator filter default value" ) );
//! Settings entry locator filter prefix
static const inline QgsSettingsEntryString settingsLocatorFilterPrefix = QgsSettingsEntryString( QStringLiteral( "locator_filters/prefix_%1" ), QgsSettings::Gui, QString(), QObject::tr( "Locator filter prefix" ) );
static const inline QgsSettingsEntryString settingsLocatorFilterPrefix = QgsSettingsEntryString( QStringLiteral( "prefix_%1" ), QgsSettings::Prefix::GUI_LOCATORFILTERS, QString(), QObject::tr( "Locator filter prefix" ) );
#endif
signals:

View File

@ -427,7 +427,7 @@ class CORE_EXPORT QgsMapRendererJob : public QObject SIP_ABSTRACT
#ifndef SIP_RUN
//! Settings entry log canvas refresh event
static const inline QgsSettingsEntryBool settingsLogCanvasRefreshEvent = QgsSettingsEntryBool( QStringLiteral( "Map/logCanvasRefreshEvent" ), QgsSettings::NoSection, false );
static const inline QgsSettingsEntryBool settingsLogCanvasRefreshEvent = QgsSettingsEntryBool( QStringLiteral( "logCanvasRefreshEvent" ), QgsSettings::Prefix::MAP, false );
#endif
signals:

View File

@ -609,7 +609,7 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
#ifndef SIP_RUN
//! Settings entry network timeout
static const inline QgsSettingsEntryInteger settingsNetworkTimeout = QgsSettingsEntryInteger( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), QgsSettings::NoSection, 60000, QObject::tr( "Network timeout" ) );
static const inline QgsSettingsEntryInteger settingsNetworkTimeout = QgsSettingsEntryInteger( QStringLiteral( "networkTimeout" ), QgsSettings::Prefix::QGIS_NETWORKANDPROXY, 60000, QObject::tr( "Network timeout" ) );
#endif
/**

View File

@ -113,13 +113,13 @@ class CORE_EXPORT QgsNewsFeedParser : public QObject
#ifndef SIP_RUN
//! Settings entry last fetch time
static const inline QgsSettingsEntryInteger settingsFeedLastFetchTime = QgsSettingsEntryInteger( QStringLiteral( "%1/lastFetchTime" ), QgsSettings::Core, 0, QObject::tr( "Feed last fetch time" ), Qgis::SettingsOptions(), 0 );
static const inline QgsSettingsEntryInteger settingsFeedLastFetchTime = QgsSettingsEntryInteger( QStringLiteral( "%1/lastFetchTime" ), QgsSettings::Prefix::CORE, 0, QObject::tr( "Feed last fetch time" ), Qgis::SettingsOptions(), 0 );
//! Settings entry feed language
static const inline QgsSettingsEntryString settingsFeedLanguage = QgsSettingsEntryString( QStringLiteral( "%1/lang" ), QgsSettings::Core, QString(), QObject::tr( "Feed language" ) );
static const inline QgsSettingsEntryString settingsFeedLanguage = QgsSettingsEntryString( QStringLiteral( "%1/lang" ), QgsSettings::Prefix::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" ) );
static const inline QgsSettingsEntryDouble settingsFeedLatitude = QgsSettingsEntryDouble( QStringLiteral( "%1/latitude" ), QgsSettings::Prefix::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" ) );
static const inline QgsSettingsEntryDouble settingsFeedLongitude = QgsSettingsEntryDouble( QStringLiteral( "%1/longitude" ), QgsSettings::Prefix::CORE, 0.0, QObject::tr( "Feed longitude" ) );
#endif
public slots:

View File

@ -110,13 +110,13 @@ class CORE_EXPORT QgsProcessing
#ifndef SIP_RUN
//! 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" ) );
static const inline QgsSettingsEntryBool settingsPreferFilenameAsLayerName = QgsSettingsEntryBool( QStringLiteral( "PREFER_FILENAME_AS_LAYER_NAME" ), QgsSettings::Prefix::PROCESSING_CONFIGURATION, 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() );
static const inline QgsSettingsEntryString settingsTempPath = QgsSettingsEntryString( QStringLiteral( "TEMP_PATH2" ), QgsSettings::Prefix::PROCESSING_CONFIGURATION, QString() );
//! Settings entry default output vector layer ext
static const inline QgsSettingsEntryInteger settingsDefaultOutputVectorLayerExt = QgsSettingsEntryInteger( QStringLiteral( "Processing/Configuration/DefaultOutputVectorLayerExt" ), QgsSettings::NoSection, -1 );
static const inline QgsSettingsEntryInteger settingsDefaultOutputVectorLayerExt = QgsSettingsEntryInteger( QStringLiteral( "DefaultOutputVectorLayerExt" ), QgsSettings::Prefix::PROCESSING_CONFIGURATION, -1 );
//! Settings entry default output raster layer ext
static const inline QgsSettingsEntryInteger settingsDefaultOutputRasterLayerExt = QgsSettingsEntryInteger( QStringLiteral( "Processing/Configuration/DefaultOutputRasterLayerExt" ), QgsSettings::NoSection, -1 );
static const inline QgsSettingsEntryInteger settingsDefaultOutputRasterLayerExt = QgsSettingsEntryInteger( QStringLiteral( "DefaultOutputRasterLayerExt" ), QgsSettings::Prefix::PROCESSING_CONFIGURATION, -1 );
#endif
};

View File

@ -1009,15 +1009,15 @@ class CORE_EXPORT QgsApplication : public QApplication
#ifndef SIP_RUN
//! Settings entry locale user locale
static const inline QgsSettingsEntryString settingsLocaleUserLocale = QgsSettingsEntryString( QStringLiteral( "locale/userLocale" ), QgsSettings::NoSection, QString() );
static const inline QgsSettingsEntryString settingsLocaleUserLocale = QgsSettingsEntryString( QStringLiteral( "userLocale" ), QgsSettings::Prefix::LOCALE, QString() );
//! Settings entry locale override flag
static const inline QgsSettingsEntryBool settingsLocaleOverrideFlag = QgsSettingsEntryBool( QStringLiteral( "locale/overrideFlag" ), QgsSettings::NoSection, false );
static const inline QgsSettingsEntryBool settingsLocaleOverrideFlag = QgsSettingsEntryBool( QStringLiteral( "overrideFlag" ), QgsSettings::Prefix::LOCALE, false );
//! Settings entry locale global locale
static const inline QgsSettingsEntryString settingsLocaleGlobalLocale = QgsSettingsEntryString( QStringLiteral( "locale/globalLocale" ), QgsSettings::NoSection, QString() );
static const inline QgsSettingsEntryString settingsLocaleGlobalLocale = QgsSettingsEntryString( QStringLiteral( "globalLocale" ), QgsSettings::Prefix::LOCALE, QString() );
//! Settings entry locale show group separator
static const inline QgsSettingsEntryBool settingsLocaleShowGroupSeparator = QgsSettingsEntryBool( QStringLiteral( "locale/showGroupSeparator" ), QgsSettings::NoSection, false );
static const inline QgsSettingsEntryBool settingsLocaleShowGroupSeparator = QgsSettingsEntryBool( QStringLiteral( "showGroupSeparator" ), QgsSettings::Prefix::LOCALE, false );
//! Settings entry search path for SVG
static const inline QgsSettingsEntryStringList settingsSearchPathsForSVG = QgsSettingsEntryStringList( QStringLiteral( "svg/searchPathsForSVG" ), QgsSettings::NoSection, QStringList() );
static const inline QgsSettingsEntryStringList settingsSearchPathsForSVG = QgsSettingsEntryStringList( QStringLiteral( "searchPathsForSVG" ), QgsSettings::Prefix::SVG, QStringList() );
#endif
#ifdef SIP_RUN

View File

@ -134,7 +134,7 @@ class CORE_EXPORT QgsGeometryOptions : public QObject
#ifndef SIP_RUN
//! Settings entry search path for templates
static const inline QgsSettingsEntryString settingsGeometryValidationDefaultChecks = QgsSettingsEntryString( QStringLiteral( "geometry_validation/default_checks" ), QgsSettings::NoSection, QString() );
static const inline QgsSettingsEntryString settingsGeometryValidationDefaultChecks = QgsSettingsEntryString( QStringLiteral( "default_checks" ), QgsSettings::Prefix::GEOMETRYVALIDATION, QString() );
#endif
signals:

View File

@ -68,7 +68,7 @@ class CORE_EXPORT QgsLocalizedDataPathRegistry
#ifndef SIP_RUN
//! Settings entry localized data paths
static const inline QgsSettingsEntryStringList settingsLocalizedDataPaths = QgsSettingsEntryStringList( QStringLiteral( "/qgis/localized_data_paths" ), QgsSettings::NoSection, QStringList() );
static const inline QgsSettingsEntryStringList settingsLocalizedDataPaths = QgsSettingsEntryStringList( QStringLiteral( "localized_data_paths" ), QgsSettings::Prefix::QGIS, QStringList() );
#endif
private:

View File

@ -79,6 +79,32 @@ class CORE_EXPORT QgsSettings : public QObject
Gps, //!< GPS section, since QGIS 3.22
};
/**
* \ingroup core
* \brief Prefixes for the settings keys
* \since QGIS 3.26
*/
class Prefix SIP_SKIP
{
public:
static const inline char *APP_GEOREFERENCER = "app/georeferencer";
static const inline char *CORE = "core";
static const inline char *CORE_LAYOUT = "core/Layout";
static const inline char *GEOMETRYVALIDATION = "geometry_validation";
static const inline char *GPS = "gps";
static const inline char *GUI_LOCATORFILTERS = "gui/locator_filters";
static const inline char *GUI_QGIS = "gui/qgis";
static const inline char *LOCALE = "locale";
static const inline char *MAP = "Map";
static const inline char *PLUGINS = "plugins";
static const inline char *PROCESSING_CONFIGURATION = "Processing/Configuration";
static const inline char *QGIS = "qgis";
static const inline char *QGIS_DIGITIZING = "qgis/digitizing";
static const inline char *QGIS_DIGITIZING_SHAPEMAPTOOLS = "qgis/digitizing/shape-map-tools";
static const inline char *QGIS_NETWORKANDPROXY = "qgis/networkAndProxy";
static const inline char *SVG = "svg";
};
/**
* Constructs a QgsSettings object for accessing settings of the application
* called application from the organization called organization, and with parent parent.

View File

@ -64,56 +64,18 @@ bool QgsSettingsEntryBase::keyIsValid( const QString &key ) const
{
if ( !key.contains( definitionKey() ) )
return false;
else
return key == definitionKey();
}
// Key to check
QString completeKeyToCheck = key;
QString settingsPrefix = QgsSettings().prefixedKey( QString(), section() );
settingsPrefix.chop( 1 );
if ( !completeKeyToCheck.startsWith( settingsPrefix ) )
{
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 completeKeyToCheck == prefixedSettingsKey;
const QRegularExpression regularExpression( prefixedSettingsKey.replace( QRegularExpression( QStringLiteral( "%\\d+" ) ), QStringLiteral( ".*" ) ) );
const QRegularExpressionMatch regularExpressionMatch = regularExpression.match( completeKeyToCheck );
const QRegularExpression regularExpression( definitionKey().replace( QRegularExpression( QStringLiteral( "%\\d+" ) ), QStringLiteral( ".*" ) ) );
const QRegularExpressionMatch regularExpressionMatch = regularExpression.match( key );
return regularExpressionMatch.hasMatch();
}
QString QgsSettingsEntryBase::definitionKey() const
{
QString completeKey = mKey;
if ( !mPluginName.isEmpty() )
{
if ( !completeKey.startsWith( '/' ) )
completeKey.prepend( '/' );
completeKey.prepend( mPluginName );
}
return completeKey;
return mKey;
}
bool QgsSettingsEntryBase::hasDynamicKey() const
@ -124,27 +86,22 @@ bool QgsSettingsEntryBase::hasDynamicKey() const
bool QgsSettingsEntryBase::exists( const QString &dynamicKeyPart ) const
{
return QgsSettings().contains( key( dynamicKeyPart ), section() );
return QgsSettings().contains( key( dynamicKeyPart ) );
}
bool QgsSettingsEntryBase::exists( const QStringList &dynamicKeyPartList ) const
{
return QgsSettings().contains( key( dynamicKeyPartList ), section() );
return QgsSettings().contains( key( dynamicKeyPartList ) );
}
void QgsSettingsEntryBase::remove( const QString &dynamicKeyPart ) const
{
QgsSettings().remove( key( dynamicKeyPart ), section() );
QgsSettings().remove( key( dynamicKeyPart ) );
}
void QgsSettingsEntryBase::remove( const QStringList &dynamicKeyPartList ) const
{
QgsSettings().remove( key( dynamicKeyPartList ), section() );
}
QgsSettings::Section QgsSettingsEntryBase::section() const
{
return mSection;
QgsSettings().remove( key( dynamicKeyPartList ) );
}
bool QgsSettingsEntryBase::setVariantValue( const QVariant &value, const QString &dynamicKeyPart ) const
@ -166,11 +123,11 @@ bool QgsSettingsEntryBase::setVariantValuePrivate( const QVariant &value, const
QVariant currentValue = valueAsVariant( key( dynamicKeyPartList ) );
if ( value != currentValue )
{
QgsSettings().setValue( formerValuekey( dynamicKeyPartList ), currentValue, section() );
QgsSettings().setValue( formerValuekey( dynamicKeyPartList ), currentValue );
}
}
}
QgsSettings().setValue( key( dynamicKeyPartList ), value, section() );
QgsSettings().setValue( key( dynamicKeyPartList ), value );
return true;
}
@ -189,7 +146,7 @@ QVariant QgsSettingsEntryBase::valueAsVariant( const QString &dynamicKeyPart ) c
QVariant QgsSettingsEntryBase::valueAsVariant( const QStringList &dynamicKeyPartList ) const
{
return QgsSettings().value( key( dynamicKeyPartList ), mDefaultValue, mSection );
return QgsSettings().value( key( dynamicKeyPartList ), mDefaultValue );
}
QVariant QgsSettingsEntryBase::valueAsVariant( const QString &dynamicKeyPart, bool useDefaultValueOverride, const QVariant &defaultValueOverride ) const
@ -202,19 +159,19 @@ QVariant QgsSettingsEntryBase::valueAsVariant( const QString &dynamicKeyPart, bo
QVariant QgsSettingsEntryBase::valueAsVariant( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride, const QVariant &defaultValueOverride ) const
{
if ( useDefaultValueOverride )
return QgsSettings().value( key( dynamicKeyPartList ), defaultValueOverride, mSection );
return QgsSettings().value( key( dynamicKeyPartList ), defaultValueOverride );
else
return QgsSettings().value( key( dynamicKeyPartList ), mDefaultValue, mSection );
return QgsSettings().value( key( dynamicKeyPartList ), mDefaultValue );
}
QVariant QgsSettingsEntryBase::valueAsVariantWithDefaultOverride( const QVariant &defaultValueOverride, const QString &dynamicKeyPart ) const
{
return QgsSettings().value( key( dynamicKeyPart ), defaultValueOverride, mSection );
return QgsSettings().value( key( dynamicKeyPart ), defaultValueOverride );
}
QVariant QgsSettingsEntryBase::valueAsVariantWithDefaultOverride( const QVariant &defaultValueOverride, const QStringList &dynamicKeyPartList ) const
{
return QgsSettings().value( key( dynamicKeyPartList ), defaultValueOverride, mSection );
return QgsSettings().value( key( dynamicKeyPartList ), defaultValueOverride );
}
@ -237,7 +194,7 @@ QVariant QgsSettingsEntryBase::formerValueAsVariant( const QStringList &dynamicK
{
Q_ASSERT( mOptions.testFlag( Qgis::SettingsOption::SaveFormerValue ) );
QVariant defaultValueOverride = valueAsVariant( key( dynamicKeyPartList ) );
return QgsSettings().value( formerValuekey( dynamicKeyPartList ), defaultValueOverride, mSection );
return QgsSettings().value( formerValuekey( dynamicKeyPartList ), defaultValueOverride );
}
QString QgsSettingsEntryBase::formerValuekey( const QStringList &dynamicKeyPartList ) const

View File

@ -61,7 +61,6 @@ class CORE_EXPORT QgsSettingsEntryBase
public:
#ifndef SIP_RUN
/**
* Constructor for QgsSettingsEntryBase.
@ -73,44 +72,16 @@ class CORE_EXPORT QgsSettingsEntryBase
* The \a options argument specifies the options for the settings entry.
*/
QgsSettingsEntryBase( const QString &key,
QgsSettings::Section section,
const QString &section,
const QVariant &defaultValue = QVariant(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: mKey( key )
: mKey( QStringLiteral( "%1/%2" ).arg( section, key ) )
, mDefaultValue( defaultValue )
, mSection( section )
, mDescription( description )
, mPluginName()
, mOptions( options )
{
}
#endif
/**
* Constructor for QgsSettingsEntryBase.
* This constructor is intended to be used from plugins.
*
* The \a key argument specifies the key of the settings.
* The \a pluginName argument is inserted in the key after the section.
* The \a defaultValue argument specifies the default value for the settings entry.
* The \a description argument specifies a description for the settings entry.
* The \a options arguments specifies the options for the settings entry.
*/
QgsSettingsEntryBase( const QString &key,
const QString &pluginName,
const QVariant &defaultValue = QVariant(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: mKey( key )
, mDefaultValue( defaultValue )
, mSection( QgsSettings::Plugins )
, mDescription( description )
, mPluginName( pluginName )
, mOptions( options )
{
}
{}
/**
* Destructor for QgsSettingsEntryBase.
@ -184,8 +155,9 @@ class CORE_EXPORT QgsSettingsEntryBase
/**
* Returns settings section. The settings section of the parent group is returned if available.
* \deprecated since QGIS 3.26 the key is entirely self-defined
*/
QgsSettings::Section section() const;
Q_DECL_DEPRECATED QgsSettings::Section section() const {return QgsSettings::NoSection;}
/**
* Set settings value.
@ -288,7 +260,6 @@ class CORE_EXPORT QgsSettingsEntryBase
QString mKey;
QVariant mDefaultValue;
QgsSettings::Section mSection;
QString mDescription;
QString mPluginName;
Qgis::SettingsOptions mOptions;
@ -310,44 +281,22 @@ class CORE_EXPORT QgsSettingsEntryByReference : public QgsSettingsEntryBase
{
public:
#ifndef SIP_RUN
/**
* Constructor for QgsSettingsEntryByReference.
*
* The \a key argument specifies the key of the settings.
* The \a section argument specifies the section.
* The \a defaultValue argument specifies the default value for the settings entry.
* The \a description argument specifies a description for the settings entry.
* The \a options arguments specifies the options for the settings entry.
*/
QgsSettingsEntryByReference( const QString &key,
QgsSettings::Section section,
const QString &section,
const T &defaultValue,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryBase( key, section, defaultValue, description, options )
{}
#endif
/**
* Constructor for QgsSettingsEntryByReference.
* This constructor is intended to be used from plugins.
*
* The \a key argument specifies the key of the settings.
* The \a pluginName argument is inserted in the key after the section.
* The \a defaultValue argument specifies the default value for the settings entry.
* The \a description argument specifies a description for the settings entry.
* The \a options arguments specifies the options for the settings entry.
*/
QgsSettingsEntryByReference( const QString &key,
const QString &pluginName,
const T &defaultValue,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryBase( key, pluginName, QVariant::fromValue<T>( defaultValue ), description, options )
{}
virtual Qgis::SettingsType settingsType() const override = 0;
@ -465,7 +414,6 @@ class CORE_EXPORT QgsSettingsEntryByValue : public QgsSettingsEntryBase
{
public:
#ifndef SIP_RUN
/**
* Constructor for QgsSettingsEntryByValue.
@ -476,30 +424,10 @@ class CORE_EXPORT QgsSettingsEntryByValue : public QgsSettingsEntryBase
* The \a description argument specifies a description for the settings entry.
* The \a options arguments specifies the options for the settings entry.
*/
QgsSettingsEntryByValue( const QString &key, QgsSettings::Section section, QVariant defaultValue, const QString &description = QString(), Qgis::SettingsOptions options = Qgis::SettingsOptions() )
QgsSettingsEntryByValue( const QString &key, const QString &section, QVariant defaultValue, const QString &description = QString(), Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryBase( key, section, defaultValue, description, options )
{}
#endif
/**
* Constructor for QgsSettingsEntryByValue.
* This constructor is intended to be used from plugins.
*
* The \a key argument specifies the key of the settings.
* The \a pluginName argument is inserted in the key after the section.
* The \a defaultValue argument specifies the default value for the settings entry.
* The \a description argument specifies a description for the settings entry.
* The \a options arguments specifies the options for the settings entry.
*/
QgsSettingsEntryByValue( const QString &key,
const QString &pluginName,
T defaultValue,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryBase( key, pluginName, defaultValue, description, options )
{}
virtual Qgis::SettingsType settingsType() const override = 0;
/**

View File

@ -46,7 +46,7 @@ class CORE_EXPORT QgsSettingsEntryEnumFlag : public QgsSettingsEntryByValue<T>
* \note The enum needs to be declared with Q_ENUM, and flags with Q_FLAG (not Q_FLAGS).
* \note for Python bindings, a custom implementation is achieved in Python directly
*/
QgsSettingsEntryEnumFlag( const QString &key, QgsSettings::Section section, T defaultValue, const QString &description = QString(), Qgis::SettingsOptions options = Qgis::SettingsOptions() )
QgsSettingsEntryEnumFlag( const QString &key, const QString &section, T defaultValue, const QString &description = QString(), Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryByValue<T>( key,
section,
QMetaEnum::fromType<T>().isFlag() ? qgsFlagValueToKeys( defaultValue ) : qgsEnumValueToKey( defaultValue ),

View File

@ -17,14 +17,12 @@
#include "qgssettingsentryimpl.h"
Qgis::SettingsType QgsSettingsEntryVariant::settingsType() const
{
return Qgis::SettingsType::Variant;
}
bool QgsSettingsEntryString::checkValue( const QString &value ) const
{
if ( value.length() < mMinLength )
@ -95,13 +93,13 @@ bool QgsSettingsEntryBool::convertFromVariant( const QVariant &value ) const
return value.toBool();
}
Qgis::SettingsType QgsSettingsEntryBool::settingsType() const
{
return Qgis::SettingsType::Bool;
}
bool QgsSettingsEntryInteger::checkValue( qlonglong value ) const
{
if ( value < mMinValue )

View File

@ -30,7 +30,6 @@ class CORE_EXPORT QgsSettingsEntryVariant : public QgsSettingsEntryByReference<Q
{
public:
#ifndef SIP_RUN
/**
* Constructor for QgsSettingsEntryVariant.
@ -42,15 +41,14 @@ class CORE_EXPORT QgsSettingsEntryVariant : public QgsSettingsEntryByReference<Q
* The \a options argument specifies the options for the settings entry.
*/
QgsSettingsEntryVariant( const QString &key,
QgsSettings::Section section,
const QString &section,
const QVariant &defaultValue = QVariant(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryByReference( key, section, defaultValue, description, options )
{
}
Qgis::SettingsOptions options = Qgis::SettingsOptions() ) SIP_MAKE_PRIVATE
: QgsSettingsEntryByReference( key, section, defaultValue, description, options )
{}
#endif
#ifdef SIP_RUN
/**
* Constructor for QgsSettingsEntryVariant.
@ -66,10 +64,11 @@ class CORE_EXPORT QgsSettingsEntryVariant : public QgsSettingsEntryByReference<Q
const QString &pluginName,
const QVariant &defaultValue = QVariant(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryByReference( key, pluginName, defaultValue, description, options )
{
}
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
% MethodCode
sipCpp = new sipQgsSettingsEntryVariant( QgsSettingsEntryVariant( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), *a2, *a3, *a4 ) );
% End
#endif
virtual Qgis::SettingsType settingsType() const override;
@ -90,8 +89,6 @@ class CORE_EXPORT QgsSettingsEntryString : public QgsSettingsEntryByReference<QS
{
public:
#ifndef SIP_RUN
/**
* Constructor for QgsSettingsEntryString.
*
@ -104,19 +101,19 @@ class CORE_EXPORT QgsSettingsEntryString : public QgsSettingsEntryByReference<QS
* The \a maxLength argument specifies the maximal length of the string value. -1 means no limit.
*/
QgsSettingsEntryString( const QString &key,
QgsSettings::Section section,
const QString &section,
const QString &defaultValue = QString(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions(),
int minLength = 0,
int maxLength = -1 )
: QgsSettingsEntryByReference<QString>( key, section, defaultValue, description, options )
, mMinLength( minLength )
, mMaxLength( maxLength )
int maxLength = -1 ) SIP_MAKE_PRIVATE
: QgsSettingsEntryByReference<QString>( key, section, defaultValue, description, options )
, mMinLength( minLength )
, mMaxLength( maxLength )
{
}
#endif
#ifdef SIP_RUN
/**
* Constructor for QgsSettingsEntryString.
@ -132,12 +129,13 @@ class CORE_EXPORT QgsSettingsEntryString : public QgsSettingsEntryByReference<QS
const QString &pluginName,
const QString &defaultValue = QString(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryByReference<QString>( key, pluginName, defaultValue, description, options )
, mMinLength( 0 )
, mMaxLength( -1 )
{
}
Qgis::SettingsOptions options = Qgis::SettingsOptions(),
int minLength = 0,
int maxLength = -1 );
% MethodCode
sipCpp = new sipQgsSettingsEntryString( QgsSettingsEntryString( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), *a2, *a3, *a4 ) );
% End
#endif
virtual Qgis::SettingsType settingsType() const override;
@ -186,8 +184,6 @@ class CORE_EXPORT QgsSettingsEntryStringList : public QgsSettingsEntryByReferenc
{
public:
#ifndef SIP_RUN
/**
* Constructor for QgsSettingsEntryStringList.
*
@ -198,15 +194,15 @@ class CORE_EXPORT QgsSettingsEntryStringList : public QgsSettingsEntryByReferenc
* The \a options arguments specifies the options for the settings entry.
*/
QgsSettingsEntryStringList( const QString &key,
QgsSettings::Section section,
const QString &section,
const QStringList &defaultValue = QStringList(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryByReference( key, section, defaultValue, description, options )
Qgis::SettingsOptions options = Qgis::SettingsOptions() ) SIP_MAKE_PRIVATE
: QgsSettingsEntryByReference( key, section, defaultValue, description, options )
{
}
#endif
#ifdef SIP_RUN
/**
* Constructor for QgsSettingsEntryStringList.
@ -222,10 +218,11 @@ class CORE_EXPORT QgsSettingsEntryStringList : public QgsSettingsEntryByReferenc
const QString &pluginName,
const QStringList &defaultValue = QStringList(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryByReference( key, pluginName, defaultValue, description, options )
{
}
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
% MethodCode
sipCpp = new sipQgsSettingsEntryStringList( QgsSettingsEntryStringList( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), *a2, *a3, *a4 ) );
% End
#endif
virtual Qgis::SettingsType settingsType() const override;
@ -246,8 +243,6 @@ class CORE_EXPORT QgsSettingsEntryBool : public QgsSettingsEntryByValue<bool>
{
public:
#ifndef SIP_RUN
/**
* Constructor for QgsSettingsEntryBool.
*
@ -258,15 +253,14 @@ class CORE_EXPORT QgsSettingsEntryBool : public QgsSettingsEntryByValue<bool>
* The \a options arguments specifies the options for the settings entry.
*/
QgsSettingsEntryBool( const QString &key,
QgsSettings::Section section,
const QString &section,
bool defaultValue = false,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryByValue( key, section, defaultValue, description, options )
{
}
Qgis::SettingsOptions options = Qgis::SettingsOptions() ) SIP_MAKE_PRIVATE
: QgsSettingsEntryByValue( key, section, defaultValue, description, options )
{}
#endif
#ifdef SIP_RUN
/**
* Constructor for QgsSettingsEntryBool.
@ -278,9 +272,16 @@ class CORE_EXPORT QgsSettingsEntryBool : public QgsSettingsEntryByValue<bool>
* The \a description argument specifies a description for the settings entry.
* The \a options arguments specifies the options for the settings entry.
*/
QgsSettingsEntryBool( const QString &key, const QString &pluginName, bool defaultValue = false, const QString &description = QString(), Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryByValue( key, pluginName, defaultValue, description, options )
{}
QgsSettingsEntryBool( const QString &key,
const QString &pluginName,
bool defaultValue = false,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
% MethodCode
sipCpp = new sipQgsSettingsEntryBool( QgsSettingsEntryBool( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), a2, *a3, *a4 ) );
% End
#endif
virtual Qgis::SettingsType settingsType() const override;
@ -300,9 +301,6 @@ class CORE_EXPORT QgsSettingsEntryInteger : public QgsSettingsEntryByValue<qlong
{
public:
#ifndef SIP_RUN
/**
* Constructor for QgsSettingsEntryInteger.
*
@ -315,40 +313,43 @@ class CORE_EXPORT QgsSettingsEntryInteger : public QgsSettingsEntryByValue<qlong
* The \a maxValue argument specifies the maximal value.
*/
QgsSettingsEntryInteger( const QString &key,
QgsSettings::Section section,
const QString &section,
qlonglong defaultValue = 0,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions(),
qlonglong minValue = std::numeric_limits<qlonglong>::min(),
qlonglong maxValue = std::numeric_limits<qlonglong>::max() )
: QgsSettingsEntryByValue( key, section, defaultValue, description, options )
, mMinValue( minValue )
, mMaxValue( maxValue )
{
}
qlonglong maxValue = std::numeric_limits<qlonglong>::max() ) SIP_MAKE_PRIVATE
: QgsSettingsEntryByValue( key, section, defaultValue, description, options )
, mMinValue( minValue )
, mMaxValue( maxValue )
{ }
#endif
#ifdef SIP_RUN
/**
* Constructor for QgsSettingsEntryInteger.
* This constructor is intended to be used from plugins.
*
* The \a key argument specifies the key of the settings.
* The \a pluginName argument is inserted in the key after the section.
* The \a pluginName argument is used to define the key of the setting
* The \a defaultValue argument specifies the default value for the settings entry.
* The \a description argument specifies a description for the settings entry.
* The \a options arguments specifies the options for the settings entry.
* The \a minValue argument specifies the minimal value.
* The \a maxValue argument specifies the maximal value.
*/
QgsSettingsEntryInteger( const QString &key,
const QString &pluginName,
qlonglong defaultValue = 0,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryByValue( key, pluginName, defaultValue, description, options )
, mMinValue( std::numeric_limits<qlonglong>::min() )
, mMaxValue( std::numeric_limits<qlonglong>::max() )
{
}
Qgis::SettingsOptions options = Qgis::SettingsOptions(),
qlonglong minValue = std::numeric_limits<qlonglong>::min(),
qlonglong maxValue = std::numeric_limits<qlonglong>::max() );
% MethodCode
sipCpp = new sipQgsSettingsEntryInteger( QgsSettingsEntryInteger( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), a2, *a3, *a4, a5, a6 ) );
% End
#endif
virtual Qgis::SettingsType settingsType() const override;
/**
@ -395,8 +396,6 @@ class CORE_EXPORT QgsSettingsEntryDouble : public QgsSettingsEntryByValue<double
{
public:
#ifndef SIP_RUN
/**
* Constructor for QgsSettingsEntryDouble.
*
@ -411,43 +410,47 @@ class CORE_EXPORT QgsSettingsEntryDouble : public QgsSettingsEntryByValue<double
* for example for a QDoubleSpinBox.
*/
QgsSettingsEntryDouble( const QString &key,
QgsSettings::Section section,
const QString &section,
double defaultValue = 0.0,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions(),
double minValue = std::numeric_limits<double>::lowest(),
double maxValue = std::numeric_limits<double>::max(),
int displayDecimals = 1 )
: QgsSettingsEntryByValue( key, section, defaultValue, description, options )
, mMinValue( minValue )
, mMaxValue( maxValue )
, mDisplayHintDecimals( displayDecimals )
{
}
int displayDecimals = 1 ) SIP_MAKE_PRIVATE
: QgsSettingsEntryByValue( key, section, defaultValue, description, options )
, mMinValue( minValue )
, mMaxValue( maxValue )
, mDisplayHintDecimals( displayDecimals )
{}
#endif
#ifdef SIP_RUN
/**
* Constructor for QgsSettingsEntryDouble.
* This constructor is intended to be used from plugins.
*
* The \a key argument specifies the key of the settings.
* The \a pluginName argument is inserted in the key after the section.
* The \a pluginName argument is used to define the key of the setting
* The \a defaultValue argument specifies the default value for the settings entry.
* The \a options arguments specifies the options for the settings entry.
* The \a description argument specifies a description for the settings entry.
* The \a minValue argument specifies the minimal value.
* The \a maxValue argument specifies the maximal value.
* The \a displayDecimals specifies an hint for the gui about how much decimals to show
*/
QgsSettingsEntryDouble( const QString &key,
const QString &pluginName,
double defaultValue,
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryByValue( key, pluginName, defaultValue, description, options )
, mMinValue( std::numeric_limits<double>::lowest() )
, mMaxValue( std::numeric_limits<double>::max() )
, mDisplayHintDecimals( 1 )
{
}
Qgis::SettingsOptions options = Qgis::SettingsOptions(),
double minValue = std::numeric_limits<double>::lowest(),
double maxValue = std::numeric_limits<double>::max(),
int displayDecimals = 1 );
% MethodCode
sipCpp = new sipQgsSettingsEntryDouble( QgsSettingsEntryDouble( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), a2, *a3, *a4, a5, a6, a7 ) );
% End
#endif
virtual Qgis::SettingsType settingsType() const override;
@ -510,8 +513,6 @@ class CORE_EXPORT QgsSettingsEntryColor : public QgsSettingsEntryByReference<QCo
{
public:
#ifndef SIP_RUN
/**
* Constructor for QgsSettingsEntryColor.
*
@ -522,15 +523,14 @@ class CORE_EXPORT QgsSettingsEntryColor : public QgsSettingsEntryByReference<QCo
* The \a options arguments specifies the options for the settings entry.
*/
QgsSettingsEntryColor( const QString &key,
QgsSettings::Section section,
const QString &section,
const QColor &defaultValue = QColor(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryByReference( key, section, defaultValue, description, options )
{
}
Qgis::SettingsOptions options = Qgis::SettingsOptions() ) SIP_MAKE_PRIVATE
: QgsSettingsEntryByReference( key, section, defaultValue, description, options )
{}
#endif
#ifdef SIP_RUN
/**
* Constructor for QgsSettingsEntryColor.
@ -546,10 +546,12 @@ class CORE_EXPORT QgsSettingsEntryColor : public QgsSettingsEntryByReference<QCo
const QString &pluginName,
const QColor &defaultValue = QColor(),
const QString &description = QString(),
Qgis::SettingsOptions options = Qgis::SettingsOptions() )
: QgsSettingsEntryByReference( key, pluginName, defaultValue, description, options )
{
}
Qgis::SettingsOptions options = Qgis::SettingsOptions() );
% MethodCode
sipCpp = new sipQgsSettingsEntryColor( QgsSettingsEntryColor( *a0, QStringLiteral( "plugins/%1" ).arg( *a1 ), *a2, *a3, *a4 ) );
% End
#endif
virtual Qgis::SettingsType settingsType() const override;
private:

View File

@ -25,6 +25,7 @@
#include "qgslocalizeddatapathregistry.h"
#include "qgsmaprendererjob.h"
QgsSettingsRegistryCore::QgsSettingsRegistryCore()
: QgsSettingsRegistry()
{

View File

@ -39,6 +39,7 @@ template class CORE_EXPORT QgsSettingsEntryEnumFlag<QgsUnitTypes::LayoutUnit> SI
template class CORE_EXPORT QgsSettingsEntryEnumFlag< class QFlags<enum QgsMapLayerProxyModel::Filter> > SIP_SKIP;
#endif
/**
* \ingroup core
* \class QgsSettingsRegistryCore
@ -52,8 +53,8 @@ class CORE_EXPORT QgsSettingsRegistryCore : public QgsSettingsRegistry
public:
/**
* Constructor for QgsSettingsRegistryCore.
*/
* Constructor for QgsSettingsRegistryCore.
*/
QgsSettingsRegistryCore();
/**
@ -63,124 +64,124 @@ class CORE_EXPORT QgsSettingsRegistryCore : public QgsSettingsRegistry
#ifndef SIP_RUN
//! Settings entry digitizing stream tolerance
static const inline QgsSettingsEntryInteger settingsDigitizingStreamTolerance = QgsSettingsEntryInteger( QStringLiteral( "/qgis/digitizing/stream_tolerance" ), QgsSettings::NoSection, 2 );
static const inline QgsSettingsEntryInteger settingsDigitizingStreamTolerance = QgsSettingsEntryInteger( QStringLiteral( "stream_tolerance" ), QgsSettings::Prefix::QGIS_DIGITIZING, 2 );
//! Settings entry digitizing line width
static const inline QgsSettingsEntryInteger settingsDigitizingLineWidth = QgsSettingsEntryInteger( QStringLiteral( "/qgis/digitizing/line_width" ), QgsSettings::NoSection, 1 );
static const inline QgsSettingsEntryInteger settingsDigitizingLineWidth = QgsSettingsEntryInteger( QStringLiteral( "line_width" ), QgsSettings::Prefix::QGIS_DIGITIZING, 1 );
//! Settings entry digitizing line color red
static const inline QgsSettingsEntryInteger settingsDigitizingLineColorRed = QgsSettingsEntryInteger( QStringLiteral( "/qgis/digitizing/line_color_red" ), QgsSettings::NoSection, 255 );
static const inline QgsSettingsEntryInteger settingsDigitizingLineColorRed = QgsSettingsEntryInteger( QStringLiteral( "line_color_red" ), QgsSettings::Prefix::QGIS_DIGITIZING, 255 );
//! Settings entry digitizing line color green
static const inline QgsSettingsEntryInteger settingsDigitizingLineColorGreen = QgsSettingsEntryInteger( QStringLiteral( "/qgis/digitizing/line_color_green" ), QgsSettings::NoSection, 0 );
static const inline QgsSettingsEntryInteger settingsDigitizingLineColorGreen = QgsSettingsEntryInteger( QStringLiteral( "line_color_green" ), QgsSettings::Prefix::QGIS_DIGITIZING, 0 );
//! Settings entry digitizing line color blue
static const inline QgsSettingsEntryInteger settingsDigitizingLineColorBlue = QgsSettingsEntryInteger( QStringLiteral( "/qgis/digitizing/line_color_blue" ), QgsSettings::NoSection, 0 );
static const inline QgsSettingsEntryInteger settingsDigitizingLineColorBlue = QgsSettingsEntryInteger( QStringLiteral( "line_color_blue" ), QgsSettings::Prefix::QGIS_DIGITIZING, 0 );
//! Settings entry digitizing line color alpha
static const inline QgsSettingsEntryInteger settingsDigitizingLineColorAlpha = QgsSettingsEntryInteger( QStringLiteral( "/qgis/digitizing/line_color_alpha" ), QgsSettings::NoSection, 200 );
static const inline QgsSettingsEntryInteger settingsDigitizingLineColorAlpha = QgsSettingsEntryInteger( QStringLiteral( "line_color_alpha" ), QgsSettings::Prefix::QGIS_DIGITIZING, 200 );
//! Settings entry digitizing line color alpha scale
static const inline QgsSettingsEntryDouble settingsDigitizingLineColorAlphaScale = QgsSettingsEntryDouble( QStringLiteral( "/qgis/digitizing/line_color_alpha_scale" ), QgsSettings::NoSection, 0.75 );
static const inline QgsSettingsEntryDouble settingsDigitizingLineColorAlphaScale = QgsSettingsEntryDouble( QStringLiteral( "line_color_alpha_scale" ), QgsSettings::Prefix::QGIS_DIGITIZING, 0.75 );
//! Settings entry digitizing fill color red
static const inline QgsSettingsEntryInteger settingsDigitizingFillColorRed = QgsSettingsEntryInteger( QStringLiteral( "/qgis/digitizing/fill_color_red" ), QgsSettings::NoSection, 255 );
static const inline QgsSettingsEntryInteger settingsDigitizingFillColorRed = QgsSettingsEntryInteger( QStringLiteral( "fill_color_red" ), QgsSettings::Prefix::QGIS_DIGITIZING, 255 );
//! Settings entry digitizing fill color green
static const inline QgsSettingsEntryInteger settingsDigitizingFillColorGreen = QgsSettingsEntryInteger( QStringLiteral( "/qgis/digitizing/fill_color_green" ), QgsSettings::NoSection, 0 );
static const inline QgsSettingsEntryInteger settingsDigitizingFillColorGreen = QgsSettingsEntryInteger( QStringLiteral( "fill_color_green" ), QgsSettings::Prefix::QGIS_DIGITIZING, 0 );
//! Settings entry digitizing fill color blue
static const inline QgsSettingsEntryInteger settingsDigitizingFillColorBlue = QgsSettingsEntryInteger( QStringLiteral( "/qgis/digitizing/fill_color_blue" ), QgsSettings::NoSection, 0 );
static const inline QgsSettingsEntryInteger settingsDigitizingFillColorBlue = QgsSettingsEntryInteger( QStringLiteral( "fill_color_blue" ), QgsSettings::Prefix::QGIS_DIGITIZING, 0 );
//! Settings entry digitizing fill color alpha
static const inline QgsSettingsEntryInteger settingsDigitizingFillColorAlpha = QgsSettingsEntryInteger( QStringLiteral( "/qgis/digitizing/fill_color_alpha" ), QgsSettings::NoSection, 30 );
static const inline QgsSettingsEntryInteger settingsDigitizingFillColorAlpha = QgsSettingsEntryInteger( QStringLiteral( "fill_color_alpha" ), QgsSettings::Prefix::QGIS_DIGITIZING, 30 );
//! Settings entry digitizing line ghost
static const inline QgsSettingsEntryBool settingsDigitizingLineGhost = QgsSettingsEntryBool( QStringLiteral( "/qgis/digitizing/line_ghost" ), QgsSettings::NoSection, false );
static const inline QgsSettingsEntryBool settingsDigitizingLineGhost = QgsSettingsEntryBool( QStringLiteral( "line_ghost" ), QgsSettings::Prefix::QGIS_DIGITIZING, false );
//! Settings entry digitizing default z value
static const inline QgsSettingsEntryDouble settingsDigitizingDefaultZValue = QgsSettingsEntryDouble( QStringLiteral( "/qgis/digitizing/default_z_value" ), QgsSettings::NoSection, Qgis::DEFAULT_Z_COORDINATE );
static const inline QgsSettingsEntryDouble settingsDigitizingDefaultZValue = QgsSettingsEntryDouble( QStringLiteral( "default_z_value" ), QgsSettings::Prefix::QGIS_DIGITIZING, Qgis::DEFAULT_Z_COORDINATE );
//! Settings entry digitizing default m value
static const inline QgsSettingsEntryDouble settingsDigitizingDefaultMValue = QgsSettingsEntryDouble( QStringLiteral( "/qgis/digitizing/default_m_value" ), QgsSettings::NoSection, Qgis::DEFAULT_M_COORDINATE );
static const inline QgsSettingsEntryDouble settingsDigitizingDefaultMValue = QgsSettingsEntryDouble( QStringLiteral( "default_m_value" ), QgsSettings::Prefix::QGIS_DIGITIZING, Qgis::DEFAULT_M_COORDINATE );
//! Settings entry digitizing default snap enabled
static const inline QgsSettingsEntryBool settingsDigitizingDefaultSnapEnabled = QgsSettingsEntryBool( QStringLiteral( "/qgis/digitizing/default_snap_enabled" ), QgsSettings::NoSection, false );
static const inline QgsSettingsEntryBool settingsDigitizingDefaultSnapEnabled = QgsSettingsEntryBool( QStringLiteral( "default_snap_enabled" ), QgsSettings::Prefix::QGIS_DIGITIZING, false );
//! Settings entry digitizing default snap type
static const inline QgsSettingsEntryEnumFlag<Qgis::SnappingMode> settingsDigitizingDefaultSnapMode = QgsSettingsEntryEnumFlag<Qgis::SnappingMode>( QStringLiteral( "/qgis/digitizing/default_snap_mode" ), QgsSettings::NoSection, Qgis::SnappingMode::AllLayers );
static const inline QgsSettingsEntryEnumFlag<Qgis::SnappingMode> settingsDigitizingDefaultSnapMode = QgsSettingsEntryEnumFlag<Qgis::SnappingMode>( QStringLiteral( "default_snap_mode" ), QgsSettings::Prefix::QGIS_DIGITIZING, Qgis::SnappingMode::AllLayers );
//! Settings entry digitizing default snap type
static const inline QgsSettingsEntryEnumFlag<Qgis::SnappingType> settingsDigitizingDefaultSnapType = QgsSettingsEntryEnumFlag<Qgis::SnappingType>( QStringLiteral( "/qgis/digitizing/default_snap_type" ), QgsSettings::NoSection, Qgis::SnappingType::Vertex );
static const inline QgsSettingsEntryEnumFlag<Qgis::SnappingType> settingsDigitizingDefaultSnapType = QgsSettingsEntryEnumFlag<Qgis::SnappingType>( QStringLiteral( "default_snap_type" ), QgsSettings::Prefix::QGIS_DIGITIZING, Qgis::SnappingType::Vertex );
//! Settings entry digitizing default snapping tolerance
static const inline QgsSettingsEntryDouble settingsDigitizingDefaultSnappingTolerance = QgsSettingsEntryDouble( QStringLiteral( "/qgis/digitizing/default_snapping_tolerance" ), QgsSettings::NoSection, Qgis::DEFAULT_SNAP_TOLERANCE );
static const inline QgsSettingsEntryDouble settingsDigitizingDefaultSnappingTolerance = QgsSettingsEntryDouble( QStringLiteral( "default_snapping_tolerance" ), QgsSettings::Prefix::QGIS_DIGITIZING, Qgis::DEFAULT_SNAP_TOLERANCE );
//! Settings entry digitizing default snapping tolerance unit
static const inline QgsSettingsEntryEnumFlag<QgsTolerance::UnitType> settingsDigitizingDefaultSnappingToleranceUnit = QgsSettingsEntryEnumFlag<QgsTolerance::UnitType>( QStringLiteral( "/qgis/digitizing/default_snapping_tolerance_unit" ), QgsSettings::NoSection, Qgis::DEFAULT_SNAP_UNITS );
static const inline QgsSettingsEntryEnumFlag<QgsTolerance::UnitType> settingsDigitizingDefaultSnappingToleranceUnit = QgsSettingsEntryEnumFlag<QgsTolerance::UnitType>( QStringLiteral( "default_snapping_tolerance_unit" ), QgsSettings::Prefix::QGIS_DIGITIZING, Qgis::DEFAULT_SNAP_UNITS );
//! Settings entry digitizing search radius vertex edit
static const inline QgsSettingsEntryDouble settingsDigitizingSearchRadiusVertexEdit = QgsSettingsEntryDouble( QStringLiteral( "/qgis/digitizing/search_radius_vertex_edit" ), QgsSettings::NoSection, 10 );
static const inline QgsSettingsEntryDouble settingsDigitizingSearchRadiusVertexEdit = QgsSettingsEntryDouble( QStringLiteral( "search_radius_vertex_edit" ), QgsSettings::Prefix::QGIS_DIGITIZING, 10 );
//! Settings entry digitizing search radius vertex edit unit
static const inline QgsSettingsEntryEnumFlag<QgsTolerance::UnitType> settingsDigitizingSearchRadiusVertexEditUnit = QgsSettingsEntryEnumFlag<QgsTolerance::UnitType>( QStringLiteral( "/qgis/digitizing/search_radius_vertex_edit_unit" ), QgsSettings::NoSection, QgsTolerance::Pixels );
static const inline QgsSettingsEntryEnumFlag<QgsTolerance::UnitType> settingsDigitizingSearchRadiusVertexEditUnit = QgsSettingsEntryEnumFlag<QgsTolerance::UnitType>( QStringLiteral( "search_radius_vertex_edit_unit" ), QgsSettings::Prefix::QGIS_DIGITIZING, QgsTolerance::Pixels );
//! Settings entry digitizing snap color
static const inline QgsSettingsEntryColor settingsDigitizingSnapColor = QgsSettingsEntryColor( QStringLiteral( "/qgis/digitizing/snap_color" ), QgsSettings::NoSection, QColor( Qt::magenta ) );
static const inline QgsSettingsEntryColor settingsDigitizingSnapColor = QgsSettingsEntryColor( QStringLiteral( "snap_color" ), QgsSettings::Prefix::QGIS_DIGITIZING, QColor( Qt::magenta ) );
//! Settings entry digitizing snap tooltip
static const inline QgsSettingsEntryBool settingsDigitizingSnapTooltip = QgsSettingsEntryBool( QStringLiteral( "/qgis/digitizing/snap_tooltip" ), QgsSettings::NoSection, false );
static const inline QgsSettingsEntryBool settingsDigitizingSnapTooltip = QgsSettingsEntryBool( QStringLiteral( "snap_tooltip" ), QgsSettings::Prefix::QGIS_DIGITIZING, false );
//! Settings entry digitizing snap invisible feature
static const inline QgsSettingsEntryBool settingsDigitizingSnapInvisibleFeature = QgsSettingsEntryBool( QStringLiteral( "/qgis/digitizing/snap_invisible_feature" ), QgsSettings::NoSection, false );
static const inline QgsSettingsEntryBool settingsDigitizingSnapInvisibleFeature = QgsSettingsEntryBool( QStringLiteral( "snap_invisible_feature" ), QgsSettings::Prefix::QGIS_DIGITIZING, false );
//! Settings entry digitizing marker only for selected
static const inline QgsSettingsEntryBool settingsDigitizingMarkerOnlyForSelected = QgsSettingsEntryBool( QStringLiteral( "/qgis/digitizing/marker_only_for_selected" ), QgsSettings::NoSection, true );
static const inline QgsSettingsEntryBool settingsDigitizingMarkerOnlyForSelected = QgsSettingsEntryBool( QStringLiteral( "marker_only_for_selected" ), QgsSettings::Prefix::QGIS_DIGITIZING, true );
//! Settings entry digitizing marker style
static const inline QgsSettingsEntryString settingsDigitizingMarkerStyle = QgsSettingsEntryString( QStringLiteral( "/qgis/digitizing/marker_style" ), QgsSettings::NoSection, "Cross" );
static const inline QgsSettingsEntryString settingsDigitizingMarkerStyle = QgsSettingsEntryString( QStringLiteral( "marker_style" ), QgsSettings::Prefix::QGIS_DIGITIZING, "Cross" );
//! Settings entry digitizing marker size mm
static const inline QgsSettingsEntryDouble settingsDigitizingMarkerSizeMm = QgsSettingsEntryDouble( QStringLiteral( "/qgis/digitizing/marker_size_mm" ), QgsSettings::NoSection, 2.0 );
static const inline QgsSettingsEntryDouble settingsDigitizingMarkerSizeMm = QgsSettingsEntryDouble( QStringLiteral( "marker_size_mm" ), QgsSettings::Prefix::QGIS_DIGITIZING, 2.0 );
//! Settings entry digitizing reuseLastValues
static const inline QgsSettingsEntryBool settingsDigitizingReuseLastValues = QgsSettingsEntryBool( QStringLiteral( "/qgis/digitizing/reuseLastValues" ), QgsSettings::NoSection, false );
static const inline QgsSettingsEntryBool settingsDigitizingReuseLastValues = QgsSettingsEntryBool( QStringLiteral( "reuseLastValues" ), QgsSettings::Prefix::QGIS_DIGITIZING, false );
//! Settings entry digitizing disable enter attribute values dialog
static const inline QgsSettingsEntryBool settingsDigitizingDisableEnterAttributeValuesDialog = QgsSettingsEntryBool( QStringLiteral( "/qgis/digitizing/disable_enter_attribute_values_dialog" ), QgsSettings::NoSection, false );
static const inline QgsSettingsEntryBool settingsDigitizingDisableEnterAttributeValuesDialog = QgsSettingsEntryBool( QStringLiteral( "disable_enter_attribute_values_dialog" ), QgsSettings::Prefix::QGIS_DIGITIZING, false );
//! Settings entry digitizing validate geometries
static const inline QgsSettingsEntryInteger settingsDigitizingValidateGeometries = QgsSettingsEntryInteger( QStringLiteral( "/qgis/digitizing/validate_geometries" ), QgsSettings::NoSection, 1 );
static const inline QgsSettingsEntryInteger settingsDigitizingValidateGeometries = QgsSettingsEntryInteger( QStringLiteral( "validate_geometries" ), QgsSettings::Prefix::QGIS_DIGITIZING, 1 );
//! Settings entry digitizing offset join style
static const inline QgsSettingsEntryEnumFlag<Qgis::JoinStyle> settingsDigitizingOffsetJoinStyle = QgsSettingsEntryEnumFlag<Qgis::JoinStyle>( QStringLiteral( "/qgis/digitizing/offset_join_style" ), QgsSettings::NoSection, Qgis::JoinStyle::Round );
static const inline QgsSettingsEntryEnumFlag<Qgis::JoinStyle> settingsDigitizingOffsetJoinStyle = QgsSettingsEntryEnumFlag<Qgis::JoinStyle>( QStringLiteral( "offset_join_style" ), QgsSettings::Prefix::QGIS_DIGITIZING, Qgis::JoinStyle::Round );
//! Settings entry digitizing offset quad seg
static const inline QgsSettingsEntryInteger settingsDigitizingOffsetQuadSeg = QgsSettingsEntryInteger( QStringLiteral( "/qgis/digitizing/offset_quad_seg" ), QgsSettings::NoSection, 8 );
static const inline QgsSettingsEntryInteger settingsDigitizingOffsetQuadSeg = QgsSettingsEntryInteger( QStringLiteral( "offset_quad_seg" ), QgsSettings::Prefix::QGIS_DIGITIZING, 8 );
//! Settings entry digitizing offset miter limit
static const inline QgsSettingsEntryDouble settingsDigitizingOffsetMiterLimit = QgsSettingsEntryDouble( QStringLiteral( "/qgis/digitizing/offset_miter_limit" ), QgsSettings::NoSection, 5.0 );
static const inline QgsSettingsEntryDouble settingsDigitizingOffsetMiterLimit = QgsSettingsEntryDouble( QStringLiteral( "offset_miter_limit" ), QgsSettings::Prefix::QGIS_DIGITIZING, 5.0 );
//! Settings entry digitizing convert to curve
static const inline QgsSettingsEntryBool settingsDigitizingConvertToCurve = QgsSettingsEntryBool( QStringLiteral( "/qgis/digitizing/convert_to_curve" ), QgsSettings::NoSection, false );
static const inline QgsSettingsEntryBool settingsDigitizingConvertToCurve = QgsSettingsEntryBool( QStringLiteral( "convert_to_curve" ), QgsSettings::Prefix::QGIS_DIGITIZING, false );
//! Settings entry digitizing convert to curve angle tolerance
static const inline QgsSettingsEntryDouble settingsDigitizingConvertToCurveAngleTolerance = QgsSettingsEntryDouble( QStringLiteral( "/qgis/digitizing/convert_to_curve_angle_tolerance" ), QgsSettings::NoSection, 1e-6 );
static const inline QgsSettingsEntryDouble settingsDigitizingConvertToCurveAngleTolerance = QgsSettingsEntryDouble( QStringLiteral( "convert_to_curve_angle_tolerance" ), QgsSettings::Prefix::QGIS_DIGITIZING, 1e-6 );
//! Settings entry digitizing convert to curve distance tolerance
static const inline QgsSettingsEntryDouble settingsDigitizingConvertToCurveDistanceTolerance = QgsSettingsEntryDouble( QStringLiteral( "/qgis/digitizing/convert_to_curve_distance_tolerance" ), QgsSettings::NoSection, 1e-6 );
static const inline QgsSettingsEntryDouble settingsDigitizingConvertToCurveDistanceTolerance = QgsSettingsEntryDouble( QStringLiteral( "convert_to_curve_distance_tolerance" ), QgsSettings::Prefix::QGIS_DIGITIZING, 1e-6 );
//! Settings entry digitizing offset cap style
static const inline QgsSettingsEntryEnumFlag<Qgis::EndCapStyle> settingsDigitizingOffsetCapStyle = QgsSettingsEntryEnumFlag<Qgis::EndCapStyle>( QStringLiteral( "/qgis/digitizing/offset_cap_style" ), QgsSettings::NoSection, Qgis::EndCapStyle::Round );
static const inline QgsSettingsEntryEnumFlag<Qgis::EndCapStyle> settingsDigitizingOffsetCapStyle = QgsSettingsEntryEnumFlag<Qgis::EndCapStyle>( QStringLiteral( "offset_cap_style" ), QgsSettings::Prefix::QGIS_DIGITIZING, Qgis::EndCapStyle::Round );
//! Settings entry digitizing offset show advanced
static const inline QgsSettingsEntryBool settingsDigitizingOffsetShowAdvanced = QgsSettingsEntryBool( QStringLiteral( "/qgis/digitizing/offset_show_advanced" ), QgsSettings::NoSection, false );
static const inline QgsSettingsEntryBool settingsDigitizingOffsetShowAdvanced = QgsSettingsEntryBool( QStringLiteral( "offset_show_advanced" ), QgsSettings::Prefix::QGIS_DIGITIZING, false );
//! Settings entry digitizing tracing max feature count
static const inline QgsSettingsEntryInteger settingsDigitizingTracingMaxFeatureCount = QgsSettingsEntryInteger( QStringLiteral( "/qgis/digitizing/tracing_max_feature_count" ), QgsSettings::NoSection, 10000 );
static const inline QgsSettingsEntryInteger settingsDigitizingTracingMaxFeatureCount = QgsSettingsEntryInteger( QStringLiteral( "tracing_max_feature_count" ), QgsSettings::Prefix::QGIS_DIGITIZING, 10000 );
//! Settings entry path to GPSBabel executable.
static const inline QgsSettingsEntryString settingsGpsBabelPath = QgsSettingsEntryString( QStringLiteral( "gpsbabelPath" ), QgsSettings::Gps, QStringLiteral( "gpsbabel" ) );
static const inline QgsSettingsEntryString settingsGpsBabelPath = QgsSettingsEntryString( QStringLiteral( "gpsbabelPath" ), QgsSettings::Prefix::GPS, QStringLiteral( "gpsbabel" ) );
#endif
};

View File

@ -46,7 +46,7 @@ class GUI_EXPORT QgsSettingsRegistryGui : public QgsSettingsRegistry
#ifndef SIP_RUN
//! Settings entry respect screen dpi
static const inline QgsSettingsEntryBool settingsRespectScreenDPI = QgsSettingsEntryBool( QStringLiteral( "qgis/respect_screen_dpi" ), QgsSettings::Gui, false );
static const inline QgsSettingsEntryBool settingsRespectScreenDPI = QgsSettingsEntryBool( QStringLiteral( "respect_screen_dpi" ), QgsSettings::Prefix::GUI_QGIS, false );
#endif
};

View File

@ -32,6 +32,9 @@ class TestQgsSettingsEntry : public QObject
{
Q_OBJECT
private:
const QString mSettingsSection = QStringLiteral( "settingsEntryBool" );
private slots:
void settingsKey();
void enumValue();
@ -44,7 +47,7 @@ void TestQgsSettingsEntry::settingsKey()
QgsSettings settings;
{
const QString key( QStringLiteral( "/qgis/testing/settingsKey" ) );
const QString key( QStringLiteral( "/settingsKey" ) );
// Be sure that settings does not exist already
settings.remove( key );
@ -52,12 +55,12 @@ void TestQgsSettingsEntry::settingsKey()
// Check that keys are handled same way for QgsSettings and QgsSettingsEntry
settings.setValue( key, 42 );
const QgsSettingsEntryInteger settingsEntryInteger( key, QgsSettings::NoSection, 0 );
const QgsSettingsEntryInteger settingsEntryInteger( key, 0 );
QCOMPARE( settingsEntryInteger.value(), 42 );
}
{
const QString key( QStringLiteral( "qgis/testing/settingsKey" ) );
const QString key( QStringLiteral( "settingsKey" ) );
// Be sure that settings does not exist already
settings.remove( key );
@ -65,45 +68,19 @@ void TestQgsSettingsEntry::settingsKey()
// Check that keys are handled same way for QgsSettings and QgsSettingsEntry
settings.setValue( key, 43 );
const QgsSettingsEntryInteger settingsEntryInteger( key, QgsSettings::NoSection, 0 );
const QgsSettingsEntryInteger settingsEntryInteger( key, 0 );
QCOMPARE( settingsEntryInteger.value(), 43 );
}
{
const QString key( QStringLiteral( "/qgis/testing/settingsKey" ) );
// Be sure that settings does not exist already
settings.remove( key, QgsSettings::Core );
// Check that keys are handled same way for QgsSettings and QgsSettingsEntry
settings.setValue( key, 44, QgsSettings::Core );
const QgsSettingsEntryInteger settingsEntryInteger( key, QgsSettings::Core, 0 );
QCOMPARE( settingsEntryInteger.value(), 44 );
}
{
const QString key( QStringLiteral( "qgis/testing/settingsKey" ) );
// Be sure that settings does not exist already
settings.remove( key, QgsSettings::Core );
// Check that keys are handled same way for QgsSettings and QgsSettingsEntry
settings.setValue( key, 45, QgsSettings::Core );
const QgsSettingsEntryInteger settingsEntryInteger( key, QgsSettings::Core, 0 );
QCOMPARE( settingsEntryInteger.value(), 45 );
}
}
void TestQgsSettingsEntry::enumValue()
{
const QString settingsKey( QStringLiteral( "qgis/testing/my_enum_value_for_units" ) );
const QString settingsKey( QStringLiteral( "my_enum_value_for_units" ) );
// Make sure the setting is not existing
QgsSettings().remove( settingsKey, QgsSettings::NoSection );
QgsSettings().remove( settingsKey );
const QgsSettingsEntryEnumFlag settingsEntryEnum( settingsKey, QgsSettings::NoSection, QgsUnitTypes::LayoutMeters, QStringLiteral( "Layout unit" ) );
const QgsSettingsEntryEnumFlag settingsEntryEnum( settingsKey, mSettingsSection, QgsUnitTypes::LayoutMeters, QStringLiteral( "Layout unit" ) );
// Check default value
QCOMPARE( settingsEntryEnum.defaultValue(), QgsUnitTypes::LayoutMeters );
@ -112,12 +89,12 @@ void TestQgsSettingsEntry::enumValue()
{
const bool success = settingsEntryEnum.setValue( QgsUnitTypes::LayoutFeet );
QCOMPARE( success, true );
const QgsUnitTypes::LayoutUnit qgsSettingsValue = QgsSettings().enumValue( settingsKey, QgsUnitTypes::LayoutMeters, QgsSettings::NoSection );
const QgsUnitTypes::LayoutUnit qgsSettingsValue = QgsSettings().enumValue( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKey ), QgsUnitTypes::LayoutMeters );
QCOMPARE( qgsSettingsValue, QgsUnitTypes::LayoutFeet );
}
// Check get value
QgsSettings().setEnumValue( settingsKey, QgsUnitTypes::LayoutPicas, QgsSettings::NoSection );
QgsSettings().setEnumValue( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKey ), QgsUnitTypes::LayoutPicas );
QCOMPARE( settingsEntryEnum.value(), QgsUnitTypes::LayoutPicas );
// Check settings type
@ -129,7 +106,7 @@ void TestQgsSettingsEntry::enumValue()
QCOMPARE( success, false );
// Current value should not have changed
const QgsUnitTypes::LayoutUnit qgsSettingsValue = QgsSettings().enumValue( settingsKey, QgsUnitTypes::LayoutMeters, QgsSettings::NoSection );
const QgsUnitTypes::LayoutUnit qgsSettingsValue = QgsSettings().enumValue( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKey ), QgsUnitTypes::LayoutMeters );
QCOMPARE( qgsSettingsValue, QgsUnitTypes::LayoutPicas );
}
@ -137,22 +114,22 @@ void TestQgsSettingsEntry::enumValue()
QCOMPARE( settingsEntryEnum.valueAsVariant().toString(), QMetaEnum::fromType<QgsUnitTypes::LayoutUnit>().key( QgsUnitTypes::LayoutPicas ) );
// auto conversion of old settings (int to str)
QSettings().setValue( settingsKey, static_cast<int>( QgsUnitTypes::LayoutCentimeters ) );
QSettings().setValue( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKey ), static_cast<int>( QgsUnitTypes::LayoutCentimeters ) );
QCOMPARE( settingsEntryEnum.valueAsVariant().toInt(), QgsUnitTypes::LayoutCentimeters );
QCOMPARE( settingsEntryEnum.value(), QgsUnitTypes::LayoutCentimeters );
}
void TestQgsSettingsEntry::flagValue()
{
const QString settingsKey( QStringLiteral( "qgis/testing/my_flag_value_for_units" ) );
const QString settingsKey( QStringLiteral( "my_flag_value_for_units" ) );
const QgsMapLayerProxyModel::Filters pointAndLine = QgsMapLayerProxyModel::Filters( QgsMapLayerProxyModel::PointLayer | QgsMapLayerProxyModel::LineLayer );
const QgsMapLayerProxyModel::Filters pointAndPolygon = QgsMapLayerProxyModel::Filters( QgsMapLayerProxyModel::PointLayer | QgsMapLayerProxyModel::PolygonLayer );
const QgsMapLayerProxyModel::Filters hasGeometry = QgsMapLayerProxyModel::Filters( QgsMapLayerProxyModel::HasGeometry );
// Make sure the setting is not existing
QgsSettings().remove( settingsKey, QgsSettings::NoSection );
QgsSettings().remove( settingsKey );
const QgsSettingsEntryEnumFlag settingsEntryFlag( settingsKey, QgsSettings::NoSection, pointAndLine, QStringLiteral( "Filters" ) );
const QgsSettingsEntryEnumFlag settingsEntryFlag( settingsKey, mSettingsSection, pointAndLine, QStringLiteral( "Filters" ) );
// Check default value
QCOMPARE( settingsEntryFlag.defaultValue(), pointAndLine );
@ -161,12 +138,12 @@ void TestQgsSettingsEntry::flagValue()
{
const bool success = settingsEntryFlag.setValue( hasGeometry );
QCOMPARE( success, true );
const QgsMapLayerProxyModel::Filters qgsSettingsValue = QgsSettings().flagValue( settingsKey, pointAndLine, QgsSettings::NoSection );
const QgsMapLayerProxyModel::Filters qgsSettingsValue = QgsSettings().flagValue( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKey ), pointAndLine );
QCOMPARE( qgsSettingsValue, hasGeometry );
}
// Check get value
QgsSettings().setFlagValue( settingsKey, pointAndLine, QgsSettings::NoSection );
QgsSettings().setFlagValue( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKey ), pointAndLine );
QCOMPARE( settingsEntryFlag.value(), pointAndLine );
// Check settings type
@ -176,40 +153,40 @@ void TestQgsSettingsEntry::flagValue()
QCOMPARE( settingsEntryFlag.valueAsVariant().toByteArray(), QMetaEnum::fromType<QgsMapLayerProxyModel::Filters>().valueToKeys( pointAndLine ) );
// auto conversion of old settings (int to str)
QSettings().setValue( settingsKey, static_cast<int>( pointAndPolygon ) );
QSettings().setValue( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKey ), static_cast<int>( pointAndPolygon ) );
QCOMPARE( settingsEntryFlag.valueAsVariant().toInt(), pointAndPolygon );
QCOMPARE( settingsEntryFlag.value(), pointAndPolygon );
}
void TestQgsSettingsEntry::testFormerValue()
{
const QString settingsKey( QStringLiteral( "qgis/testing/settingsEntryInteger/integer-former-value" ) );
const QString settingsKey( QStringLiteral( "settingsEntryInteger/integer-former-value" ) );
const QString settingsKeyFormer = settingsKey + ( QStringLiteral( "_formervalue" ) );
QgsSettings().remove( settingsKey, QgsSettings::NoSection );
QgsSettings().remove( settingsKeyFormer, QgsSettings::NoSection );
QgsSettings().remove( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKey ) );
QgsSettings().remove( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKeyFormer ) );
int defaultValue = 111;
int defaultFormerValue = 222;
QgsSettingsEntryInteger settingsEntryInteger = QgsSettingsEntryInteger( settingsKey, QgsSettings::NoSection, defaultValue, QString(), Qgis::SettingsOption::SaveFormerValue );
QgsSettingsEntryInteger settingsEntryInteger = QgsSettingsEntryInteger( settingsKey, mSettingsSection, defaultValue, QString(), Qgis::SettingsOption::SaveFormerValue );
QCOMPARE( settingsEntryInteger.formerValue(), defaultValue );
QCOMPARE( QgsSettings().value( settingsKey, defaultValue, QgsSettings::NoSection ), defaultValue );
QCOMPARE( QgsSettings().value( settingsKeyFormer, defaultFormerValue, QgsSettings::NoSection ), defaultFormerValue );
QCOMPARE( QgsSettings().value( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKey ), defaultValue ), defaultValue );
QCOMPARE( QgsSettings().value( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKeyFormer ), defaultFormerValue ), defaultFormerValue );
settingsEntryInteger.setValue( 2 );
QCOMPARE( QgsSettings().value( settingsKey, defaultValue, QgsSettings::NoSection ), 2 );
QCOMPARE( QgsSettings().value( settingsKeyFormer, defaultFormerValue, QgsSettings::NoSection ), defaultFormerValue );
QCOMPARE( QgsSettings().value( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKey ), defaultValue ), 2 );
QCOMPARE( QgsSettings().value( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKeyFormer ), defaultFormerValue ), defaultFormerValue );
QCOMPARE( settingsEntryInteger.formerValue(), 2 );
settingsEntryInteger.setValue( 2 );
QCOMPARE( QgsSettings().value( settingsKey, defaultValue, QgsSettings::NoSection ), 2 );
QCOMPARE( QgsSettings().value( settingsKeyFormer, defaultFormerValue, QgsSettings::NoSection ), defaultFormerValue );
QCOMPARE( QgsSettings().value( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKey ), defaultValue ), 2 );
QCOMPARE( QgsSettings().value( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKeyFormer ), defaultFormerValue ), defaultFormerValue );
QCOMPARE( settingsEntryInteger.formerValue(), 2 );
settingsEntryInteger.setValue( 3 );
QCOMPARE( QgsSettings().value( settingsKey, defaultValue, QgsSettings::NoSection ), 3 );
QCOMPARE( QgsSettings().value( settingsKeyFormer, defaultFormerValue, QgsSettings::NoSection ).toLongLong(), 2 );
QCOMPARE( QgsSettings().value( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKey ), defaultValue ), 3 );
QCOMPARE( QgsSettings().value( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsKeyFormer ), defaultFormerValue ).toLongLong(), 2 );
QCOMPARE( settingsEntryInteger.formerValue(), 2 );
settingsEntryInteger.setValue( 2 );

View File

@ -41,6 +41,10 @@ class TestQgsSettingsRegistry : public QObject
{
Q_OBJECT
private:
const QString mSettingsSection = QStringLiteral( "settingsEntryBool" );
private slots:
void getSettingsEntries();
void getSettingsEntriesWithDynamicKeys();
@ -49,54 +53,54 @@ class TestQgsSettingsRegistry : public QObject
void TestQgsSettingsRegistry::getSettingsEntries()
{
const QString settingsEntryBoolKey( QStringLiteral( "/qgis/testing/settingsEntryBool" ) );
QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false );
const QString settingsEntryIntegerKey( QStringLiteral( "/qgis/testing/settingsEntryInteger" ) );
QgsSettingsEntryInteger settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 );
const QString settingsEntryBoolKey( QStringLiteral( "settingsEntryBool" ) );
QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, mSettingsSection, false );
const QString settingsEntryIntegerKey( QStringLiteral( "settingsEntryInteger" ) );
QgsSettingsEntryInteger settingsEntryInteger( settingsEntryIntegerKey, mSettingsSection, 123 );
const QString settingsEntryInexisting( QStringLiteral( "/qgis/testing/settingsEntryInexisting" ) );
const QString settingsEntryInexisting( QStringLiteral( "settingsEntryInexisting" ) );
SettingsRegistryTest settingsRegistry;
settingsRegistry.addSettingsEntry( nullptr ); // should not crash
settingsRegistry.addSettingsEntry( &settingsEntryBool );
settingsRegistry.addSettingsEntry( &settingsEntryInteger );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryBoolKey ), &settingsEntryBool );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryIntegerKey ), &settingsEntryInteger );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryInexisting ), nullptr );
QCOMPARE( settingsRegistry.settingsEntry( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsEntryBoolKey ) ), &settingsEntryBool );
QCOMPARE( settingsRegistry.settingsEntry( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsEntryIntegerKey ) ), &settingsEntryInteger );
QCOMPARE( settingsRegistry.settingsEntry( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsEntryInexisting ) ), nullptr );
}
void TestQgsSettingsRegistry::getSettingsEntriesWithDynamicKeys()
{
QString settingsEntryBoolKey( QStringLiteral( "/qgis/testing/%1_settingsEntryBool" ) );
QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false );
QString settingsEntryIntegerKey( QStringLiteral( "/qgis/testing/%1/settingsEntryInteger" ) );
QgsSettingsEntryInteger settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 );
QString settingsEntryDoubleKey( QStringLiteral( "/qgis/testing/%1/settingsEntryDouble_%2" ) );
QgsSettingsEntryDouble settingsEntryDouble( settingsEntryDoubleKey, QgsSettings::NoSection, 1.23 );
QString settingsEntryBoolKey( QStringLiteral( "%1_settingsEntryBool" ) );
QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, mSettingsSection, false );
QString settingsEntryIntegerKey( QStringLiteral( "%1/settingsEntryInteger" ) );
QgsSettingsEntryInteger settingsEntryInteger( settingsEntryIntegerKey, mSettingsSection, 123 );
QString settingsEntryDoubleKey( QStringLiteral( "%1/settingsEntryDouble_%2" ) );
QgsSettingsEntryDouble settingsEntryDouble( settingsEntryDoubleKey, mSettingsSection, 1.23 );
const QString settingsEntryInexisting( QStringLiteral( "/qgis/testing/settingsEntryInexisting%1" ) );
const QString settingsEntryInexisting( QStringLiteral( "settingsEntryInexisting%1" ) );
SettingsRegistryTest settingsRegistry;
settingsRegistry.addSettingsEntry( &settingsEntryBool );
settingsRegistry.addSettingsEntry( &settingsEntryInteger );
settingsRegistry.addSettingsEntry( &settingsEntryDouble );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryBoolKey ), &settingsEntryBool );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryBoolKey.replace( QLatin1String( "%1" ), QLatin1String( "1st" ) ) ), &settingsEntryBool );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryIntegerKey ), &settingsEntryInteger );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryIntegerKey.replace( QLatin1String( "%1" ), QLatin1String( "Second" ) ) ), &settingsEntryInteger );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryDoubleKey ), &settingsEntryDouble );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryDoubleKey.replace( QLatin1String( "%1" ), QLatin1String( "1st" ) ).replace( QLatin1String( "%2" ), QLatin1String( "2nd" ) ) ), &settingsEntryDouble );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryInexisting ), nullptr );
QCOMPARE( settingsRegistry.settingsEntry( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsEntryBoolKey ) ), &settingsEntryBool );
QCOMPARE( settingsRegistry.settingsEntry( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsEntryBoolKey ).replace( QLatin1String( "%1" ), QLatin1String( "1st" ) ) ), &settingsEntryBool );
QCOMPARE( settingsRegistry.settingsEntry( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsEntryIntegerKey ) ), &settingsEntryInteger );
QCOMPARE( settingsRegistry.settingsEntry( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsEntryIntegerKey ).replace( QLatin1String( "%1" ), QLatin1String( "Second" ) ) ), &settingsEntryInteger );
QCOMPARE( settingsRegistry.settingsEntry( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsEntryDoubleKey ) ), &settingsEntryDouble );
QCOMPARE( settingsRegistry.settingsEntry( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsEntryDoubleKey ).replace( QLatin1String( "%1" ), QLatin1String( "1st" ) ).replace( QLatin1String( "%2" ), QLatin1String( "2nd" ) ) ), &settingsEntryDouble );
QCOMPARE( settingsRegistry.settingsEntry( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsEntryInexisting ) ), nullptr );
}
void TestQgsSettingsRegistry::childRegistry()
{
const QString settingsEntryBoolKey( QStringLiteral( "/qgis/testing/settingsEntryBool" ) );
QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false );
const QString settingsEntryIntegerKey( QStringLiteral( "/qgis/testing/settingsEntryInteger" ) );
QgsSettingsEntryInteger settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 );
const QString settingsEntryBoolKey( QStringLiteral( "settingsEntryBool" ) );
QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, mSettingsSection, false );
const QString settingsEntryIntegerKey( QStringLiteral( "settingsEntryInteger" ) );
QgsSettingsEntryInteger settingsEntryInteger( settingsEntryIntegerKey, mSettingsSection, 123 );
SettingsRegistryTest settingsRegistryChild;
settingsRegistryChild.addSettingsEntry( &settingsEntryInteger );
@ -107,10 +111,10 @@ void TestQgsSettingsRegistry::childRegistry()
settingsRegistry.addSubRegistry( &settingsRegistryChild );
// Search only in parent
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryIntegerKey, false ), nullptr );
QCOMPARE( settingsRegistry.settingsEntry( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsEntryIntegerKey ), false ), nullptr );
// Search including child registries
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryIntegerKey, true ), &settingsEntryInteger );
QCOMPARE( settingsRegistry.settingsEntry( QStringLiteral( "%1/%2" ).arg( mSettingsSection, settingsEntryIntegerKey ), true ), &settingsEntryInteger );
}
QGSTEST_MAIN( TestQgsSettingsRegistry )

View File

@ -10,9 +10,12 @@ the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
from qgis import core as qgis_core
from qgis.core import Qgis, QgsSettings, QgsSettingsEntryVariant, QgsSettingsEntryString, QgsSettingsEntryStringList, QgsSettingsEntryBool, QgsSettingsEntryInteger, QgsSettingsEntryDouble, QgsSettingsEntryEnumFlag, QgsUnitTypes, QgsMapLayerProxyModel
from qgis.testing import start_app, unittest
from qgis.PyQt.QtGui import QColor
__author__ = 'Damiano Lombardi'
__date__ = '02/04/2021'
__copyright__ = 'Copyright 2021, The QGIS Project'
@ -33,10 +36,10 @@ class TestQgsSettingsEntry(unittest.TestCase):
def test_settings_entry_base(self):
settingsKey = "settingsEntryBase/variantValue"
settingsKeyComplete = self.pluginName + "/" + settingsKey
settingsKeyComplete = "plugins/{}/{}".format(self.pluginName, settingsKey)
# Make sure settings does not exists
QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins)
QgsSettings().remove(settingsKeyComplete)
defaultValue = 42
description = "Variant value for basic functionality test"
@ -57,9 +60,6 @@ class TestQgsSettingsEntry(unittest.TestCase):
settingsEntryVariant.remove()
self.assertEqual(settingsEntryVariant.exists(), False)
# Section
self.assertEqual(settingsEntryVariant.section(), QgsSettings.Plugins)
# DefaultValue
self.assertEqual(settingsEntryVariant.defaultValueAsVariant(), defaultValue)
@ -68,7 +68,7 @@ class TestQgsSettingsEntry(unittest.TestCase):
self.assertEqual(settingsEntryVariant.valueAsVariant(), defaultValue)
settingsEntryVariant.setValue(43)
# Verify setValue using QgsSettings
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), 43)
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue), 43)
self.assertEqual(settingsEntryVariant.valueAsVariant(), 43)
# Settings type
@ -77,12 +77,33 @@ class TestQgsSettingsEntry(unittest.TestCase):
# Description
self.assertEqual(settingsEntryVariant.description(), description)
def test_settings_plugin_key(self):
# be sure that the constructor in PyQGIS only creates keys with plugins prefix
settings_types = [x for x in dir(qgis_core) if x.startswith('QgsSettingsEntry') and not x.endswith('Base')]
hardcoded_types = {
'QgsSettingsEntryBool': True,
'QgsSettingsEntryColor': QColor(),
'QgsSettingsEntryDouble': 0.0,
'QgsSettingsEntryEnumFlag': QgsUnitTypes.LayoutMeters,
'QgsSettingsEntryInteger': 1,
'QgsSettingsEntryString': 'Hello',
'QgsSettingsEntryStringList': [],
'QgsSettingsEntryVariant': 1
}
self.assertEqual(settings_types, list(hardcoded_types.keys()))
for setting_type, default_value in hardcoded_types.items():
settings_key = "settings/key_{}".format(setting_type)
settings_key_complete = "plugins/{}/{}".format(self.pluginName, settings_key)
QgsSettings().remove(settings_key_complete)
settings_entry = eval('qgis_core.{}(settings_key, self.pluginName, default_value)'.format(setting_type))
self.assertEqual(settings_entry.key(), settings_key_complete)
def test_settings_entry_base_default_value_override(self):
settingsKey = "settingsEntryBase/defaultValueOverride/variantValue"
settingsKeyComplete = self.pluginName + "/" + settingsKey
settingsKeyComplete = "plugins/{}/{}".format(self.pluginName, settingsKey)
# Make sure settings does not exists
QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins)
QgsSettings().remove(settingsKeyComplete)
defaultValue = 42
defaultValueOverride = 123
@ -93,21 +114,21 @@ class TestQgsSettingsEntry(unittest.TestCase):
self.assertEqual(settingsEntryVariant.value(), defaultValue)
# Normal default value
self.assertEqual(settingsEntryVariant.value(None, False, defaultValueOverride), defaultValue)
self.assertEqual(settingsEntryVariant.value(), defaultValue)
# Overridden default value
self.assertEqual(settingsEntryVariant.value(None, True, defaultValueOverride), defaultValueOverride)
self.assertEqual(settingsEntryVariant.valueWithDefaultOverride(defaultValueOverride), defaultValueOverride)
def test_settings_entry_base_dynamic_key(self):
settingsKeyDynamic = "settingsEntryBase/%1/variantValue"
dynamicKeyPart1 = "first"
dynamicKeyPart2 = "second"
settingsKeyComplete1 = self.pluginName + "/" + settingsKeyDynamic.replace("%1", dynamicKeyPart1)
settingsKeyComplete2 = self.pluginName + "/" + settingsKeyDynamic.replace("%1", dynamicKeyPart2)
settingsKeyComplete1 = "plugins/{}/{}".format(self.pluginName, settingsKeyDynamic).replace("%1", dynamicKeyPart1)
settingsKeyComplete2 = "plugins/{}/{}".format(self.pluginName, settingsKeyDynamic).replace("%1", dynamicKeyPart2)
# Make sure settings does not exists
QgsSettings().remove(settingsKeyComplete1, QgsSettings.Plugins)
QgsSettings().remove(settingsKeyComplete2, QgsSettings.Plugins)
QgsSettings().remove(settingsKeyComplete1)
QgsSettings().remove(settingsKeyComplete2)
defaultValue = 42
settingsEntryVariantDynamic = QgsSettingsEntryVariant(settingsKeyDynamic, self.pluginName, defaultValue, "Variant value for dynamic key functionality test")
@ -119,8 +140,8 @@ class TestQgsSettingsEntry(unittest.TestCase):
# Get set values
settingsEntryVariantDynamic.setValue(43, dynamicKeyPart1)
settingsEntryVariantDynamic.setValue(44, dynamicKeyPart2)
self.assertEqual(QgsSettings().value(settingsKeyComplete1, defaultValue, section=QgsSettings.Plugins), 43)
self.assertEqual(QgsSettings().value(settingsKeyComplete2, defaultValue, section=QgsSettings.Plugins), 44)
self.assertEqual(QgsSettings().value(settingsKeyComplete1, defaultValue), 43)
self.assertEqual(QgsSettings().value(settingsKeyComplete2, defaultValue), 44)
self.assertEqual(settingsEntryVariantDynamic.value(dynamicKeyPart1), 43)
self.assertEqual(settingsEntryVariantDynamic.value(dynamicKeyPart2), 44)
@ -128,11 +149,10 @@ class TestQgsSettingsEntry(unittest.TestCase):
settingsKeyDynamic = "settingsEntryBase/%1/anotherPart_%2/variantValue"
dynamicKeyPart1 = "first"
dynamicKeyPart2 = "second"
settingsKeyComplete = self.pluginName + "/" + settingsKeyDynamic.replace("%1", dynamicKeyPart1)
settingsKeyComplete = settingsKeyComplete.replace("%2", dynamicKeyPart2)
settingsKeyComplete = "plugins/{}/{}".format(self.pluginName, settingsKeyDynamic).replace("%1", dynamicKeyPart1).replace("%2", dynamicKeyPart2)
# Make sure settings does not exists
QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins)
QgsSettings().remove(settingsKeyComplete)
defaultValue = 42
settingsEntryVariantDynamic = QgsSettingsEntryVariant(settingsKeyDynamic, self.pluginName, defaultValue, "Variant value for dynamic multiple keys functionality test")
@ -142,15 +162,15 @@ class TestQgsSettingsEntry(unittest.TestCase):
# Get set values
settingsEntryVariantDynamic.setValue(43, [dynamicKeyPart1, dynamicKeyPart2])
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), 43)
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue), 43)
self.assertEqual(settingsEntryVariantDynamic.value([dynamicKeyPart1, dynamicKeyPart2]), 43)
def test_settings_entry_variant(self):
settingsKey = "settingsEntryVariant/variantValue"
settingsKeyComplete = self.pluginName + "/" + settingsKey
settingsKeyComplete = "plugins/{}/{}".format(self.pluginName, settingsKey)
# Make sure settings does not exists
QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins)
QgsSettings().remove(settingsKeyComplete)
defaultValue = 42
description = "Variant value functionality test"
@ -161,7 +181,7 @@ class TestQgsSettingsEntry(unittest.TestCase):
self.assertEqual(settingsEntryVariant.valueAsVariant(), defaultValue)
settingsEntryVariant.setValue("abc")
# Verify setValue using QgsSettings
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), "abc")
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue), "abc")
self.assertEqual(settingsEntryVariant.valueAsVariant(), "abc")
# Settings type
@ -169,10 +189,10 @@ class TestQgsSettingsEntry(unittest.TestCase):
def test_settings_entry_string(self):
settingsKey = "settingsEntryString/stringValue"
settingsKeyComplete = self.pluginName + "/" + settingsKey
settingsKeyComplete = "plugins/{}/{}".format(self.pluginName, settingsKey)
# Make sure settings does not exists
QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins)
QgsSettings().remove(settingsKeyComplete)
defaultValue = "abc"
description = "String value functionality test"
@ -183,7 +203,7 @@ class TestQgsSettingsEntry(unittest.TestCase):
self.assertEqual(settingsEntryString.valueAsVariant(), defaultValue)
settingsEntryString.setValue("xyz")
# Verify setValue using QgsSettings
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), "xyz")
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue), "xyz")
self.assertEqual(settingsEntryString.valueAsVariant(), "xyz")
# Settings type
@ -191,10 +211,10 @@ class TestQgsSettingsEntry(unittest.TestCase):
def test_settings_entry_stringlist(self):
settingsKey = "settingsEntryStringList/stringListValue"
settingsKeyComplete = self.pluginName + "/" + settingsKey
settingsKeyComplete = "plugins/{}/{}".format(self.pluginName, settingsKey)
# Make sure settings does not exists
QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins)
QgsSettings().remove(settingsKeyComplete)
defaultValue = ["abc", "def"]
description = "String list value functionality test"
@ -205,7 +225,7 @@ class TestQgsSettingsEntry(unittest.TestCase):
self.assertEqual(settingsEntryStringList.valueAsVariant(), defaultValue)
settingsEntryStringList.setValue(["uvw", "xyz"])
# Verify setValue using QgsSettings
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), ["uvw", "xyz"])
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue), ["uvw", "xyz"])
self.assertEqual(settingsEntryStringList.valueAsVariant(), ["uvw", "xyz"])
# Settings type
@ -213,10 +233,10 @@ class TestQgsSettingsEntry(unittest.TestCase):
def test_settings_entry_bool(self):
settingsKey = "settingsEntryBool/boolValue"
settingsKeyComplete = self.pluginName + "/" + settingsKey
settingsKeyComplete = "plugins/{}/{}".format(self.pluginName, settingsKey)
# Make sure settings does not exists
QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins)
QgsSettings().remove(settingsKeyComplete)
defaultValue = False
description = "Bool value functionality test"
@ -227,7 +247,7 @@ class TestQgsSettingsEntry(unittest.TestCase):
self.assertEqual(settingsEntryBool.valueAsVariant(), defaultValue)
settingsEntryBool.setValue(True)
# Verify setValue using QgsSettings
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), True)
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue), True)
self.assertEqual(settingsEntryBool.valueAsVariant(), True)
# Settings type
@ -235,10 +255,10 @@ class TestQgsSettingsEntry(unittest.TestCase):
def test_settings_entry_integer(self):
settingsKey = "settingsEntryInteger/integerValue"
settingsKeyComplete = self.pluginName + "/" + settingsKey
settingsKeyComplete = "plugins/{}/{}".format(self.pluginName, settingsKey)
# Make sure settings does not exists
QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins)
QgsSettings().remove(settingsKeyComplete)
defaultValue = 42
description = "Integer value functionality test"
@ -249,13 +269,13 @@ class TestQgsSettingsEntry(unittest.TestCase):
self.assertEqual(settingsEntryInteger.valueAsVariant(), defaultValue)
settingsEntryInteger.setValue(43)
# Verify setValue using QgsSettings
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), 43)
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue), 43)
self.assertEqual(settingsEntryInteger.valueAsVariant(), 43)
# Set/Get negative value
settingsEntryInteger.setValue(-42)
# Verify setValue using QgsSettings
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), -42)
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue), -42)
self.assertEqual(settingsEntryInteger.valueAsVariant(), -42)
# Settings type
@ -263,10 +283,10 @@ class TestQgsSettingsEntry(unittest.TestCase):
def test_settings_entry_double(self):
settingsKey = "settingsEntryDouble/doubleValue"
settingsKeyComplete = self.pluginName + "/" + settingsKey
settingsKeyComplete = "plugins/{}/{}".format(self.pluginName, settingsKey)
# Make sure settings does not exists
QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins)
QgsSettings().remove(settingsKeyComplete)
defaultValue = 3.14
description = "Double value functionality test"
@ -277,13 +297,13 @@ class TestQgsSettingsEntry(unittest.TestCase):
self.assertEqual(settingsEntryDouble.valueAsVariant(), defaultValue)
settingsEntryDouble.setValue(1.618)
# Verify setValue using QgsSettings
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), 1.618)
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue), 1.618)
self.assertEqual(settingsEntryDouble.valueAsVariant(), 1.618)
# Set/Get negative value
settingsEntryDouble.setValue(-273.15)
# Verify setValue using QgsSettings
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue, section=QgsSettings.Plugins), -273.15)
self.assertEqual(QgsSettings().value(settingsKeyComplete, defaultValue), -273.15)
self.assertEqual(settingsEntryDouble.valueAsVariant(), -273.15)
# Settings type
@ -291,10 +311,10 @@ class TestQgsSettingsEntry(unittest.TestCase):
def test_settings_entry_enum(self):
settingsKey = "settingsEntryEnum/enumValue"
settingsKeyComplete = self.pluginName + "/" + settingsKey
settingsKeyComplete = "plugins/{}/{}".format(self.pluginName, settingsKey)
# Make sure settings does not exists
QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins)
QgsSettings().remove(settingsKeyComplete)
defaultValue = QgsUnitTypes.LayoutMeters
description = "Enum value functionality test"
@ -306,11 +326,11 @@ class TestQgsSettingsEntry(unittest.TestCase):
# Check set value
success = settingsEntryEnum.setValue(QgsUnitTypes.LayoutFeet)
self.assertEqual(success, True)
qgsSettingsValue = QgsSettings().enumValue(settingsKeyComplete, QgsUnitTypes.LayoutMeters, QgsSettings.Plugins)
qgsSettingsValue = QgsSettings().enumValue(settingsKeyComplete, QgsUnitTypes.LayoutMeters)
self.assertEqual(qgsSettingsValue, QgsUnitTypes.LayoutFeet)
# Check get value
QgsSettings().setEnumValue(settingsKeyComplete, QgsUnitTypes.LayoutPicas, QgsSettings.Plugins)
QgsSettings().setEnumValue(settingsKeyComplete, QgsUnitTypes.LayoutPicas)
self.assertEqual(settingsEntryEnum.value(), QgsUnitTypes.LayoutPicas)
# Check settings type
@ -321,19 +341,19 @@ class TestQgsSettingsEntry(unittest.TestCase):
self.assertEqual(success, False)
# Current value should not have changed
qgsSettingsValue = QgsSettings().enumValue(settingsKeyComplete, QgsUnitTypes.LayoutMeters, QgsSettings.Plugins)
qgsSettingsValue = QgsSettings().enumValue(settingsKeyComplete, QgsUnitTypes.LayoutMeters)
self.assertEqual(qgsSettingsValue, QgsUnitTypes.LayoutPicas)
def test_settings_entry_flag(self):
settingsKey = "settingsEntryFlag/flagValue"
settingsKeyComplete = self.pluginName + "/" + settingsKey
settingsKeyComplete = "plugins/{}/{}".format(self.pluginName, settingsKey)
pointAndLine = QgsMapLayerProxyModel.Filters(QgsMapLayerProxyModel.PointLayer | QgsMapLayerProxyModel.LineLayer)
pointAndPolygon = QgsMapLayerProxyModel.Filters(QgsMapLayerProxyModel.PointLayer | QgsMapLayerProxyModel.PolygonLayer)
hasGeometry = QgsMapLayerProxyModel.Filters(QgsMapLayerProxyModel.HasGeometry)
# Make sure settings does not exists
QgsSettings().remove(settingsKeyComplete, QgsSettings.Plugins)
QgsSettings().remove(settingsKeyComplete)
description = "Flag value functionality test"
settingsEntryFlag = QgsSettingsEntryEnumFlag(settingsKey, self.pluginName, pointAndLine, description)
@ -344,11 +364,11 @@ class TestQgsSettingsEntry(unittest.TestCase):
# Check set value
success = settingsEntryFlag.setValue(hasGeometry)
self.assertEqual(success, True)
qgsSettingsValue = QgsSettings().flagValue(settingsKeyComplete, pointAndLine, QgsSettings.Plugins)
qgsSettingsValue = QgsSettings().flagValue(settingsKeyComplete, pointAndLine)
self.assertEqual(qgsSettingsValue, hasGeometry)
# Check get value
QgsSettings().setValue(settingsKeyComplete, 'PointLayer|PolygonLayer', QgsSettings.Plugins)
QgsSettings().setValue(settingsKeyComplete, 'PointLayer|PolygonLayer')
self.assertEqual(settingsEntryFlag.value(), pointAndPolygon)
# Check settings type