aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllanguage/data
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-05-11 17:37:07 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-24 05:52:32 +0200
commit4709f30b26042427b225dd164648e3f5907c9d33 (patch)
tree3edac8d14d3fb77406ef93aa2c34c42131109625 /tests/auto/qml/qqmllanguage/data
parent2542778d4837143a61dfcf143c32683acc8b998a (diff)
Enable binding to properties of type QJSValue.
This allows javascript objects of all types to be bound to properties declared in c++. Compared to a QVariant the primary benefit this offers is a type which functions and objects with functions can be bound to. Change-Id: Idb3313e7ff1d616ab12d44f616083c8296201f3a Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmllanguage/data')
-rw-r--r--tests/auto/qml/qqmllanguage/data/assignLiteralToJSValue.qml109
-rw-r--r--tests/auto/qml/qqmllanguage/data/bindTypeToJSValue.qml60
2 files changed, 169 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/assignLiteralToJSValue.qml b/tests/auto/qml/qqmllanguage/data/assignLiteralToJSValue.qml
new file mode 100644
index 0000000000..fce248a381
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/assignLiteralToJSValue.qml
@@ -0,0 +1,109 @@
+// This tests assigning literals to QJSValue properties.
+// These properties store JavaScript object references.
+
+import QtQuick 2.0
+import Test 1.0
+
+QtObject {
+ property list<QtObject> resources: [
+ MyQmlObject { id: testObj1; objectName: "test1"; qjsvalue: 1 },
+ MyQmlObject { id: testObj2; objectName: "test2"; qjsvalue: 1.7 },
+ MyQmlObject { id: testObj3; objectName: "test3"; qjsvalue: "Hello world!" },
+ MyQmlObject { id: testObj4; objectName: "test4"; qjsvalue: "#FF008800" },
+ MyQmlObject { id: testObj5; objectName: "test5"; qjsvalue: "10,10,10x10" },
+ MyQmlObject { id: testObj6; objectName: "test6"; qjsvalue: "10,10" },
+ MyQmlObject { id: testObj7; objectName: "test7"; qjsvalue: "10x10" },
+ MyQmlObject { id: testObj8; objectName: "test8"; qjsvalue: "100,100,100" },
+ MyQmlObject { id: testObj9; objectName: "test9"; qjsvalue: String("#FF008800") },
+ MyQmlObject { id: testObj10; objectName: "test10"; qjsvalue: true },
+ MyQmlObject { id: testObj11; objectName: "test11"; qjsvalue: false },
+ MyQmlObject { id: testObj12; objectName: "test12"; qjsvalue: Qt.rgba(0.2, 0.3, 0.4, 0.5) },
+ MyQmlObject { id: testObj13; objectName: "test13"; qjsvalue: Qt.rect(10, 10, 10, 10) },
+ MyQmlObject { id: testObj14; objectName: "test14"; qjsvalue: Qt.point(10, 10) },
+ MyQmlObject { id: testObj15; objectName: "test15"; qjsvalue: Qt.size(10, 10) },
+ MyQmlObject { id: testObj16; objectName: "test16"; qjsvalue: Qt.vector3d(100, 100, 100); },
+ MyQmlObject { id: testObj17; objectName: "test17"; qjsvalue: "1" },
+ MyQmlObject { id: testObj18; objectName: "test18"; qjsvalue: "1.7" },
+ MyQmlObject { id: testObj19; objectName: "test19"; qjsvalue: "true" },
+ MyQmlObject { id: testObj20; objectName: "test20"; qjsvalue: function(val) { return val * 3; } },
+ MyQmlObject { id: testObj21; objectName: "test21"; qjsvalue: undefined },
+ MyQmlObject { id: testObj22; objectName: "test22"; qjsvalue: null },
+ MyQmlObject { id: testObj1Bound; objectName: "test1Bound"; qjsvalue: testObj1.qjsvalue + 4 }, // 1 + 4 + 4 = 9
+ MyQmlObject { id: testObj20Bound; objectName: "test20Bound"; qjsvalue: testObj20.qjsvalue(testObj1Bound.qjsvalue) }, // 9 * 3 = 27
+ QtObject {
+ id: varProperties
+ objectName: "varProperties"
+ property var test1: testObj1.qjsvalue
+ property var test2: testObj2.qjsvalue
+ property var test3: testObj3.qjsvalue
+ property var test4: testObj4.qjsvalue
+ property var test5: testObj5.qjsvalue
+ property var test6: testObj6.qjsvalue
+ property var test7: testObj7.qjsvalue
+ property var test8: testObj8.qjsvalue
+ property var test9: testObj9.qjsvalue
+ property var test10: testObj10.qjsvalue
+ property var test11: testObj11.qjsvalue
+ property var test12: testObj12.qjsvalue
+ property var test13: testObj13.qjsvalue
+ property var test14: testObj14.qjsvalue
+ property var test15: testObj15.qjsvalue
+ property var test16: testObj16.qjsvalue
+ property var test20: testObj20.qjsvalue
+
+ property var test1Bound: testObj1.qjsvalue + 4 // 1 + 4 + 4 = 9
+ property var test20Bound: testObj20.qjsvalue(test1Bound) // 9 * 3 = 27
+ },
+ QtObject {
+ id: variantProperties
+ objectName: "variantProperties"
+ property variant test1: testObj1.qjsvalue
+ property variant test2: testObj2.qjsvalue
+ property variant test3: testObj3.qjsvalue
+ property variant test4: testObj4.qjsvalue
+ property variant test5: testObj5.qjsvalue
+ property variant test6: testObj6.qjsvalue
+ property variant test7: testObj7.qjsvalue
+ property variant test8: testObj8.qjsvalue
+ property variant test9: testObj9.qjsvalue
+ property variant test10: testObj10.qjsvalue
+ property variant test11: testObj11.qjsvalue
+ property variant test12: testObj12.qjsvalue
+ property variant test13: testObj13.qjsvalue
+ property variant test14: testObj14.qjsvalue
+ property variant test15: testObj15.qjsvalue
+ property variant test16: testObj16.qjsvalue
+
+ property variant test1Bound: testObj1.qjsvalue + 4 // 1 + 4 + 4 = 9
+ property variant test20Bound: testObj20.qjsvalue(test1Bound) // 9 * 3 = 27
+ },
+ MyTypeObject {
+ objectName: "typedProperties"
+ intProperty: testObj1.qjsvalue
+ doubleProperty: testObj2.qjsvalue
+ stringProperty: testObj3.qjsvalue
+ boolProperty: testObj10.qjsvalue
+ colorProperty: testObj12.qjsvalue
+ rectFProperty: testObj13.qjsvalue
+ pointFProperty: testObj14.qjsvalue
+ sizeFProperty: testObj15.qjsvalue
+ vectorProperty: testObj16.qjsvalue
+ },
+ MyTypeObject {
+ objectName: "stringProperties"
+ intProperty: testObj17.qjsvalue
+ doubleProperty: testObj18.qjsvalue
+ stringProperty: testObj3.qjsvalue
+ boolProperty: testObj19.qjsvalue
+ colorProperty: testObj4.qjsvalue
+ rectFProperty: testObj5.qjsvalue
+ pointFProperty: testObj6.qjsvalue
+ sizeFProperty: testObj7.qjsvalue
+ vectorProperty: testObj8.qjsvalue
+ }
+ ]
+
+ Component.onCompleted: {
+ testObj1.qjsvalue = testObj1.qjsvalue + 4
+ }
+}
diff --git a/tests/auto/qml/qqmllanguage/data/bindTypeToJSValue.qml b/tests/auto/qml/qqmllanguage/data/bindTypeToJSValue.qml
new file mode 100644
index 0000000000..ff724a4162
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/bindTypeToJSValue.qml
@@ -0,0 +1,60 @@
+import Test 1.0
+import QtQuick 2.0
+
+MyTypeObject {
+ flagProperty: "FlagVal1 | FlagVal3"
+ enumProperty: "EnumVal2"
+ stringProperty: "Hello World!"
+ uintProperty: 10
+ intProperty: -19
+ realProperty: 23.2
+ doubleProperty: -19.7
+ floatProperty: 8.5
+ colorProperty: "red"
+ dateProperty: "1982-11-25"
+ timeProperty: "11:11:32"
+ dateTimeProperty: "2009-05-12T13:22:01"
+ pointProperty: "99,13"
+ pointFProperty: "-10.1,12.3"
+ sizeProperty: "99x13"
+ sizeFProperty: "0.1x0.2"
+ rectProperty: "9,7,100x200"
+ rectFProperty: "1000.1,-10.9,400x90.99"
+ boolProperty: true
+ variantProperty: "Hello World!"
+ vectorProperty: "10,1,2.2"
+ vector4Property: "10,1,2.2,2.3"
+ urlProperty: "main.qml?with%3cencoded%3edata"
+
+ objectProperty: MyTypeObject {}
+
+ property var varProperty: "Hello World!"
+
+ property list<MyQmlObject> resources: [
+ MyQmlObject { objectName: "flagProperty"; qjsvalue: flagProperty },
+ MyQmlObject { objectName: "enumProperty"; qjsvalue: enumProperty },
+ MyQmlObject { objectName: "stringProperty"; qjsvalue: stringProperty },
+ MyQmlObject { objectName: "uintProperty"; qjsvalue: uintProperty },
+ MyQmlObject { objectName: "intProperty"; qjsvalue: intProperty },
+ MyQmlObject { objectName: "realProperty"; qjsvalue: realProperty },
+ MyQmlObject { objectName: "doubleProperty"; qjsvalue: doubleProperty },
+ MyQmlObject { objectName: "floatProperty"; qjsvalue: floatProperty },
+ MyQmlObject { objectName: "colorProperty"; qjsvalue: colorProperty },
+ MyQmlObject { objectName: "dateProperty"; qjsvalue: dateProperty },
+ MyQmlObject { objectName: "timeProperty"; qjsvalue: timeProperty },
+ MyQmlObject { objectName: "dateTimeProperty"; qjsvalue: dateTimeProperty },
+ MyQmlObject { objectName: "pointProperty"; qjsvalue: pointProperty },
+ MyQmlObject { objectName: "pointFProperty"; qjsvalue: pointFProperty },
+ MyQmlObject { objectName: "sizeProperty"; qjsvalue: sizeProperty },
+ MyQmlObject { objectName: "sizeFProperty"; qjsvalue: sizeFProperty },
+ MyQmlObject { objectName: "rectProperty"; qjsvalue: rectProperty },
+ MyQmlObject { objectName: "rectFProperty"; qjsvalue: rectFProperty },
+ MyQmlObject { objectName: "boolProperty"; qjsvalue: boolProperty },
+ MyQmlObject { objectName: "variantProperty"; qjsvalue: variantProperty },
+ MyQmlObject { objectName: "vectorProperty"; qjsvalue: vectorProperty },
+ MyQmlObject { objectName: "vector4Property"; qjsvalue: vector4Property },
+ MyQmlObject { objectName: "urlProperty"; qjsvalue: urlProperty },
+ MyQmlObject { objectName: "objectProperty"; qjsvalue: objectProperty },
+ MyQmlObject { objectName: "varProperty"; qjsvalue: varProperty }
+ ]
+}