diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-04-30 02:47:48 (GMT) |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-04-30 04:29:01 (GMT) |
commit | b57ad033b5fa48efd2e57f17d26f541f1f50dc02 (patch) | |
tree | 757d62b51126b9a4dee5cc2e61200f5fd81e80ec | |
parent | 14b067f85f92194f2c444259e2a70fb095dfb73f (diff) | |
download | Qt-b57ad033b5fa48efd2e57f17d26f541f1f50dc02.zip Qt-b57ad033b5fa48efd2e57f17d26f541f1f50dc02.tar.gz Qt-b57ad033b5fa48efd2e57f17d26f541f1f50dc02.tar.bz2 |
Add QML value types for math3d types
QVector3D was already supported. Add QVector2D, QVector4D,
QQuaternion, and QMatrix4x4.
Reviewed-by: Warwick Allison
12 files changed, 626 insertions, 1 deletions
diff --git a/src/declarative/qml/qdeclarativevaluetype.cpp b/src/declarative/qml/qdeclarativevaluetype.cpp index c6fe161..dbc25bb 100644 --- a/src/declarative/qml/qdeclarativevaluetype.cpp +++ b/src/declarative/qml/qdeclarativevaluetype.cpp @@ -116,8 +116,16 @@ QDeclarativeValueType *QDeclarativeValueTypeFactory::valueType(int t) return new QDeclarativeRectValueType; case QVariant::RectF: return new QDeclarativeRectFValueType; + case QVariant::Vector2D: + return new QDeclarativeVector2DValueType; case QVariant::Vector3D: return new QDeclarativeVector3DValueType; + case QVariant::Vector4D: + return new QDeclarativeVector4DValueType; + case QVariant::Quaternion: + return new QDeclarativeQuaternionValueType; + case QVariant::Matrix4x4: + return new QDeclarativeMatrix4x4ValueType; case QVariant::EasingCurve: return new QDeclarativeEasingValueType; case QVariant::Font: @@ -460,6 +468,54 @@ void QDeclarativeRectValueType::setHeight(int h) rect.setHeight(h); } +QDeclarativeVector2DValueType::QDeclarativeVector2DValueType(QObject *parent) +: QDeclarativeValueType(parent) +{ +} + +void QDeclarativeVector2DValueType::read(QObject *obj, int idx) +{ + void *a[] = { &vector, 0 }; + QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); +} + +void QDeclarativeVector2DValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) +{ + int status = -1; + void *a[] = { &vector, 0, &status, &flags }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); +} + +QVariant QDeclarativeVector2DValueType::value() +{ + return QVariant(vector); +} + +void QDeclarativeVector2DValueType::setValue(QVariant value) +{ + vector = qvariant_cast<QVector2D>(value); +} + +qreal QDeclarativeVector2DValueType::x() const +{ + return vector.x(); +} + +qreal QDeclarativeVector2DValueType::y() const +{ + return vector.y(); +} + +void QDeclarativeVector2DValueType::setX(qreal x) +{ + vector.setX(x); +} + +void QDeclarativeVector2DValueType::setY(qreal y) +{ + vector.setY(y); +} + QDeclarativeVector3DValueType::QDeclarativeVector3DValueType(QObject *parent) : QDeclarativeValueType(parent) { @@ -518,6 +574,170 @@ void QDeclarativeVector3DValueType::setZ(qreal z) vector.setZ(z); } +QDeclarativeVector4DValueType::QDeclarativeVector4DValueType(QObject *parent) +: QDeclarativeValueType(parent) +{ +} + +void QDeclarativeVector4DValueType::read(QObject *obj, int idx) +{ + void *a[] = { &vector, 0 }; + QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); +} + +void QDeclarativeVector4DValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) +{ + int status = -1; + void *a[] = { &vector, 0, &status, &flags }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); +} + +QVariant QDeclarativeVector4DValueType::value() +{ + return QVariant(vector); +} + +void QDeclarativeVector4DValueType::setValue(QVariant value) +{ + vector = qvariant_cast<QVector4D>(value); +} + +qreal QDeclarativeVector4DValueType::x() const +{ + return vector.x(); +} + +qreal QDeclarativeVector4DValueType::y() const +{ + return vector.y(); +} + +qreal QDeclarativeVector4DValueType::z() const +{ + return vector.z(); +} + +qreal QDeclarativeVector4DValueType::w() const +{ + return vector.w(); +} + +void QDeclarativeVector4DValueType::setX(qreal x) +{ + vector.setX(x); +} + +void QDeclarativeVector4DValueType::setY(qreal y) +{ + vector.setY(y); +} + +void QDeclarativeVector4DValueType::setZ(qreal z) +{ + vector.setZ(z); +} + +void QDeclarativeVector4DValueType::setW(qreal w) +{ + vector.setW(w); +} + +QDeclarativeQuaternionValueType::QDeclarativeQuaternionValueType(QObject *parent) +: QDeclarativeValueType(parent) +{ +} + +void QDeclarativeQuaternionValueType::read(QObject *obj, int idx) +{ + void *a[] = { &quaternion, 0 }; + QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); +} + +void QDeclarativeQuaternionValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) +{ + int status = -1; + void *a[] = { &quaternion, 0, &status, &flags }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); +} + +QVariant QDeclarativeQuaternionValueType::value() +{ + return QVariant(quaternion); +} + +void QDeclarativeQuaternionValueType::setValue(QVariant value) +{ + quaternion = qvariant_cast<QQuaternion>(value); +} + +qreal QDeclarativeQuaternionValueType::scalar() const +{ + return quaternion.scalar(); +} + +qreal QDeclarativeQuaternionValueType::x() const +{ + return quaternion.x(); +} + +qreal QDeclarativeQuaternionValueType::y() const +{ + return quaternion.y(); +} + +qreal QDeclarativeQuaternionValueType::z() const +{ + return quaternion.z(); +} + +void QDeclarativeQuaternionValueType::setScalar(qreal scalar) +{ + quaternion.setScalar(scalar); +} + +void QDeclarativeQuaternionValueType::setX(qreal x) +{ + quaternion.setX(x); +} + +void QDeclarativeQuaternionValueType::setY(qreal y) +{ + quaternion.setY(y); +} + +void QDeclarativeQuaternionValueType::setZ(qreal z) +{ + quaternion.setZ(z); +} + +QDeclarativeMatrix4x4ValueType::QDeclarativeMatrix4x4ValueType(QObject *parent) +: QDeclarativeValueType(parent) +{ +} + +void QDeclarativeMatrix4x4ValueType::read(QObject *obj, int idx) +{ + void *a[] = { &matrix, 0 }; + QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); +} + +void QDeclarativeMatrix4x4ValueType::write(QObject *obj, int idx, QDeclarativePropertyPrivate::WriteFlags flags) +{ + int status = -1; + void *a[] = { &matrix, 0, &status, &flags }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); +} + +QVariant QDeclarativeMatrix4x4ValueType::value() +{ + return QVariant(matrix); +} + +void QDeclarativeMatrix4x4ValueType::setValue(QVariant value) +{ + matrix = qvariant_cast<QMatrix4x4>(value); +} + QDeclarativeEasingValueType::QDeclarativeEasingValueType(QObject *parent) : QDeclarativeValueType(parent) { diff --git a/src/declarative/qml/qdeclarativevaluetype_p.h b/src/declarative/qml/qdeclarativevaluetype_p.h index d1833bb..476c73d 100644 --- a/src/declarative/qml/qdeclarativevaluetype_p.h +++ b/src/declarative/qml/qdeclarativevaluetype_p.h @@ -60,7 +60,11 @@ #include <QtCore/qrect.h> #include <QtCore/qeasingcurve.h> #include <QtCore/qvariant.h> +#include <QtGui/qvector2d.h> #include <QtGui/qvector3d.h> +#include <QtGui/qvector4d.h> +#include <QtGui/qmatrix4x4.h> +#include <QtGui/qquaternion.h> #include <QtGui/qfont.h> QT_BEGIN_NAMESPACE @@ -241,6 +245,28 @@ private: QRect rect; }; +class Q_AUTOTEST_EXPORT QDeclarativeVector2DValueType : public QDeclarativeValueType +{ + Q_PROPERTY(qreal x READ x WRITE setX) + Q_PROPERTY(qreal y READ y WRITE setY) + Q_OBJECT +public: + QDeclarativeVector2DValueType(QObject *parent = 0); + + virtual void read(QObject *, int); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); + virtual QVariant value(); + virtual void setValue(QVariant value); + + qreal x() const; + qreal y() const; + void setX(qreal); + void setY(qreal); + +private: + QVector2D vector; +}; + class Q_AUTOTEST_EXPORT QDeclarativeVector3DValueType : public QDeclarativeValueType { Q_PROPERTY(qreal x READ x WRITE setX) @@ -266,6 +292,127 @@ private: QVector3D vector; }; +class Q_AUTOTEST_EXPORT QDeclarativeVector4DValueType : public QDeclarativeValueType +{ + Q_PROPERTY(qreal x READ x WRITE setX) + Q_PROPERTY(qreal y READ y WRITE setY) + Q_PROPERTY(qreal z READ z WRITE setZ) + Q_PROPERTY(qreal w READ w WRITE setW) + Q_OBJECT +public: + QDeclarativeVector4DValueType(QObject *parent = 0); + + virtual void read(QObject *, int); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); + virtual QVariant value(); + virtual void setValue(QVariant value); + + qreal x() const; + qreal y() const; + qreal z() const; + qreal w() const; + void setX(qreal); + void setY(qreal); + void setZ(qreal); + void setW(qreal); + +private: + QVector4D vector; +}; + +class Q_AUTOTEST_EXPORT QDeclarativeQuaternionValueType : public QDeclarativeValueType +{ + Q_PROPERTY(qreal scalar READ scalar WRITE setScalar) + Q_PROPERTY(qreal x READ x WRITE setX) + Q_PROPERTY(qreal y READ y WRITE setY) + Q_PROPERTY(qreal z READ z WRITE setZ) + Q_OBJECT +public: + QDeclarativeQuaternionValueType(QObject *parent = 0); + + virtual void read(QObject *, int); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); + virtual QVariant value(); + virtual void setValue(QVariant value); + + qreal scalar() const; + qreal x() const; + qreal y() const; + qreal z() const; + void setScalar(qreal); + void setX(qreal); + void setY(qreal); + void setZ(qreal); + +private: + QQuaternion quaternion; +}; + +class Q_AUTOTEST_EXPORT QDeclarativeMatrix4x4ValueType : public QDeclarativeValueType +{ + Q_PROPERTY(qreal m11 READ m11 WRITE setM11) + Q_PROPERTY(qreal m12 READ m12 WRITE setM12) + Q_PROPERTY(qreal m13 READ m13 WRITE setM13) + Q_PROPERTY(qreal m14 READ m14 WRITE setM14) + Q_PROPERTY(qreal m21 READ m21 WRITE setM21) + Q_PROPERTY(qreal m22 READ m22 WRITE setM22) + Q_PROPERTY(qreal m23 READ m23 WRITE setM23) + Q_PROPERTY(qreal m24 READ m24 WRITE setM24) + Q_PROPERTY(qreal m31 READ m31 WRITE setM31) + Q_PROPERTY(qreal m32 READ m32 WRITE setM32) + Q_PROPERTY(qreal m33 READ m33 WRITE setM33) + Q_PROPERTY(qreal m34 READ m34 WRITE setM34) + Q_PROPERTY(qreal m41 READ m41 WRITE setM41) + Q_PROPERTY(qreal m42 READ m42 WRITE setM42) + Q_PROPERTY(qreal m43 READ m43 WRITE setM43) + Q_PROPERTY(qreal m44 READ m44 WRITE setM44) + Q_OBJECT +public: + QDeclarativeMatrix4x4ValueType(QObject *parent = 0); + + virtual void read(QObject *, int); + virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags); + virtual QVariant value(); + virtual void setValue(QVariant value); + + qreal m11() const { return matrix(0, 0); } + qreal m12() const { return matrix(0, 1); } + qreal m13() const { return matrix(0, 2); } + qreal m14() const { return matrix(0, 3); } + qreal m21() const { return matrix(1, 0); } + qreal m22() const { return matrix(1, 1); } + qreal m23() const { return matrix(1, 2); } + qreal m24() const { return matrix(1, 3); } + qreal m31() const { return matrix(2, 0); } + qreal m32() const { return matrix(2, 1); } + qreal m33() const { return matrix(2, 2); } + qreal m34() const { return matrix(2, 3); } + qreal m41() const { return matrix(3, 0); } + qreal m42() const { return matrix(3, 1); } + qreal m43() const { return matrix(3, 2); } + qreal m44() const { return matrix(3, 3); } + + void setM11(qreal value) { matrix(0, 0) = value; } + void setM12(qreal value) { matrix(0, 1) = value; } + void setM13(qreal value) { matrix(0, 2) = value; } + void setM14(qreal value) { matrix(0, 3) = value; } + void setM21(qreal value) { matrix(1, 0) = value; } + void setM22(qreal value) { matrix(1, 1) = value; } + void setM23(qreal value) { matrix(1, 2) = value; } + void setM24(qreal value) { matrix(1, 3) = value; } + void setM31(qreal value) { matrix(2, 0) = value; } + void setM32(qreal value) { matrix(2, 1) = value; } + void setM33(qreal value) { matrix(2, 2) = value; } + void setM34(qreal value) { matrix(2, 3) = value; } + void setM41(qreal value) { matrix(3, 0) = value; } + void setM42(qreal value) { matrix(3, 1) = value; } + void setM43(qreal value) { matrix(3, 2) = value; } + void setM44(qreal value) { matrix(3, 3) = value; } + +private: + QMatrix4x4 matrix; +}; + class Q_AUTOTEST_EXPORT QDeclarativeEasingValueType : public QDeclarativeValueType { Q_OBJECT diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/matrix4x4_read.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/matrix4x4_read.qml new file mode 100644 index 0000000..6c4a682 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/matrix4x4_read.qml @@ -0,0 +1,22 @@ +import Test 1.0 + +MyTypeObject { + property real v_m11: matrix.m11 + property real v_m12: matrix.m12 + property real v_m13: matrix.m13 + property real v_m14: matrix.m14 + property real v_m21: matrix.m21 + property real v_m22: matrix.m22 + property real v_m23: matrix.m23 + property real v_m24: matrix.m24 + property real v_m31: matrix.m31 + property real v_m32: matrix.m32 + property real v_m33: matrix.m33 + property real v_m34: matrix.m34 + property real v_m41: matrix.m41 + property real v_m42: matrix.m42 + property real v_m43: matrix.m43 + property real v_m44: matrix.m44 + property variant copy: matrix +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/matrix4x4_write.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/matrix4x4_write.qml new file mode 100644 index 0000000..2a9f154 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/matrix4x4_write.qml @@ -0,0 +1,21 @@ +import Test 1.0 + +MyTypeObject { + matrix.m11: if (true) 11 + matrix.m12: if (true) 12 + matrix.m13: if (true) 13 + matrix.m14: if (true) 14 + matrix.m21: if (true) 21 + matrix.m22: if (true) 22 + matrix.m23: if (true) 23 + matrix.m24: if (true) 24 + matrix.m31: if (true) 31 + matrix.m32: if (true) 32 + matrix.m33: if (true) 33 + matrix.m34: if (true) 34 + matrix.m41: if (true) 41 + matrix.m42: if (true) 42 + matrix.m43: if (true) 43 + matrix.m44: if (true) 44 +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/quaternion_read.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/quaternion_read.qml new file mode 100644 index 0000000..d1a21dc --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/quaternion_read.qml @@ -0,0 +1,10 @@ +import Test 1.0 + +MyTypeObject { + property real v_scalar: quaternion.scalar + property real v_x: quaternion.x + property real v_y: quaternion.y + property real v_z: quaternion.z + property variant copy: quaternion +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/quaternion_write.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/quaternion_write.qml new file mode 100644 index 0000000..0c3e5af --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/quaternion_write.qml @@ -0,0 +1,9 @@ +import Test 1.0 + +MyTypeObject { + quaternion.scalar: if (true) 88.5 + quaternion.x: if (true) -0.3 + quaternion.y: if (true) -12.9 + quaternion.z: if (true) 907.4 +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/vector2d_read.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/vector2d_read.qml new file mode 100644 index 0000000..fc315f7 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/vector2d_read.qml @@ -0,0 +1,8 @@ +import Test 1.0 + +MyTypeObject { + property real v_x: vector2.x + property real v_y: vector2.y + property variant copy: vector2 +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/vector2d_write.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/vector2d_write.qml new file mode 100644 index 0000000..f0e35ff --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/vector2d_write.qml @@ -0,0 +1,7 @@ +import Test 1.0 + +MyTypeObject { + vector2.x: if (true) -0.3 + vector2.y: if (true) -12.9 +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/vector4d_read.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/vector4d_read.qml new file mode 100644 index 0000000..f9d5d60 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/vector4d_read.qml @@ -0,0 +1,10 @@ +import Test 1.0 + +MyTypeObject { + property real v_x: vector4.x + property real v_y: vector4.y + property real v_z: vector4.z + property real v_w: vector4.w + property variant copy: vector4 +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/vector4d_write.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/vector4d_write.qml new file mode 100644 index 0000000..5486981 --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/vector4d_write.qml @@ -0,0 +1,9 @@ +import Test 1.0 + +MyTypeObject { + vector4.x: if (true) -0.3 + vector4.y: if (true) -12.9 + vector4.z: if (true) 907.4 + vector4.w: if (true) 88.5 +} + diff --git a/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h b/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h index 8a9b981..1da9990 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h +++ b/tests/auto/declarative/qdeclarativevaluetypes/testtypes.h @@ -48,7 +48,11 @@ #include <QSizeF> #include <QRect> #include <QRectF> +#include <QVector2D> #include <QVector3D> +#include <QVector4D> +#include <QQuaternion> +#include <QMatrix4x4> #include <QFont> #include <qdeclarative.h> #include <QDeclarativePropertyValueSource> @@ -66,7 +70,11 @@ class MyTypeObject : public QObject Q_PROPERTY(QSize sizereadonly READ size NOTIFY changed) Q_PROPERTY(QRect rect READ rect WRITE setRect NOTIFY changed) Q_PROPERTY(QRectF rectf READ rectf WRITE setRectf NOTIFY changed) + Q_PROPERTY(QVector2D vector2 READ vector2 WRITE setVector2 NOTIFY changed) Q_PROPERTY(QVector3D vector READ vector WRITE setVector NOTIFY changed) + Q_PROPERTY(QVector4D vector4 READ vector4 WRITE setVector4 NOTIFY changed) + Q_PROPERTY(QQuaternion quaternion READ quaternion WRITE setQuaternion NOTIFY changed) + Q_PROPERTY(QMatrix4x4 matrix READ matrix WRITE setMatrix NOTIFY changed) Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed) public: @@ -77,7 +85,11 @@ public: m_sizef(0.1, 100923.2), m_rect(2, 3, 109, 102), m_rectf(103.8, 99.2, 88.1, 77.6), - m_vector(23.88, 3.1, 4.3) + m_vector2(32.88, 1.3), + m_vector(23.88, 3.1, 4.3), + m_vector4(54.2, 23.88, 3.1, 4.3), + m_quaternion(4.3, 54.2, 23.88, 3.1), + m_matrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) { m_font.setFamily("Arial"); m_font.setBold(true); @@ -116,10 +128,26 @@ public: QRectF rectf() const { return m_rectf; } void setRectf(const QRectF &v) { m_rectf = v; emit changed(); } + QVector2D m_vector2; + QVector2D vector2() const { return m_vector2; } + void setVector2(const QVector2D &v) { m_vector2 = v; emit changed(); } + QVector3D m_vector; QVector3D vector() const { return m_vector; } void setVector(const QVector3D &v) { m_vector = v; emit changed(); } + QVector4D m_vector4; + QVector4D vector4() const { return m_vector4; } + void setVector4(const QVector4D &v) { m_vector4 = v; emit changed(); } + + QQuaternion m_quaternion; + QQuaternion quaternion() const { return m_quaternion; } + void setQuaternion(const QQuaternion &v) { m_quaternion = v; emit changed(); } + + QMatrix4x4 m_matrix; + QMatrix4x4 matrix() const { return m_matrix; } + void setMatrix(const QMatrix4x4 &v) { m_matrix = v; emit changed(); } + QFont m_font; QFont font() const { return m_font; } void setFont(const QFont &v) { m_font = v; emit changed(); } diff --git a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp index b733b10..c18fbf5 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp +++ b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp @@ -62,7 +62,11 @@ private slots: void sizereadonly(); void rect(); void rectf(); + void vector2d(); void vector3d(); + void vector4d(); + void quaternion(); + void matrix4x4(); void font(); void bindingAssignment(); @@ -293,6 +297,31 @@ void tst_qdeclarativevaluetypes::rectf() } } +void tst_qdeclarativevaluetypes::vector2d() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("vector2d_read.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QCOMPARE((float)object->property("v_x").toDouble(), (float)32.88); + QCOMPARE((float)object->property("v_y").toDouble(), (float)1.3); + QCOMPARE(object->property("copy"), QVariant(QVector2D(32.88, 1.3))); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("vector2d_write.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->vector2(), QVector2D(-0.3, -12.9)); + + delete object; + } +} + void tst_qdeclarativevaluetypes::vector3d() { { @@ -319,6 +348,106 @@ void tst_qdeclarativevaluetypes::vector3d() } } +void tst_qdeclarativevaluetypes::vector4d() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("vector4d_read.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QCOMPARE((float)object->property("v_x").toDouble(), (float)54.2); + QCOMPARE((float)object->property("v_y").toDouble(), (float)23.88); + QCOMPARE((float)object->property("v_z").toDouble(), (float)3.1); + QCOMPARE((float)object->property("v_w").toDouble(), (float)4.3); + QCOMPARE(object->property("copy"), QVariant(QVector4D(54.2, 23.88, 3.1, 4.3))); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("vector4d_write.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->vector4(), QVector4D(-0.3, -12.9, 907.4, 88.5)); + + delete object; + } +} + +void tst_qdeclarativevaluetypes::quaternion() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("quaternion_read.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QCOMPARE((float)object->property("v_scalar").toDouble(), (float)4.3); + QCOMPARE((float)object->property("v_x").toDouble(), (float)54.2); + QCOMPARE((float)object->property("v_y").toDouble(), (float)23.88); + QCOMPARE((float)object->property("v_z").toDouble(), (float)3.1); + QCOMPARE(object->property("copy"), QVariant(QQuaternion(4.3, 54.2, 23.88, 3.1))); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("quaternion_write.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->quaternion(), QQuaternion(88.5, -0.3, -12.9, 907.4)); + + delete object; + } +} + +void tst_qdeclarativevaluetypes::matrix4x4() +{ + { + QDeclarativeComponent component(&engine, TEST_FILE("matrix4x4_read.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QCOMPARE((float)object->property("v_m11").toDouble(), (float)1); + QCOMPARE((float)object->property("v_m12").toDouble(), (float)2); + QCOMPARE((float)object->property("v_m13").toDouble(), (float)3); + QCOMPARE((float)object->property("v_m14").toDouble(), (float)4); + QCOMPARE((float)object->property("v_m21").toDouble(), (float)5); + QCOMPARE((float)object->property("v_m22").toDouble(), (float)6); + QCOMPARE((float)object->property("v_m23").toDouble(), (float)7); + QCOMPARE((float)object->property("v_m24").toDouble(), (float)8); + QCOMPARE((float)object->property("v_m31").toDouble(), (float)9); + QCOMPARE((float)object->property("v_m32").toDouble(), (float)10); + QCOMPARE((float)object->property("v_m33").toDouble(), (float)11); + QCOMPARE((float)object->property("v_m34").toDouble(), (float)12); + QCOMPARE((float)object->property("v_m41").toDouble(), (float)13); + QCOMPARE((float)object->property("v_m42").toDouble(), (float)14); + QCOMPARE((float)object->property("v_m43").toDouble(), (float)15); + QCOMPARE((float)object->property("v_m44").toDouble(), (float)16); + QCOMPARE(object->property("copy"), + QVariant(QMatrix4x4(1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12, + 13, 14, 15, 16))); + + delete object; + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("matrix4x4_write.qml")); + MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); + QVERIFY(object != 0); + + QCOMPARE(object->matrix(), QMatrix4x4(11, 12, 13, 14, + 21, 22, 23, 24, + 31, 32, 33, 34, + 41, 42, 43, 44)); + + delete object; + } +} + void tst_qdeclarativevaluetypes::font() { { @@ -665,7 +794,12 @@ void tst_qdeclarativevaluetypes::cppClasses() CPP_TEST(QDeclarativeSizeFValueType, QSizeF(-100.7, 18.2)); CPP_TEST(QDeclarativeRectValueType, QRect(13, 39, 10928, 88)); CPP_TEST(QDeclarativeRectFValueType, QRectF(88.2, -90.1, 103.2, 118)); + CPP_TEST(QDeclarativeVector2DValueType, QVector2D(19.7, 1002)); CPP_TEST(QDeclarativeVector3DValueType, QVector3D(18.2, 19.7, 1002)); + CPP_TEST(QDeclarativeVector4DValueType, QVector4D(18.2, 19.7, 1002, 54)); + CPP_TEST(QDeclarativeQuaternionValueType, QQuaternion(18.2, 19.7, 1002, 54)); + CPP_TEST(QDeclarativeMatrix4x4ValueType, + QMatrix4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)); CPP_TEST(QDeclarativeFontValueType, QFont("Helvetica")); } |