From 0720dea139e735b3438968f42c9abf7b198cd69b Mon Sep 17 00:00:00 2001 From: Frank Meerkoetter Date: Thu, 16 Jul 2015 22:34:42 +0200 Subject: Port QDate/QDateTime/QRectF away from QQmlVmeVariant Store QDate/QDateTime/QRectF in a javascript array. The values are wrapped inside a QV4::Variant. This is part of a series sliming down the memory usage of properties. Change-Id: I1b5c4e24c1e46d19c5c861941655efb7a972a6a5 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlvmemetaobject.cpp | 99 +++++++++++++++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 9 deletions(-) (limited to 'src/qml/qml/qqmlvmemetaobject.cpp') diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 60f56dff5f..d4ad0f2a9a 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -635,6 +635,29 @@ void QQmlVMEMetaObject::writeProperty(int id, const QUrl& v) vp->putIndexed(id, sv); } +// TODO: can we store the QDate in a QV4::Value primitive? +void QQmlVMEMetaObject::writeProperty(int id, const QDate& v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); + vp->putIndexed(id, sv); +} + +void QQmlVMEMetaObject::writeProperty(int id, const QDateTime& v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); + vp->putIndexed(id, sv); +} + void QQmlVMEMetaObject::writeProperty(int id, const QPointF& v) { if (!ensurePropertiesAllocated()) @@ -657,6 +680,17 @@ void QQmlVMEMetaObject::writeProperty(int id, const QSizeF& v) vp->putIndexed(id, sv); } +void QQmlVMEMetaObject::writeProperty(int id, const QRectF& v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); + vp->putIndexed(id, sv); +} + int QQmlVMEMetaObject::readPropertyAsInt(int id) { if (!ensurePropertiesAllocated()) @@ -733,6 +767,38 @@ QUrl QQmlVMEMetaObject::readPropertyAsUrl(int id) return v->d()->data.value(); } +QDate QQmlVMEMetaObject::readPropertyAsDate(int id) +{ + if (!ensurePropertiesAllocated()) + return QDate(); + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + const QV4::VariantObject *v = sv->as(); + if (!v || v->d()->data.type() != QVariant::Date) { + writeProperty(id, QDate()); + return QDate(); + } + return v->d()->data.value(); +} + +QDateTime QQmlVMEMetaObject::readPropertyAsDateTime(int id) +{ + if (!ensurePropertiesAllocated()) + return QDateTime(); + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + const QV4::VariantObject *v = sv->as(); + if (!v || v->d()->data.type() != QVariant::DateTime) { + writeProperty(id, QDateTime()); + return QDateTime(); + } + return v->d()->data.value(); +} + QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id) { if (!ensurePropertiesAllocated()) @@ -765,6 +831,21 @@ QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id) return v->d()->data.value(); } +QRectF QQmlVMEMetaObject::readPropertyAsRectF(int id) +{ + if (!ensurePropertiesAllocated()) + return QRectF(); + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + const QV4::VariantObject *v = sv->as(); + if (!v || v->d()->data.type() != QVariant::RectF) { + writeProperty(id, QRectF()); + return QRectF(); + } + return v->d()->data.value(); +} int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) { @@ -887,13 +968,13 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) *reinterpret_cast(a[0]) = readPropertyAsUrl(id); break; case QVariant::Date: - *reinterpret_cast(a[0]) = data[id].asQDate(); + *reinterpret_cast(a[0]) = readPropertyAsDate(id); break; case QVariant::DateTime: - *reinterpret_cast(a[0]) = data[id].asQDateTime(); + *reinterpret_cast(a[0]) = readPropertyAsDateTime(id); break; case QVariant::RectF: - *reinterpret_cast(a[0]) = data[id].asQRectF(); + *reinterpret_cast(a[0]) = readPropertyAsRectF(id); break; case QVariant::SizeF: *reinterpret_cast(a[0]) = readPropertyAsSizeF(id); @@ -944,16 +1025,16 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::Date: - needActivate = *reinterpret_cast(a[0]) != data[id].asQDate(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsDate(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::DateTime: - needActivate = *reinterpret_cast(a[0]) != data[id].asQDateTime(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsDateTime(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::RectF: - needActivate = *reinterpret_cast(a[0]) != data[id].asQRectF(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsRectF(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::SizeF: needActivate = *reinterpret_cast(a[0]) != readPropertyAsSizeF(id); -- cgit v1.2.3