Class: QgsSettingsEntryBase¶
Represents a settings entry and provides methods for reading and writing settings values.
Different subclasses are provided for different settings types with metainformations to validate set values and provide more accurate settings description for the gui.
Added in version 3.20.
Class Hierarchy¶
Subclasses¶
Base abstract class for settings entries with typed get and set methods. |
|
Base abstract class for settings entries with typed get and set methods. |
|
Base abstract class for settings entries with typed get and set methods. |
|
Base abstract class for settings entries with typed get and set methods. |
|
Base abstract class for settings entries with typed get and set methods. |
|
Base abstract class for settings entries with typed get and set methods. |
|
Base abstract class for settings entries with typed get and set methods. |
|
Base abstract class for settings entries with typed get and set methods. |
|
class PyQgsSettingsEntryEnumFlag An enum settings entry. since QGIS 3.20 |
Enums
Types of settings entries |
Methods
Copies the value from a given key if it exists. |
|
Copies the settings to the given key. |
|
Copies the settings to the given key, if it has changed during the current QGIS session (see |
|
Returns settings default value. |
|
Returns settings entry defining key. |
|
Returns the settings entry description. |
|
Returns |
|
Returns the former value of the settings if it has been enabled in the options. |
|
Returns |
|
Returns |
|
Returns settings entry key. |
|
Returns |
|
Returns the name of the settings |
|
Returns the settings options |
|
Returns the origin of the setting if it exists |
|
Returns the parent tree element |
|
Removes the settings from the underlying QSettings. |
|
Returns settings section. |
|
Set settings value. |
|
Returns settings value with:param dynamicKeyPart: specifying the dynamic part of the settings key. |
|
Returns settings value with a defaultValueOverride |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsSettingsEntryBase. See the FAQ for more details.
Returns |
|
Returns the settings entry type. |
|
Returns the id of the type of settings This can be re-implemented in a custom implementation of a setting |
Static Methods
Transforms a dynamic key part string to list |
- class qgis.core.QgsSettingsEntryBase[source]¶
Bases:
object
- __init__(key: str | None, section: str | None, defaultValue: Any = None, description: str | None = '', options: Qgis.SettingsOptions | Qgis.SettingsOption = Qgis.SettingsOptions())
Constructor for QgsSettingsEntryBase.
- Parameters:
key (Optional[str]) – specifies the key of the settings.
section (Optional[str]) – specifies the section.
defaultValue (Any = None) – specifies the default value for the settings entry.
description (Optional[str] = '') – specifies a description for the settings entry.
options (Union[Qgis.SettingsOptions, Qgis.SettingsOption] = Qgis.SettingsOptions()) – specifies the options for the settings entry.
- __init__(name: str | None, parent: QgsSettingsTreeNode | None, defaultValue: Any = None, description: str | None = '', options: Qgis.SettingsOptions | Qgis.SettingsOption = Qgis.SettingsOptions())
Constructor for QgsSettingsEntryBase.
- Parameters:
name (Optional[str]) – specifies the name of the setting.
parent (Optional[QgsSettingsTreeNode]) – specifies the parent in the tree of settings.
defaultValue (Any = None) – specifies the default value for the settings entry.
description (Optional[str] = '') – specifies a description for the settings entry.
options (Union[Qgis.SettingsOptions, Qgis.SettingsOption] = Qgis.SettingsOptions()) – specifies the options for the settings entry.
- Raises:
QgsSettingsException – if the number of given parent named items doesn’t match the complete key definition
Added in version 3.30.
- __init__(a0: QgsSettingsEntryBase)
- Parameters:
a0 (QgsSettingsEntryBase)
- class SettingsType(*values)¶
Bases:
IntEnum
Types of settings entries
Added in version 3.26.
Custom
: Custom implementationVariant
: Generic variantString
: StringStringList
: List of stringsVariantMap
: Map of stringsBool
: BooleanInteger
: IntegerDouble
: Double precision numberEnumFlag
: Enum or FlagColor
: Color
- virtual checkValueVariant(self, value: Any) bool [source]¶
Returns
True
if the givenvalue
is valid towards the setting definition- Parameters:
value (Any)
- Return type:
bool
- copyValueFromKey(self, key: str | None, removeSettingAtKey: bool = False) bool [source]¶
Copies the value from a given key if it exists.
- Parameters:
key (Optional[str]) – the key to copy the setting value from.
removeSettingAtKey (bool = False) – if
True
, the setting at the old key will be removed.
- Return type:
bool
- Returns:
True
if the key exists and the setting value could be copied.
Added in version 3.30.
- copyValueFromKey(self, key: str | None, dynamicKeyPartList: Iterable[str | None], removeSettingAtKey: bool = False) bool [source]
Copies the value from a given key if it exists.
- Parameters:
key (Optional[str]) – the key to copy the setting value from.
dynamicKeyPartList (Iterable[Optional[str]]) – is the optional dynamic key part to determine the key. It must be the same for origin and destination keys.
removeSettingAtKey (bool = False) – if
True
, the setting at the old key will be removed.
- Return type:
bool
- Returns:
True
if the key exists and the setting value could be copied.
Added in version 3.30.
- copyValueToKey(self, key: str | None, dynamicKeyPartList: Iterable[str | None] = [])[source]¶
Copies the settings to the given key.
- Parameters:
key (Optional[str]) – the key to copy the setting value to.
dynamicKeyPartList (Iterable[Optional[str]] = []) – is the optional dynamic key part to determine the key. It must be the same for origin and destination keys.
Added in version 3.30.
- copyValueToKeyIfChanged(self, key: str | None, dynamicKeyPartList: Iterable[str | None] = [])[source]¶
Copies the settings to the given key, if it has changed during the current QGIS session (see
hasChanged()
).- Parameters:
key (Optional[str]) – the key to copy the setting value to.
dynamicKeyPartList (Iterable[Optional[str]] = []) – is the optional dynamic key part to determine the key. It must be the same for origin and destination keys.
Added in version 3.36.
- definitionKey(self) str [source]¶
Returns settings entry defining key. For dynamic settings it return the key with the placeholder for dynamic part included. For non-dynamic settings returns the same as
key()
.- Return type:
str
- static dynamicKeyPartToList(dynamicKeyPart: str | None) List[str] [source]¶
Transforms a dynamic key part string to list
Added in version 3.26.
- Parameters:
dynamicKeyPart (Optional[str])
- Return type:
List[str]
- exists(self, dynamicKeyPart: str | None = '') bool [source]¶
Returns
True
if the settings is contained in the underlying QSettings.- Parameters:
dynamicKeyPart (Optional[str] = '') – specifies the dynamic part of the settings key.
- Return type:
bool
- exists(self, dynamicKeyPartList: Iterable[str | None]) bool [source]
Returns
True
if the settings is contained in the underlying QSettings.- Parameters:
dynamicKeyPartList (Iterable[Optional[str]]) – specifies the list of dynamic parts of the settings key.
- Return type:
bool
- formerValueAsVariant(self, dynamicKeyPart: str | None) Any [source]¶
Returns the former value of the settings if it has been enabled in the options. Returns the current value (or default) if there is no former value.
Added in version 3.26.
- Parameters:
dynamicKeyPart (Optional[str])
- Return type:
Any
- formerValueAsVariant(self, dynamicKeyPartList: Iterable[str | None]) Any [source]
Returns the former value of the settings if it has been enabled in the options Returns the current value (or default) if there is no former value.
Added in version 3.26.
- Parameters:
dynamicKeyPartList (Iterable[Optional[str]])
- Return type:
Any
- hasChanged(self) bool [source]¶
Returns
True
if the setting was changed during the current QGIS session.Added in version 3.36.
- Return type:
bool
- hasDynamicKey(self) bool [source]¶
Returns
True
if a part of the settings key is built dynamically.- Return type:
bool
- key(self, dynamicKeyPart: str | None = '') str [source]¶
Returns settings entry key.
- Parameters:
dynamicKeyPart (Optional[str] = '') – specifies the dynamic part of the settings key.
- Return type:
str
- key(self, dynamicKeyPartList: Iterable[str | None]) str [source]
Returns settings entry key.
- Parameters:
dynamicKeyPartList (Iterable[Optional[str]]) – specifies the list of dynamic parts of the settings key.
- Return type:
str
- keyIsValid(self, key: str | None) bool [source]¶
Returns
True
if the provided key match the settings entry.This is useful for settings with dynamic keys. For example this permits one to check that the settings key “NewsFeed/httpsfeedqgisorg/27/content” is valid for the settings entry defined with the key “NewsFeed/%1/%2/content”
- Parameters:
key (Optional[str]) – to check
- Return type:
bool
- options(self) Qgis.SettingsOptions [source]¶
Returns the settings options
Added in version 3.26.
- Return type:
- origin(self, dynamicKeyPartList: Iterable[str | None]) Qgis.SettingsOrigin [source]¶
Returns the origin of the setting if it exists
Note
it will return
Qgis
.SettingsOrigin.Any if the key doesn’t existAdded in version 3.30.
- Parameters:
dynamicKeyPartList (Iterable[Optional[str]])
- Return type:
- parent(self) QgsSettingsTreeNode | None [source]¶
Returns the parent tree element
Added in version 3.30.
- Return type:
Optional[QgsSettingsTreeNode]
- remove(self, dynamicKeyPart: str | None = '')[source]¶
Removes the settings from the underlying QSettings.
- Parameters:
dynamicKeyPart (Optional[str] = '') – specifies the dynamic part of the settings key.
- remove(self, dynamicKeyPartList: Iterable[str | None])[source]
Removes the settings from the underlying QSettings.
- Parameters:
dynamicKeyPartList (Iterable[Optional[str]]) – specifies the list of dynamic parts of the settings key.
- section(self) int [source]¶
Returns settings section. The settings section of the parent group is returned if available.
Deprecated since version 3.26: The key is entirely self-defined.
- Return type:
int
- setVariantValue(self, value: Any, dynamicKeyPart: str | None = '') bool [source]¶
Set settings value.
- Parameters:
value (Any) – specifies the value to set.
dynamicKeyPart (Optional[str] = '') – specifies the dynamic part of the settings key.
- Return type:
bool
- setVariantValue(self, value: Any, dynamicKeyPartList: Iterable[str | None]) bool [source]
Set settings value. This should be called from any implementation as it takes care of actually calling QSettings
- Parameters:
value (Any) – specifies the value to set.
dynamicKeyPartList (Iterable[Optional[str]]) – specifies the list of dynamic parts of the settings key.
- Return type:
bool
- virtual settingsType(self) Qgis.SettingsType [source]¶
Returns the settings entry type.
- Return type:
- virtual typeId(self) str [source]¶
Returns the id of the type of settings This can be re-implemented in a custom implementation of a setting
Added in version 3.32.
- Return type:
str
- valueAsVariant(self, dynamicKeyPart: str | None = '') Any [source]¶
Returns settings value with:param dynamicKeyPart: specifying the dynamic part of the settings key.
- Parameters:
dynamicKeyPart (Optional[str] = '')
- Return type:
Any
- valueAsVariant(self, dynamicKeyPartList: Iterable[str | None]) Any [source]
Returns settings value with:param dynamicKeyPartList: specifying the dynamic part of the settings key.
- Parameters:
dynamicKeyPartList (Iterable[Optional[str]])
- Return type:
Any
- valueAsVariant(self, dynamicKeyPart: str | None, useDefaultValueOverride: bool, defaultValueOverride: Any) Any [source]
Returns settings value with an optional default value override
Deprecated since version 3.26: Use
valueAsVariantWithDefaultOverride()
instead.- Parameters:
dynamicKeyPart (Optional[str])
useDefaultValueOverride (bool)
defaultValueOverride (Any)
- Return type:
Any
- valueAsVariant(self, dynamicKeyPartList: Iterable[str | None], useDefaultValueOverride: bool, defaultValueOverride: Any) Any [source]
Returns settings value with an optional default value override
Deprecated since version 3.26: Use
valueAsVariantWithDefaultOverride()
instead.- Parameters:
dynamicKeyPartList (Iterable[Optional[str]])
useDefaultValueOverride (bool)
defaultValueOverride (Any)
- Return type:
Any
- valueAsVariantWithDefaultOverride(self, defaultValueOverride: Any, dynamicKeyPart: str | None = '') Any [source]¶
Returns settings value with a
defaultValueOverride
Added in version 3.26.
- Parameters:
defaultValueOverride (Any)
dynamicKeyPart (Optional[str] = '')
- Return type:
Any
- valueAsVariantWithDefaultOverride(self, defaultValueOverride: Any, dynamicKeyPartList: Iterable[str | None]) Any [source]
Returns settings value.
- Parameters:
dynamicKeyPartList (Iterable[Optional[str]]) – specifies the list of dynamic parts of the settings key.
defaultValueOverride (Any) – if valid is used instead of the normal default value.
Added in version 3.26.
- Return type:
Any