From eaf52673ef38b4d7a14f9fb9f258d8f1c6097401 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Thu, 14 Jul 2011 15:40:30 +1000 Subject: Add support for a vector4d type in QML QVector4D is a value-type which is supported but was not able to be constructed using a Qt object function. This commit allows properties of vector4d type to be constructed, and adds a function to the global Qt object and adds unit tests to ensure that it behaves correctly. Task-number: QTBUG-18559 Change-Id: I96509a4f496b644d20fdb1d977d0afe430d89e13 Reviewed-on: http://codereview.qt.nokia.com/1626 Reviewed-by: Qt Sanity Bot Reviewed-by: Aaron Kennedy --- .../declarative/qdeclarativeqt/data/vector4.qml | 8 ++++++++ .../qdeclarativeqt/tst_qdeclarativeqt.cpp | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativeqt/data/vector4.qml (limited to 'tests/auto/declarative/qdeclarativeqt') diff --git a/tests/auto/declarative/qdeclarativeqt/data/vector4.qml b/tests/auto/declarative/qdeclarativeqt/data/vector4.qml new file mode 100644 index 0000000000..554dd1e9d4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeqt/data/vector4.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 + +QtObject { + property variant test1: Qt.vector4d(1, 0, 0.9, 0.6); + property variant test2: Qt.vector4d(102, -10, -982.1, 10); + property variant test3: Qt.vector4d(102, -10, -982.1); + property variant test4: Qt.vector4d(102, -10, -982.1, 10, 15); +} diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp index 4a9bb4513c..d9cd2b8fdf 100644 --- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp +++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp @@ -72,6 +72,7 @@ private slots: void point(); void size(); void vector(); + void vector4d(); void lighter(); void darker(); void tint(); @@ -243,6 +244,26 @@ void tst_qdeclarativeqt::vector() delete object; } +void tst_qdeclarativeqt::vector4d() +{ + QDeclarativeComponent component(&engine, TEST_FILE("vector4.qml")); + + QString warning1 = component.url().toString() + ":6: Error: Qt.vector4d(): Invalid arguments"; + QString warning2 = component.url().toString() + ":7: Error: Qt.vector4d(): Invalid arguments"; + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1)); + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2)); + + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(qvariant_cast(object->property("test1")), QVector4D(1, 0, 0.9, 0.6)); + QCOMPARE(qvariant_cast(object->property("test2")), QVector4D(102, -10, -982.1, 10)); + QCOMPARE(qvariant_cast(object->property("test3")), QVector4D()); + QCOMPARE(qvariant_cast(object->property("test4")), QVector4D()); + + delete object; +} + void tst_qdeclarativeqt::lighter() { QDeclarativeComponent component(&engine, TEST_FILE("lighter.qml")); -- cgit v1.2.3