Saving and loading settings. More...
#include <settings.h>
Public Slots | |
| void | flush () |
| QString | readExpand (const QString &key, const QString &defValue=QString::null) |
| QString | read (const QString &key, const QString &defValue=QString::null) |
| bool | readBool (const QString &key, bool defValue=false) |
| int | readNum (const QString &key, int defValue=0) |
| void | write (const QString &key, const QString &value) |
| void | write (const QString &key, int value) |
| void | remove (const QString &key) |
| void | removeAll (const QString &key) |
| QString | expand (QString s) |
| QString | getFullPathName (const QString &nameOfPath, QString fileName=QString::null, const QString &prefix=QString::null) |
Signals | |
| void | settingChanged (QString) |
Public Member Functions | |
| ~Settings () | |
| void | saveWindow (QWidget *win, const QString &name) |
| void | restoreWindow (QWidget *win, const QString &name) |
| void | saveSplitter (QSplitter *spl, const QString &name) |
| void | restoreSplitter (QSplitter *spl, const QString &name) |
| QStringList | readPath (const QString &name, const QString &prefix="path/") |
| QStringList | readList (const QString &name, const QString &separator=",") |
Static Public Member Functions | |
| static Settings * | getInstance () |
Private Member Functions | |
| Settings () | |
| void | init () |
| void | initSettings () |
Private Attributes | |
| QSettings * | set |
| StaticSettings * | staticSet |
Saving and loading settings.
Class managing settings, saving and loading single settings or window states
| gui::Settings::~Settings | ( | ) |
Default destructor
References staticSet.
| gui::Settings::Settings | ( | ) | [private] |
| QString gui::Settings::expand | ( | QString | s | ) | [slot] |
Expand environment variables in given string (like $HOME, etc ..)
| s | String to expand |
References gui::APP_PATH_VAR, appPath, and gui::DATA_PATH_VAR.
Referenced by readExpand(), and readPath().
| void gui::Settings::flush | ( | ) | [slot] |
flushes settings, saving all changes to disk
References initSettings(), and staticSet.
| QString gui::Settings::getFullPathName | ( | const QString & | nameOfPath, | |
| QString | fileName = QString::null, |
|||
| const QString & | prefix = QString::null | |||
| ) | [slot] |
Given name of the file, finds and returns full path to the file, considering all relevant settings
| nameOfPath | Name of paths in settings for this file (e.g. "icon") | |
| fileName | Name of file. If not specified, the path itself is the filename we want to find | |
| prefix | Path prefix (Can be specified if desired to read from different configuration key than default) |
References debug::DBG_WARN, guiPrintDbg, Q_OUT, and readPath().
Referenced by gui::PropertyModeController::PropertyModeController().
| Settings * gui::Settings::getInstance | ( | ) | [static] |
Return Instance of Settings. Ensures only one instance of Settings exists at any time (singleton) If no instance exists, it is created.
References gui::globalSettings, and Settings().
| void gui::Settings::init | ( | ) | [private] |
| void gui::Settings::initSettings | ( | ) | [private] |
creates and inits new QSettings Object. Set paths to config files
References appPath, CONFIG_DIR, gui::CONFIG_FILE, debug::DBG_ERR, guiPrintDbg, Q_OUT, staticSet, and gui::StaticSettings::tryLoad().
| QString gui::Settings::read | ( | const QString & | key, | |
| const QString & | defValue = QString::null | |||
| ) | [slot] |
Read settings with given key from configuration file and return as QString
| key | Key to read from settings | |
| defValue | default value to use if key not found in settings. |
References gui::APP_KEY, gui::StaticSettings::readEntry(), and staticSet.
Referenced by gui::IconCache::IconCache(), main(), gui::PageSpace::PageSpace(), readBool(), readExpand(), readList(), readNum(), readPath(), gui::StringOption::readValue(), restoreSplitter(), and restoreWindow().
| bool gui::Settings::readBool | ( | const QString & | key, | |
| bool | defValue = false | |||
| ) | [slot] |
Read settings with given key from configuration file and return as bool
| key | Key to read from settings | |
| defValue | default value to use if key not found in settings. |
References read().
Referenced by gui::CommandWindow::reloadSettings().
| QString gui::Settings::readExpand | ( | const QString & | key, | |
| const QString & | defValue = QString::null | |||
| ) | [slot] |
Read settings with given key from configuration file and return as QString Any environment variable references (in form $VARIABLE) are expanded in the string.
| key | Key to read from settings | |
| defValue | default value to use if key not found in settings. |
References expand(), and read().
Referenced by gui::CommandWindow::addCommand(), gui::CommandWindow::addError(), gui::CommandWindow::addString(), gui::CommandWindow::loadHistory(), and gui::CommandWindow::saveHistory().
| QStringList gui::Settings::readList | ( | const QString & | name, | |
| const QString & | separator = "," | |||
| ) |
Read list of values from config file and return as string list. List elements are expected to be separated by defined separator (default is comma)
| name | Identifier of list in config file | |
| separator | String separating items in the list |
References read().
| int gui::Settings::readNum | ( | const QString & | key, | |
| int | defValue = 0 | |||
| ) | [slot] |
Read settings with given key from configuration file and return as integer
| key | Key to read from settings | |
| defValue | default value to use if key not found in settings. |
References read().
Referenced by gui::CommandWindow::CommandWindow(), gui::PageSpace::getResizingZone(), and gui::PageSpace::setSelectionMode().
| QStringList gui::Settings::readPath | ( | const QString & | name, | |
| const QString & | prefix = "path/" | |||
| ) |
Read path list element from config file. Expands variables ($HOME, etc ...) and return as string list. Path elements are expected to be separated by semicolon. Trailing slashes are removed from path elements.
| name | Identifier of path in config file | |
| prefix | Path prefix (Can be specified if desired to read from different configuration key than default "path"/) |
References expand(), and read().
Referenced by getFullPathName(), gui::HelpWindow::HelpWindow(), gui::IconCache::IconCache(), and gui::BaseConsole::runInitScript().
| void gui::Settings::remove | ( | const QString & | key | ) | [slot] |
Remove key from user settings, effectively restoring the setting to its default value
| key | Key to remove |
| void gui::Settings::removeAll | ( | const QString & | key | ) | [slot] |
Remove all keys directly under specified key according to hiararchic structure
| key | Key to remove |
| void gui::Settings::restoreSplitter | ( | QSplitter * | spl, | |
| const QString & | name | |||
| ) |
Restore splitter positions from setting.
| spl | Splitter to be resized | |
| name | Name of key to be used in configuration |
References util::explode(), and read().
Referenced by gui::CommandWindow::restoreWindowState().
| void gui::Settings::restoreWindow | ( | QWidget * | win, | |
| const QString & | name | |||
| ) |
Restore window/widget size and position from setting.
| win | Widget that will be resized and moved | |
| name | Name of key to be used in configuration |
References util::explode(), and read().
Referenced by gui::AddItemDialog::AddItemDialog(), and gui::HelpWindow::HelpWindow().
| void gui::Settings::saveSplitter | ( | QSplitter * | spl, | |
| const QString & | name | |||
| ) |
Save splitter positions to settings.
| spl | Splitter to save positions | |
| name | Name of key to be used in configuration |
References write().
Referenced by gui::CommandWindow::saveWindowState().
| void gui::Settings::saveWindow | ( | QWidget * | win, | |
| const QString & | name | |||
| ) |
Save window/widget size and position to settings.
| win | Widget that will have it's size and position stored | |
| name | Name of key to be used in configuration |
References write().
Referenced by gui::HelpWindow::~HelpWindow().
| void gui::Settings::settingChanged | ( | QString | ) | [signal] |
Signal emitted when any setting is changed. Key of changed settings is sent. Can be used to monitor settings changes
Referenced by write().
| void gui::Settings::write | ( | const QString & | key, | |
| int | value | |||
| ) | [slot] |
Write settings with given key and value to configuration
| key | Key to write to settings | |
| value | Value to write to settings |
References gui::APP_KEY, and settingChanged().
| void gui::Settings::write | ( | const QString & | key, | |
| const QString & | value | |||
| ) | [slot] |
Write settings with given key and value to configuration
| key | Key to write to settings | |
| value | Value to write to settings |
References gui::APP_KEY, and settingChanged().
Referenced by main(), saveSplitter(), saveWindow(), gui::CommandWindow::setHistoryFile(), gui::CommandWindow::setHistorySize(), gui::PageSpace::setResizingZone(), and gui::StringOption::writeValue().
QSettings* gui::Settings::set [private] |
Settings object used to load configuration These settings takle precedence before staticSettings
StaticSettings* gui::Settings::staticSet [private] |
Settings object used to load static configuration (menu, etc ...) These settings are never changed (and never written)
Referenced by flush(), initSettings(), read(), and ~Settings().