QtMvvm  1.0.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
quickpresenter.h
1 #ifndef QTMVVM_QUICKPRESENTER_H
2 #define QTMVVM_QUICKPRESENTER_H
3 
4 #include <QtCore/qobject.h>
5 #include <QtCore/qscopedpointer.h>
6 #include <QtCore/qurl.h>
7 #include <QtCore/qmetaobject.h>
8 
9 #include <QtMvvmCore/ipresenter.h>
10 #include <QtMvvmCore/serviceregistry.h>
11 
12 #include "QtMvvmQuick/qtmvvmquick_global.h"
13 #include "QtMvvmQuick/inputviewfactory.h"
14 
15 namespace QtMvvm {
16 
17 class QuickPresenterPrivate;
19 class Q_MVVMQUICK_EXPORT QuickPresenter : public QObject, public IPresenter
20 {
21  Q_OBJECT
22  Q_INTERFACES(QtMvvm::IPresenter)
23 
24 
25  Q_PROPERTY(InputViewFactory* inputViewFactory READ inputViewFactory WRITE setInputViewFactory NOTIFY inputViewFactoryChanged)
26  QTMVVM_INJECT(InputViewFactory*, inputViewFactory)
27 
28 public:
30  Q_INVOKABLE explicit QuickPresenter(QObject *parent = nullptr);
31  ~QuickPresenter();
32 
34  template <typename TPresenter>
35  static void registerAsPresenter();
36 
38  static void addViewSearchDir(const QString &dirPath);
40  template <typename TViewModel>
41  static void registerViewExplicitly(const QUrl &viewUrl);
43  static void registerViewExplicitly(const QMetaObject *viewModelType, const QUrl &viewUrl);
44 
45  void present(ViewModel *viewModel, const QVariantHash &params, QPointer<ViewModel> parent) override;
46  void showDialog(const MessageConfig &config, MessageResult *result) override;
47 
49  virtual bool presentToQml(QObject *qmlPresenter, QObject *viewObject);
50 
52  InputViewFactory* inputViewFactory() const;
53 
54 public Q_SLOTS:
56  void setInputViewFactory(InputViewFactory* inputViewFactory);
57 
58 Q_SIGNALS:
60  void inputViewFactoryChanged(InputViewFactory* inputViewFactory, QPrivateSignal);
61 
62 protected:
64  virtual QUrl findViewUrl(const QMetaObject *viewModelType);
66  virtual int presentMethodIndex(const QMetaObject *presenterMetaObject, QObject *viewObject);
67 
69  bool nameOrClassContains(const QObject *obj, const QString &contained, Qt::CaseSensitivity caseSensitive = Qt::CaseInsensitive) const;
70 
71 private:
72  friend class QtMvvm::QuickPresenterPrivate;
73  QScopedPointer<QuickPresenterPrivate> d;
74 };
75 
76 template<typename TPresenter>
77 void QuickPresenter::registerAsPresenter()
78 {
79  static_assert(std::is_base_of<QuickPresenter, TPresenter>::value, "TPresenter must inherit QtMvvm::QuickPresenter!");
81 }
82 
83 template<typename TViewModel>
85 {
86  static_assert(std::is_base_of<ViewModel, TViewModel>::value, "TViewModel must inherit ViewModel!");
87  registerViewExplicitly(&TViewModel::staticMetaObject, viewUrl);
88 }
89 
90 
91 }
92 
93 #endif // QTMVVM_QUICKPRESENTER_H
A factory class to generate input edit views by their type names.
A configuration for a simple dialog to be shown from the core code.
Definition: message.h:18
static void registerViewExplicitly(const QUrl &viewUrl)
Register a view for a viewmodel to be found by the presenter.
The interface for a GUI view presenter.
Definition: ipresenter.h:36
#define QTMVVM_INJECT(classType, name)
Mark a property for injection.
The base class for all viewmodels.
Definition: viewmodel.h:20
The IPresenter implementation for the quick module.
A result watcher to get the result once a dialog has finished.
Definition: message.h:172
The primary namespace of the QtMvvm library.
Definition: binding.h:10
void registerInterface(bool weak=false)
Register a service for its interface via the type.
static ServiceRegistry * instance()
Returns the ServiceRegistry singleton instance.