QtMvvm  1.1.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() override;
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 
46  static InputViewFactory* getInputViewFactory();
47 
48  void present(ViewModel *viewModel, const QVariantHash &params, QPointer<ViewModel> parent) override;
49  void showDialog(const MessageConfig &config, MessageResult *result) override;
50 
52  virtual bool presentToQml(QObject *qmlPresenter, QObject *viewObject);
53 
55  InputViewFactory* inputViewFactory() const;
56 
57 public Q_SLOTS:
59  void setInputViewFactory(InputViewFactory* inputViewFactory);
60 
61 Q_SIGNALS:
63  void inputViewFactoryChanged(InputViewFactory* inputViewFactory, QPrivateSignal);
64 
65 protected:
67  virtual QUrl findViewUrl(const QMetaObject *viewModelType);
69  virtual int presentMethodIndex(const QMetaObject *presenterMetaObject, QObject *viewObject);
70 
72  bool nameOrClassContains(const QObject *obj, const QString &contained, Qt::CaseSensitivity caseSensitive = Qt::CaseInsensitive) const;
73 
74 private:
75  friend class QtMvvm::QuickPresenterPrivate;
76  QScopedPointer<QuickPresenterPrivate> d;
77 };
78 
79 template<typename TPresenter>
80 void QuickPresenter::registerAsPresenter()
81 {
82  static_assert(std::is_base_of<QuickPresenter, TPresenter>::value, "TPresenter must inherit QtMvvm::QuickPresenter!");
84 }
85 
86 template<typename TViewModel>
88 {
89  static_assert(std::is_base_of<ViewModel, TViewModel>::value, "TViewModel must inherit ViewModel!");
90  registerViewExplicitly(&TViewModel::staticMetaObject, viewUrl);
91 }
92 
93 
94 }
95 
96 #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:20
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:21
The IPresenter implementation for the quick module.
A result watcher to get the result once a dialog has finished.
Definition: message.h:204
The primary namespace of the QtMvvm library.
void registerInterface(DestructionScope scope=DestroyOnAppDestroy, bool weak=false)
Register a service for its interface via the type.
static ServiceRegistry * instance()
Returns the ServiceRegistry singleton instance.