diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-05-17 14:34:51 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-05-18 11:08:28 +0000 |
commit | 26bfe7cb1a5f068b5287174f113335c8731dac82 (patch) | |
tree | f12186d8ec7d02c0c64e968262c4dd3319ac07c8 /src | |
parent | 6bd301a56a4f7d010383ebcb04f7ef398b3be3ae (diff) |
Incorporate QQuickDialog::result from QQuickPlatformDialog
The experimental QQuickPlatformDialog in Qt.labs.platform had a bit
more elaborate accepted vs. rejected dialog result handling. Copy the
same logic to QQuickDialog in QtQuick.Controls.
[ChangeLog][Controls][Dialog] Added "result" property that holds
whether the dialog was previously accepted or rejected.
Change-Id: I2c55848b5eeaad2130d32a337c2590212736f22c
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quicktemplates2/qquickdialog.cpp | 57 | ||||
-rw-r--r-- | src/quicktemplates2/qquickdialog_p.h | 13 | ||||
-rw-r--r-- | src/quicktemplates2/qquickdialog_p_p.h | 3 |
3 files changed, 65 insertions, 8 deletions
diff --git a/src/quicktemplates2/qquickdialog.cpp b/src/quicktemplates2/qquickdialog.cpp index 3ac99caa..00719ae4 100644 --- a/src/quicktemplates2/qquickdialog.cpp +++ b/src/quicktemplates2/qquickdialog.cpp @@ -301,16 +301,43 @@ void QQuickDialog::setStandardButtons(QPlatformDialogHelper::StandardButtons but } /*! + \since QtQuick.Controls 2.3 + \qmlproperty int QtQuick.Controls::Dialog::result + + This property holds the result code. + + Standard result codes: + \value Dialog.Accepted The dialog was accepted. + \value Dialog.Rejected The dialog was rejected. + + \sa accept(), reject(), done() +*/ +int QQuickDialog::result() const +{ + Q_D(const QQuickDialog); + return d->result; +} + +void QQuickDialog::setResult(int result) +{ + Q_D(QQuickDialog); + if (d->result == result) + return; + + d->result = result; + emit resultChanged(); +} + +/*! \qmlmethod void QtQuick.Controls::Dialog::accept() Closes the dialog and emits the \l accepted() signal. - \sa reject() + \sa reject(), done() */ void QQuickDialog::accept() { - close(); - emit accepted(); + done(Accepted); } /*! @@ -318,12 +345,32 @@ void QQuickDialog::accept() Closes the dialog and emits the \l rejected() signal. - \sa accept() + \sa accept(), done() */ void QQuickDialog::reject() { + done(Rejected); +} + +/*! + \since QtQuick.Controls 2.3 + \qmlmethod void Qt.labs.platform::Dialog::done(int result) + + Closes the dialog, sets the \a result, and emits \l accepted() or + \l rejected() depending on whether the result is \c Dialog.Accepted + or \c Dialog.Rejected, respectively. + + \sa accept(), reject(), result +*/ +void QQuickDialog::done(int result) +{ close(); - emit rejected(); + setResult(result); + + if (result == Accepted) + emit accepted(); + else if (result == Rejected) + emit rejected(); } void QQuickDialog::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) diff --git a/src/quicktemplates2/qquickdialog_p.h b/src/quicktemplates2/qquickdialog_p.h index 97c90a59..0743ee0a 100644 --- a/src/quicktemplates2/qquickdialog_p.h +++ b/src/quicktemplates2/qquickdialog_p.h @@ -62,6 +62,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickDialog : public QQuickPopup Q_PROPERTY(QQuickItem *header READ header WRITE setHeader NOTIFY headerChanged FINAL) Q_PROPERTY(QQuickItem *footer READ footer WRITE setFooter NOTIFY footerChanged FINAL) Q_PROPERTY(QPlatformDialogHelper::StandardButtons standardButtons READ standardButtons WRITE setStandardButtons NOTIFY standardButtonsChanged FINAL) + Q_PROPERTY(int result READ result WRITE setResult NOTIFY resultChanged FINAL REVISION 3) Q_FLAGS(QPlatformDialogHelper::StandardButtons) public: @@ -79,9 +80,16 @@ public: QPlatformDialogHelper::StandardButtons standardButtons() const; void setStandardButtons(QPlatformDialogHelper::StandardButtons buttons); + enum StandardCode { Rejected, Accepted }; + Q_ENUM(StandardCode) + + int result() const; + void setResult(int result); + public Q_SLOTS: - void accept(); - void reject(); + virtual void accept(); + virtual void reject(); + virtual void done(int result); Q_SIGNALS: void accepted(); @@ -91,6 +99,7 @@ Q_SIGNALS: void headerChanged(); void footerChanged(); void standardButtonsChanged(); + Q_REVISION(3) void resultChanged(); protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; diff --git a/src/quicktemplates2/qquickdialog_p_p.h b/src/quicktemplates2/qquickdialog_p_p.h index 13885ca9..2a0f4b53 100644 --- a/src/quicktemplates2/qquickdialog_p_p.h +++ b/src/quicktemplates2/qquickdialog_p_p.h @@ -60,13 +60,14 @@ class QQuickDialogPrivate : public QQuickPopupPrivate Q_DECLARE_PUBLIC(QQuickDialog) public: - QQuickDialogPrivate() : buttonBox(nullptr) { } + QQuickDialogPrivate() : result(0), buttonBox(nullptr) { } static QQuickDialogPrivate *get(QQuickDialog *dialog) { return dialog->d_func(); } + int result; QString title; QQuickDialogButtonBox *buttonBox; QScopedPointer<QQuickPageLayout> layout; |