The IPresenter implementation for the widgets module. More...
#include <widgetspresenter.h>
Public Slots | |
void | setInputWidgetFactory (InputWidgetFactory *inputWidgetFactory) |
WRITE accessor for WidgetsPresenter::inputWidgetFactory. | |
Signals | |
void | inputWidgetFactoryChanged (InputWidgetFactory *inputWidgetFactory, QPrivateSignal) |
NOTIFY accessor for WidgetsPresenter::inputWidgetFactory. | |
Public Member Functions | |
Q_INVOKABLE | WidgetsPresenter (QObject *parent=nullptr) |
Invokable constructor. | |
void | present (ViewModel *viewModel, const QVariantHash ¶ms, QPointer< ViewModel > parent) override |
Called to present a viewmodel. More... | |
void | showDialog (const MessageConfig &config, MessageResult *result) override |
Called to present a dialog via a message config. More... | |
InputWidgetFactory * | inputWidgetFactory () const |
READ accessor for WidgetsPresenter::inputWidgetFactory. | |
![]() | |
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 | |
template<typename TPresenter > | |
static void | registerAsPresenter () |
Register a subclass of the WidgetsPresenter as the active presenter for the CoreApp. | |
template<typename TView > | |
static void | registerView () |
Register a view to be found by the presenter. More... | |
static void | registerView (const QMetaObject *viewType) |
Register a view to be found by the presenter. More... | |
template<typename TViewModel , typename TView > | |
static void | registerViewExplicitly () |
Register a view for a viewmodel to be found by the presenter. More... | |
static void | registerViewExplicitly (const QMetaObject *viewModelType, const QMetaObject *viewType) |
Register a view for a viewmodel to be found by the presenter. More... | |
static InputWidgetFactory * | getInputWidgetFactory () |
Returns the internally used input widget factory. | |
![]() | |
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 const QMetaObject * | findWidgetMetaObject (const QMetaObject *viewModelMetaObject) |
Is called to find the meta object of the view to be used for the given viewmodel. More... | |
virtual bool | tryPresent (QWidget *view, QWidget *parentView) |
Try to present the given view on the parent view. More... | |
virtual void | showForeground (QWidget *view) const |
Called to show a widget in the foreground. More... | |
virtual void | presentMessageBox (const MessageConfig &config, QPointer< MessageResult > result) |
Called to present a dialog of MessageConfig::TypeMessageBox. More... | |
virtual void | presentInputDialog (const MessageConfig &config, QPointer< MessageResult > result) |
Called to present a dialog of MessageConfig::TypeInputDialog. More... | |
virtual void | presentFileDialog (const MessageConfig &config, QPointer< MessageResult > result) |
Called to present a dialog of MessageConfig::TypeFileDialog. More... | |
void | presentColorDialog (const MessageConfig &config, const QPointer< MessageResult > &result) |
Called to present a dialog of MessageConfig::TypeColorDialog. | |
void | presentProgressDialog (const MessageConfig &config, const QPointer< MessageResult > &result) |
Called to present a dialog of MessageConfig::TypeProgressDialog. | |
virtual void | presentOtherDialog (const MessageConfig &config, QPointer< MessageResult > result) |
Called to present a dialog of a non standard MessageConfig::type. More... | |
![]() | |
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) |
Properties | |
InputWidgetFactory | inputWidgetFactory |
The factory to create input widgets with, as injected property. More... | |
![]() | |
objectName | |
The IPresenter implementation for the widgets module.
This presenter is automatically registered as the default presenter for the IPresenter interface with the ServiceRegistry, but as weak service, in order to make it possible to overwrite it.
The class handles all the logic required for presenting widget based views. You can extend this class and reimplement it's virtual methods if you need to adjust how certain views or dialogs are presented, or if you want to support custom stuff
Definition at line 19 of file widgetspresenter.h.
|
protectedvirtual |
Is called to find the meta object of the view to be used for the given viewmodel.
viewModelMetaObject | The metobject of the viewmodel to find a view for |
nullptr
if none was found PresenterException | If no view could be found |
The default implementation simply check all explicitly registered views and then tries to match the name with the implicitly registered ones. If no match if found, the same is tried for the parent viewmodel type recursively, until the ViewModel base is reached.
|
overridevirtual |
Called to present a viewmodel.
viewModel | The ViewModel to be presenter |
params | Additional parameters for the viemodel initialization |
parent | An optional parent for the viewmodels view |
PresenterException | When presenting fails for whatever reason |
This method should:
If this method returns it is assumed the presentation was successful. If you throw the exception, presenting has failed, and the app will automatically destroy the viewmodel and handle cleanups and results.
Implements QtMvvm::IPresenter.
|
protectedvirtual |
Called to present a dialog of MessageConfig::TypeFileDialog.
config | The configuration of the file dialog |
result | The message result to report the result to |
PresenterException | If presenting the dialog failed |
This method is called by showDialog() to present a dialog from a message config with the MessageConfig::type set to MessageConfig::TypeFileDialog. You can override it to customize how to show them.
|
protectedvirtual |
Called to present a dialog of MessageConfig::TypeInputDialog.
config | The configuration of the input dialog |
result | The message result to report the result to |
PresenterException | If presenting the dialog failed |
This method is called by showDialog() to present a dialog from a message config with the MessageConfig::type set to MessageConfig::TypeInputDialog. You can override it to customize how to show them.
|
protectedvirtual |
Called to present a dialog of MessageConfig::TypeMessageBox.
config | The configuration of the message box |
result | The message result to report the result to |
PresenterException | If presenting the dialog failed |
This method is called by showDialog() to present a dialog from a message config with the MessageConfig::type set to MessageConfig::TypeMessageBox. You can override it to customize how to show them.
|
protectedvirtual |
Called to present a dialog of a non standard MessageConfig::type.
config | The configuration of the dialog |
result | The message result to report the result to |
PresenterException | If presenting the dialog failed |
This method is called by showDialog() to present a dialog from a message config with the MessageConfig::type set to to custom type (i.e. none of the 3 default types). The default implementation simply throws the PresenterException. If you want to support additional types to the 3 default types, reimplement this method to do so.
|
static |
Register a view to be found by the presenter.
TView | The widget type register within the presenter. Must extend QWidget |
The widget is registered with the current presenter. It is registered implicitly, which means that it's name will be used to find it when a viewmodel is presented for it. Thus, it must be named after the viewmodel. If the viewmodel is for example named MyViewModel
, then the view must start with My
too. For example it can be named MyWidget
, MyDialog
, MyWindow
, MyView
, ...
Definition at line 102 of file widgetspresenter.h.
|
static |
Register a view to be found by the presenter.
viewType | The widget type register within the presenter. Must extend QWidget |
The widget is registered with the current presenter. It is registered implicitly, which means that it's name will be used to find it when a viewmodel is presented for it. Thus, it must be named after the viewmodel. If the viewmodel is for example named MyViewModel
, then the view must start with My
too. For example it can be named MyWidget
, MyDialog
, MyWindow
, MyView
, ...
|
static |
Register a view for a viewmodel to be found by the presenter.
TViewModel | The viewmodel to to register the view for |
TView | The widget type register within the presenter. Must extend QWidget |
The widget is registered with the current presenter. It is registered explicitly, which means that whenever the given viewmodel is beeing presented, this exact view will be used. Explicit registration have precedence over implicit ones.
Definition at line 113 of file widgetspresenter.h.
|
static |
Register a view for a viewmodel to be found by the presenter.
viewModelType | The viewmodel to to register the view for |
viewType | The widget type register within the presenter. Must extend QWidget |
The widget is registered with the current presenter. It is registered explicitly, which means that whenever the given viewmodel is beeing presented, this exact view will be used. Explicit registration have precedence over implicit ones.
|
overridevirtual |
Called to present a dialog via a message config.
config | The configuration for the dialog to be shown |
result | A reference to the object to report results to |
PresenterException | When presenting fails for whatever reason |
This method should create a simple dialog based of the configuration passed to it. Read the MessageConfig for more details on the parameters. The MessageConfig::type and MessageConfig::subType properties are used to determine the kind of dialog to be shown. The other properties are used to configure the dialog.
The result is a reference to a result object to report the result value and the pressed button to. The result is owned by the caller, you must never delete it. Use the special "GUI methods" to report the result and configure a close target.
If this method returns it is assumed the presentation was successful. If you throw the exception, presenting has failed, and the app will automatically complete the message result with the MessageConfig::NoButton constant.
Implements QtMvvm::IPresenter.
|
protectedvirtual |
Called to show a widget in the foreground.
view | The view to be presented |
This method is called by tryPresent() to simply show a standard window. The method however does not only show the window, but also makes shure it becomes the currently active foreground window.
Try to present the given view on the parent view.
view | The view to be presented |
parentView | The parent view to present the view to |
true
if successfully presented, false
if notThis method is called to perform the actual presentation (i.e. the parenting and how to show) the view. The default implementation first checks if the parent implements IPresentingView and if yes if it is able to present the view. If not, a bunch of standard widget types are checked for special presentation methods. QDialogs are presented via QDialog::open. QDockWidgets that are presented to a QMainWindow are added as dock widget (QMainWindow::addDockWidget). If the parent or its central widget are a QMdiArea, and the views class name ends with MdiWindow
, it is presented as QMdiSubWindow. For all other cases, showForeground() is called.
|
readwrite |
The factory to create input widgets with, as 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 factory different from the default one.
Accessors | |
---|---|
READ | inputWidgetFactory() |
WRITE | setInputWidgetFactory() |
NOTIFY | inputWidgetFactoryChanged() |
Definition at line 25 of file widgetspresenter.h.