Updraft  1.0
Open source glider flight visualisation tool.
Updraft::Core::SettingsManager Class Reference

The main settings class. More...

#include <settingsmanager.h>

Collaboration diagram for Updraft::Core::SettingsManager:

List of all members.

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.
SettingInterfaceaddSetting (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.
SettingsDialogdialog
 The settings dialog.
SettingsModelmodel
 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

Detailed Description

The main settings class.

Owns the SettingsModel instance, executes the settings dialog and allows for setting group and setting creation.


Constructor & Destructor Documentation

Prepare the settings manager to a state where settings are loaded and accessible, but don't do anything gui-related.

Note:
finishInit(); must be called after both SettingsManager and TranslationManager are created!

Member Function Documentation

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.

Parameters:
groupIdAn identifier of the group to create or change description.
descriptionDescription of the group. This is displayed in the dialog next to the settings icon.
typeWhether the group should be visible, advanced or hidden.
iconThe 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.

Parameters:
groupIdThe string identifier of the group (with the suffix denoting the group type.
descriptionThe description of the group that will be shown in the settings dialog.
iconThe decorating icon for this group for the settings dialog.
Returns:
Model index of the desired group.
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.

Parameters:
settingIdIdentifier 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.
descriptionDescription of the setting. This will be displayed in the settings dialog.
defaultValueThis is the initial value for the setting if it is newly created.
typeWhether the setting is being added to a visible, advanced or hidden group.
Returns:
Interface for setting and reading the setting value. In case of failure, NULL is returned.
QString Updraft::Core::SettingsManager::checkSettingsXml ( const QString &  dir1,
const QString &  dir2 
) [private]

Check if file settings.xml exists in dir/dir2.

Parameters:
dir1Path to the directory containing the settings file.
dir2Name of the directory containing the settings file.
Returns:
Absolute path to settings.xml, or empty string if it wasn't found.
QString Updraft::Core::SettingsManager::createSettingsXml ( const QString &  dir1,
const QString &  dir2 
) [private]

Create file settings.xml in dir/dir2.

Parameters:
dir1Path to the directory that should contain the settings file.
dir2Name of the directory that should contain the settings file.
Returns:
Absolute path to settings.xml, or empty string if something went wrong.

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.

Parameters:
groupIdThe string identifier of the gropu whose index should be retrieved. The identifier should contain the suffixes that denote the type of the group.
Returns:
The model index of the desired settings group.
QModelIndex Updraft::Core::SettingsManager::getSetting ( const QString &  settingId,
QModelIndex  groupIndex 
) [private]

Returns an index for the given setting.

Parameters:
settingIdThe identifier of the setting without the group name.
groupIndexThe model index of the group for the setting.
Returns:
The model index for the desired setting.
Returns:
Directory where the currently used settings file resides

Searches the standard locations for a settings file.

Returns:
The location of the settings file.

Handles the value change of a settings item by calling the valueChanged() signals of all the BasicSetting s pointing to it.

Registers a BasicSetting instance to the settings item.

This is to be able to call all BasicSetting instances on the setting's value change.

Parameters:
itemThe SettingsItem representing the desired setting.
settingThe new BasicSetting instance that should be registered.

Resets all the defined settings to their default values.

Unregisters a BasicSetting instance that was registred using the registerSetting() method.

This is usually done when the BasicSetting instance is destructed.

Parameters:
itemThe setting item, to which the BasicSetting instance was registered.
settingThe BasicSetting instance to be unregistered.

Friends And Related Function Documentation

friend class BasicSetting [friend]

Member Data Documentation

The settings dialog.

Regular expression that matches a setting or group identifier.

The settings data model.

The associative container of SettingsItem instances to BasicSetting instances.

Used in methods registerSetting() and unregisterSetting().

The action that executes the settings dialog.

Filename of the settings file.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines