A logicaly application object to drive the mvvm application from the core part. More...
#include <coreapp.h>
Public Slots | |
void | bootApp () |
Boots up the app and starts the mvvm presenting. More... | |
Signals | |
void | appStarted (QPrivateSignal) |
Is emitted once the app has successfully started. | |
Public Member Functions | |
CoreApp (QObject *parent=nullptr) | |
Default Constructor. | |
void | registerApp () |
Registers this instance as the CoreApp instance. More... | |
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 () |
Static Public Member Functions | |
static CoreApp * | instance () |
Returns the current CoreApp instance. | |
static void | disableAutoBoot () |
Disables the automatic startup of the CoreApp. More... | |
template<typename TViewModel > | |
static void | show (const QVariantHash ¶ms={}, QPointer< ViewModel > parentViewModel=nullptr) |
Show a new ViewModel by its type. More... | |
static void | show (const char *viewModelName, const QVariantHash ¶ms={}) |
Show a new ViewModel by its name. More... | |
static void | show (const char *viewModelName, const QVariantHash ¶ms, QPointer< ViewModel > parentViewModel) |
Show a new ViewModel by its name. More... | |
static void | show (const QMetaObject *viewModelMetaObject, const QVariantHash ¶ms={}) |
Show a new ViewModel by its metaobject. More... | |
static void | show (const QMetaObject *viewModelMetaObject, const QVariantHash ¶ms, QPointer< ViewModel > parentViewModel) |
Show a new ViewModel by its metaobject. More... | |
static MessageResult * | showDialog (const MessageConfig &config) |
Show a basic dialog. More... | |
static QVariant | safeCastInputType (const QByteArray &type, const QVariant &value) |
Safely casts a value of the given edit type to the corresponding variant type. More... | |
template<typename T > | |
static void | registerInputTypeMapping (const QByteArray &type) |
Register a type to be used as variant type for the given edit type. More... | |
static void | registerInputTypeMapping (const QByteArray &type, int targetType) |
Register a type to be used as variant type for the given edit type. More... | |
static IPresenter * | presenter () |
Returns the currently used presenter. | |
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 | |
virtual void | performRegistrations () |
Is called as part of the app registration, before any view setups. More... | |
virtual int | startApp (const QStringList &arguments)=0 |
Is called as part of the app start/boot, after all the view setups to start the app. More... | |
virtual void | closeApp () |
Is called when the app is about to quit. More... | |
bool | autoParse (QCommandLineParser &parser, const QStringList &arguments) |
Can be used to automatically handle help and version commandline arguments. 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 | |
Properties inherited from QObject | |
objectName | |
A logicaly application object to drive the mvvm application from the core part.
Every QtMvvm Application needs a core application that performs the application setup and manages the ViewModels in order to present them. If you want to use QtMvvm, you need to perform the following steps:
Simple example for a custom CoreApp:
Then in the GUI project add to, for example, the main.cpp
:
When using the app that way, a 3-step startup is performed:
|
protected |
Can be used to automatically handle help and version commandline arguments.
parser | A reference to the commandline parser to use |
arguments | The arguments to be parsed |
true
If parsing was successfull and you can continue starting the AppUse this method in your startApp() implementation in order to automatically handle special cases:
--help
)--version
)For those three cases false
is returned and a dialog of the specific GUI shown to the user with either and error string, the help or the version information. To correctly use it, your startApp() function should look like this:
EXIT_SUCCESS
from the parser in order to actually show the dialogs to the user. Returning any other value would simply silently quit the application.
|
slot |
Boots up the app and starts the mvvm presenting.
Internally it performs the actual start of the application and calls startApp() to start all services and show the initial viewmodels.
If startApp() returned successfully, appStarted() is emitted and thus the startup completed.
|
protectedvirtual |
Is called when the app is about to quit.
Is connected to the QCoreApplication::aboutToQuit signal and is called to clean up your application. Using this method is more convenient as it is only called in case the startup was successfull (returned EXIT_SUCCESS
).
|
static |
Disables the automatic startup of the CoreApp.
In case you don't want your application be be started automatically whenQCoreApplication::exec is called, you must call this method before The QCoreApplication (or any other application) constructor is called:
In order to eventually start the app, simply call bootApp().
|
protectedvirtual |
Is called as part of the app registration, before any view setups.
Is called by registerApp() (and thus automatically when using the QTMVVM_REGISTER_CORE_APP macro) in order to perform initial registrations of types etc. before any such code is beeing executed for the gui projects.
QtMvvm::CoreApp::registerApp | ( | ) |
Registers this instance as the CoreApp instance.
Internally it performs some initial registrations, calls performRegistrations() and then schedules the automatic call of bootApp() if not disabled.
|
static |
Register a type to be used as variant type for the given edit type.
T | The C++ type to be registered for the given edit type |
type | The edit type to register the C++ type for |
Registeres the given type, so that whenever type is passed to safeCastInputType(), the given variant will be converter to T
|
static |
Register a type to be used as variant type for the given edit type.
type | The edit type to register the C++ type for |
targetType | The id of C++ type to be registered for the given edit type |
Registeres the given type, so that whenever type is passed to safeCastInputType(), the given variant will be converter to targetType
|
static |
Safely casts a value of the given edit type to the corresponding variant type.
type | The edit type the given value is supposed to be of |
value | The value to be cast to the type specified by the edit type |
The primary function of this method is to cast types like url
to their respective C++ equivalent, i.e. QUrl
. The table below shows the default type conversion map, and custom entries can be added via registerInputTypeMapping(). For all types not in that mapping, the function tries to see type
like a C++ typename, i.e. int
and use that to convert the variant. If no type can be determined, the value is returned without doing anything.
Edit-Type | C++-Type |
---|---|
switch | bool |
string | QString |
number | double |
range | int |
date | QDateTime |
color | QColor |
url | QUrl |
var | QVariant |
variant | QVariant |
selection | QVariant |
list | QVariant |
radiolist | QVariant |
|
inlinestatic |
Show a new ViewModel by its type.
TViewModel | The type of the viewmodel to be presented |
params | A map of named parameters to be passed to the viewmodel |
parentViewModel | The viewmodel to be used as logical parent to the new one, for presenting |
Creates a new instance of the Viewmodel class, creates to corresponding view and then shows it. This is done via the IPresenter that is currently registered.
|
static |
Show a new ViewModel by its name.
viewModelName | The name of the viewmodel to be presented |
params | A map of named parameters to be passed to the viewmodel |
parentViewModel | The viewmodel to be used as logical parent to the new one, for presenting |
Creates a new instance of the Viewmodel class, creates to corresponding view and then shows it. This is done via the IPresenter that is currently registered, taking the parent viewmodel into consideration where neccessary.
|
static |
Show a new ViewModel by its name.
viewModelName | The name of the viewmodel to be presented |
params | A map of named parameters to be passed to the viewmodel |
parentViewModel | The viewmodel to be used as logical parent to the new one, for presenting |
Creates a new instance of the Viewmodel class, creates to corresponding view and then shows it. This is done via the IPresenter that is currently registered, taking the parent viewmodel into consideration where neccessary.
|
static |
Show a new ViewModel by its metaobject.
viewModelMetaObject | The metaobject of the viewmodel to be presented |
params | A map of named parameters to be passed to the viewmodel |
parentViewModel | The viewmodel to be used as logical parent to the new one, for presenting |
Creates a new instance of the Viewmodel class, creates to corresponding view and then shows it. This is done via the IPresenter that is currently registered, taking the parent viewmodel into consideration where neccessary.
|
static |
Show a new ViewModel by its metaobject.
viewModelMetaObject | The metaobject of the viewmodel to be presented |
params | A map of named parameters to be passed to the viewmodel |
parentViewModel | The viewmodel to be used as logical parent to the new one, for presenting |
Creates a new instance of the Viewmodel class, creates to corresponding view and then shows it. This is done via the IPresenter that is currently registered, taking the parent viewmodel into consideration where neccessary.
|
static |
Show a basic dialog.
config | The configuration of the message to be shown |
The configuration is passed to the presenter in order to show a simple dialog. You can use the returned object to monitor the dialog and receive the result.
|
protectedpure virtual |
Is called as part of the app start/boot, after all the view setups to start the app.
arguments | The command line arguments that have been passed to the application |
Is called by bootApp() (and thus automatically when using the QTMVVM_REGISTER_CORE_APP macro) in order to start the app logic and show initial viewmodels. Return EXIT_SUCCESS
(0) to indicate the start was successful. If any other value is returned, the application exits with that value as return code.