QSettingsDialog  1.0.0
A Qt library to easily create a settings dialog for user configurable settings
Public Member Functions | Static Public Member Functions | List of all members
QSettingsSettingsLoader Class Reference

A loader to load data from QSettings. More...

#include <qsettingssettingsloader.h>

+ Inheritance diagram for QSettingsSettingsLoader:

Public Member Functions

 QSettingsSettingsLoader (const QString &key)
 Creates a loader for a key in the default QSettings.
 
 QSettingsSettingsLoader (QSettings *settings, const QString &key, bool ownSettings=false)
 Creates a loader for a key in given QSettings. More...
 
 ~QSettingsSettingsLoader ()
 Destructor.
 
bool load (QVariant outParam data, bool outParam userEdited) override
 Will be called if settings need to be loaded form this loader. More...
 
bool save (const QVariant &data) override
 Will be called to save settings from the dialog to this loader. More...
 
bool reset () override
 Will be called to reset the data this loader manages. More...
 
- Public Member Functions inherited from QSimpleSettingsLoader
bool isAsync () const final
 Specifies, whether this loader is async or not.
 
- Public Member Functions inherited from QSettingsLoader
virtual ~QSettingsLoader ()
 Virtual destructor.
 
QSimpleSettingsLoadersimple ()
 Casts this instance to a QSimpleSettingsLoader. Will assert if the conversion fails.
 
QAsyncSettingsLoaderasync ()
 Casts this instance to a QAsyncSettingsLoader. Will assert if the conversion fails.
 

Static Public Member Functions

static QHash< QString, QSettingsSettingsLoader * > createLoaders (QSettings *settings, const QString &rootKey=QString(), bool recursive=false)
 Creates a list of loaders for a group in the settings. More...
 

Detailed Description

A loader to load data from QSettings.

With this loader type, any value from QSettings can be used in the dialog

Note
QSettings does not preserve the type for simple types as int/double/… . If you check the returned QVariants type, you will always get QString for those. However, the values are convertible to int/double/… . So as long as you know which type to use, it's fine. Because of this, and because an entry can be not existing, unlike the property loader, the QSettings loader does not provide a member to get the metatype of the used settings entry.

Constructor & Destructor Documentation

QSettingsSettingsLoader::QSettingsSettingsLoader ( QSettings settings,
const QString key,
bool  ownSettings = false 
)

Creates a loader for a key in given QSettings.

Parameters
settingsThe settings object to be used
keyThe key within the settings to load/write to
ownSettingsIf true, the loader will delete the settings when it's destroyed. If false, thats not the case

If you set the settings to be owned, the desturction of the loader will destroy them too. If not, the loader will not do anything. However, if you pass not owned settings, you have to make shure the object will not be destroyed until the loader was destroyed. Otherwise, your application will most likely crash.

Member Function Documentation

QSettingsSettingsLoader::createLoaders ( QSettings settings,
const QString rootKey = QString(),
bool  recursive = false 
)
static

Creates a list of loaders for a group in the settings.

Parameters
settingsThe settings object to be used
rootKeyThe group key to scan
recursiveSpecifies, whether searching should be performed recusive or not
Returns
A map of settings keys (including the key part) to the loader for that key.

This function will scan the given key group of the settings and create loaders for all child entries in that group. If recursive is false, only the direct child entries will be used. If it is true, this function will recusivly scan all subgroups and create entries for all of them.

The resulting map contains all entries with their keys as key. Each key will include the key that was passed to this function. The settings state will not be changed, and none of the returned loaders will have ownership of the settings.

bool QSettingsSettingsLoader::load ( QVariant outParam  data,
bool outParam  userEdited 
)
overridevirtual

Will be called if settings need to be loaded form this loader.

Parameters
data[outParam] A reference to the QVariant object to load the data into. (Defaults to QVariant::Invalid)
userEdited[outParam] A reference to a bool to specify whether the value comes from the user or is the default. (Defaults to false)
Returns
Should return true, if loading was successful, false if not

This method will be called from the engine to load settings for the display dialog. The loaded value should be written into data. You can use the userEdited parameter to activate/deactivate the entry. If loading was successful return true. If not return false and an error will be shown to the user and the entry that uses this loader will be diabled.

Implements QSimpleSettingsLoader.

bool QSettingsSettingsLoader::reset ( )
overridevirtual

Will be called to reset the data this loader manages.

Returns
true, if resetting was successful, false if not

If resetting was successful return true. If not return false and an error will be shown to the user and the entry that uses this loader will be diabled.

Implements QSimpleSettingsLoader.

bool QSettingsSettingsLoader::save ( const QVariant data)
overridevirtual

Will be called to save settings from the dialog to this loader.

Parameters
dataThe data to be saved.
Returns
true, if saving was successful, false if not

If saving was successful return true. If not return false and an error will be shown to the user and the entry that uses this loader will be diabled.

Implements QSimpleSettingsLoader.


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