From: Shawn Rutledge Date: Mon, 4 Nov 2013 13:56:34 +0000 (+0100) Subject: Replace Message attached property with gadget types X-Git-Tag: upstream/5.2.1~56 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e17ae3b8b716b00c7cb6156347101f2e789dbd58;p=platform%2Fupstream%2Fqtdeclarative.git Replace Message attached property with gadget types This is a more efficient way to expose the StandardButton and StandardIcon enums. Change-Id: I9d0becf54be2a883d55c9eaeaf10b83b23e59f3c Reviewed-by: Gabriel de Dietrich Reviewed-by: Alan Alpert --- diff --git a/examples/quick/dialogs/systemdialogs/MessageDialogs.qml b/examples/quick/dialogs/systemdialogs/MessageDialogs.qml index e6fdf57..9c70228 100644 --- a/examples/quick/dialogs/systemdialogs/MessageDialogs.qml +++ b/examples/quick/dialogs/systemdialogs/MessageDialogs.qml @@ -61,12 +61,12 @@ Rectangle { detailedText: customizeDetailedText.checked ? detailedTextField.text : "" onButtonClicked: console.log("clicked button " + clickedButton) onAccepted: lastChosen.text = "Accepted " + - (clickedButton == Message.Ok ? "(OK)" : (clickedButton == Message.Retry ? "(Retry)" : "(Ignore)")) + (clickedButton == StandardButton.Ok ? "(OK)" : (clickedButton == StandardButton.Retry ? "(Retry)" : "(Ignore)")) onRejected: lastChosen.text = "Rejected " + - (clickedButton == Message.Close ? "(Close)" : (clickedButton == Message.Abort ? "(Abort)" : "(Cancel)")) + (clickedButton == StandardButton.Close ? "(Close)" : (clickedButton == StandardButton.Abort ? "(Abort)" : "(Cancel)")) onHelp: lastChosen.text = "Yelped for help!" - onYes: lastChosen.text = (clickedButton == Message.Yes ? "Yeessss!!" : "Yes, now and always") - onNo: lastChosen.text = (clickedButton == Message.No ? "Oh No." : "No, no, a thousand times no!") + onYes: lastChosen.text = (clickedButton == StandardButton.Yes ? "Yeessss!!" : "Yes, now and always") + onNo: lastChosen.text = (clickedButton == StandardButton.No ? "Oh No." : "No, no, a thousand times no!") onApply: lastChosen.text = "Apply" onReset: lastChosen.text = "Reset" } @@ -105,7 +105,7 @@ Rectangle { function updateIcon(icon, checked) { if (updating) return updating = true - messageDialog.icon = (checked ? icon : Message.NoIcon) + messageDialog.icon = (checked ? icon : StandardIcon.NoIcon) for (var i = 0; i < children.length; ++i) if (children[i].icon !== icon) children[i].checked = false @@ -115,7 +115,7 @@ Rectangle { CheckBox { id: iconInformation text: "Information" - property int icon: Message.Information + property int icon: StandardIcon.Information onCheckedChanged: parent.updateIcon(icon, checked) } @@ -123,7 +123,7 @@ Rectangle { id: iconWarning text: "Warning" checked: true - property int icon: Message.Warning + property int icon: StandardIcon.Warning onCheckedChanged: parent.updateIcon(icon, checked) Component.onCompleted: parent.updateIcon(icon, true) } @@ -131,14 +131,14 @@ Rectangle { CheckBox { id: iconCritical text: "Critical" - property int icon: Message.Critical + property int icon: StandardIcon.Critical onCheckedChanged: parent.updateIcon(icon, checked) } CheckBox { id: iconQuestion text: "Question" - property int icon: Message.Question + property int icon: StandardIcon.Question onCheckedChanged: parent.updateIcon(icon, checked) } } @@ -182,75 +182,75 @@ Rectangle { if (children[i].checked) buttons |= children[i].button if (!buttons) - buttons = Message.Ok + buttons = StandardButton.Ok messageDialog.standardButtons = buttons updating = false } CheckBox { text: "Help" - property int button: Message.Help + property int button: StandardButton.Help onCheckedChanged: parent.updateButtons(button, checked) } CheckBox { text: "Abort" - property int button: Message.Abort + property int button: StandardButton.Abort onCheckedChanged: parent.updateButtons(button, checked) } CheckBox { text: "Close" - property int button: Message.Close + property int button: StandardButton.Close onCheckedChanged: parent.updateButtons(button, checked) } CheckBox { text: "Cancel" - property int button: Message.Cancel + property int button: StandardButton.Cancel onCheckedChanged: parent.updateButtons(button, checked) } CheckBox { text: "NoToAll" - property int button: Message.NoToAll + property int button: StandardButton.NoToAll onCheckedChanged: parent.updateButtons(button, checked) } CheckBox { text: "No" - property int button: Message.No + property int button: StandardButton.No onCheckedChanged: parent.updateButtons(button, checked) } CheckBox { text: "YesToAll" - property int button: Message.YesToAll + property int button: StandardButton.YesToAll onCheckedChanged: parent.updateButtons(button, checked) } CheckBox { text: "Yes" - property int button: Message.Yes + property int button: StandardButton.Yes onCheckedChanged: parent.updateButtons(button, checked) } CheckBox { text: "Ignore" - property int button: Message.Ignore + property int button: StandardButton.Ignore onCheckedChanged: parent.updateButtons(button, checked) } CheckBox { text: "Retry" - property int button: Message.Retry + property int button: StandardButton.Retry onCheckedChanged: parent.updateButtons(button, checked) } CheckBox { text: "OK" checked: true - property int button: Message.Ok + property int button: StandardButton.Ok onCheckedChanged: parent.updateButtons(button, checked) } } diff --git a/src/imports/dialogs/dialogs.pro b/src/imports/dialogs/dialogs.pro index e6ca7a2..1abad55 100644 --- a/src/imports/dialogs/dialogs.pro +++ b/src/imports/dialogs/dialogs.pro @@ -25,7 +25,7 @@ HEADERS += \ qquickabstractmessagedialog_p.h \ qquickplatformmessagedialog_p.h \ qquickmessagedialog_p.h \ - qquickmessageattached_p.h \ + qquickdialogassets_p.h \ qquickabstractfiledialog_p.h \ qquickplatformfiledialog_p.h \ qquickfiledialog_p.h \ diff --git a/src/imports/dialogs/plugin.cpp b/src/imports/dialogs/plugin.cpp index 1c852ab..c85d270 100644 --- a/src/imports/dialogs/plugin.cpp +++ b/src/imports/dialogs/plugin.cpp @@ -43,7 +43,7 @@ #include #include "qquickmessagedialog_p.h" #include "qquickabstractmessagedialog_p.h" -#include "qquickmessageattached_p.h" +#include "qquickdialogassets_p.h" #include "qquickplatformmessagedialog_p.h" #include "qquickfiledialog_p.h" #include "qquickabstractfiledialog_p.h" @@ -122,7 +122,10 @@ public: // Otherwise fall back to a pure-QML implementation. // MessageDialog - qmlRegisterUncreatableType(uri, 1, 1, "Message", QQuickMessageAttached::tr("Message can only be used via the attached property.")); + qmlRegisterUncreatableType(uri, 1, 1, "StandardButton", + QLatin1String("Do not create objects of type StandardButton")); + qmlRegisterUncreatableType(uri, 1, 1, "StandardIcon", + QLatin1String("Do not create objects of type StandardIcon")); #ifndef PURE_QML_ONLY if (QGuiApplicationPrivate::platformTheme()->usePlatformNativeDialog(QPlatformTheme::MessageDialog)) qmlRegisterType(uri, 1, 0, "MessageDialog"); diff --git a/src/imports/dialogs/qquickmessageattached_p.h b/src/imports/dialogs/qquickdialogassets_p.h similarity index 82% rename from src/imports/dialogs/qquickmessageattached_p.h rename to src/imports/dialogs/qquickdialogassets_p.h index c1cb94a..406b68a 100644 --- a/src/imports/dialogs/qquickmessageattached_p.h +++ b/src/imports/dialogs/qquickdialogassets_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QQUICKMESSAGEATTACHED_H -#define QQUICKMESSAGEATTACHED_H +#ifndef QQUICKDIALOGASSETS_P_H +#define QQUICKDIALOGASSETS_P_H #include #include @@ -48,22 +48,18 @@ QT_BEGIN_NAMESPACE -class Q_DECL_EXPORT QQuickMessageAttached : public QObject +class QQuickStandardButton { - Q_OBJECT - Q_ENUMS(QQuickAbstractMessageDialog::Icon) + Q_GADGET Q_ENUMS(QQuickAbstractMessageDialog::StandardButton) +}; -public: - static QQuickMessageAttached *qmlAttachedProperties(QObject *obj) { - return new QQuickMessageAttached(obj); } - - QQuickMessageAttached(QObject *parent = 0) : QObject(parent) { } +class QQuickStandardIcon +{ + Q_GADGET + Q_ENUMS(QQuickAbstractMessageDialog::Icon) }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QQuickMessageAttached) -QML_DECLARE_TYPEINFO(QQuickMessageAttached, QML_HAS_ATTACHED_PROPERTIES) - -#endif // QQUICKMESSAGEATTACHED_H +#endif // QQUICKDIALOGASSETS_P_H