#include <settings.h>
|
| Settings (QObject *parent=nullptr) |
|
Q_INVOKABLE void | setValue (const QString &key, const QVariant &value) |
| Set the value for a given key. More...
|
|
Q_INVOKABLE void | remove (const QString &key) |
| Remove the value from both the primary and legacy locations. More...
|
|
Q_INVOKABLE QVariant | value (const QString &key, const QVariant &defaultValue={}) const |
| Obtain a value for a given key. More...
|
|
template<typename T > |
T | get (const QString &key, const T &defaultValue={}) const |
| Obtain a value for a given key, coerced to the given type. More...
|
|
Q_INVOKABLE bool | contains (const QString &key) const |
|
Q_INVOKABLE QStringList | childGroups () const |
|
|
static void | setLegacyNames (const QString &organizationName, const QString &applicationName={}) |
| Add a legacy organisation/application name to migrate settings from. More...
|
|
|
QSettings | legacySettings { legacyOrganizationName, legacyApplicationName } |
|
Definition at line 16 of file settings.h.
◆ Settings()
Quotient::Settings::Settings |
( |
QObject * |
parent = nullptr | ) |
|
|
explicit |
◆ childGroups()
Q_INVOKABLE QStringList Quotient::Settings::childGroups |
( |
| ) |
const |
◆ contains()
Q_INVOKABLE bool Quotient::Settings::contains |
( |
const QString & |
key | ) |
const |
◆ get()
template<typename T >
T Quotient::Settings::get |
( |
const QString & |
key, |
|
|
const T & |
defaultValue = {} |
|
) |
| const |
|
inline |
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.
◆ remove()
Q_INVOKABLE void Quotient::Settings::remove |
( |
const QString & |
key | ) |
|
Remove the value from both the primary and legacy locations.
◆ setLegacyNames()
static void Quotient::Settings::setLegacyNames |
( |
const QString & |
organizationName, |
|
|
const QString & |
applicationName = {} |
|
) |
| |
|
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.
◆ setValue()
Q_INVOKABLE void Quotient::Settings::setValue |
( |
const QString & |
key, |
|
|
const QVariant & |
value |
|
) |
| |
Set the value for a given key.
If the key exists in the legacy location, it is removed.
◆ value()
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.
- See also
- setLegacyNames, get
◆ legacySettings
QSettings Quotient::Settings::legacySettings { legacyOrganizationName, legacyApplicationName } |
|
protected |
The documentation for this class was generated from the following file: