aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlvmemetaobject.cpp
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 /src/qml/qml/qqmlvmemetaobject.cpp
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 'src/qml/qml/qqmlvmemetaobject.cpp')
-rw-r--r--src/qml/qml/qqmlvmemetaobject.cpp66
1 files changed, 64 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp
index 1c07dd676e..c982856453 100644
--- a/src/qml/qml/qqmlvmemetaobject.cpp
+++ b/src/qml/qml/qqmlvmemetaobject.cpp
@@ -101,6 +101,8 @@ public:
inline const QDate &asQDate();
inline const QDateTime &asQDateTime();
inline const QRectF &asQRectF();
+ inline const QPointF &asQPointF();
+ inline const QSizeF &asQSizeF();
inline const QJSValue &asQJSValue();
inline void setValue(QObject *v, QQmlVMEMetaObject *target, int index);
@@ -114,6 +116,8 @@ public:
inline void setValue(const QDate &);
inline void setValue(const QDateTime &);
inline void setValue(const QRectF &);
+ inline void setValue(const QPointF &);
+ inline void setValue(const QSizeF &);
inline void setValue(const QJSValue &);
inline void setDataType(int t);
@@ -176,6 +180,12 @@ void QQmlVMEVariant::cleanup()
} else if (type == QMetaType::QRectF) {
((QRectF *)dataPtr())->~QRectF();
type = QVariant::Invalid;
+ } else if (type == QMetaType::QPointF) {
+ ((QPointF *)dataPtr())->~QPointF();
+ type = QVariant::Invalid;
+ } else if (type == QMetaType::QSizeF) {
+ ((QSizeF *)dataPtr())->~QSizeF();
+ type = QVariant::Invalid;
} else if (type == qMetaTypeId<QVariant>()) {
((QVariant *)dataPtr())->~QVariant();
type = QVariant::Invalid;
@@ -297,6 +307,22 @@ const QRectF &QQmlVMEVariant::asQRectF()
return *(QRectF *)(dataPtr());
}
+const QSizeF &QQmlVMEVariant::asQSizeF()
+{
+ if (type != QMetaType::QSizeF)
+ setValue(QSizeF());
+
+ return *(QSizeF *)(dataPtr());
+}
+
+const QPointF &QQmlVMEVariant::asQPointF()
+{
+ if (type != QMetaType::QPointF)
+ setValue(QPointF());
+
+ return *(QPointF *)(dataPtr());
+}
+
const QJSValue &QQmlVMEVariant::asQJSValue()
{
if (type != qMetaTypeId<QJSValue>())
@@ -419,6 +445,28 @@ void QQmlVMEVariant::setValue(const QRectF &v)
}
}
+void QQmlVMEVariant::setValue(const QPointF &v)
+{
+ if (type != QMetaType::QPointF) {
+ cleanup();
+ type = QMetaType::QPointF;
+ new (dataPtr()) QPointF(v);
+ } else {
+ *(QPointF *)(dataPtr()) = v;
+ }
+}
+
+void QQmlVMEVariant::setValue(const QSizeF &v)
+{
+ if (type != QMetaType::QSizeF) {
+ cleanup();
+ type = QMetaType::QSizeF;
+ new (dataPtr()) QSizeF(v);
+ } else {
+ *(QSizeF *)(dataPtr()) = v;
+ }
+}
+
void QQmlVMEVariant::setValue(const QJSValue &v)
{
if (type != qMetaTypeId<QJSValue>()) {
@@ -685,6 +733,12 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
case QVariant::RectF:
*reinterpret_cast<QRectF *>(a[0]) = data[id].asQRectF();
break;
+ case QVariant::SizeF:
+ *reinterpret_cast<QSizeF *>(a[0]) = data[id].asQSizeF();
+ break;
+ case QVariant::PointF:
+ *reinterpret_cast<QPointF *>(a[0]) = data[id].asQPointF();
+ break;
case QMetaType::QObjectStar:
*reinterpret_cast<QObject **>(a[0]) = data[id].asQObject();
break;
@@ -692,7 +746,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
*reinterpret_cast<QVariant *>(a[0]) = readPropertyAsVariant(id);
break;
default:
- QQml_valueTypeProvider()->readValueType(data[id].dataType(), data[id].dataPtr(), t, a[0]);
+ QQml_valueTypeProvider()->readValueType(data[id].dataType(), data[id].dataPtr(), data->dataSize(), t, a[0]);
break;
}
if (t == qMetaTypeId<QQmlListProperty<QObject> >()) {
@@ -739,6 +793,14 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
needActivate = *reinterpret_cast<QRectF *>(a[0]) != data[id].asQRectF();
data[id].setValue(*reinterpret_cast<QRectF *>(a[0]));
break;
+ case QVariant::SizeF:
+ needActivate = *reinterpret_cast<QSizeF *>(a[0]) != data[id].asQSizeF();
+ data[id].setValue(*reinterpret_cast<QSizeF *>(a[0]));
+ break;
+ case QVariant::PointF:
+ needActivate = *reinterpret_cast<QPointF *>(a[0]) != data[id].asQPointF();
+ data[id].setValue(*reinterpret_cast<QPointF *>(a[0]));
+ break;
case QMetaType::QObjectStar:
needActivate = *reinterpret_cast<QObject **>(a[0]) != data[id].asQObject();
data[id].setValue(*reinterpret_cast<QObject **>(a[0]), this, id);
@@ -748,7 +810,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
break;
default:
data[id].ensureValueType(t);
- needActivate = !QQml_valueTypeProvider()->equalValueType(t, a[0], data[id].dataPtr());
+ needActivate = !QQml_valueTypeProvider()->equalValueType(t, a[0], data[id].dataPtr(), data[id].dataSize());
QQml_valueTypeProvider()->writeValueType(t, a[0], data[id].dataPtr(), data[id].dataSize());
break;
}