aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/util/qquickglobal.cpp
diff options
context:
space:
mode:
authorFrank Meerkoetter <frank.meerkoetter@basyskom.com>2015-07-25 19:43:43 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-08-18 20:26:00 +0000
commit37fbe667e6b5a528592b244124189981ba4aada9 (patch)
treedfc87ec938d0d7724f290163dab0b94be934c2fb /src/quick/util/qquickglobal.cpp
parent44ac9e797ce30c1c9f6af704a7677fe0c9ac5794 (diff)
Adapt the ValueTypeProvider interface and port its types
The ValueTypeProvider system allows non-QML modules to add new basic QML types. It needs to be changed when porting away from QQmlVmeVariant as underlying type of properties. Change-Id: I2b52d7e6f578647a39832896c28553404b9a679f Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/quick/util/qquickglobal.cpp')
-rw-r--r--src/quick/util/qquickglobal.cpp132
1 files changed, 40 insertions, 92 deletions
diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp
index fd172006e0..adf3a68e92 100644
--- a/src/quick/util/qquickglobal.cpp
+++ b/src/quick/util/qquickglobal.cpp
@@ -397,41 +397,30 @@ public:
return 0;
}
- template<typename T>
- bool typedInit(void *data, size_t dataSize)
- {
- ASSERT_VALID_SIZE(dataSize, sizeof(T));
- T *t = reinterpret_cast<T *>(data);
- new (t) T();
- return true;
- }
-
- bool init(int type, void *data, size_t dataSize)
+ bool init(int type, QVariant& dst)
{
switch (type) {
case QMetaType::QColor:
- return typedInit<QColor>(data, dataSize);
+ dst.setValue<QColor>(QColor());
+ return true;
case QMetaType::QFont:
- return typedInit<QFont>(data, dataSize);
+ dst.setValue<QFont>(QFont());
+ return true;
case QMetaType::QVector2D:
- return typedInit<QVector2D>(data, dataSize);
+ dst.setValue<QVector2D>(QVector2D());
+ return true;
case QMetaType::QVector3D:
- return typedInit<QVector3D>(data, dataSize);
+ dst.setValue<QVector3D>(QVector3D());
+ return true;
case QMetaType::QVector4D:
- return typedInit<QVector4D>(data, dataSize);
+ dst.setValue<QVector4D>(QVector4D());
+ return true;
case QMetaType::QQuaternion:
- return typedInit<QQuaternion>(data, dataSize);
+ dst.setValue<QQuaternion>(QQuaternion());
+ return true;
case QMetaType::QMatrix4x4:
- {
- if (dataSize >= sizeof(QMatrix4x4))
- return typedInit<QMatrix4x4>(data, dataSize);
-
- // special case: init matrix-containing qvariant.
- Q_ASSERT(dataSize >= sizeof(QVariant));
- QVariant *matvar = reinterpret_cast<QVariant *>(data);
- new (matvar) QVariant(QMatrix4x4());
+ dst.setValue<QMatrix4x4>(QMatrix4x4());
return true;
- }
default: break;
}
@@ -691,12 +680,12 @@ public:
}
template<typename T>
- bool typedEqual(const void *lhs, const void *rhs)
+ bool typedEqual(const void *lhs, const QVariant& rhs)
{
- return (*(reinterpret_cast<const T *>(lhs)) == *(reinterpret_cast<const T *>(rhs)));
+ return (*(reinterpret_cast<const T *>(lhs)) == rhs.value<T>());
}
- bool equal(int type, const void *lhs, const void *rhs, size_t rhsSize)
+ bool equal(int type, const void *lhs, const QVariant &rhs)
{
switch (type) {
case QMetaType::QColor:
@@ -712,14 +701,7 @@ public:
case QMetaType::QQuaternion:
return typedEqual<QQuaternion>(lhs, rhs);
case QMetaType::QMatrix4x4:
- {
- if (rhsSize >= sizeof(QMatrix4x4))
- return typedEqual<QMatrix4x4>(lhs, rhs);
-
- Q_ASSERT(rhsSize >= sizeof(QVariant));
- QMatrix4x4 rhsmat = reinterpret_cast<const QVariant *>(rhs)->value<QMatrix4x4>();
- return typedEqual<QMatrix4x4>(lhs, &rhsmat);
- }
+ return typedEqual<QMatrix4x4>(lhs, rhs);
default: break;
}
@@ -778,50 +760,34 @@ public:
}
template<typename T>
- bool typedRead(int srcType, const void *src, size_t srcSize, int dstType, void *dst)
+ bool typedRead(const QVariant& src, int dstType, void *dst)
{
T *dstT = reinterpret_cast<T *>(dst);
- if (srcType == dstType) {
- ASSERT_VALID_SIZE(srcSize, sizeof(T));
- const T *srcT = reinterpret_cast<const T *>(src);
- *dstT = *srcT;
+ if (src.type() == static_cast<uint>(dstType)) {
+ *dstT = src.value<T>();
} else {
*dstT = T();
}
return true;
}
- bool read(int srcType, const void *src, size_t srcSize, int dstType, void *dst)
+ bool read(const QVariant &src, void *dst, int dstType)
{
switch (dstType) {
case QMetaType::QColor:
- return typedRead<QColor>(srcType, src, srcSize, dstType, dst);
+ return typedRead<QColor>(src, dstType, dst);
case QMetaType::QFont:
- return typedRead<QFont>(srcType, src, srcSize, dstType, dst);
+ return typedRead<QFont>(src, dstType, dst);
case QMetaType::QVector2D:
- return typedRead<QVector2D>(srcType, src, srcSize, dstType, dst);
+ return typedRead<QVector2D>(src, dstType, dst);
case QMetaType::QVector3D:
- return typedRead<QVector3D>(srcType, src, srcSize, dstType, dst);
+ return typedRead<QVector3D>(src, dstType, dst);
case QMetaType::QVector4D:
- return typedRead<QVector4D>(srcType, src, srcSize, dstType, dst);
+ return typedRead<QVector4D>(src, dstType, dst);
case QMetaType::QQuaternion:
- return typedRead<QQuaternion>(srcType, src, srcSize, dstType, dst);
+ return typedRead<QQuaternion>(src, dstType, dst);
case QMetaType::QMatrix4x4:
- {
- if (srcSize >= sizeof(QMatrix4x4))
- return typedRead<QMatrix4x4>(srcType, src, srcSize, dstType, dst);
-
- // the source data may be stored in a QVariant.
- QMatrix4x4 *dstMat = reinterpret_cast<QMatrix4x4 *>(dst);
- if (srcType == dstType) {
- Q_ASSERT(srcSize >= sizeof(QVariant));
- const QVariant *srcMatVar = reinterpret_cast<const QVariant *>(src);
- *dstMat = srcMatVar->value<QMatrix4x4>();
- } else {
- *dstMat = QMatrix4x4();
- }
- return true;
- }
+ return typedRead<QMatrix4x4>(src, dstType, dst);
default: break;
}
@@ -829,51 +795,33 @@ public:
}
template<typename T>
- bool typedWrite(const void *src, void *dst, size_t dstSize)
+ bool typedWrite(const void *src, QVariant& dst)
{
- ASSERT_VALID_SIZE(dstSize, sizeof(T));
const T *srcT = reinterpret_cast<const T *>(src);
- T *dstT = reinterpret_cast<T *>(dst);
- if (*dstT != *srcT) {
- *dstT = *srcT;
+ if (dst.value<T>() != *srcT) {
+ dst = *srcT;
return true;
}
return false;
}
- bool write(int type, const void *src, void *dst, size_t dstSize)
+ bool write(int type, const void *src, QVariant& dst)
{
switch (type) {
case QMetaType::QColor:
- return typedWrite<QColor>(src, dst, dstSize);
+ return typedWrite<QColor>(src, dst);
case QMetaType::QFont:
- return typedWrite<QFont>(src, dst, dstSize);
+ return typedWrite<QFont>(src, dst);
case QMetaType::QVector2D:
- return typedWrite<QVector2D>(src, dst, dstSize);
+ return typedWrite<QVector2D>(src, dst);
case QMetaType::QVector3D:
- return typedWrite<QVector3D>(src, dst, dstSize);
+ return typedWrite<QVector3D>(src, dst);
case QMetaType::QVector4D:
- return typedWrite<QVector4D>(src, dst, dstSize);
+ return typedWrite<QVector4D>(src, dst);
case QMetaType::QQuaternion:
- return typedWrite<QQuaternion>(src, dst, dstSize);
+ return typedWrite<QQuaternion>(src, dst);
case QMetaType::QMatrix4x4:
- {
- if (dstSize >= sizeof(QMatrix4x4))
- return typedWrite<QMatrix4x4>(src, dst, dstSize);
-
- // special case: storing matrix into variant
- // eg, QVMEMO QVMEVariant data cell is big enough to store
- // QVariant, but not large enough to store QMatrix4x4.
- Q_ASSERT(dstSize >= sizeof(QVariant));
- const QMatrix4x4 *srcMat = reinterpret_cast<const QMatrix4x4 *>(src);
- QVariant *dstMatVar = reinterpret_cast<QVariant *>(dst);
- QMatrix4x4 dstMatVal = dstMatVar->value<QMatrix4x4>();
- if (dstMatVal != *srcMat) {
- *dstMatVar = QVariant(*srcMat);
- return true;
- }
- return false;
- }
+ return typedWrite<QMatrix4x4>(src, dst);
default: break;
}