Skip to content
Permalink
Browse files

Added support for settings with keys with multiple dynamic parts

  • Loading branch information
domi4484 committed Apr 14, 2021
1 parent 9762206 commit 4891bd6ebb65cc18e19f39a03e7b20bc6621aea0
@@ -30,15 +30,16 @@ class _PyQgsSettingsEntryEnumFlag(QgsSettingsEntryBase):
"""

def __init__(self, key, pluginName, defaultValue, description=str()):
""" Constructor for QgsSettingsEntryEnum.
""" Constructor for _PyQgsSettingsEntryEnumFlag.
:param self: the QgsSettingsEntryEnum object
:param key: argument specifies the final part of the settings key.
:param pluginName: argument is inserted in the key after the section.
:param defaultValue: argument specifies the default value for the settings entry.
:param description: argument specifies a description for the settings entry.
.. note:: The enum needs to be declared with Q_ENUM.
.. note:: This constructor should not be used. Use PyQgsSettingsEntryEnum
or PyQgsSettingsEntryFlag instead.
"""

defaultValueStr = str()
@@ -57,18 +58,23 @@ def __init__(self, key, pluginName, defaultValue, description=str()):
def value(self, dynamicKeyPart=str()):
""" Get settings value.
:param self: the QgsSettingsEntryEnum object
:param self: the _PyQgsSettingsEntryEnumFlag object
:param dynamicKeyPart: argument specifies the dynamic part of the settings key.
"""

return QgsSettings().enumValue(self.key(dynamicKeyPart),
self.defaultValue(),
self.section())
if self.settingsType() is self.Enum:
return QgsSettings().enumValue(self.key(dynamicKeyPart),
self.defaultValue(),
self.section())
else:
return QgsSettings().flagValue(self.key(dynamicKeyPart),
self.defaultValue(),
self.section())

def defaultValue(self):
""" Get settings default value.
:param self: the QgsSettingsEntryEnum object
:param self: the _PyQgsSettingsEntryEnumFlag object
"""

if self.__metaEnum is None or not self.__metaEnum.isValid():
@@ -91,7 +97,7 @@ def defaultValue(self):
def setValue(self, value, dynamicKeyPart=str()):
""" Set settings value.
:param self: the QgsSettingsEntryEnum object
:param self: the _PyQgsSettingsEntryEnumFlag object
:param dynamicKeyPart: argument specifies the dynamic part of the settings key.
"""

@@ -132,17 +138,6 @@ def __init__(self, key, pluginName, defaultValue, description=str()):

super().__init__(key, pluginName, defaultValue, description)

def value(self, dynamicKeyPart=str()):
""" Get settings value.
:param self: the QgsSettingsEntryEnum object
:param dynamicKeyPart: argument specifies the dynamic part of the settings key.
"""

return QgsSettings().enumValue(self.key(dynamicKeyPart),
self.defaultValue(),
self.section())

def settingsType(self):
""" Get the settings entry type.
@@ -173,17 +168,6 @@ def __init__(self, key, pluginName, defaultValue, description=str()):

super().__init__(key, pluginName, defaultValue, description)

def value(self, dynamicKeyPart=str()):
""" Get settings value.
:param self: the QgsSettingsEntryFlag object
:param dynamicKeyPart: argument specifies the dynamic part of the settings key.
"""

return QgsSettings().flagValue(self.key(dynamicKeyPart),
self.defaultValue(),
self.section())

def settingsType(self):
""" Get the settings entry type.
@@ -75,6 +75,13 @@ The ``description`` argument specifies a description for the settings entry.
Get settings entry key.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

QString key( const QStringList &dynamicKeyPartList ) const;
%Docstring
Get settings entry key.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

bool hasDynamicKey() const;
@@ -87,13 +94,27 @@ Returns true if a part of the settings key is built dynamically.
Returns true if the settings is contained in the underlying QSettings.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

bool exists( const QStringList &dynamicKeyPartList ) const;
%Docstring
Returns true if the settings is contained in the underlying QSettings.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

void remove( const QString &dynamicKeyPart = QString() ) const;
%Docstring
Removes the settings from the underlying QSettings.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

void remove( const QStringList &dynamicKeyPartList ) const;
%Docstring
Removes the settings from the underlying QSettings.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

QgsSettings::Section section() const;
@@ -107,13 +128,28 @@ Set settings value.

The ``value`` to set.
The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

virtual bool setVariantValue( const QVariant &value, const QStringList &dynamicKeyPartList ) const;
%Docstring
Set settings value.

The ``value`` to set.
The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

QVariant valueAsVariant( const QString &dynamicKeyPart = QString() ) const;
%Docstring
Get settings value.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

QVariant valueAsVariant( const QStringList &dynamicKeyPartList ) const;
%Docstring
Get settings value.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

QVariant defaultValueAsVariant() const;
@@ -162,20 +198,34 @@ The ``default`` value argument specifies the default value for the settings entr
The ``description`` argument specifies a description for the settings entry.
%End


bool setValue( const QVariant &value, const QString &dynamicKeyPart = QString() ) const;
%Docstring
Set settings value.

The ``value`` to set.
The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

bool setValue( const QVariant &value, const QStringList &dynamicKeyPartList ) const;
%Docstring
Set settings value.

The ``value`` to set.
The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

QVariant value( const QString &dynamicKeyPart = QString() ) const;
%Docstring
Get settings value.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

QVariant value( const QStringList &dynamicKeyPartList ) const;
%Docstring
Get settings value.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

QVariant defaultValue() const;
@@ -224,13 +274,28 @@ Set settings value.

The ``value`` to set.
The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

bool setValue( const QString &value, const QStringList &dynamicKeyPartList ) const;
%Docstring
Set settings value.

The ``value`` to set.
The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

QString value( const QString &dynamicKeyPart = QString() ) const;
%Docstring
Get settings value.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

QString value( const QStringList &dynamicKeyPartList ) const;
%Docstring
Get settings value.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

QString defaultValue() const;
@@ -304,13 +369,28 @@ Set settings value.

The ``value`` to set.
The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

bool setValue( const QStringList &value, const QStringList &dynamicKeyPartList ) const;
%Docstring
Set settings value.

The ``value`` to set.
The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

QStringList value( const QString &dynamicKeyPart = QString() ) const;
%Docstring
Get settings value.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

QStringList value( const QStringList &dynamicKeyPartList ) const;
%Docstring
Get settings value.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

QStringList defaultValue() const;
@@ -360,13 +440,28 @@ Set settings value.

The ``value`` to set.
The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

bool setValue( bool value, const QStringList &dynamicKeyPartList ) const;
%Docstring
Set settings value.

The ``value`` to set.
The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

bool value( const QString &dynamicKeyPart = QString() ) const;
%Docstring
Get settings value.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

bool value( const QStringList &dynamicKeyPartList ) const;
%Docstring
Get settings value.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

bool defaultValue() const;
@@ -416,13 +511,28 @@ Set settings value.

The ``value`` to set.
The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

bool setValue( qlonglong value, const QStringList &dynamicKeyPartList ) const;
%Docstring
Set settings value.

The ``value`` to set.
The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

qlonglong value( const QString &dynamicKeyPart = QString() ) const;
%Docstring
Get settings value.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

qlonglong value( const QStringList &dynamicKeyPartList ) const;
%Docstring
Get settings value.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

qlonglong defaultValue() const;
@@ -496,13 +606,28 @@ Set settings value.

The ``value`` to set.
The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

bool setValue( double value, const QStringList &dynamicKeyPartList ) const;
%Docstring
Set settings value.

The ``value`` to set.
The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

double value( const QString &dynamicKeyPart = QString() ) const;
%Docstring
Get settings value.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

double value( const QStringList &dynamicKeyPartList ) const;
%Docstring
Get settings value.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

double defaultValue() const;
@@ -154,11 +154,11 @@ class CORE_EXPORT QgsLocator : public QObject
QStringList completionList() const {return mAutocompletionList;}

//! Settings entry locator filter enabled
static const inline QgsSettingsEntryBool settingsLocatorFilterEnabled = QgsSettingsEntryBool( QStringLiteral( "locator_filters/enabled_%" ), QgsSettings::Gui, true, "Locator filter enabled" );
static const inline QgsSettingsEntryBool settingsLocatorFilterEnabled = QgsSettingsEntryBool( QStringLiteral( "locator_filters/enabled_%1" ), QgsSettings::Gui, true, "Locator filter enabled" );
//! Settings entry locator filter default value
static const inline QgsSettingsEntryBool settingsLocatorFilterDefault = QgsSettingsEntryBool( QStringLiteral( "locator_filters/default_%" ), QgsSettings::Gui, false, "Locator filter default value" );
static const inline QgsSettingsEntryBool settingsLocatorFilterDefault = QgsSettingsEntryBool( QStringLiteral( "locator_filters/default_%1" ), QgsSettings::Gui, false, "Locator filter default value" );
//! Settings entry locator filter prefix
static const inline QgsSettingsEntryString settingsLocatorFilterPrefix = QgsSettingsEntryString( QStringLiteral( "locator_filters/prefix_%" ), QgsSettings::Gui, QString(), "Locator filter prefix" );
static const inline QgsSettingsEntryString settingsLocatorFilterPrefix = QgsSettingsEntryString( QStringLiteral( "locator_filters/prefix_%1" ), QgsSettings::Gui, QString(), "Locator filter prefix" );

signals:

0 comments on commit 4891bd6

Please sign in to comment.