diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-08-14 16:36:57 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-08-14 14:40:49 +0000 |
commit | 8773fdb215709a6680070a462082a42aa3b82585 (patch) | |
tree | 3a29dc22a8fe21abb21890917107e3d52516304d /src/imports/platform | |
parent | 781aae2f348190796475bc28003813a9591678ed (diff) |
Platform: add Dialog::done(int) and Dialog::result
A more generic replacement for MessageDialog.clickedButton.
Change-Id: I060f70a48ab258485e3155188e483c4cf24210e0
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/imports/platform')
-rw-r--r-- | src/imports/platform/plugins.qmltypes | 17 | ||||
-rw-r--r-- | src/imports/platform/qquickplatformdialog.cpp | 49 | ||||
-rw-r--r-- | src/imports/platform/qquickplatformdialog_p.h | 10 | ||||
-rw-r--r-- | src/imports/platform/qquickplatformmessagedialog.cpp | 34 | ||||
-rw-r--r-- | src/imports/platform/qquickplatformmessagedialog_p.h | 5 |
5 files changed, 72 insertions, 43 deletions
diff --git a/src/imports/platform/plugins.qmltypes b/src/imports/platform/plugins.qmltypes index a6b80bda..2bee7276 100644 --- a/src/imports/platform/plugins.qmltypes +++ b/src/imports/platform/plugins.qmltypes @@ -83,18 +83,30 @@ Module { exports: ["Qt.labs.platform/Dialog 1.0"] isCreatable: false exportMetaObjectRevisions: [0] + Enum { + name: "StandardCode" + values: { + "Rejected": 0, + "Accepted": 1 + } + } Property { name: "data"; type: "QObject"; isList: true; isReadonly: true } Property { name: "parentWindow"; type: "QWindow"; isPointer: true } Property { name: "title"; type: "string" } Property { name: "flags"; type: "Qt::WindowFlags" } Property { name: "modality"; type: "Qt::WindowModality" } Property { name: "visible"; type: "bool" } + Property { name: "result"; type: "int" } Signal { name: "accepted" } Signal { name: "rejected" } Method { name: "open" } Method { name: "close" } Method { name: "accept" } Method { name: "reject" } + Method { + name: "done" + Parameter { name: "result"; type: "int" } + } } Component { name: "QQuickPlatformFileDialog" @@ -296,11 +308,6 @@ Module { Property { name: "informativeText"; type: "string" } Property { name: "detailedText"; type: "string" } Property { name: "buttons"; type: "QPlatformDialogHelper::StandardButtons" } - Property { - name: "clickedButton" - type: "QPlatformDialogHelper::StandardButton" - isReadonly: true - } Signal { name: "clicked" Parameter { name: "button"; type: "QPlatformDialogHelper::StandardButton" } diff --git a/src/imports/platform/qquickplatformdialog.cpp b/src/imports/platform/qquickplatformdialog.cpp index 924db815..62b4d974 100644 --- a/src/imports/platform/qquickplatformdialog.cpp +++ b/src/imports/platform/qquickplatformdialog.cpp @@ -85,6 +85,7 @@ QQuickPlatformDialog::QQuickPlatformDialog(QObject *parent) : QObject(parent), m_visible(false), m_complete(false), + m_result(0), m_parentWindow(nullptr), m_flags(Qt::Dialog), m_modality(Qt::WindowModal), @@ -220,6 +221,32 @@ void QQuickPlatformDialog::setVisible(bool visible) } /*! + \qmlproperty int Qt.labs.platform::Dialog::result + + This property holds the result code. + + Standard result codes: + \value Dialog.Accepted + \value Dialog.Rejected + + \note MessageDialog sets the result to the value of the clicked standard + button instead of using the standard result codes. +*/ +int QQuickPlatformDialog::result() const +{ + return m_result; +} + +void QQuickPlatformDialog::setResult(int result) +{ + if (m_result == result) + return; + + m_result = result; + emit resultChanged(); +} + +/*! \qmlmethod void Qt.labs.platform::Dialog::open() Opens the dialog. @@ -263,8 +290,7 @@ void QQuickPlatformDialog::close() */ void QQuickPlatformDialog::accept() { - close(); - emit accepted(); + done(Accepted); } /*! @@ -276,8 +302,25 @@ void QQuickPlatformDialog::accept() */ void QQuickPlatformDialog::reject() { + done(Rejected); +} + +/*! + \qmlmethod void Qt.labs.platform::Dialog::done(int result) + + Closes the dialog and sets the \a result. + + \sa accept(), reject(), result +*/ +void QQuickPlatformDialog::done(int result) +{ close(); - emit rejected(); + setResult(result); + + if (result == Accepted) + emit accepted(); + else if (result == Rejected) + emit rejected(); } void QQuickPlatformDialog::classBegin() diff --git a/src/imports/platform/qquickplatformdialog_p.h b/src/imports/platform/qquickplatformdialog_p.h index 23956270..212e1bd1 100644 --- a/src/imports/platform/qquickplatformdialog_p.h +++ b/src/imports/platform/qquickplatformdialog_p.h @@ -69,7 +69,9 @@ class QQuickPlatformDialog : public QObject, public QQmlParserStatus Q_PROPERTY(Qt::WindowFlags flags READ flags WRITE setFlags NOTIFY flagsChanged FINAL) Q_PROPERTY(Qt::WindowModality modality READ modality WRITE setModality NOTIFY modalityChanged FINAL) Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL) + Q_PROPERTY(int result READ result WRITE setResult NOTIFY resultChanged FINAL) Q_CLASSINFO("DefaultProperty", "data") + Q_ENUMS(StandardCode) public: explicit QQuickPlatformDialog(QObject *parent = nullptr); @@ -94,11 +96,17 @@ public: bool isVisible() const; void setVisible(bool visible); + enum StandardCode { Rejected, Accepted }; + + int result() const; + void setResult(int result); + public Q_SLOTS: void open(); void close(); virtual void accept(); virtual void reject(); + virtual void done(int result); Q_SIGNALS: void accepted(); @@ -108,6 +116,7 @@ Q_SIGNALS: void flagsChanged(); void modalityChanged(); void visibleChanged(); + void resultChanged(); protected: void classBegin() override; @@ -124,6 +133,7 @@ protected: private: bool m_visible; bool m_complete; + int m_result; QWindow *m_parentWindow; QString m_title; Qt::WindowFlags m_flags; diff --git a/src/imports/platform/qquickplatformmessagedialog.cpp b/src/imports/platform/qquickplatformmessagedialog.cpp index 68ef3553..b9395eba 100644 --- a/src/imports/platform/qquickplatformmessagedialog.cpp +++ b/src/imports/platform/qquickplatformmessagedialog.cpp @@ -119,7 +119,7 @@ QT_BEGIN_NAMESPACE This signal is emitted when a dialog \a button is clicked. - \sa buttons, clickedButton + \sa buttons */ /*! @@ -233,9 +233,7 @@ QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(qtLabsPlatformDialogs) QQuickPlatformMessageDialog::QQuickPlatformMessageDialog(QObject *parent) - : QQuickPlatformDialog(parent), - m_options(QMessageDialogOptions::create()), - m_clickedButton(QPlatformDialogHelper::NoButton) + : QQuickPlatformDialog(parent), m_options(QMessageDialogOptions::create()) { } @@ -331,7 +329,7 @@ void QQuickPlatformMessageDialog::setDetailedText(const QString &text) \value MessageDialog.Ignore An "Ignore" button defined with the \c AcceptRole. \value MessageDialog.NoButton The dialog has no buttons. - \sa clicked(), clickedButton + \sa clicked() */ QPlatformDialogHelper::StandardButtons QQuickPlatformMessageDialog::buttons() const { @@ -347,18 +345,6 @@ void QQuickPlatformMessageDialog::setButtons(QPlatformDialogHelper::StandardButt emit buttonsChanged(); } -/*! - \qmlproperty enumeration Qt.labs.platform::MessageDialog::clickedButton - - This property holds the button that was clicked. The default value is \c MessageDialog.NoButton. - - \sa buttons -*/ -QPlatformDialogHelper::StandardButton QQuickPlatformMessageDialog::clickedButton() const -{ - return m_clickedButton; -} - QPlatformDialogHelper *QQuickPlatformMessageDialog::createHelper() { QPlatformDialogHelper *dialog = QGuiApplicationPrivate::platformTheme()->createPlatformDialogHelper(QPlatformTheme::MessageDialog); @@ -384,20 +370,8 @@ void QQuickPlatformMessageDialog::applyOptions(QPlatformDialogHelper *handle) void QQuickPlatformMessageDialog::handleClick(QPlatformDialogHelper::StandardButton button) { - bool changed = m_clickedButton != button; - m_clickedButton = button; - - QPlatformDialogHelper::ButtonRole role = QPlatformDialogHelper::buttonRole(button); - if (role == QPlatformDialogHelper::AcceptRole) - accept(); - else if (role == QPlatformDialogHelper::RejectRole) - reject(); - else - close(); - + done(button); emit clicked(button); - if (changed) - emit clickedButtonChanged(); switch (button) { case QPlatformDialogHelper::Ok: emit okClicked(); break; diff --git a/src/imports/platform/qquickplatformmessagedialog_p.h b/src/imports/platform/qquickplatformmessagedialog_p.h index 87ead6f8..656d8f1f 100644 --- a/src/imports/platform/qquickplatformmessagedialog_p.h +++ b/src/imports/platform/qquickplatformmessagedialog_p.h @@ -60,7 +60,6 @@ class QQuickPlatformMessageDialog : public QQuickPlatformDialog Q_PROPERTY(QString informativeText READ informativeText WRITE setInformativeText NOTIFY informativeTextChanged FINAL) Q_PROPERTY(QString detailedText READ detailedText WRITE setDetailedText NOTIFY detailedTextChanged FINAL) Q_PROPERTY(QPlatformDialogHelper::StandardButtons buttons READ buttons WRITE setButtons NOTIFY buttonsChanged FINAL) - Q_PROPERTY(QPlatformDialogHelper::StandardButton clickedButton READ clickedButton NOTIFY clickedButtonChanged FINAL) Q_FLAGS(QPlatformDialogHelper::StandardButtons) public: @@ -78,14 +77,11 @@ public: QPlatformDialogHelper::StandardButtons buttons() const; void setButtons(QPlatformDialogHelper::StandardButtons buttons); - QPlatformDialogHelper::StandardButton clickedButton() const; - Q_SIGNALS: void textChanged(); void informativeTextChanged(); void detailedTextChanged(); void buttonsChanged(); - void clickedButtonChanged(); void clicked(QPlatformDialogHelper::StandardButton button); void okClicked(); @@ -116,7 +112,6 @@ private Q_SLOTS: private: QSharedPointer<QMessageDialogOptions> m_options; - QPlatformDialogHelper::StandardButton m_clickedButton; }; QT_END_NAMESPACE |