return QVariant();
}
+bool QQmlValueTypeProvider::equalValueType(int type, const void *lhs, const void *rhs)
+{
+ Q_ASSERT(lhs);
+ Q_ASSERT(rhs);
+
+ QQmlValueTypeProvider *p = this;
+ do {
+ if (p->equal(type, lhs, rhs))
+ return true;
+ } while ((p = p->next));
+
+ return false;
+}
+
bool QQmlValueTypeProvider::storeValueType(int type, const void *src, void *dst, size_t n)
{
Q_ASSERT(src);
bool QQmlValueTypeProvider::createStringFrom(int, const void *, QString *) { return false; }
bool QQmlValueTypeProvider::variantFromString(const QString &, QVariant *) { return false; }
bool QQmlValueTypeProvider::variantFromString(int, const QString &, QVariant *) { return false; }
+bool QQmlValueTypeProvider::equal(int, const void *, const void *) { return false; }
bool QQmlValueTypeProvider::store(int, const void *, void *, size_t) { return false; }
bool QQmlValueTypeProvider::read(int, const void *, int, void *) { return false; }
bool QQmlValueTypeProvider::write(int, const void *, void *, size_t) { return false; }
QVariant createVariantFromString(const QString &);
QVariant createVariantFromString(int, const QString &, bool *);
+ bool equalValueType(int, const void *, const void *);
bool storeValueType(int, const void *, void *, size_t);
bool readValueType(int, const void *, int, void *);
bool writeValueType(int, const void *, void *, size_t);
virtual bool variantFromString(const QString &, QVariant *);
virtual bool variantFromString(int, const QString &, QVariant *);
+ virtual bool equal(int, const void *, const void *);
virtual bool store(int, const void *, void *, size_t);
virtual bool read(int, const void *, int, void *);
virtual bool write(int, const void *, void *, size_t);
inline void setDataType(int t);
+ inline void ensureValueType(int);
+
private:
int type;
void *data[6]; // Large enough to hold all types
type = t;
}
+void QQmlVMEVariant::ensureValueType(int t)
+{
+ if (type != t) {
+ cleanup();
+ type = t;
+ QQml_valueTypeProvider()->initValueType(t, dataPtr(), dataSize());
+ }
+}
+
QQmlVMEMetaObjectEndpoint::QQmlVMEMetaObjectEndpoint()
{
callback = &vmecallback;
writeProperty(id, *reinterpret_cast<QVariant *>(a[0]));
break;
default:
- if (! data[id].dataType())
- QQml_valueTypeProvider()->initValueType(t, data[id].dataPtr(), data[id].dataSize());
- needActivate = QQml_valueTypeProvider()->writeValueType(t, a[0], data[id].dataPtr(), data[id].dataSize());
- if (needActivate) {
- data[id].setDataType(t);
- }
+ data[id].ensureValueType(t);
+ needActivate = !QQml_valueTypeProvider()->equalValueType(t, a[0], data[id].dataPtr());
+ QQml_valueTypeProvider()->writeValueType(t, a[0], data[id].dataPtr(), data[id].dataSize());
break;
}
}
};
+// Note: The functions in this class provide handling only for the types
+// that the QML engine will currently actually call them for, so many
+// appear incompletely implemented. For some functions, the implementation
+// would be obvious, but for others (particularly create and createFromString)
+// the exact semantics are unknown. For this reason unused functionality
+// has been omitted.
+
class QQuickValueTypeProvider : public QQmlValueTypeProvider
{
public:
return false;
}
+ template<typename T>
+ bool typedEqual(const void *lhs, const void *rhs)
+ {
+ return (*(reinterpret_cast<const T *>(lhs)) == *(reinterpret_cast<const T *>(rhs)));
+ }
+
+ bool equal(int type, const void *lhs, const void *rhs)
+ {
+ switch (type) {
+ case QMetaType::QColor:
+ return typedEqual<QColor>(lhs, rhs);
+ case QMetaType::QVector3D:
+ return typedEqual<QVector3D>(lhs, rhs);
+ case QMetaType::QVector4D:
+ return typedEqual<QVector4D>(lhs, rhs);
+ }
+
+ return false;
+ }
+
bool store(int type, const void *src, void *dst, size_t n)
{
switch (type) {
--- /dev/null
+import QtQuick 2.0
+
+ListView {
+ property bool test: false
+
+ width: 200
+ height: 200
+ model: 20
+
+ delegate: Text {
+ text: qsTr(props.titleText).arg(index)
+ color: props.titleColor
+ font.pointSize: props.titlePointSize
+ }
+
+ property QtObject props: QtObject {
+ property string titleText: "List Item %1 Title"
+ property color titleColor: Qt.rgba(1, 0, 0, 0)
+ property int titlePointSize: 18
+ }
+
+ Component.onCompleted: {
+ test = (props.titleText == "List Item %1 Title") &&
+ (props.titleColor == Qt.rgba(1, 0, 0, 0)) &&
+ (props.titlePointSize == 18)
+ }
+}
void varAssignment();
void bindingsSpliceCorrectly();
void nonValueTypeComparison();
+ void initializeByWrite();
private:
QQmlEngine engine;
delete object;
}
+void tst_qqmlvaluetypes::initializeByWrite()
+{
+ QQmlComponent component(&engine, testFileUrl("initializeByWrite.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("test").toBool(), true);
+
+ delete object;
+}
+
QTEST_MAIN(tst_qqmlvaluetypes)
#include "tst_qqmlvaluetypes.moc"