roviz  0.7
Code Documentation of roviz
Signals | Public Member Functions | Static Public Member Functions | Properties | List of all members
SettingsScope Class Reference

The SettingsScope class acts as a container for scoped settings. More...

#include <settings_scope.h>

Inheritance diagram for SettingsScope:
Inheritance graph
Collaboration diagram for SettingsScope:
Collaboration graph

Signals

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...
 

Public Member Functions

 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...
 
SettingsScopeparentScope () 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...
 

Static Public Member Functions

static SettingsScopeapplicationScope ()
 Returns the top level application scope. More...
 
static SettingsScopeglobalScope ()
 Returns the global scope. More...
 
static void init ()
 This function has to be called once at start in order to initialize global and application settings scope. More...
 
static void deinit ()
 This function has to be called once at application end in order to save the global and application settings. More...
 

Properties

QString name
 The name associated with this settings scope. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SettingsScope()

SettingsScope::SettingsScope ( const QString &  name,
SettingsScope parent = 0 
)
explicit

Constructs a new SettingsScope named name with parent setting scope parent.

Parameters
nameThe name to be associated with the settings scope.
parentAn optional settings scope parent.
Here is the call graph for this function:

Member Function Documentation

◆ 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
recurseIf 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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ applicationScope()

SettingsScope * SettingsScope::applicationScope ( )
static

Returns the top level application scope.

Returns
The top level application scope.
Here is the caller graph for this function:

◆ deinit()

void SettingsScope::deinit ( )
static

This function has to be called once at application end in order to save the global and application settings.

Usually you would call StartupHelper::addComponent<SettingsScope>(); somewhere in your application initialization phase.

See also
StartupHelper
Here is the call graph for this function:

◆ globalScope()

SettingsScope * SettingsScope::globalScope ( )
static

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

This function has to be called once at start in order to initialize global and application settings scope.

Usually you would call StartupHelper::addComponent<SettingsScope>(); somewhere in your application initialization phase.

See also
StartupHelper
Here is the call graph for this function:

◆ load()

bool SettingsScope::load ( const QDomElement &  parent)

Loads persisted settings scope from given DOM element parent.

Returns true on success, false otherwise.

Parameters
parentThe DOM element to read the the persisted settings scope from.
Returns
true on success, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ name()

const QString& SettingsScope::name ( ) const

Returns the name associated with this settings scope.

Returns
The name associated with this settings scope.
Here is the caller graph for this function:

◆ parentScope()

SettingsScope* SettingsScope::parentScope ( ) const
inline

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.
Here is the caller graph for this function:

◆ parentScopeChanged

void SettingsScope::parentScopeChanged ( SettingsScope old)
signal

Emitted when the parent of the scope changed.

Parameters
oldThe previous parent
Here is the caller graph for this function:

◆ save()

bool SettingsScope::save ( QDomDocument &  doc,
QDomElement &  parent 
)

Persists this settings scope to given DOM element parent.

Parameters
doc
parent
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ 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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
nameThe new name.
Here is the call graph for this function:

◆ setParentScope()

void SettingsScope::setParentScope ( SettingsScope newParent)

Attaches newParent as parent scope.

Parameters
newParentthe new parent scope.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
keyThe setting key.
valueThe setting's value. If invalid, the setting is removed from this settings scope.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
keyThe setting key.
defaultValueDefault value to be returned, if no defined value could be found.
searchAllIf 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.
Here is the caller graph for this function:

◆ 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
keyThe related setting key.
valueThe new setting value.
Here is the caller graph for this function:

Property Documentation

◆ 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: