libQuotient
A Qt library for building matrix clients
|
#include <settings.h>
Public Member Functions | |
Settings (QObject *parent=nullptr) | |
Q_INVOKABLE void | setValue (const QString &key, const QVariant &value) |
Set the value for a given key. | |
Q_INVOKABLE void | remove (const QString &key) |
Remove the value from both the primary and legacy locations. | |
Q_INVOKABLE QVariant | value (const QString &key, const QVariant &defaultValue={}) const |
Obtain a value for a given key. | |
template<typename T > | |
T | get (const QString &key, const T &defaultValue={}) const |
Obtain a value for a given key, coerced to the given type. | |
Q_INVOKABLE bool | contains (const QString &key) const |
Q_INVOKABLE QStringList | childGroups () const |
Obtain the list of child groups from the current or, if missing, legacy settings. | |
Static Public Member Functions | |
static void | setLegacyNames (const QString &organizationName, const QString &applicationName={}) |
Add a legacy organisation/application name to migrate settings from. | |
static QString | escapedForSettings (QString key) |
Escape forward- and backslashes in keys because QSettings doesn't (see #842) | |
static QString | unescapedFromSettings (QString key) |
Unescape \ and / in keys stored with escapedForSettings() | |
Protected Attributes | |
QSettings | legacySettings { legacyOrganizationName, legacyApplicationName } |
Definition at line 16 of file settings.h.
|
explicit |
Q_INVOKABLE QStringList Quotient::Settings::childGroups | ( | ) | const |
Obtain the list of child groups from the current or, if missing, legacy settings.
Accounts
group will be automatically unescaped Q_INVOKABLE bool Quotient::Settings::contains | ( | const QString & | key | ) | const |
Escape forward- and backslashes in keys because QSettings doesn't (see #842)
Obtain a value for a given key, coerced to the given type.
On top of value(), this function unwraps the QVariant and returns its contents assuming the type passed as the template parameter. If the type is different from the one stored inside the QVariant, defaultValue
is returned. In presence of legacy settings, only the first found value is checked; if its type does not match, further checks through legacy settings are not performed and defaultValue
is returned.
Definition at line 63 of file settings.h.
Q_INVOKABLE void Quotient::Settings::remove | ( | const QString & | key | ) |
Remove the value from both the primary and legacy locations.
|
static |
Add a legacy organisation/application name to migrate settings from.
Use this function before creating any Settings objects in order to set a legacy location where configuration has previously been stored. This will provide an additional fallback in case of renaming the organisation/application. Values in legacy locations are removed when setValue() or remove() is called.
Set the value for a given key.
If the key exists in the legacy location, it is removed.
Unescape \
and /
in keys stored with escapedForSettings()
Q_INVOKABLE QVariant Quotient::Settings::value | ( | const QString & | key, |
const QVariant & | defaultValue = {} |
||
) | const |
Obtain a value for a given key.
If the key doesn't exist in the primary settings location, the legacy location is checked. If neither location has the key, defaultValue
is returned.
This function returns a QVariant; use get<>() to get the unwrapped value if you know the type upfront.
|
protected |
Definition at line 86 of file settings.h.