QuasarAppLib 1.0.530.c9fba11
QuasarAppUtils::Settings Class Reference

The Settings class This is wrapper of the QSettings object. More...

#include <settings.h>

Inheritance diagram for QuasarAppUtils::Settings:
Inheritance graph
Collaboration diagram for QuasarAppUtils::Settings:
Collaboration graph

Public Member Functions

 Settings (QSettings::Format format=QSettings::IniFormat)
 Settings This is the main constructor of the Settings object.
const QSet< QString > & boolOptions () const
 boolOptions returns current map with keys that has a bool type.
void setBoolOptions (const QSet< QString > &newBoolOptions)
 setBoolOptions This method sets new map of the boolean options.
Public Member Functions inherited from QuasarAppUtils::ISettings
 ~ISettings () override
 ~ISettings This is the destructor of the ISettings class. It removes the object from the global service list and disconnects the internal signals.
Q_INVOKABLE QVariant getValue (const QString &key, const QVariant &def={})
 getValue This method return the value of the settings.
Q_INVOKABLE QString getStrValue (const QString &key, const QString &def={})
 getStrValue some as getValue but convert result object to QString type.
Q_INVOKABLE void resetToDefault ()
 resetToDefault This method reset all settings to default values.
void sync ()
 sync This method save all settings data on a hard disk;
void forceReloadCache ()
 forceReloadCache This method force reload settings data from disk.
SettingsSaveMode getMode () const
 getMode This method return the current mode of the settings.
void setMode (const SettingsSaveMode &mode)
 setMode This method sets a new value of the settings mode.
Public Member Functions inherited from QuasarAppUtils::Service< ISettings >
 Service ()
 Service This is the default constructor of the Service template class. It does nothing and is used only to allow the inheritance from the Service class.

Static Public Member Functions

static bool initService ()
 initService This method initialize default object of the QuasarAppUtils::Settings type.
static ISettings * autoInstance ()
 autoInstance This method returns the default object of the QuasarAppUtils::Settings type and if it was not initialized yet - it will be created automatically.
Static Public Member Functions inherited from QuasarAppUtils::ISettings
static ISettings * instance ()
 instance This method returns pointer to current settings object.
static bool initService (std::unique_ptr< ISettings > obj)
 initService This method initialize the global settings object.
Static Public Member Functions inherited from QuasarAppUtils::Service< ISettings >
static std::unique_ptr< ISettings > & initService ()
 initService This method initialize the Base object as a service using the default constructor. If the service is already initialized then the current service object will be returned.
static ISettings * instance ()
 instance This method return pointerer to current service object.
static ISettings * autoInstance ()
 autoInstance This method return pointerer to current service object and if it is not inited try to initialize it use default constructor.
static void deinitService ()
 deinitService This is destructor method for the service.

Protected Member Functions

void syncImplementation () override
 syncImplementation This method saves all settings data to the hard disk. This is the QSettings based implementation of the ISettings::syncImplementation method.
QVariant getValueImplementation (const QString &key, const QVariant &def) override
 getValueImplementation This method returns the value of the key setting from the QSettings backend.
void setValueImplementation (const QString key, const QVariant &value) override
 setValueImplementation This method sets a new value for the key setting in the QSettings backend.
bool ignoreToRest (const QString &) const override
 ignoreToRest This method checks if the key is a boolean option.
QHash< QString, QVariant > defaultSettings () override
 defaultSettings This method returns the default map of the settings and their values. By default the map is empty.
virtual bool isBool (const QString &key) const
 isBool This method should be return true if the key's type is bool. This is needed because QVariant will be converted alvays to true value in a qml code.
void setGroup (const QString &)
 setGroup This method sets a new settings group in the QSettings backend. All values that will be read or written after the call will be stored in this group. Use empty string for remove the current group.
Protected Member Functions inherited from QuasarAppUtils::ISettings
 ISettings (SettingsSaveMode mode=SettingsSaveMode::Auto)
void clearCache ()
 clearCache This method clear all data from cache.
QHash< QString, QVariant > & settingsMap ()
 settingsMap This method returns initialized settings map. Settings map contains pairs with settings key and default value.

Additional Inherited Members

Public Slots inherited from QuasarAppUtils::ISettings
void setValue (const QString &key, const QVariant &value)
 setValue This slot sets new value for a key setting
void setStrValue (const QString &key, const QString &value)
 setStrValue This is some as setValue but working with the QString type.
Signals inherited from QuasarAppUtils::ISettings
void valueChanged (QString key, QVariant value)
 valueChanged This signal when value of the key settings changed
void valueStrChanged (QString key, QString value)
 valueStrChanged some as valueChanged(QString key, QVariant value) but value has ben converted to the QString type.

Detailed Description

The Settings class This is wrapper of the QSettings object.

Example of initialisation :

auto settingsInstance = QuasarAppUtils::Setting::initService();
// on any another site you can use the instance method for get settings instance object.
auto settingsInstance = QuasarAppUtils::Setting::instance();
// and you can destroy setting object if they are not needed anymore
QuasarAppUtils::Setting::deinitService();

Or you can use the Settings::autoInstance method.

auto settingsInstance = QuasarAppUtils::Setting::autoInstance();
See also
Settings::init

Definition at line 42 of file settings.h.

Constructor & Destructor Documentation

◆ Settings()

QuasarAppUtils::Settings::Settings ( QSettings::Format format = QSettings::IniFormat)

Settings This is the main constructor of the Settings object.

Parameters
formatThis is the format of the QSettings backend. By default QSettings::IniFormat.

Definition at line 16 of file settings.cpp.

Member Function Documentation

◆ autoInstance()

ISettings * QuasarAppUtils::Settings::autoInstance ( )
static

autoInstance This method returns the default object of the QuasarAppUtils::Settings type and if it was not initialized yet - it will be created automatically.

Returns
pointer to the default settings object.
See also
ISettings::autoInstance

Definition at line 72 of file settings.cpp.

Here is the call graph for this function:

◆ boolOptions()

const QSet< QString > & QuasarAppUtils::Settings::boolOptions ( ) const

boolOptions returns current map with keys that has a bool type.

Returns
current map with keys that has a bool type
See also
Settings::setBoolOptions
Settings::isBool

Definition at line 58 of file settings.cpp.

◆ defaultSettings()

QHash< QString, QVariant > QuasarAppUtils::Settings::defaultSettings ( )
overrideprotectedvirtual

defaultSettings This method returns the default map of the settings and their values. By default the map is empty.

Returns
the default settings map.

Implements QuasarAppUtils::ISettings.

Definition at line 50 of file settings.cpp.

◆ getValueImplementation()

QVariant QuasarAppUtils::Settings::getValueImplementation ( const QString & key,
const QVariant & def )
overrideprotectedvirtual

getValueImplementation This method returns the value of the key setting from the QSettings backend.

Parameters
keyThis is name of the required settings value.
defThis is default value if a value is not found.
Returns
value of a key

Implements QuasarAppUtils::ISettings.

Definition at line 34 of file settings.cpp.

Here is the call graph for this function:

◆ ignoreToRest()

bool QuasarAppUtils::Settings::ignoreToRest ( const QString & ) const
overrideprotectedvirtual

ignoreToRest This method checks if the key is a boolean option.

Returns
true if the key option can't be reset to default else false.

Reimplemented from QuasarAppUtils::ISettings.

Definition at line 46 of file settings.cpp.

◆ initService()

bool QuasarAppUtils::Settings::initService ( )
static

initService This method initialize default object of the QuasarAppUtils::Settings type.

Returns
true if initialization finished successful else false.
See also
ISettings::initService

Definition at line 68 of file settings.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isBool()

bool QuasarAppUtils::Settings::isBool ( const QString & key) const
protectedvirtual

isBool This method should be return true if the key's type is bool. This is needed because QVariant will be converted alvays to true value in a qml code.

Parameters
keyThis is key of checks setting.
Returns
true if the key is boolean variable. The default implementation check key in the inner map.
See also
Settings::setBoolOptions
Settings::boolOptions

Definition at line 54 of file settings.cpp.

Here is the caller graph for this function:

◆ setBoolOptions()

void QuasarAppUtils::Settings::setBoolOptions ( const QSet< QString > & newBoolOptions)

setBoolOptions This method sets new map of the boolean options.

Parameters
newBoolOptionsThis is new map of the boolean options.
See also
Settings::boolOptions
Settings::isBool

Definition at line 63 of file settings.cpp.

◆ setGroup()

void QuasarAppUtils::Settings::setGroup ( const QString & )
protected

setGroup This method sets a new settings group in the QSettings backend. All values that will be read or written after the call will be stored in this group. Use empty string for remove the current group.

◆ setValueImplementation()

void QuasarAppUtils::Settings::setValueImplementation ( const QString key,
const QVariant & value )
overrideprotectedvirtual

setValueImplementation This method sets a new value for the key setting in the QSettings backend.

Parameters
keyThis is name of the changed setting.
valueThis is a new value of the setting.

Implements QuasarAppUtils::ISettings.

Definition at line 42 of file settings.cpp.

◆ syncImplementation()

void QuasarAppUtils::Settings::syncImplementation ( )
overrideprotectedvirtual

syncImplementation This method saves all settings data to the hard disk. This is the QSettings based implementation of the ISettings::syncImplementation method.

Implements QuasarAppUtils::ISettings.

Definition at line 30 of file settings.cpp.


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