QtMvvm  1.1.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
Public Slots | Public Member Functions | List of all members
QtMvvm::QSettingsAccessor Class Reference

A settings accessor implementation that wrapps QSettings. More...

#include <qsettingsaccessor.h>

+ Inheritance diagram for QtMvvm::QSettingsAccessor:

Public Slots

void sync () override
 Synchronizes the settings to the disk or whatever is needed to permanently store them. More...
 
- Public Slots inherited from QtMvvm::ISettingsAccessor
virtual void sync ()=0
 Synchronizes the settings to the disk or whatever is needed to permanently store them. More...
 

Public Member Functions

Q_INVOKABLE QSettingsAccessor (QObject *parent=nullptr)
 Default Constructor.
 
 QSettingsAccessor (QSettings *settings, QObject *parent=nullptr)
 Constructor, with settings to be used (takes ownership of the settings)
 
bool contains (const QString &key) const override
 Checks if a value is stored for the given key. More...
 
QVariant load (const QString &key, const QVariant &defaultValue) const override
 Loads the value for the given key from the settings. More...
 
void save (const QString &key, const QVariant &value) override
 Stores the given value under the given key in the settings. More...
 
void remove (const QString &key) override
 Removes the key and all its subkeys from the settings. More...
 
QSettingssettings () const
 Returns the internally used settings.
 
- Public Member Functions inherited from QtMvvm::ISettingsAccessor
 ISettingsAccessor (QObject *parent=nullptr)
 Constructor.
 
- Public Member Functions inherited from QObject
virtual const QMetaObjectmetaObject () const const
 
virtual void * qt_metacast (const char *)
 
virtual int qt_metacall (QMetaObject::Call, int, void **)
 
 QObject (QObject *parent)
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
bool signalsBlocked () const const
 
bool blockSignals (bool block)
 
QThreadthread () const const
 
void moveToThread (QThread *targetThread)
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
void killTimer (int id)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
const QObjectList & children () const const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
void dumpObjectTree () const const
 
void dumpObjectInfo () const const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const const
 
QList< QByteArraydynamicPropertyNames () const const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
bool inherits (const char *className) const const
 
void deleteLater ()
 

Additional Inherited Members

- Signals inherited from QtMvvm::ISettingsAccessor
void entryChanged (const QString &key, const QVariant &value)
 Is emitted whenever a settings value was changed, at least via this instance.
 
void entryRemoved (const QString &key)
 Is emitted whenever a settings value was removed, at least via this instance.
 
- Static Public Member Functions inherited from QtMvvm::ISettingsAccessor
template<typename T >
static void setDefaultAccessor ()
 
static void setDefaultAccessor (int typeId)
 
static ISettingsAccessorcreateDefaultAccessor (QObject *parent=nullptr)
 Create a new instance of the default accessor type. More...
 
- Static Public Member Functions inherited from QObject
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
- Protected Member Functions inherited from QObject
QObjectsender () const const
 
int senderSignalIndex () const const
 
int receivers (const char *signal) const const
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

A settings accessor implementation that wrapps QSettings.

Definition at line 14 of file qsettingsaccessor.h.

Member Function Documentation

◆ contains()

bool QtMvvm::QSettingsAccessor::contains ( const QString key) const
overridevirtual

Checks if a value is stored for the given key.

Parameters
keyThe key of the settings entry to be checked for existance
Returns
true, if a value for that key was stored, false if not

This should only check for values, not for groups, i.e. if key referes to a group that has child keys, but no value by itself, you should still return false.

See also
ISettingsAccessor::load

Implements QtMvvm::ISettingsAccessor.

◆ load()

QVariant QtMvvm::QSettingsAccessor::load ( const QString key,
const QVariant defaultValue 
) const
overridevirtual

Loads the value for the given key from the settings.

Parameters
keyThe key of the settings entry to be loaded
defaultValueA alternative value to be returned if there is no data stored for that key
Returns
The data loaded for the key, or the default value

If the given value does exist, it should be loaded and returned. If the is on data stored for that key, simply return whatever is passed as the default value.

See also
Storing data, ISettingsAccessor::contains, ISettingsAccessor::save

Implements QtMvvm::ISettingsAccessor.

◆ remove()

void QtMvvm::QSettingsAccessor::remove ( const QString key)
overridevirtual

Removes the key and all its subkeys from the settings.

Parameters
keyThe key of the settings entry to be removed

This method should remove the given key and all of its subkeys. If for example the settings contained the values group/subgroup and group/subgroup/key, after this method, both must have been removed. Permanent storing is done asynchronously, but can be forced via sync().

Any implementation of this method must emit the entryRemoved() signal for all the removed entries. I.e. for the example above, it must be emitted for both, group/subgroup and group/subgroup/key.

See also
Storing data, ISettingsAccessor::entryRemoved, ISettingsAccessor::save, ISettingsAccessor::sync

Implements QtMvvm::ISettingsAccessor.

◆ save()

void QtMvvm::QSettingsAccessor::save ( const QString key,
const QVariant value 
)
overridevirtual

Stores the given value under the given key in the settings.

Parameters
keyThe key of the settings entry to be saved
valueThe data to be stored under that key

Should simply store the passed data under the given key. You dont have to check if the variant is actually serializable, as the meta system will automatically warn the user if thats not the case. Permanent storing is done asynchronously, but can be forced via sync().

Any implementation of this method must emit the entryChanged() signal with the passed data and key.

See also
Storing data, ISettingsAccessor::entryChanged, ISettingsAccessor::load, ISettingsAccessor::remove, ISettingsAccessor::sync

Implements QtMvvm::ISettingsAccessor.

◆ sync

void QtMvvm::QSettingsAccessor::sync ( )
overrideslot

Synchronizes the settings to the disk or whatever is needed to permanently store them.

You can call this method to immediatly store any changed data to permanent store. This exists because typically, calls to save() and remove() only "cache" the changes, and then later write them to the permanent store in a single transaction, as this can be an expensive operation. Normally, you don't have to care about this, as this happens automatically, but sometimes you might want to manually perform this step. Thats what this method is for.

See also
ISettingsAccessor::save, ISettingsAccessor::remove, QSettings::sync

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