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

A ViewModel for a generic settings dialog based of an XML settings file. More...

#include <settingsviewmodel.h>

+ Inheritance diagram for QtMvvm::SettingsViewModel:

Public Slots

virtual void callAction (const QString &key, const QVariantMap &parameters)
 Is called when an action type edit is pressed. More...
 
QTMVVM_REVISION_1 void setAccessor (QtMvvm::ISettingsAccessor *accessor)
 WRITE accessor for SettingsViewModel::accessor.
 
void setSettingsSetupLoader (QtMvvm::ISettingsSetupLoader *settingsSetupLoader)
 WRITE accessor for SettingsViewModel::settingsSetupLoader.
 
- Public Slots inherited from QtMvvm::ViewModel
virtual void onResult (quint32 requestCode, const QVariant &result)
 Called by the presenter when a result of a showed viewmodel is ready. More...
 

Signals

QTMVVM_REVISION_1 void accessorChanged (QtMvvm::ISettingsAccessor *accessor)
 NOTIFY accessor for SettingsViewModel::accessor.
 
void settingsSetupLoaderChanged (QtMvvm::ISettingsSetupLoader *settingsSetupLoader, QPrivateSignal)
 NOTIFY accessor for SettingsViewModel::settingsSetupLoader.
 
void beginLoadSetup ()
 Is emitted when the initialization has been completed and the viewmodel is ready for loading settings.
 
QTMVVM_REVISION_1 void valueChanged (const QString &key)
 Signal to be emitted whenver a value in the settings is changed or removed to update the GUI.
 
QTMVVM_REVISION_1 void resetAccepted (QPrivateSignal)
 Is emitted when the user accepted the reset triggered by resetAll() More...
 
- Signals inherited from QtMvvm::ViewModel
void resultReady (const QVariant &result)
 Should be emitted when the viewmodels result is ready. More...
 
QTMVVM_REVISION_1 void instanceInvoked (const QVariantHash &params, QPrivateSignal)
 Is emitted on single instance viewmodels when they get shown again. More...
 

Public Member Functions

Q_INVOKABLE SettingsViewModel (QObject *parent=nullptr)
 Invokable constructor.
 
QtMvvm::ISettingsAccessoraccessor () const
 READ accessor for SettingsViewModel::accessor.
 
virtual bool canRestoreDefaults () const
 READ accessor for SettingsViewModel::canRestoreDefaults.
 
virtual QtMvvm::MessageConfig restoreConfig () const
 READ accessor for SettingsViewModel::restoreConfig.
 
ISettingsSetupLoadersettingsSetupLoader () const
 READ accessor for SettingsViewModel::settingsSetupLoader.
 
SettingsElements::Setup loadSetup (const QString &frontend) const
 Loads the settings setup of the prepared file for the given frontend. More...
 
QSettingssettings () const
 Returns the settings this viewmodel operates on (or null if not using QtMvvm::QSettingsAccessor)
 
virtual Q_INVOKABLE QVariant loadValue (const QString &key, const QVariant &defaultValue={}) const
 Loads the value for the given key from the settings. More...
 
virtual Q_INVOKABLE void saveValue (const QString &key, const QVariant &value)
 Saves the value with the given key. More...
 
virtual Q_INVOKABLE void resetValue (const QString &key)
 Resets the value or group identified by the key. More...
 
QTMVVM_REVISION_1 Q_INVOKABLE void resetAll (const SettingsElements::Setup &setup)
 Resets all values that are defined by the entries in the given setup. More...
 
- Public Member Functions inherited from QtMvvm::ViewModel
 ViewModel (QObject *parent=nullptr)
 Default constructor with parent.
 
- 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 ()
 

Static Public Member Functions

static QVariantHash showParams (ISettingsAccessor *accessor, const QString &setupFile={})
 Generates show parameter to show a settings viewmodel via ViewModel::show. More...
 
static QVariantHash showParams (QSettings *settings, const QString &setupFile={})
 Generates show parameter to show a settings viewmodel via ViewModel::show. 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)
 

Static Public Attributes

static const QString paramAccessor
 The parameter for an ISettingsAccessor object for the onInit() method. More...
 
static const QString paramSettings
 The parameter for a QSettings object for the onInit() method. More...
 
static const QString paramSetupFile
 The parameter for a settings setup file for the onInit() method. More...
 

Protected Member Functions

void onInit (const QVariantHash &params) override
 Called by the presenter to initialize the viewmodel. More...
 
- Protected Member Functions inherited from QtMvvm::ViewModel
template<typename TViewModel >
void show (const QVariantHash &params={}) const
 Show another viewmodel as a child of this one. More...
 
void show (const char *viewModelName, const QVariantHash &params={}) const
 Show another viewmodel as a child of this one. More...
 
void show (const QMetaObject *viewMetaObject, const QVariantHash &params={}) const
 Show another viewmodel as a child of this one. More...
 
template<typename TViewModel >
void showForResult (quint32 requestCode, const QVariantHash &params={}) const
 Show another viewmodel as a child of this one and expect its result. More...
 
void showForResult (quint32 requestCode, const char *viewModelName, const QVariantHash &params={}) const
 Show another viewmodel as a child of this one and expect its result. More...
 
void showForResult (quint32 requestCode, const QMetaObject *viewMetaObject, const QVariantHash &params={}) const
 Show another viewmodel as a child of this one and expect its result. More...
 
- 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

QtMvvm::ISettingsAccessor accessor
 Holds the settings accessor used by the viewmodel to access the settings. More...
 
bool canRestoreDefaults
 Specifies if restoring the defaults is generally allowed. More...
 
QtMvvm::MessageConfig restoreConfig
 The message configuration to be used to for a dialog to ask for settings restore. More...
 
QtMvvm::ISettingsSetupLoader settingsSetupLoader
 The settings setup loader to use to create the settings dialog. Is an injected property. More...
 
- Properties inherited from QObject
 objectName
 

Detailed Description

A ViewModel for a generic settings dialog based of an XML settings file.

It's a ready made viewmodel to show a settings dialog. See The XML settings format. To show the dialog, call show from another ViewModel or the CoreApp:

show<QtMvvm::SettingsViewModel>();
See also
Images page

Definition at line 18 of file settingsviewmodel.h.

Member Function Documentation

◆ callAction

QtMvvm::SettingsViewModel::callAction ( const QString key,
const QVariantMap &  parameters 
)
virtualslot

Is called when an action type edit is pressed.

Parameters
keyThe key of the entry that triggered the action
parametersA map with additional parameters for the action call

This method is called by the GUI when an entry with the action type is pressed by the user. The key is what would normally be used as the settings key. The parameters are deduced from the settings XML. See the type documentation for more details.

See also
action

◆ loadSetup()

QtMvvm::SettingsViewModel::loadSetup ( const QString frontend) const

Loads the settings setup of the prepared file for the given frontend.

Parameters
frontendThe name of the current frontend
Returns
The loaded settings setup

If loading fails an empty setup is returned. Logging is performed internally, so you can just proceed without error checking and show an empty settings dialog.

◆ loadValue()

QtMvvm::SettingsViewModel::loadValue ( const QString key,
const QVariant defaultValue = {} 
) const
virtual

Loads the value for the given key from the settings.

Parameters
keyThe full key of the settings entry to be loaded
defaultValuea default value to return in case the value is not found in the settings
Returns
The value found under the given key

You can override this method if you want to support loading and saving settings from something different than a ISettingsAccessor

See also
SettingsViewModel::saveValue, SettingsViewModel::resetValue

◆ onInit()

void QtMvvm::SettingsViewModel::onInit ( const QVariantHash &  params)
overrideprotectedvirtual

Called by the presenter to initialize the viewmodel.

Parameters
paramsThe parameters to initialize the viewmodel with

This method is called by the presenter right after creating the view and reparenting the viewmodel to the view. The parameters are the ones that have been passed to the show method called to show this viewmodel instance. Reimplement this method if you need to perform initializations after beeing assigned to a viewmodel or if you want to support a parametrized viewmodel.

See also
ViewModel::show, ViewModel::showForResult, CoreApp::show

Reimplemented from QtMvvm::ViewModel.

Reimplemented in QtMvvm::DataSyncSettingsViewModel.

◆ resetAccepted

QtMvvm::SettingsViewModel::resetAccepted ( QPrivateSignal  )
signal

Is emitted when the user accepted the reset triggered by resetAll()

This signal is emitted as the result of a resetAll() that was accepted by the user. As a reaction, the settings gui implementation should close itself.

See also
SettingsViewModel::resetAll

◆ resetAll()

QtMvvm::SettingsViewModel::resetAll ( const SettingsElements::Setup setup)

Resets all values that are defined by the entries in the given setup.

Parameters
setupThe setup to search for keys to be resetted

You can call this method from your gui to perform a complete reset of all the settings that are visible in the gui. Internally, the method will use SettingsViewModel::restoreConfig to create a dialog that asks the user for confirmation, and if he accepts, remove the value of all SettingsElements::Entry elements that can be found in the setup by calling resetValue().

If the user accepted the dialog and data was successfully reset, the resetAccepted() signal is emitted so the gui can close itself.

See also
SettingsViewModel::restoreConfig, SettingsViewModel::resetAccepted, SettingsViewModel::resetValue

◆ resetValue()

QtMvvm::SettingsViewModel::resetValue ( const QString key)
virtual

Resets the value or group identified by the key.

Parameters
keyThe full key of the settings entry to be resetted

You can override this method if you want to support loading and saving settings from something different than a ISettingsAccessor. if you do so, you must emit the valueChanged() signal from this method to indicate that the data was changed.

See also
SettingsViewModel::loadValue, SettingsViewModel::saveValue

◆ saveValue()

QtMvvm::SettingsViewModel::saveValue ( const QString key,
const QVariant value 
)
virtual

Saves the value with the given key.

Parameters
keyThe full key of the settings entry to be saved
valueThe value to be stored under the key

You can override this method if you want to support loading and saving settings from something different than a ISettingsAccessor. if you do so, you must emit the valueChanged() signal from this method to indicate that the data was changed.

See also
SettingsViewModel::loadValue, SettingsViewModel::resetValue

◆ showParams() [1/2]

QtMvvm::SettingsViewModel::showParams ( ISettingsAccessor accessor,
const QString setupFile = {} 
)
static

Generates show parameter to show a settings viewmodel via ViewModel::show.

Parameters
accessorThe ISettingsAccessor to operate on. Can be null to use the default accessor (QSettingsAccessor)
setupFileThe path to a file to be used to create the settings. Can be empty to use the default path
Returns
A paramater hash to be passed to ViewModel::show

It's a shortcut to generate parameters for the show methods to show a settings viewmodel. Use them as:

show<QtMvvm::SettingsViewModel>(QtMvvm::SettingsViewModel::showParams(...));
Note
Unless you need to explicitly set the settings or setup file a normal show without any parameters will just do fine.
See also
ViewModel::show, SettingsViewModel::paramAccessor, SettingsViewModel::paramSetupFile

◆ showParams() [2/2]

QtMvvm::SettingsViewModel::showParams ( QSettings settings,
const QString setupFile = {} 
)
static

Generates show parameter to show a settings viewmodel via ViewModel::show.

Parameters
settingsThe QSettings to operate on. Can be null to use the default settings
setupFileThe path to a file to be used to create the settings. Can be empty to use the default path
Returns
A paramater hash to be passed to ViewModel::show

This internally creates a QSettingsAccessor that operates on the given settings and sets it as the SettingsViewModel::accessor.

It's a shortcut to generate parameters for the show methods to show a settings viewmodel. Use them as:

show<QtMvvm::SettingsViewModel>(QtMvvm::SettingsViewModel::showParams(...));
Note
Unless you need to explicitly set the settings or setup file a normal show without any parameters will just do fine.
See also
ViewModel::show, SettingsViewModel::paramSettings, SettingsViewModel::paramSetupFile

Member Data Documentation

◆ paramAccessor

QtMvvm::SettingsViewModel::paramAccessor
static

The parameter for an ISettingsAccessor object for the onInit() method.

Value: "accessor"

See also
SettingsViewModel::showParams

Definition at line 36 of file settingsviewmodel.h.

◆ paramSettings

QtMvvm::SettingsViewModel::paramSettings
static

The parameter for a QSettings object for the onInit() method.

Value: "settings"

See also
SettingsViewModel::showParams

Definition at line 38 of file settingsviewmodel.h.

◆ paramSetupFile

QtMvvm::SettingsViewModel::paramSetupFile
static

The parameter for a settings setup file for the onInit() method.

Value: "setupFile"

See also
SettingsViewModel::showParams

Definition at line 40 of file settingsviewmodel.h.

Property Documentation

◆ accessor

QtMvvm::SettingsViewModel::accessor
readwrite

Holds the settings accessor used by the viewmodel to access the settings.

Default: nullptr (Initialized by onInit())

This acccessor is used by all the methods that access settings. This makes it possible to simply change the backend that the viewmodel should operate on without reimplementing it, and also makes it possible for change signals to be used to dynamically update the gui if the settings values change.

Accessors
READaccessor()
WRITEsetAccessor()
NOTIFYaccessorChanged()
See also
ISettingsAccessor, SettingsViewModel::showParams

Definition at line 23 of file settingsviewmodel.h.

◆ canRestoreDefaults

QtMvvm::SettingsViewModel::canRestoreDefaults
read

Specifies if restoring the defaults is generally allowed.

Default: true

Restoring defaults is only allowed if both this property and the attribute of the settings XML are true.

Accessors
READcanRestoreDefaults()
CONSTANT
See also
Attributes

Definition at line 26 of file settingsviewmodel.h.

◆ restoreConfig

QtMvvm::SettingsViewModel::restoreConfig
read

The message configuration to be used to for a dialog to ask for settings restore.

Default: A basic question messagebox

If you want to modify the text or options, you can replace the messagebox with another dialog.

Accessors
READrestoreConfig()
CONSTANT

Definition at line 28 of file settingsviewmodel.h.

◆ settingsSetupLoader

QtMvvm::SettingsViewModel::settingsSetupLoader
readwrite

The settings setup loader to use to create the settings dialog. Is an injected property.

Default: Injected

Do not set this property yourself. It is automatically injected when showing the viewmodel. You can use the ServiceRegistry::registerInterface if you need to use a loader different from the default one.

Accessors
READsettingsSetupLoader()
WRITEsetSettingsSetupLoader()
NOTIFYsettingsSetupLoaderChanged()
See also
QTMVVM_INJECT

Definition at line 31 of file settingsviewmodel.h.


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