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

A wrapper around the android SharedPreferences API. More...

#include <androidsettingsaccessor.h>

+ Inheritance diagram for QtMvvm::AndroidSettingsAccessor:

Public Types

enum  ModeFlag { Private = 0x00000000, WorldReadable = 0x00000001, MultiProcess = 0x00000004 }
 Flags to specify how the shared preferences should be created. More...
 

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 AndroidSettingsAccessor (QObject *parent=nullptr)
 Default constructor.
 
 AndroidSettingsAccessor (const QString &file, QObject *parent=nullptr)
 Constructor with the name of the shared preferences to be opened.
 
 AndroidSettingsAccessor (const QString &file, Mode mode, QObject *parent=nullptr)
 Constructor with the name of the shared preferences to be opened and the mode to open them.
 
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...
 
- 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 wrapper around the android SharedPreferences API.

Definition at line 13 of file androidsettingsaccessor.h.

Member Enumeration Documentation

◆ ModeFlag

Flags to specify how the shared preferences should be created.

Enumerator
Private 

The default. Only the application itself can access settings.

WorldReadable 

Deprecated. Everyone canwrite the settings.

MultiProcess 

Deprecated. Multiple process can use an instance in parallel.

Definition at line 20 of file androidsettingsaccessor.h.

Member Function Documentation

◆ contains()

bool QtMvvm::AndroidSettingsAccessor::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::AndroidSettingsAccessor::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::AndroidSettingsAccessor::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::AndroidSettingsAccessor::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::AndroidSettingsAccessor::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: