Updraft
1.0
Open source glider flight visualisation tool.
|
The main settings class. More...
#include <settingsmanager.h>
Public Slots | |
void | execDialog () |
Executes the settings dialog. | |
void | resetToDefaults () |
Resets all the defined settings to their default values. | |
Public Member Functions | |
SettingsManager () | |
Prepare the settings manager to a state where settings are loaded and accessible, but don't do anything gui-related. | |
~SettingsManager () | |
void | finishInit () |
Finalize the initialization. | |
SettingInterface * | addSetting (const QString &settingId, const QString &description, QVariant defaultValue, SettingsGroupType type=GROUP_VISIBLE) |
Adds a setting into the settings dialog. | |
void | addGroup (const QString &groupId, const QString &description, SettingsGroupType type=GROUP_VISIBLE, const QString &icon=":/core/icons/configure.png") |
Adds a group into the settings dialog. | |
QDir | getSettingsDir () |
Private Slots | |
void | itemValueChanged (SettingsItem *item) |
Handles the value change of a settings item by calling the valueChanged() signals of all the BasicSetting s pointing to it. | |
Private Member Functions | |
QModelIndex | getGroup (const QString &groupId) |
Returns an index for the given settings group. | |
QModelIndex | getSetting (const QString &settingId, QModelIndex groupIndex) |
Returns an index for the given setting. | |
QModelIndex | addGroupInternal (const QString &groupId, const QString &description, const QString &icon) |
Internal helper function for adding groups. | |
void | registerSetting (SettingsItem *item, BasicSetting *setting) |
Registers a BasicSetting instance to the settings item. | |
void | unregisterSetting (SettingsItem *item, BasicSetting *setting) |
Unregisters a BasicSetting instance that was registred using the registerSetting() method. | |
QString | getSettingsFilename () |
Searches the standard locations for a settings file. | |
QString | checkSettingsXml (const QString &dir1, const QString &dir2) |
Check if file settings.xml exists in dir/dir2. | |
QString | createSettingsXml (const QString &dir1, const QString &dir2) |
Create file settings.xml in dir/dir2. | |
Private Attributes | |
QString | settingsFile |
Filename of the settings file. | |
QAction * | settingsAction |
The action that executes the settings dialog. | |
SettingsDialog * | dialog |
The settings dialog. | |
SettingsModel * | model |
The settings data model. | |
QRegExp | idRegExp |
Regular expression that matches a setting or group identifier. | |
QMultiHash< SettingsItem *, BasicSetting * > | settings |
The associative container of SettingsItem instances to BasicSetting instances. | |
Friends | |
class | BasicSetting |
The main settings class.
Owns the SettingsModel instance, executes the settings dialog and allows for setting group and setting creation.
Prepare the settings manager to a state where settings are loaded and accessible, but don't do anything gui-related.
void Updraft::Core::SettingsManager::addGroup | ( | const QString & | groupId, |
const QString & | description, | ||
SettingsGroupType | type = GROUP_VISIBLE , |
||
const QString & | icon = ":/core/icons/configure.png" |
||
) |
Adds a group into the settings dialog.
If a setting group with the given ID already exists, its description and icon are changed to the new ones.
groupId | An identifier of the group to create or change description. |
description | Description of the group. This is displayed in the dialog next to the settings icon. |
type | Whether the group should be visible, advanced or hidden. |
icon | The icon of the settings group. Default is a wrench icon. |
QModelIndex Updraft::Core::SettingsManager::addGroupInternal | ( | const QString & | groupId, |
const QString & | description, | ||
const QString & | icon | ||
) | [private] |
Internal helper function for adding groups.
Does not know anything about the group types (they are encoded in the group suffix already). If the desired group already exists, its description and icon are overwritten.
groupId | The string identifier of the group (with the suffix denoting the group type. |
description | The description of the group that will be shown in the settings dialog. |
icon | The decorating icon for this group for the settings dialog. |
SettingInterface * Updraft::Core::SettingsManager::addSetting | ( | const QString & | settingId, |
const QString & | description, | ||
QVariant | defaultValue, | ||
SettingsGroupType | type = GROUP_VISIBLE |
||
) |
Adds a setting into the settings dialog.
If the setting already exists, its value is not set to the provided value but instead, the value is read from the existing setting. Ownership of the setting interface is transfered to the caller of this function.
settingId | Identifier for the setting, prepended with a ':' and the settings group identifier, where this setting will reside. If the group with the given identifier does not exist, a new one will be created with a default icon and name identical to the identifier. |
description | Description of the setting. This will be displayed in the settings dialog. |
defaultValue | This is the initial value for the setting if it is newly created. |
type | Whether the setting is being added to a visible, advanced or hidden group. |
QString Updraft::Core::SettingsManager::checkSettingsXml | ( | const QString & | dir1, |
const QString & | dir2 | ||
) | [private] |
Check if file settings.xml exists in dir/dir2.
dir1 | Path to the directory containing the settings file. |
dir2 | Name of the directory containing the settings file. |
QString Updraft::Core::SettingsManager::createSettingsXml | ( | const QString & | dir1, |
const QString & | dir2 | ||
) | [private] |
Create file settings.xml in dir/dir2.
dir1 | Path to the directory that should contain the settings file. |
dir2 | Name of the directory that should contain the settings file. |
void Updraft::Core::SettingsManager::execDialog | ( | ) | [slot] |
Executes the settings dialog.
Finalize the initialization.
Used to break the circular dependency between settings manager and translation manager.
QModelIndex Updraft::Core::SettingsManager::getGroup | ( | const QString & | groupId | ) | [private] |
Returns an index for the given settings group.
groupId | The string identifier of the gropu whose index should be retrieved. The identifier should contain the suffixes that denote the type of the group. |
QModelIndex Updraft::Core::SettingsManager::getSetting | ( | const QString & | settingId, |
QModelIndex | groupIndex | ||
) | [private] |
Returns an index for the given setting.
settingId | The identifier of the setting without the group name. |
groupIndex | The model index of the group for the setting. |
QString Updraft::Core::SettingsManager::getSettingsFilename | ( | ) | [private] |
Searches the standard locations for a settings file.
void Updraft::Core::SettingsManager::itemValueChanged | ( | SettingsItem * | item | ) | [private, slot] |
Handles the value change of a settings item by calling the valueChanged() signals of all the BasicSetting s pointing to it.
void Updraft::Core::SettingsManager::registerSetting | ( | SettingsItem * | item, |
BasicSetting * | setting | ||
) | [private] |
Registers a BasicSetting instance to the settings item.
This is to be able to call all BasicSetting instances on the setting's value change.
item | The SettingsItem representing the desired setting. |
setting | The new BasicSetting instance that should be registered. |
void Updraft::Core::SettingsManager::resetToDefaults | ( | ) | [slot] |
Resets all the defined settings to their default values.
void Updraft::Core::SettingsManager::unregisterSetting | ( | SettingsItem * | item, |
BasicSetting * | setting | ||
) | [private] |
Unregisters a BasicSetting instance that was registred using the registerSetting() method.
This is usually done when the BasicSetting instance is destructed.
item | The setting item, to which the BasicSetting instance was registered. |
setting | The BasicSetting instance to be unregistered. |
friend class BasicSetting [friend] |
The settings dialog.
QRegExp Updraft::Core::SettingsManager::idRegExp [private] |
Regular expression that matches a setting or group identifier.
The settings data model.
QMultiHash<SettingsItem*, BasicSetting*> Updraft::Core::SettingsManager::settings [private] |
The associative container of SettingsItem instances to BasicSetting instances.
Used in methods registerSetting() and unregisterSetting().
QAction* Updraft::Core::SettingsManager::settingsAction [private] |
The action that executes the settings dialog.
QString Updraft::Core::SettingsManager::settingsFile [private] |
Filename of the settings file.