The SettingsScope class acts as a container for scoped settings.
More...
#include <settings_scope.h>
|
| void | valueChanged (const QString &key, const QVariant &value) |
| | Emitted when a setting value changed or the setting is removed. If removed, value is an invalid variant. More...
|
| |
| void | scopeChanged () |
| | Emitted when this settings scope changes, i.e. a setting is added or removed to this scope or a setting from this scope changed or a property of this scope (e.g. the name) changed. More...
|
| |
| void | parentScopeChanged (SettingsScope *old) |
| | Emitted when the parent of the scope changed. More...
|
| |
|
| | SettingsScope (const QString &name, SettingsScope *parent=0) |
| | Constructs a new SettingsScope named name with parent setting scope parent. More...
|
| |
|
virtual | ~SettingsScope () |
| | Destroys the SettingsScope.
|
| |
| QVariant | value (const QString &key, QVariant defaultValue=QVariant(), bool searchAll=true) const |
| | Returns the variant value of the setting identified by key. More...
|
| |
| void | setValue (const QString &key, const QVariant &value) |
| | Sets the setting identified by key to value. More...
|
| |
| const QString & | name () const |
| | Returns the name associated with this settings scope. More...
|
| |
| void | setName (const QString &name) |
| | Sets the name associated with this settings scope to name. More...
|
| |
| QString | scopeId () const |
| | Returns a string identifier for this settings scope. More...
|
| |
| SettingsScope * | parentScope () const |
| | Returns the parent setting scope or NULL, if this settings scope has no parent settings scope. More...
|
| |
| void | setParentScope (SettingsScope *newParent) |
| | Attaches newParent as parent scope. More...
|
| |
| QHash< QString, QVariant > | allSettings (bool recurse=false) |
| | Returns a map with all settings. More...
|
| |
| bool | load (const QDomElement &parent) |
| | Loads persisted settings scope from given DOM element parent. More...
|
| |
| bool | save (QDomDocument &doc, QDomElement &parent) |
| | Persists this settings scope to given DOM element parent. More...
|
| |
|
| QString | name |
| | The name associated with this settings scope. More...
|
| |
The SettingsScope class acts as a container for scoped settings.
The SettingsScope class stores key/value pairs which can be set using setValue() and retrieved with value(). The key/value pairs can be persisted and restored using save() and load().
Creation, update and deletion of a setting is signaled with valueChanged() signal.
A SettingsScope is identified by its name() and can have a parent SettingsScope. If a setting value is requested and cannot be found in this SettingScope, the parent is consulted.
◆ SettingsScope()
| SettingsScope::SettingsScope |
( |
const QString & |
name, |
|
|
SettingsScope * |
parent = 0 |
|
) |
| |
|
explicit |
Constructs a new SettingsScope named name with parent setting scope parent.
- Parameters
-
| name | The name to be associated with the settings scope. |
| parent | An optional settings scope parent. |
◆ allSettings()
| QHash< QString, QVariant > SettingsScope::allSettings |
( |
bool |
recurse = false | ) |
|
Returns a map with all settings.
If recurse is false, only settings from this scope will be included.
If recurse is true, the settings from all parents up the chain will be merged to the output so that parent settings will never override settings from lower levels.
- Parameters
-
| recurse | If false, only settings from this scope will be returned. If false, settings from all parents up the chain will be returned. |
- Returns
- A map with all settings.
◆ applicationScope()
Returns the top level application scope.
- Returns
- The top level application scope.
◆ deinit()
| void SettingsScope::deinit |
( |
| ) |
|
|
static |
◆ globalScope()
Returns the global scope.
The global scope is a single scope without a parent or being parent. It acts as a global settings store for settings that do not need a hierarchical configuration.
- Returns
- The global scope.
◆ init()
| void SettingsScope::init |
( |
| ) |
|
|
static |
◆ load()
| bool SettingsScope::load |
( |
const QDomElement & |
parent | ) |
|
Loads persisted settings scope from given DOM element parent.
Returns true on success, false otherwise.
- Parameters
-
| parent | The DOM element to read the the persisted settings scope from. |
- Returns
true on success, false otherwise.
◆ name()
| const QString& SettingsScope::name |
( |
| ) |
const |
Returns the name associated with this settings scope.
- Returns
- The name associated with this settings scope.
◆ parentScope()
Returns the parent setting scope or NULL, if this settings scope has no parent settings scope.
- Returns
- The parent setting scope or
NULL, if this settings scope has no parent settings scope.
◆ parentScopeChanged
Emitted when the parent of the scope changed.
- Parameters
-
◆ save()
| bool SettingsScope::save |
( |
QDomDocument & |
doc, |
|
|
QDomElement & |
parent |
|
) |
| |
Persists this settings scope to given DOM element parent.
- Parameters
-
◆ scopeChanged
| void SettingsScope::scopeChanged |
( |
| ) |
|
|
signal |
Emitted when this settings scope changes, i.e. a setting is added or removed to this scope or a setting from this scope changed or a property of this scope (e.g. the name) changed.
Note that changes to other settings scopes in the parent chain will not emit this signal for this scope, scopeChanged() will be emitted for the related scope where the change was done.
◆ scopeId()
| QString SettingsScope::scopeId |
( |
| ) |
const |
Returns a string identifier for this settings scope.
The identifier is build using the parent scope path to the top level scope. It lists all scope names starting from top level scope to this settings scope, delimited by ':'.
- Returns
- A string identifier for this settings scope.
◆ setName()
| void SettingsScope::setName |
( |
const QString & |
name | ) |
|
Sets the name associated with this settings scope to name.
The name should be unique across the whole settings scope hierarchy!
- Parameters
-
◆ setParentScope()
Attaches newParent as parent scope.
- Parameters
-
| newParent | the new parent scope. |
◆ setValue()
| void SettingsScope::setValue |
( |
const QString & |
key, |
|
|
const QVariant & |
value |
|
) |
| |
Sets the setting identified by key to value.
If value is invalid and the setting is defined in this settings scope, it will be removed from this settings scope.
Signal valueChanged() and scopeChanged() is emitted. The valueChanged() signal will also be dispatched to every child scope down the chain until a child has no setting for the same key.
- Parameters
-
| key | The setting key. |
| value | The setting's value. If invalid, the setting is removed from this settings scope. |
◆ value()
| QVariant SettingsScope::value |
( |
const QString & |
key, |
|
|
QVariant |
defaultValue = QVariant(), |
|
|
bool |
searchAll = true |
|
) |
| const |
Returns the variant value of the setting identified by key.
If key cannot be found in this scope and searchAll is true, all parent scopes up the parent chain are consulted until a defined value was found.
If searchAll is false, only scope is consulted.
If no defined value can be found in either way, the function returns defaultValue. If no explicit default value is specified, an invalid variant is returned.
- Parameters
-
| key | The setting key. |
| defaultValue | Default value to be returned, if no defined value could be found. |
| searchAll | If true, all parent scopes up the parent chain are consulted until a defined value was found. If false, only scope is consulted. |
- Returns
- The variant value of the setting identified by key or defaultValue, if the setting could not be found.
◆ valueChanged
| void SettingsScope::valueChanged |
( |
const QString & |
key, |
|
|
const QVariant & |
value |
|
) |
| |
|
signal |
Emitted when a setting value changed or the setting is removed. If removed, value is an invalid variant.
Note that this signal is also emitted when a parent settings scope has changed a setting value but this settings scope has no related setting. This is because a setting can be specified in a higher level scope and will be reflected to the lower level scopes, if the lower scopes have no definition for the same setting.
- Parameters
-
| key | The related setting key. |
| value | The new setting value. |
◆ name
| const QString & SettingsScope::name |
|
readwrite |
The name associated with this settings scope.
The settings scope name should be unique across the whole hierarchy! Not checked at the moment!
The documentation for this class was generated from the following files:
- itemframework/itemframework/include/helper/settings_scope.h
- itemframework/itemframework/moc/moc_settings_scope.cpp
- itemframework/itemframework/src/helper/settings_scope.cpp