QtMvvm  1.0.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
qqmlquickpresenter.h
1 #ifndef QTMVVM_QQMLQUICKPRESENTER_H
2 #define QTMVVM_QQMLQUICKPRESENTER_H
3 
4 #include <tuple>
5 
6 #include <QtCore/QObject>
7 #include <QtCore/QCache>
8 #include <QtCore/QVariant>
9 #include <QtCore/QPointer>
10 #include <QtCore/QUrl>
11 
12 #include <QtQml/QQmlComponent>
13 
14 #include <QtMvvmCore/ViewModel>
15 #include <QtMvvmCore/Messages>
16 
17 #include <QtMvvmQuick/InputViewFactory>
18 
19 #ifdef DOXYGEN_RUN
21 
32 class QuickPresenter : public QtObject
33 #else
34 namespace QtMvvm {
35 
36 class QQmlQuickPresenter : public QObject
37 #endif
38 {
39  Q_OBJECT
40 
51  Q_PROPERTY(QString currentStyle READ currentStyle CONSTANT)
62  Q_PROPERTY(InputViewFactory* inputViewFactory READ inputViewFactory NOTIFY inputViewFactoryChanged)
63 
79  Q_PROPERTY(QObject* qmlPresenter MEMBER _qmlPresenter NOTIFY qmlPresenterChanged)
92  Q_PROPERTY(bool viewLoading READ isViewLoading NOTIFY viewLoadingChanged)
107  Q_PROPERTY(qreal loadingProgress READ loadingProgress NOTIFY loadingProgressChanged)
108 
109 public:
111  explicit QQmlQuickPresenter(QQmlEngine *engine);
112 
114  QString currentStyle() const;
116  InputViewFactory* inputViewFactory() const;
118  bool isViewLoading() const;
120  qreal loadingProgress() const;
121 
122 #ifndef DOXYGEN_RUN
123 #define static
124 #endif
125  Q_INVOKABLE static QStringList mimeTypeFilters(const QStringList &mimeTypes) const;
127 
128 #ifdef DOXYGEN_RUN
129 public:
130 #else
131 public Q_SLOTS:
132 #endif
133  static void toggleDrawer();
136  static void popView();
137 
139  static void hapticLongPress();
140 
141 #ifndef DOXYGEN_RUN
142 #undef static
143 #endif
144 
145 Q_SIGNALS:
149  void viewLoadingChanged(bool viewLoading);
151  void loadingProgressChanged(qreal loadingProgress);
153  void inputViewFactoryChanged(InputViewFactory* inputViewFactory);
154 
155 private Q_SLOTS:
156  void present(QtMvvm::ViewModel *viewModel, const QVariantHash &params, const QUrl &viewUrl, QPointer<QtMvvm::ViewModel> parent);
157  void showDialog(const QtMvvm::MessageConfig &config, QtMvvm::MessageResult *result);
158  void statusChanged(QQmlComponent::Status status);
159 
160 private:
161  typedef std::tuple<ViewModel*, QVariantHash, QPointer<ViewModel>> PresentTuple;
162  QQmlEngine *_engine;
163  QPointer<QObject> _qmlPresenter;
164 
165  QPointer<QQmlComponent> _latestComponent;
166  QCache<QUrl, QQmlComponent> _componentCache;
168 
169  void addObject(QQmlComponent *component, ViewModel *viewModel, const QVariantHash &params, QPointer<ViewModel> parent);
170 };
171 
172 }
173 
174 #endif // QTMVVM_QQMLQUICKPRESENTER_H
void qmlPresenterChanged(QObject *qmlPresenter)
NOTIFY accessor for QuickPresenter::qmlPresenter.
static void toggleDrawer()
Toggles the state of the current drawer, if any is beeing used.
static void popView()
Pops the current top level view.
QObject qmlPresenter
The primary presenter QML object.
A configuration for a simple dialog to be shown from the core code.
Definition: message.h:18
bool viewLoading
Specifies whether the presenter is currently loading a new view component.
void inputViewFactoryChanged(InputViewFactory *inputViewFactory)
NOTIFY accessor for QuickPresenter::inputViewFactory.
static Q_INVOKABLE QStringList mimeTypeFilters(const QStringList &mimeTypes) const
Converts a list of mimetypes into a list of extension filters, for a file dialog. ...
static void hapticLongPress()
Performs haptic feedback of a long press (Android only)
void viewLoadingChanged(bool viewLoading)
NOTIFY accessor for QuickPresenter::viewLoading.
void loadingProgressChanged(qreal loadingProgress)
NOTIFY accessor for QuickPresenter::loadingProgress.
The QML import for the QtMvvmQuick QML module.
Definition: ActionButton.qml:4
The base class for all viewmodels.
Definition: viewmodel.h:20
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
A QML singleton to access common presenter methods globally.