aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlvaluetypeproviders/data
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2012-06-26 18:02:35 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-11 01:46:52 +0200
commitf5cb65b35e076facbce45e896902a34da7036135 (patch)
tree7575065fde2d0c14c379a992bf8b3593e21f4881 /tests/auto/qml/qqmlvaluetypeproviders/data
parent5376906de58e1c25c77b7a61800365b6e542542f (diff)
Fix broken value-type support by allowing property definition
In QtQuick 1.x the "variant" property type was supported, which could be used to allow value type properties to be defined in QML. In QtQuick 2.0, we have deprecated the "variant" property, but its replacement ("var") is not suited for defining lightweight C++ type values (such as QColor, QFont, QRectF, QVector3D etc). This commit allows those QML basic types to be used in QML once more, by supporting them in the property definition syntax. Note that since some value types are provided by QtQuick and others are provided by QtQml, if a client imports only QtQml they can define but not use properties of certain types (eg, font). Task-number: QTBUG-21034 Task-number: QTBUG-18217 Change-Id: Ia951a8522f223408d27293bb96c276281a710277 Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmlvaluetypeproviders/data')
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/data/comparisonSemantics.qml95
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/data/cppIntegration.qml98
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/data/jsObjectConversion.qml48
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/data/qtqmlValueTypes.qml48
-rw-r--r--tests/auto/qml/qqmlvaluetypeproviders/data/qtquickValueTypes.qml119
5 files changed, 408 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/data/comparisonSemantics.qml b/tests/auto/qml/qqmlvaluetypeproviders/data/comparisonSemantics.qml
new file mode 100644
index 0000000000..e37cf9bc8d
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypeproviders/data/comparisonSemantics.qml
@@ -0,0 +1,95 @@
+import QtQuick 2.0
+
+QtObject {
+ property bool comparisonSuccess: false
+
+ property date d: new Date(1999, 8, 8)
+ property date d2: new Date(1998, 8, 8)
+
+ property rect g: Qt.rect(1, 2, 3, 4)
+ property rect g2: Qt.rect(5, 6, 7, 8)
+ property point p: Qt.point(1, 2)
+ property point p2: Qt.point(3, 4)
+ property size z: Qt.size(1, 2)
+ property size z2: Qt.size(3, 4)
+
+ property vector2d v2: Qt.vector2d(1,2)
+ property vector2d v22: Qt.vector2d(3,4)
+ property vector3d v3: Qt.vector3d(1,2,3)
+ property vector3d v32: Qt.vector3d(4,5,6)
+ property vector4d v4: Qt.vector4d(1,2,3,4)
+ property vector4d v42: Qt.vector4d(5,6,7,8)
+ property quaternion q: Qt.quaternion(1,2,3,4)
+ property quaternion q2: Qt.quaternion(5,6,7,8)
+ property matrix4x4 m: Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ property matrix4x4 m2: Qt.matrix4x4(21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36)
+ property color c: "red"
+ property color c2: "blue"
+ property font f: Qt.font({family: "Arial", pointSize: 20})
+ property font f2: Qt.font({family: "Arial", pointSize: 22})
+
+ Component.onCompleted: {
+ comparisonSuccess = true;
+
+ // same type comparison.
+ if (d == d2) comparisonSuccess = false;
+ d = d2;
+ if (d == d2) comparisonSuccess = false; // QML date uses same comparison semantics as JS date!
+ if (d.toString() != d2.toString()) comparisonSuccess = false;
+
+ if (g == g2) comparisonSuccess = false;
+ g = g2;
+ if (g != g2) comparisonSuccess = false;
+
+ if (p == p2) comparisonSuccess = false;
+ p = p2;
+ if (p != p2) comparisonSuccess = false;
+
+ if (z == z2) comparisonSuccess = false;
+ z = z2;
+ if (z != z2) comparisonSuccess = false;
+
+ if (v2 == v22) comparisonSuccess = false;
+ v2 = v22;
+ if (v2 != v22) comparisonSuccess = false;
+
+ if (v3 == v32) comparisonSuccess = false;
+ v3 = v32;
+ if (v3 != v32) comparisonSuccess = false;
+
+ if (v4 == v42) comparisonSuccess = false;
+ v4 = v42;
+ if (v4 != v42) comparisonSuccess = false;
+
+ if (q == q2) comparisonSuccess = false;
+ q = q2;
+ if (q != q2) comparisonSuccess = false;
+
+ if (m == m2) comparisonSuccess = false;
+ m = m2;
+ if (m != m2) comparisonSuccess = false;
+
+ if (c == c2) comparisonSuccess = false;
+ c = c2;
+ if (c != c2) comparisonSuccess = false;
+
+ if (f == f2) comparisonSuccess = false;
+ f = f2;
+ if (f != f2) comparisonSuccess = false;
+
+ // cross-type comparison.
+ p = Qt.point(1,2);
+ z = Qt.size(1,2);
+ v2 = Qt.vector2d(1,2);
+ if (p == z || p == v2 || z == v2) comparisonSuccess = false;
+ if (z == p || v2 == p || v2 == z) comparisonSuccess = false;
+
+ g = Qt.rect(1,2,3,4);
+ q = Qt.quaternion(1,2,3,4);
+ v4 = Qt.vector4d(1,2,3,4);
+ if (g == q || g == v4 || q == v4) comparisonSuccess = false;
+ if (q == g || v4 == g || v4 == q) comparisonSuccess = false;
+
+ if (c == f) comparisonSuccess = false;
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/data/cppIntegration.qml b/tests/auto/qml/qqmlvaluetypeproviders/data/cppIntegration.qml
new file mode 100644
index 0000000000..06756f7a18
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypeproviders/data/cppIntegration.qml
@@ -0,0 +1,98 @@
+import QtQuick 2.0
+import Test 1.0
+
+MyTypeObject {
+ property bool success: false
+
+ // the values come from the MyTypeObject property definitions,
+ // which were defined in C++.
+
+ property rect g: rectf
+ property point p: pointf
+ property size z: sizef
+
+ property vector2d v2: vector2
+ property vector3d v3: vector
+ property vector4d v4: vector4
+ property quaternion q: quaternion
+ property matrix4x4 m: matrix
+ property color c: color
+ property font f: font
+
+ Component.onCompleted: {
+ success = true;
+
+ // ensure that the semantics of the properties
+ // defined in C++ match those of the properties
+ // defined in QML, and that we can compare/assign etc.
+
+ if (g != rectf) success = false;
+ g = Qt.rect(1,2,3,4);
+ if (g == rectf) success = false;
+ g = rectf;
+ if (g != rectf) success = false;
+ g = rect;
+ if (g != rect) success = false;
+ g = rectf; // for the cpp-size value comparison.
+
+ if (p != pointf) success = false;
+ p = Qt.point(1,2);
+ if (p == pointf) success = false;
+ p = pointf;
+ if (p != pointf) success = false;
+ p = point;
+ if (p != point) success = false;
+ p = pointf; // for the cpp-size value comparison.
+
+ if (z != sizef) success = false;
+ z = Qt.size(1,2);
+ if (z == sizef) success = false;
+ z = sizef;
+ if (z != sizef) success = false;
+ z = size;
+ if (z != size) success = false;
+ z = sizef; // for the cpp-size value comparison.
+
+ if (v2 != vector2) success = false;
+ v2 = Qt.vector2d(1,2);
+ if (v2 == vector2) success = false;
+ v2 = vector2;
+ if (v2 != vector2) success = false;
+
+ if (v3 != vector) success = false;
+ v3 = Qt.vector3d(1,2,3);
+ if (v3 == vector) success = false;
+ v3 = vector;
+ if (v3 != vector) success = false;
+
+ if (v4 != vector4) success = false;
+ v4 = Qt.vector4d(1,2,3,4);
+ if (v4 == vector4) success = false;
+ v4 = vector4;
+ if (v4 != vector4) success = false;
+
+ if (q != quaternion) success = false;
+ q = Qt.quaternion(1,2,3,4);
+ if (q == quaternion) success = false;
+ q = quaternion;
+ if (q != quaternion) success = false;
+
+ if (m != matrix) success = false;
+ m = Qt.matrix4x4(120, 230, 340, 450, 560, 670, 780, 890, 900, 1010, 1120, 1230, 1340, 1450, 1560, 1670);
+ if (m == matrix) success = false;
+ m = matrix;
+ if (m != matrix) success = false;
+
+ if (c != color) success = false;
+ c = Qt.rgba(1,0,0,.5);
+ if (c == color) success = false;
+ c = color;
+ if (c != color) success = false;
+
+ if (f != font) success = false;
+ f = Qt.font({family: "Arial", pointSize: 15, weight: Font.DemiBold, italic: false});
+ if (f == font) success = false;
+ f = font;
+ if (f != font) success = false;
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/data/jsObjectConversion.qml b/tests/auto/qml/qqmlvaluetypeproviders/data/jsObjectConversion.qml
new file mode 100644
index 0000000000..cd51b6c8cb
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypeproviders/data/jsObjectConversion.qml
@@ -0,0 +1,48 @@
+import QtQuick 2.0
+
+QtObject {
+ property bool qtquickTypeSuccess: false
+
+ // currently, only conversion from js object to font and matrix is supported.
+ property matrix4x4 m: Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ property matrix4x4 m2: Qt.matrix4x4([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
+ property font f: Qt.font({ family: "Arial", pointSize: 10, weight: Font.Bold, italic: true })
+ property font f2: Qt.font({ family: "Arial", pointSize: 10, weight: Font.Bold, italic: true })
+
+ Component.onCompleted: {
+ qtquickTypeSuccess = true;
+
+ // check that the initialisation worked
+ if (m != m2) qtquickTypeSuccess = false;
+ if (f != f2) qtquickTypeSuccess = false;
+
+ // check that assignment works
+ m = Qt.matrix4x4(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4)
+ m2 = Qt.matrix4x4([1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4])
+ if (m != m2) qtquickTypeSuccess = false;
+ f = Qt.font({ family: "Arial", pointSize: 16, weight: Font.Black, italic: false });
+ f2 = Qt.font({ family: "Arial", pointSize: 16, weight: Font.Black, italic: false });
+ if (f != f2) qtquickTypeSuccess = false;
+
+ // ensure that equality works as required.
+ if (m2 != Qt.matrix4x4([1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4])) qtquickTypeSucces = false;
+ if (f2 != Qt.font({ family: "Arial", pointSize: 16, weight: Font.Black, italic: false })) qtquickTypeSuccess = false;
+
+ // just to ensure comparison of values from js object assigned values is consistent.
+ m = Qt.matrix4x4(5,5,5,5,2,2,2,2,3,3,3,3,4,4,4,4);
+ m2 = Qt.matrix4x4([6,6,6,6,2,2,2,2,3,3,3,3,4,4,4,4]);
+ if (m == m2) qtquickTypeSuccess = false;
+ m = Qt.matrix4x4(6,6,6,6,2,2,2,2,3,3,3,3,4,4,4,4);
+ if (m != m2) qtquickTypeSuccess = false;
+ m = Qt.matrix4x4([7,7,7,7,2,2,2,2,3,3,3,3,4,4,4,4]);
+ if (m == m2) qtquickTypeSuccess = false;
+ m = Qt.matrix4x4([6,6,6,6,2,2,2,2,3,3,3,3,4,4,4,4]);
+ if (m != m2) qtquickTypeSuccess = false;
+
+ f = Qt.font({ family: "Arial", pointSize: 10, weight: Font.Bold, italic: true });
+ f2 = Qt.font({ family: "Arial", pointSize: 16, weight: Font.Black, italic: false });
+ if (f == f2) qtquickTypeSuccess = false;
+ f = Qt.font({ family: "Arial", pointSize: 16, weight: Font.Black, italic: false });
+ if (f != f2) qtquickTypeSuccess = false;
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/data/qtqmlValueTypes.qml b/tests/auto/qml/qqmlvaluetypeproviders/data/qtqmlValueTypes.qml
new file mode 100644
index 0000000000..30bc92d8af
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypeproviders/data/qtqmlValueTypes.qml
@@ -0,0 +1,48 @@
+import QtQml 2.0
+
+QtObject {
+ property bool qtqmlTypeSuccess: false
+ property bool qtquickTypeSuccess: false
+
+ property int i: 10
+ property bool b: true
+ property real r: 5.5
+ property string s: "Hello"
+
+ property date d: new Date(1999, 8, 8)
+
+ property rect g: Qt.rect(1, 2, 3, 4)
+ property point p: Qt.point(1, 2)
+ property size z: Qt.size(1, 2)
+
+ // the following property types are valid syntax in QML
+ // but their valuetype implementation is provided by QtQuick.
+ // Thus, we can define properties of the type, but not use them.
+ property vector2d v2
+ property vector3d v3
+ property vector4d v4
+ property quaternion q
+ property matrix4x4 m
+ property color c
+ property font f
+
+ Component.onCompleted: {
+ qtqmlTypeSuccess = true;
+ qtquickTypeSuccess = true;
+
+ // test that the base qtqml provided types work
+ if (i != 10) qtqmlTypeSuccess = false;
+ if (b != true) qtqmlTypeSuccess = false;
+ if (r != 5.5) qtqmlTypeSuccess = false;
+ if (s != "Hello") qtqmlTypeSuccess = false;
+ if (d.toDateString() != (new Date(1999,8,8)).toDateString()) qtqmlTypeSuccess = false;
+ if (g != Qt.rect(1, 2, 3, 4)) qtqmlTypeSuccess = false;
+ if (p != Qt.point(1, 2)) qtqmlTypeSuccess = false;
+ if (z != Qt.size(1, 2)) qtqmlTypeSuccess = false;
+
+ // This should also work, as the base value types are provided by QtQml.
+ if (g.x != 1 || g.y != 2 || g.width != 3 || g.height != 4) qtqmlTypeSuccess = false;
+ if (p.x != 1 || p.y != 2) qtqmlTypeSuccess = false;
+ if (z.width != 1 || z.height != 2) qtqmlTypeSuccess = false;
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypeproviders/data/qtquickValueTypes.qml b/tests/auto/qml/qqmlvaluetypeproviders/data/qtquickValueTypes.qml
new file mode 100644
index 0000000000..f723dc3e2e
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypeproviders/data/qtquickValueTypes.qml
@@ -0,0 +1,119 @@
+import QtQuick 2.0
+
+QtObject {
+ property bool qtqmlTypeSuccess: false
+ property bool qtquickTypeSuccess: false
+
+ property int i: 10
+ property bool b: true
+ property real r: 5.5
+ property string s: "Hello"
+
+ property date d: new Date(1999, 8, 8)
+
+ property rect g: Qt.rect(1, 2, 3, 4)
+ property point p: Qt.point(1, 2)
+ property size z: Qt.size(1, 2)
+
+ property vector2d v2: Qt.vector2d(1,2)
+ property vector3d v3: Qt.vector3d(1,2,3)
+ property vector4d v4: Qt.vector4d(1,2,3,4)
+ property quaternion q: Qt.quaternion(1,2,3,4)
+ property matrix4x4 m: Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
+ property color c: "red"
+ property color c2: "red"
+ property font f: Qt.font({ family: "Arial", pointSize: 20 })
+
+ // ensure that group property specification works as expected.
+ property font f2
+ f2.family: "Arial"
+ f2.pointSize: 45
+ f2.italic: true
+ v22.x: 5
+ v22.y: 10
+ property vector2d v22
+ property font f3 // note: cannot specify grouped subproperties inline with property declaration :-/
+ f3 {
+ family: "Arial"
+ pointSize: 45
+ italic: true
+ }
+
+ Component.onCompleted: {
+ qtqmlTypeSuccess = true;
+ qtquickTypeSuccess = true;
+
+ // check base types still work even though we imported QtQuick
+ if (i != 10) qtqmlTypeSuccess = false;
+ if (b != true) qtqmlTypeSuccess = false;
+ if (r != 5.5) qtqmlTypeSuccess = false;
+ if (s != "Hello") qtqmlTypeSuccess = false;
+ if (d.toDateString() != (new Date(1999,8,8)).toDateString()) qtqmlTypeSuccess = false;
+
+ // check language-provided value types still work.
+ if (g != Qt.rect(1, 2, 3, 4)) qtqmlTypeSuccess = false;
+ if (g.x != 1 || g.y != 2 || g.width != 3 || g.height != 4) qtqmlTypeSuccess = false;
+ if (p != Qt.point(1, 2)) qtqmlTypeSuccess = false;
+ if (p.x != 1 || p.y != 2) qtqmlTypeSuccess = false;
+ if (z != Qt.size(1, 2)) qtqmlTypeSuccess = false;
+ if (z.width != 1 || z.height != 2) qtqmlTypeSuccess = false;
+
+ // Check that the value type provider for vector3d and other non-QtQml value-types is provided by QtQuick.
+ if (v2.x != 1 || v2.y != 2) qtquickTypeSuccess = false;
+ if (v2 != Qt.vector2d(1,2)) qtquickTypeSuccess = false;
+ if (v3.x != 1 || v3.y != 2 || v3.z != 3) qtquickTypeSuccess = false;
+ if (v3 != Qt.vector3d(1,2,3)) qtquickTypeSuccess = false;
+ if (v4.x != 1 || v4.y != 2 || v4.z != 3 || v4.w != 4) qtquickTypeSuccess = false;
+ if (v4 != Qt.vector4d(1,2,3,4)) qtquickTypeSuccess = false;
+ if (q.scalar != 1 || q.x != 2 || q.y != 3 || q.z != 4) qtquickTypeSuccess = false;
+ if (q != Qt.quaternion(1,2,3,4)) qtquickTypeSuccess = false;
+ if (m != Qt.matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)) qtquickTypeSuccess = false;
+ if (c != Qt.rgba(1,0,0,1)) qtquickTypeSuccess = false;
+ if (c != c2) qtquickTypeSuccess = false; // can compare two colors directly.
+ if (f.family != "Arial" || f.pointSize != 20) qtquickTypeSuccess = false;
+ if (f != Qt.font({ family: "Arial", pointSize: 20 })) qtquickTypeSuccess = false;
+ if (f2.family != "Arial" || f2.pointSize != 45 || f2.italic != true) qtquickTypeSuccess = false;
+ if (f2 != f3) qtquickTypeSuccess = false;
+ if (v22.x != 5 || v22.y != 10) qtquickTypeSuccess = false;
+
+ // font has some optional parameters.
+ var defaultFont = Qt.font({ family: "Arial", pointSize: 22 }); // normal should be default weight.
+ var lightFont = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Light });
+ var normalFont = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Normal });
+ var demiboldFont = Qt.font({ family: "Arial", pointSize: 22, weight: Font.DemiBold });
+ var boldFont = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Bold });
+ var blackFont = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Black });
+
+ f = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Light });
+ if (f.family != "Arial" || f.pointSize != 22 || f.weight != lightFont.weight || f.weight == normalFont.weight) qtquickTypeSuccess = false;
+ f = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Normal, italic: true });
+ if (f.family != "Arial" || f.pointSize != 22 || f.weight != normalFont.weight || f.italic != true) qtquickTypeSuccess = false;
+ f = Qt.font({ family: "Arial", pointSize: 22, weight: Font.DemiBold, italic: false });
+ if (f.family != "Arial" || f.pointSize != 22 || f.weight != demiboldFont.weight || f.italic != false) qtquickTypeSuccess = false;
+ f = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Bold }); // italic should be false by default
+ if (f.family != "Arial" || f.pointSize != 22 || f.weight != boldFont.weight || f.italic != false) qtquickTypeSuccess = false;
+ f = Qt.font({ family: "Arial", pointSize: 22, weight: Font.Black }); // italic should be false by default
+ if (f.family != "Arial" || f.pointSize != 22 || f.weight != blackFont.weight || f.italic != false) qtquickTypeSuccess = false;
+
+ // Check the string conversion codepaths.
+ v2 = "5,6";
+ if (v2 != Qt.vector2d(5,6)) qtquickTypeSuccess = false;
+ if (v2.toString() != "QVector2D(5, 6)") qtquickTypeSuccess = false;
+ v3 = "5,6,7";
+ if (v3 != Qt.vector3d(5,6,7)) qtquickTypeSuccess = false;
+ if (v3.toString() != "QVector3D(5, 6, 7)") qtquickTypeSuccess = false;
+ v4 = "5,6,7,8";
+ if (v4 != Qt.vector4d(5,6,7,8)) qtquickTypeSuccess = false;
+ if (v4.toString() != "QVector4D(5, 6, 7, 8)") qtquickTypeSuccess = false;
+ q = "5,6,7,8";
+ if (q != Qt.quaternion(5,6,7,8)) qtquickTypeSuccess = false;
+ if (q.toString() != "QQuaternion(5, 6, 7, 8)") qtquickTypeSuccess = false;
+ m = "4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7";
+ if (m != Qt.matrix4x4(4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7)) qtquickTypeSuccess = false;
+ if (m.toString() != "QMatrix4x4(4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7)") qtquickTypeSuccess = false;
+ c = "blue";
+ if (c.toString() != Qt.rgba(0,0,1,0).toString()) qtquickTypeSuccess = false;
+ if (c.toString() != "#0000FF" && c.toString() != "#0000ff") qtquickTypeSuccess = false; // color string converter is special
+ // no string converter for fonts.
+ }
+}