6#include <qqmlregistration.h>
9#include "qml_material/export.hpp"
10#include "qml_material/util/pool.hpp"
18class PresentationAttached;
20class QML_MATERIAL_API PopupPresentation :
public QObject {
22 QML_NAMED_ELEMENT(PopupPresentation)
23 QML_UNCREATABLE(
"PopupPresentation objects are returned by PopupPresenter.present()")
25 Q_PROPERTY(Status status READ status NOTIFY statusChanged FINAL)
26 Q_PROPERTY(
bool active READ active NOTIFY activeChanged FINAL)
27 Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged FINAL)
28 Q_PROPERTY(QVariant result READ result NOTIFY resultChanged FINAL)
44 ~PopupPresentation()
override;
46 auto status() const -> Status;
47 auto active() const ->
bool;
48 auto errorString() const -> QString;
49 auto result() const -> QVariant;
51 Q_INVOKABLE
void close();
52 Q_INVOKABLE
void cancel();
54 Q_SIGNAL
void statusChanged();
55 Q_SIGNAL
void activeChanged();
56 Q_SIGNAL
void errorStringChanged();
57 Q_SIGNAL
void resultChanged();
58 Q_SIGNAL
void opened();
59 Q_SIGNAL
void completed(const QVariant& result);
60 Q_SIGNAL
void closed();
61 Q_SIGNAL
void failed(const QString& error);
62 Q_SIGNAL
void cancelled();
69 friend class PopupPresenter;
70 friend class PresentationAttached;
80 explicit PopupPresentation(PopupPresenter* presenter);
82 void setStatus(Status value);
83 void setErrorString(QString value);
84 void setResult(QVariant value);
86 QPointer<PopupPresenter> m_presenter;
87 QPointer<PoolRequest> m_request;
88 QPointer<QObject> m_popup;
89 QPointer<PresentationAttached> m_attached;
90 Status m_status { Loading };
91 Finish m_finish { Finish::None };
92 QString m_errorString;
94 bool m_terminal {
false };
95 bool m_completed {
false };
98class QML_MATERIAL_API PresentationAttached final :
public QObject {
101 Q_PROPERTY(
bool ready READ ready WRITE setReady NOTIFY readyChanged FINAL)
104 explicit PresentationAttached(QObject* parent =
nullptr);
106 auto ready() const ->
bool;
107 void setReady(
bool value);
109 Q_INVOKABLE
void fail(const QString& error);
110 Q_INVOKABLE
void complete(const QVariant& result = {});
112 Q_SIGNAL
void readyChanged();
113 Q_SIGNAL
void failureReported(
const QString& error);
114 Q_SIGNAL
void completionRequested(
const QVariant& result);
117 friend class PopupPresenter;
119 void bind(PopupPresentation* presentation);
120 void unbind(PopupPresentation* presentation);
122 QPointer<PopupPresentation> m_presentation;
123 QString m_errorString;
124 bool m_ready {
true };
125 bool m_failed {
false };
128class QML_MATERIAL_API Presentation :
public QObject {
130 QML_NAMED_ELEMENT(Presentation)
131 QML_UNCREATABLE(
"Presentation is only available as an attached property")
132 QML_ATTACHED(PresentationAttached)
135 explicit Presentation(QObject* parent =
nullptr);
137 static PresentationAttached* qmlAttachedProperties(QObject*
object);
140class QML_MATERIAL_API PopupPresenter : public QObject {
144 Q_PROPERTY(QQuickItem* host READ host WRITE setHost NOTIFY hostChanged FINAL)
145 Q_PROPERTY(Pool::IncubationMode incubationMode READ incubationMode WRITE setIncubationMode
146 NOTIFY incubationModeChanged FINAL)
149 explicit PopupPresenter(QObject* parent =
nullptr);
150 ~PopupPresenter()
override;
152 auto host() const -> QQuickItem*;
153 void setHost(QQuickItem* value);
155 auto incubationMode() const -> Pool::IncubationMode;
156 void setIncubationMode(Pool::IncubationMode value);
158 Q_INVOKABLE PopupPresentation* present(const QVariant& source,
159 const QVariantMap& initialProperties = {});
160 Q_INVOKABLE
void closeAll();
162 Q_SIGNAL
void hostChanged();
163 Q_SIGNAL
void incubationModeChanged();
166 friend class PopupPresentation;
168 void requestClose(PopupPresentation* presentation, PopupPresentation::Finish finish);
169 void handleRequest(PopupPresentation* presentation);
170 void attachPopup(PopupPresentation* presentation, QObject* popup);
171 void openPopup(PopupPresentation* presentation);
172 void failPresentation(PopupPresentation* presentation, QString error);
173 void finishPresentation(PopupPresentation* presentation, PopupPresentation::Finish finish);
174 void completePresentation(PopupPresentation* presentation, QVariant result);
175 void popupOpened(PopupPresentation* presentation);
176 void popupClosed(PopupPresentation* presentation);
177 void popupDestroyed(PopupPresentation* presentation);
178 void presentationDestroyed(PopupPresentation* presentation);
179 void retire(PopupPresentation* presentation);
180 void ensurePoolContext();
182 QPointer<QQuickItem> m_host;
184 Pool::IncubationMode m_incubationMode { Pool::AsynchronousIfNested };
185 std::vector<QPointer<PopupPresentation>> m_presentations;
186 bool m_destroying {
false };