Skip to content
Permalink
Browse files
Added functionality to override default value for settings entries
  • Loading branch information
domi4484 committed Apr 14, 2021
1 parent 9082cfa commit abb8e80c1f006933eb05969c9fa88be69144c34e
@@ -55,20 +55,26 @@ def __init__(self, key, pluginName, defaultValue, description=str()):

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

def value(self, dynamicKeyPart=str()):
def value(self, dynamicKeyPart=None, useDefaultValueOverride=False, defaultValueOverride=None):
""" Get settings value.
:param self: the _PyQgsSettingsEntryEnumFlag object
: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.settingsType() is self.Enum:
return QgsSettings().enumValue(self.key(dynamicKeyPart),
self.defaultValue(),
defaultValue,
self.section())
else:
return QgsSettings().flagValue(self.key(dynamicKeyPart),
self.defaultValue(),
defaultValue,
self.section())

def defaultValue(self):
@@ -94,7 +100,7 @@ def defaultValue(self):
defaultValue = self.__enumFlagClass(defaultValue)
return defaultValue

def setValue(self, value, dynamicKeyPart=str()):
def setValue(self, value, dynamicKeyPart=None):
""" Set settings value.
:param self: the _PyQgsSettingsEntryEnumFlag object
@@ -138,18 +138,22 @@ 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;
QVariant valueAsVariant( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, const QVariant &defaultValueOverride = QVariant() ) const;
%Docstring
Get settings value.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used.
The ``defaultValueOverride`` argument if valid is used instead of the normal default value.
%End

QVariant valueAsVariant( const QStringList &dynamicKeyPartList ) const;
QVariant valueAsVariant( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, const QVariant &defaultValueOverride = QVariant() ) const;
%Docstring
Get settings value.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used.
The ``defaultValueOverride`` argument if valid is used instead of the normal default value.
%End

QVariant defaultValueAsVariant() const;
@@ -214,18 +218,22 @@ The ``value`` to set.
The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

QVariant value( const QString &dynamicKeyPart = QString() ) const;
QVariant value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, const QVariant &defaultValueOverride = QVariant() ) const;
%Docstring
Get settings value.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used.
The ``defaultValueOverride`` argument if valid is used instead of the normal default value.
%End

QVariant value( const QStringList &dynamicKeyPartList ) const;
QVariant value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, const QVariant &defaultValueOverride = QVariant() ) const;
%Docstring
Get settings value.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used.
The ``defaultValueOverride`` argument if valid is used instead of the normal default value.
%End

QVariant defaultValue() const;
@@ -284,18 +292,22 @@ The ``value`` to set.
The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

QString value( const QString &dynamicKeyPart = QString() ) const;
QString value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, const QString &defaultValueOverride = QString() ) const;
%Docstring
Get settings value.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used.
The ``defaultValueOverride`` argument if valid is used instead of the normal default value.
%End

QString value( const QStringList &dynamicKeyPartList ) const;
QString value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, const QString &defaultValueOverride = QString() ) const;
%Docstring
Get settings value.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used.
The ``defaultValueOverride`` argument if valid is used instead of the normal default value.
%End

QString defaultValue() const;
@@ -379,18 +391,22 @@ The ``value`` to set.
The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

QStringList value( const QString &dynamicKeyPart = QString() ) const;
QStringList value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, const QStringList &defaultValueOverride = QStringList() ) const;
%Docstring
Get settings value.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used.
The ``defaultValueOverride`` argument if valid is used instead of the normal default value.
%End

QStringList value( const QStringList &dynamicKeyPartList ) const;
QStringList value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, const QStringList &defaultValueOverride = QStringList() ) const;
%Docstring
Get settings value.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used.
The ``defaultValueOverride`` argument if valid is used instead of the normal default value.
%End

QStringList defaultValue() const;
@@ -450,18 +466,22 @@ The ``value`` to set.
The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

bool value( const QString &dynamicKeyPart = QString() ) const;
bool value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, bool defaultValueOverride = false ) const;
%Docstring
Get settings value.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used.
The ``defaultValueOverride`` argument if valid is used instead of the normal default value.
%End

bool value( const QStringList &dynamicKeyPartList ) const;
bool value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, bool defaultValueOverride = false ) const;
%Docstring
Get settings value.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used.
The ``defaultValueOverride`` argument if valid is used instead of the normal default value.
%End

bool defaultValue() const;
@@ -521,18 +541,22 @@ The ``value`` to set.
The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

qlonglong value( const QString &dynamicKeyPart = QString() ) const;
qlonglong value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, qlonglong defaultValueOverride = 0 ) const;
%Docstring
Get settings value.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used.
The ``defaultValueOverride`` argument if valid is used instead of the normal default value.
%End

qlonglong value( const QStringList &dynamicKeyPartList ) const;
qlonglong value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, qlonglong defaultValueOverride = 0 ) const;
%Docstring
Get settings value.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used.
The ``defaultValueOverride`` argument if valid is used instead of the normal default value.
%End

qlonglong defaultValue() const;
@@ -616,18 +640,22 @@ The ``value`` to set.
The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

double value( const QString &dynamicKeyPart = QString() ) const;
double value( const QString &dynamicKeyPart = QString(), bool useDefaultValueOverride = false, double defaultValueOverride = 0.0 ) const;
%Docstring
Get settings value.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used.
The ``defaultValueOverride`` argument if valid is used instead of the normal default value.
%End

double value( const QStringList &dynamicKeyPartList ) const;
double value( const QStringList &dynamicKeyPartList, bool useDefaultValueOverride = false, double defaultValueOverride = 0.0 ) const;
%Docstring
Get settings value.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
The ``useDefaultValueOverride`` argument specifies if defaultValueOverride should be used.
The ``defaultValueOverride`` argument if valid is used instead of the normal default value.
%End

double defaultValue() const;
@@ -95,12 +95,8 @@ void QgsLocator::registerFilter( QgsLocatorFilter *filter )

// restore settings
bool enabled = QgsLocator::settingsLocatorFilterEnabled.value( filter->name() );
bool byDefault = filter->useWithoutPrefix();
if ( QgsLocator::settingsLocatorFilterDefault.exists( filter->name() ) )
byDefault = QgsLocator::settingsLocatorFilterDefault.value( filter->name() );
QString prefix = filter->prefix();
if ( QgsLocator::settingsLocatorFilterPrefix.exists( filter->name() ) )
prefix = QgsLocator::settingsLocatorFilterPrefix.value( filter->name() );
bool byDefault = QgsLocator::settingsLocatorFilterDefault.value( filter->name(), true, filter->useWithoutPrefix() );
QString prefix = QgsLocator::settingsLocatorFilterPrefix.value( filter->name(), true, filter->prefix() );
if ( prefix.isEmpty() )
{
prefix = filter->prefix();

0 comments on commit abb8e80

Please sign in to comment.