libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
Quotient::Settings Class Reference

#include <settings.h>

Inheritance diagram for Quotient::Settings:
Collaboration diagram for Quotient::Settings:

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 }
 

Detailed Description

Definition at line 16 of file settings.h.

Constructor & Destructor Documentation

◆ Settings()

Quotient::Settings::Settings ( QObject *  parent = nullptr)
explicit

Member Function Documentation

◆ childGroups()

Q_INVOKABLE QStringList Quotient::Settings::childGroups ( ) const

Obtain the list of child groups from the current or, if missing, legacy settings.

Note
Group names under Accounts group will be automatically unescaped
See also
AccountSettings

◆ contains()

Q_INVOKABLE bool Quotient::Settings::contains ( const QString key) const

◆ escapedForSettings()

static QString Quotient::Settings::escapedForSettings ( QString  key)
static

Escape forward- and backslashes in keys because QSettings doesn't (see #842)

◆ 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.

◆ unescapedFromSettings()

static QString Quotient::Settings::unescapedFromSettings ( QString  key)
static

Unescape \ and / in keys stored with escapedForSettings()

◆ 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

Member Data Documentation

◆ legacySettings

QSettings Quotient::Settings::legacySettings { legacyOrganizationName, legacyApplicationName }
protected

Definition at line 86 of file settings.h.


The documentation for this class was generated from the following file: