QtMvvm  1.1.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
Public Member Functions | List of all members
QtMvvm::IPresenter Class Referenceabstract

The interface for a GUI view presenter. More...

#include <ipresenter.h>

+ Inheritance diagram for QtMvvm::IPresenter:

Public Member Functions

virtual void present (ViewModel *viewModel, const QVariantHash &params, QPointer< ViewModel > parent=nullptr)=0
 Called to present a viewmodel. More...
 
virtual void showDialog (const MessageConfig &config, MessageResult *result)=0
 Called to present a dialog via a message config. More...
 

Detailed Description

The interface for a GUI view presenter.

This class is what you need to implement if you want to create your own GUI frontend for mvvm. Once you created your custom presenter class, register it as service before calling CoreApp::bootApp() (Or entering the eventloop, in case of automatic startup, like with QTMVVM_REGISTER_CORE_APP)

To register it, it is recommended to use a startup hook like this:

void myPresenterInit()
{
}
Q_COREAPP_STARTUP_FUNCTION(myPresenterInit)
See also
QtMvvm_IPresenterIid

Definition at line 36 of file ipresenter.h.

Member Function Documentation

◆ present()

QtMvvm::IPresenter::present ( ViewModel viewModel,
const QVariantHash &  params,
QPointer< ViewModel parent = nullptr 
)
pure virtual

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

Implemented in QtMvvm::WidgetsPresenter, and QtMvvm::QuickPresenter.

◆ showDialog()

QtMvvm::IPresenter::showDialog ( const MessageConfig config,
MessageResult result 
)
pure virtual

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

Implemented in QtMvvm::WidgetsPresenter, and QtMvvm::QuickPresenter.


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