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 | Protected Member Functions | Properties | List of all members
QtMvvm::WidgetsPresenter Class Reference

The IPresenter implementation for the widgets module. More...

#include <widgetspresenter.h>

+ Inheritance diagram for QtMvvm::WidgetsPresenter:

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 &params, 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...
 
InputWidgetFactoryinputWidgetFactory () const
 READ accessor for WidgetsPresenter::inputWidgetFactory.
 
- 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

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 InputWidgetFactorygetInputWidgetFactory ()
 Returns the internally used input widget factory.
 
- 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 const QMetaObjectfindWidgetMetaObject (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...
 
- 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

InputWidgetFactory inputWidgetFactory
 The factory to create input widgets with, as injected property. More...
 
- Properties inherited from QObject
 objectName
 

Detailed Description

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.

Member Function Documentation

◆ findWidgetMetaObject()

QtMvvm::WidgetsPresenter::findWidgetMetaObject ( const QMetaObject viewModelMetaObject)
protectedvirtual

Is called to find the meta object of the view to be used for the given viewmodel.

Parameters
viewModelMetaObjectThe metobject of the viewmodel to find a view for
Returns
The metaobject of the view to used, or nullptr if none was found
Exceptions
PresenterExceptionIf 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.

◆ present()

void QtMvvm::WidgetsPresenter::present ( ViewModel viewModel,
const QVariantHash &  params,
QPointer< ViewModel parent 
)
overridevirtual

Called to present a viewmodel.

Parameters
viewModelThe ViewModel to be presenter
paramsAdditional parameters for the viemodel initialization
parentAn optional parent for the viewmodels view
Exceptions
PresenterExceptionWhen presenting fails for whatever reason

This method should:

  1. Find and create a view for the viewmodel
  2. Use the view of the parent viewModel to make the new view a child of that parent view
  3. Make the viewmodel a child of the view (via QObject::setParent)
  4. Call the viewmodels ViewModel::onInit method with the given parameters
  5. Find a presentation method for the view (based on the view/viewmodel and/or parent)
  6. Show the view to the user

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.

Note
If you need to present asynchronous, then you need to perform this step yourself in case the asynchronous presentation failed.
See also
IPresenter::showDialog

Implements QtMvvm::IPresenter.

◆ presentFileDialog()

QtMvvm::WidgetsPresenter::presentFileDialog ( const MessageConfig config,
QPointer< MessageResult result 
)
protectedvirtual

Called to present a dialog of MessageConfig::TypeFileDialog.

Parameters
configThe configuration of the file dialog
resultThe message result to report the result to
Exceptions
PresenterExceptionIf 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.

See also
WidgetsPresenter::showDialog

◆ presentInputDialog()

QtMvvm::WidgetsPresenter::presentInputDialog ( const MessageConfig config,
QPointer< MessageResult result 
)
protectedvirtual

Called to present a dialog of MessageConfig::TypeInputDialog.

Parameters
configThe configuration of the input dialog
resultThe message result to report the result to
Exceptions
PresenterExceptionIf 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.

See also
WidgetsPresenter::showDialog

◆ presentMessageBox()

QtMvvm::WidgetsPresenter::presentMessageBox ( const MessageConfig config,
QPointer< MessageResult result 
)
protectedvirtual

Called to present a dialog of MessageConfig::TypeMessageBox.

Parameters
configThe configuration of the message box
resultThe message result to report the result to
Exceptions
PresenterExceptionIf 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.

See also
WidgetsPresenter::showDialog

◆ presentOtherDialog()

QtMvvm::WidgetsPresenter::presentOtherDialog ( const MessageConfig config,
QPointer< MessageResult result 
)
protectedvirtual

Called to present a dialog of a non standard MessageConfig::type.

Parameters
configThe configuration of the dialog
resultThe message result to report the result to
Exceptions
PresenterExceptionIf 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.

See also
WidgetsPresenter::showDialog

◆ registerView() [1/2]

template<typename TView >
QtMvvm::WidgetsPresenter::registerView ( )
static

Register a view to be found by the presenter.

Template Parameters
TViewThe 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, ...

Note
Implicit detection of views for viewmodels can sometimes lead to ambiguities and thus a wrong view beeing found. In such cases, use registerViewExplicitly() instead.
See also
WidgetsPresenter::registerViewExplicitly

Definition at line 102 of file widgetspresenter.h.

◆ registerView() [2/2]

QtMvvm::WidgetsPresenter::registerView ( const QMetaObject viewType)
static

Register a view to be found by the presenter.

Parameters
viewTypeThe 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, ...

Note
Implicit detection of views for viewmodels can sometimes lead to ambiguities and thus a wrong view beeing found. In such cases, use registerViewExplicitly() instead.
See also
WidgetsPresenter::registerViewExplicitly

◆ registerViewExplicitly() [1/2]

template<typename TViewModel , typename TView >
QtMvvm::WidgetsPresenter::registerViewExplicitly ( )
static

Register a view for a viewmodel to be found by the presenter.

Template Parameters
TViewModelThe viewmodel to to register the view for
TViewThe 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.

See also
WidgetsPresenter::registerView

Definition at line 113 of file widgetspresenter.h.

◆ registerViewExplicitly() [2/2]

QtMvvm::WidgetsPresenter::registerViewExplicitly ( const QMetaObject viewModelType,
const QMetaObject viewType 
)
static

Register a view for a viewmodel to be found by the presenter.

Parameters
viewModelTypeThe viewmodel to to register the view for
viewTypeThe 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.

See also
WidgetsPresenter::registerView

◆ showDialog()

void QtMvvm::WidgetsPresenter::showDialog ( const MessageConfig config,
MessageResult result 
)
overridevirtual

Called to present a dialog via a message config.

Parameters
configThe configuration for the dialog to be shown
resultA reference to the object to report results to
Exceptions
PresenterExceptionWhen 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.

Note
If you need to present asynchronous, then you need to perform this step yourself in case the asynchronous presentation failed.
See also
IPresenter::present, MessageConfig, MessageResult, MessageResult::complete, MessageResult::setCloseTarget

Implements QtMvvm::IPresenter.

◆ showForeground()

QtMvvm::WidgetsPresenter::showForeground ( QWidget view) const
protectedvirtual

Called to show a widget in the foreground.

Parameters
viewThe 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.

See also
WidgetsPresenter::tryPresent

◆ tryPresent()

QtMvvm::WidgetsPresenter::tryPresent ( QWidget view,
QWidget parentView 
)
protectedvirtual

Try to present the given view on the parent view.

Parameters
viewThe view to be presented
parentViewThe parent view to present the view to
Returns
true if successfully presented, false if not

This 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.

See also
WidgetsPresenter::showForeground, QDialog, QMainWindow, QDockWidget, QMdiArea

Property Documentation

◆ inputWidgetFactory

QtMvvm::WidgetsPresenter::inputWidgetFactory
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
READinputWidgetFactory()
WRITEsetInputWidgetFactory()
NOTIFYinputWidgetFactoryChanged()
See also
QTMVVM_INJECT

Definition at line 25 of file widgetspresenter.h.


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