diff options
author | Chris Adams <christopher.adams@nokia.com> | 2012-06-26 18:02:35 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-11 01:46:52 +0200 |
commit | f5cb65b35e076facbce45e896902a34da7036135 (patch) | |
tree | 7575065fde2d0c14c379a992bf8b3593e21f4881 /tests/auto/qml/qqmlvaluetypeproviders/data/cppIntegration.qml | |
parent | 5376906de58e1c25c77b7a61800365b6e542542f (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/cppIntegration.qml')
-rw-r--r-- | tests/auto/qml/qqmlvaluetypeproviders/data/cppIntegration.qml | 98 |
1 files changed, 98 insertions, 0 deletions
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; + } +} |