The base class for all viewmodels. More...
#include <viewmodel.h>
Public Slots | |
virtual void | onInit (const QVariantHash ¶ms) |
Called by the presenter to initialize the viewmodel. More... | |
virtual void | onResult (quint32 requestCode, const QVariant &result) |
Called by the presenter when a result of a showed viewmodel is ready. More... | |
Signals | |
void | resultReady (const QVariant &result) |
Should be emitted when the viewmodels result is ready. More... | |
QTMVVM_REVISION_1 void | instanceInvoked (const QVariantHash ¶ms, QPrivateSignal) |
Is emitted on single instance viewmodels when they get shown again. More... | |
Public Member Functions | |
ViewModel (QObject *parent=nullptr) | |
Default constructor with parent. | |
Public Member Functions inherited from QObject | |
virtual const QMetaObject * | metaObject () 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) |
QThread * | thread () 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) |
T | 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 ®Exp, 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< QByteArray > | dynamicPropertyNames () const const |
void | destroyed (QObject *obj) |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
bool | inherits (const char *className) const const |
void | deleteLater () |
Protected Member Functions | |
template<typename TViewModel > | |
void | show (const QVariantHash ¶ms={}) const |
Show another viewmodel as a child of this one. More... | |
void | show (const char *viewModelName, const QVariantHash ¶ms={}) const |
Show another viewmodel as a child of this one. More... | |
void | show (const QMetaObject *viewMetaObject, const QVariantHash ¶ms={}) const |
Show another viewmodel as a child of this one. More... | |
template<typename TViewModel > | |
void | showForResult (quint32 requestCode, const QVariantHash ¶ms={}) const |
Show another viewmodel as a child of this one and expect its result. More... | |
void | showForResult (quint32 requestCode, const char *viewModelName, const QVariantHash ¶ms={}) const |
Show another viewmodel as a child of this one and expect its result. More... | |
void | showForResult (quint32 requestCode, const QMetaObject *viewMetaObject, const QVariantHash ¶ms={}) const |
Show another viewmodel as a child of this one and expect its result. More... | |
Protected Member Functions inherited from QObject | |
QObject * | sender () 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) |
Additional Inherited Members | |
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) |
Properties inherited from QObject | |
objectName | |
The base class for all viewmodels.
The ViewModel is the primary class of the core library is must be implemented to create custom viewmodels to be shown via the mvvm mechanism. To create a custom viewmodel, simply implement this class and show the viewmodel via one of the show methods. Viewmodels presented that way support automatic injection via injectable properties.
Normally, showing a viewmodel will always create a new instance of it, and thus show a new gui. However, by adding the QTMVVM_SINGLETON macro to the class definition, your viewmodel becomes a single instance. This means, it will only be created once, and subsequent show requests will instead only trigger the instanceInvoked() signal on the existing instance.
If the existing instance gets destroyed at some point, show requests will show a new instance.
Some viewmodel require a special viewmodel as their parent to be show in. To simplify the handling of those viewmodel, you can specify a parent container for a viewmodel via the QTMVVM_CONTAINER_VM macro. If added, everytime you try to show a viewmodel of this kind, the presenter will first create a new viewmodel of the type specified by the macro, and then show the original viewmodel immediatly after as child of the newly created parent. (The parent and the child can both be singletons)
You can specify parameters to be passed to the parent that is to be created via a special parameter named "qtmvvm_container_params"
. The value of that property must be a variant hash as well. In addition, a special parameter is added to the parent parameter, the "qtmvvm_container_for"
parameter, which contains the name of the viewmodel that triggered its creation.
Definition at line 21 of file viewmodel.h.
|
signal |
Is emitted on single instance viewmodels when they get shown again.
params | The show parameters that were passed to the show method |
If this viewmodel is a single instance viewmodel (QTMVVM_SINGLETON), then only the first show will actually create a viewmodel. All subsequent shows for that type will instead trigger this signal on the existing instance.
|
virtualslot |
Called by the presenter to initialize the viewmodel.
params | The 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.
Reimplemented in QtMvvm::DataSyncViewModel, QtMvvm::SettingsViewModel, QtMvvm::NetworkExchangeViewModel, and QtMvvm::DataSyncSettingsViewModel.
|
virtualslot |
Called by the presenter when a result of a showed viewmodel is ready.
requestCode | The request code of the show request for the viewmodel that triggered the result |
result | The result passed from the viewmodel |
When showing a child viewmodel via showForResult(), then the result of that show request is reported back via this function. The requestCode is the one that was passed to the showForResult() method, and the result what the viewmodel reported back. If the showed viewmodel emitted resultReady() before beeing destroyed, this value passed to that signal is whats reported as result. If the child viewmodel gets destroyed without ever emitting that signal, this method is still called, but with an invalid QVariant as result.
Reimplemented in QtMvvm::DataSyncViewModel, and QtMvvm::NetworkExchangeViewModel.
|
signal |
Should be emitted when the viewmodels result is ready.
result | The result that should be passed to the parent viewmodel |
Viewmodels that have been created via showForResult() must emit this signal to report back the result of the show request. Doing so will lead to the onResult() method of the showing viewmodel beeing with the emitted result as second parameter. Not emitting this signal before the viewmodel gets destroy leads to the onResult() beeing called with an invalid result.
|
inlineprotected |
Show another viewmodel as a child of this one.
params | The show parameters to be passed to the created viewmodel |
This method will send a show request to the core app to show a viewmodel of the given type. The parameters are passed to the onInit() method by the presenter after creating and parenting the view. The viewmodel will be shown asynchronously, so this method will return immediatly.
Definition at line 77 of file viewmodel.h.
|
protected |
Show another viewmodel as a child of this one.
viewModelName | The name of the viewmodel class to be shown |
params | The show parameters to be passed to the created viewmodel |
This method will send a show request to the core app to show a viewmodel of the given type. The parameters are passed to the onInit() method by the presenter after creating and parenting the view. The viewmodel will be shown asynchronously, so this method will return immediatly.
|
protected |
Show another viewmodel as a child of this one.
viewMetaObject | The metaobject of the viewmodel class to be shown |
params | The show parameters to be passed to the created viewmodel |
This method will send a show request to the core app to show a viewmodel of the given type. The parameters are passed to the onInit() method by the presenter after creating and parenting the view. The viewmodel will be shown asynchronously, so this method will return immediatly.
|
inlineprotected |
Show another viewmodel as a child of this one and expect its result.
requestCode | The code of the show request |
params | The show parameters to be passed to the created viewmodel |
This method will send a show request to the core app to show a viewmodel of the given type. The parameters are passed to the onInit() method by the presenter after creating and parenting the view. The viewmodel will be shown asynchronously, so this method will return immediatly. The viewmodel is show for a result, meaning that a result is reported back via onInit() as soon as the shown viewmodel emits resultReady() or has been destroyed. The request code is passed to the onResult() method in order to identify the show request.
Definition at line 84 of file viewmodel.h.
|
protected |
Show another viewmodel as a child of this one and expect its result.
viewModelName | The name of the viewmodel class to be shown |
requestCode | The code of the show request |
params | The show parameters to be passed to the created viewmodel |
This method will send a show request to the core app to show a viewmodel of the given type. The parameters are passed to the onInit() method by the presenter after creating and parenting the view. The viewmodel will be shown asynchronously, so this method will return immediatly. The viewmodel is show for a result, meaning that a result is reported back via onInit() as soon as the shown viewmodel emits resultReady() or has been destroyed. The request code is passed to the onResult() method in order to identify the show request.
|
protected |
Show another viewmodel as a child of this one and expect its result.
viewMetaObject | The metaobject of the viewmodel class to be shown |
requestCode | The code of the show request |
params | The show parameters to be passed to the created viewmodel |
This method will send a show request to the core app to show a viewmodel of the given type. The parameters are passed to the onInit() method by the presenter after creating and parenting the view. The viewmodel will be shown asynchronously, so this method will return immediatly. The viewmodel is show for a result, meaning that a result is reported back via onInit() as soon as the shown viewmodel emits resultReady() or has been destroyed. The request code is passed to the onResult() method in order to identify the show request.