aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlvmemetaobject.cpp
diff options
context:
space:
mode:
authorFrank Meerkoetter <frank.meerkoetter@basyskom.com>2015-07-16 22:34:42 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-08-18 20:25:34 +0000
commit0720dea139e735b3438968f42c9abf7b198cd69b (patch)
treeb65cc3d69223b9eedff9ca02eb0a92ceb2cf9a05 /src/qml/qml/qqmlvmemetaobject.cpp
parent0cbab3b17fb70208476b910d7d82ae653a9a1050 (diff)
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 <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/qml/qqmlvmemetaobject.cpp')
-rw-r--r--src/qml/qml/qqmlvmemetaobject.cpp99
1 files changed, 90 insertions, 9 deletions
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<QUrl>();
}
+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<QV4::VariantObject>();
+ if (!v || v->d()->data.type() != QVariant::Date) {
+ writeProperty(id, QDate());
+ return QDate();
+ }
+ return v->d()->data.value<QDate>();
+}
+
+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<QV4::VariantObject>();
+ if (!v || v->d()->data.type() != QVariant::DateTime) {
+ writeProperty(id, QDateTime());
+ return QDateTime();
+ }
+ return v->d()->data.value<QDateTime>();
+}
+
QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id)
{
if (!ensurePropertiesAllocated())
@@ -765,6 +831,21 @@ QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id)
return v->d()->data.value<QPointF>();
}
+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<QV4::VariantObject>();
+ if (!v || v->d()->data.type() != QVariant::RectF) {
+ writeProperty(id, QRectF());
+ return QRectF();
+ }
+ return v->d()->data.value<QRectF>();
+}
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<QUrl *>(a[0]) = readPropertyAsUrl(id);
break;
case QVariant::Date:
- *reinterpret_cast<QDate *>(a[0]) = data[id].asQDate();
+ *reinterpret_cast<QDate *>(a[0]) = readPropertyAsDate(id);
break;
case QVariant::DateTime:
- *reinterpret_cast<QDateTime *>(a[0]) = data[id].asQDateTime();
+ *reinterpret_cast<QDateTime *>(a[0]) = readPropertyAsDateTime(id);
break;
case QVariant::RectF:
- *reinterpret_cast<QRectF *>(a[0]) = data[id].asQRectF();
+ *reinterpret_cast<QRectF *>(a[0]) = readPropertyAsRectF(id);
break;
case QVariant::SizeF:
*reinterpret_cast<QSizeF *>(a[0]) = readPropertyAsSizeF(id);
@@ -944,16 +1025,16 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
writeProperty(id, *reinterpret_cast<QUrl *>(a[0]));
break;
case QVariant::Date:
- needActivate = *reinterpret_cast<QDate *>(a[0]) != data[id].asQDate();
- data[id].setValue(*reinterpret_cast<QDate *>(a[0]));
+ needActivate = *reinterpret_cast<QDate *>(a[0]) != readPropertyAsDate(id);
+ writeProperty(id, *reinterpret_cast<QDate *>(a[0]));
break;
case QVariant::DateTime:
- needActivate = *reinterpret_cast<QDateTime *>(a[0]) != data[id].asQDateTime();
- data[id].setValue(*reinterpret_cast<QDateTime *>(a[0]));
+ needActivate = *reinterpret_cast<QDateTime *>(a[0]) != readPropertyAsDateTime(id);
+ writeProperty(id, *reinterpret_cast<QDateTime *>(a[0]));
break;
case QVariant::RectF:
- needActivate = *reinterpret_cast<QRectF *>(a[0]) != data[id].asQRectF();
- data[id].setValue(*reinterpret_cast<QRectF *>(a[0]));
+ needActivate = *reinterpret_cast<QRectF *>(a[0]) != readPropertyAsRectF(id);
+ writeProperty(id, *reinterpret_cast<QRectF *>(a[0]));
break;
case QVariant::SizeF:
needActivate = *reinterpret_cast<QSizeF *>(a[0]) != readPropertyAsSizeF(id);