Replace Message attached property with gadget types
authorShawn Rutledge <shawn.rutledge@digia.com>
Mon, 4 Nov 2013 13:56:34 +0000 (14:56 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 5 Nov 2013 11:20:39 +0000 (12:20 +0100)
This is a more efficient way to expose the StandardButton and
StandardIcon enums.

Change-Id: I9d0becf54be2a883d55c9eaeaf10b83b23e59f3c
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
examples/quick/dialogs/systemdialogs/MessageDialogs.qml
src/imports/dialogs/dialogs.pro
src/imports/dialogs/plugin.cpp
src/imports/dialogs/qquickdialogassets_p.h [moved from src/imports/dialogs/qquickmessageattached_p.h with 82% similarity]

index e6fdf57..9c70228 100644 (file)
@@ -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)
             }
         }
index e6ca7a2..1abad55 100644 (file)
@@ -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 \
index 1c852ab..c85d270 100644 (file)
@@ -43,7 +43,7 @@
 #include <QtQml/qqmlextensionplugin.h>
 #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<QQuickMessageAttached>(uri, 1, 1, "Message", QQuickMessageAttached::tr("Message can only be used via the attached property."));
+        qmlRegisterUncreatableType<QQuickStandardButton>(uri, 1, 1, "StandardButton",
+            QLatin1String("Do not create objects of type StandardButton"));
+        qmlRegisterUncreatableType<QQuickStandardIcon>(uri, 1, 1, "StandardIcon",
+            QLatin1String("Do not create objects of type StandardIcon"));
 #ifndef PURE_QML_ONLY
         if (QGuiApplicationPrivate::platformTheme()->usePlatformNativeDialog(QPlatformTheme::MessageDialog))
             qmlRegisterType<QQuickPlatformMessageDialog>(uri, 1, 0, "MessageDialog");
similarity index 82%
rename from src/imports/dialogs/qquickmessageattached_p.h
rename to src/imports/dialogs/qquickdialogassets_p.h
index c1cb94a..406b68a 100644 (file)
@@ -39,8 +39,8 @@
 **
 ****************************************************************************/
 
-#ifndef QQUICKMESSAGEATTACHED_H
-#define QQUICKMESSAGEATTACHED_H
+#ifndef QQUICKDIALOGASSETS_P_H
+#define QQUICKDIALOGASSETS_P_H
 
 #include <private/qtquickglobal_p.h>
 #include <QtGui/qpa/qplatformdialoghelper.h>
 
 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