From aff524d218e9d2f2ed4a02258a5a159be3e61de6 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Fri, 24 Jul 2009 15:37:14 +1000 Subject: Add QVector3D as a value type to QML Reviewed-by: Aaron Kennedy --- src/declarative/qml/qmlvaluetype.cpp | 49 ++++++++++++++++++++++++++++++++++++ src/declarative/qml/qmlvaluetype_p.h | 25 ++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/src/declarative/qml/qmlvaluetype.cpp b/src/declarative/qml/qmlvaluetype.cpp index a01b4a7..571263e 100644 --- a/src/declarative/qml/qmlvaluetype.cpp +++ b/src/declarative/qml/qmlvaluetype.cpp @@ -61,6 +61,8 @@ QmlValueType *QmlValueTypeFactory::valueType(int t) switch (t) { case QVariant::Rect: return new QmlRectValueType; + case QVariant::Vector3D: + return new QmlVector3DValueType; default: return 0; } @@ -128,4 +130,51 @@ void QmlRectValueType::setHeight(int h) rect.setHeight(h); } +QmlVector3DValueType::QmlVector3DValueType(QObject *parent) +: QmlValueType(parent) +{ +} + +void QmlVector3DValueType::read(QObject *obj, int idx) +{ + void *a[] = { &vector, 0 }; + QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); +} + +void QmlVector3DValueType::write(QObject *obj, int idx) +{ + void *a[] = { &vector, 0 }; + QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); +} + +qreal QmlVector3DValueType::x() const +{ + return vector.x(); +} + +qreal QmlVector3DValueType::y() const +{ + return vector.y(); +} + +qreal QmlVector3DValueType::z() const +{ + return vector.z(); +} + +void QmlVector3DValueType::setX(qreal x) +{ + vector.setX(x); +} + +void QmlVector3DValueType::setY(qreal y) +{ + vector.setY(y); +} + +void QmlVector3DValueType::setZ(qreal z) +{ + vector.setZ(z); +} + QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlvaluetype_p.h b/src/declarative/qml/qmlvaluetype_p.h index 5581df7..b19c1ba 100644 --- a/src/declarative/qml/qmlvaluetype_p.h +++ b/src/declarative/qml/qmlvaluetype_p.h @@ -56,6 +56,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -105,6 +106,30 @@ public: private: QRect rect; }; + +class QmlVector3DValueType : public QmlValueType +{ + 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: + QmlVector3DValueType(QObject *parent = 0); + + virtual void read(QObject *, int); + virtual void write(QObject *, int); + + qreal x() const; + qreal y() const; + qreal z() const; + void setX(qreal); + void setY(qreal); + void setZ(qreal); + +private: + QVector3D vector; +}; + QT_END_NAMESPACE #endif // QMLVALUETYPE_P_H -- cgit v0.12