aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Meerkoetter <frank.meerkoetter@basyskom.com>2015-07-16 22:04:39 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-08-18 20:25:29 +0000
commit0cbab3b17fb70208476b910d7d82ae653a9a1050 (patch)
treed2b447d578cf2bd2b16bc89611542ed3fcf06c0b
parent496b69a6c73c354c0a440a3fc4779eb8325abc4a (diff)
Port QUrl/QSizeF away from QQmlVmeVariant
Store QUrl/QSizeF 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: I62338fe7fe101496340a8d89f33030d0df5121b7 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
-rw-r--r--src/qml/qml/qqmlvmemetaobject.cpp67
-rw-r--r--src/qml/qml/qqmlvmemetaobject_p.h4
2 files changed, 65 insertions, 6 deletions
diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp
index a359cb72b8..60f56dff5f 100644
--- a/src/qml/qml/qqmlvmemetaobject.cpp
+++ b/src/qml/qml/qqmlvmemetaobject.cpp
@@ -624,6 +624,28 @@ void QQmlVMEMetaObject::writeProperty(int id, const QString& v)
vp->putIndexed(id, s);
}
+void QQmlVMEMetaObject::writeProperty(int id, const QUrl& 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())
+ 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 QSizeF& v)
{
if (!ensurePropertiesAllocated())
@@ -695,6 +717,22 @@ QString QQmlVMEMetaObject::readPropertyAsString(int id)
return sv->stringValue()->toQString();
}
+QUrl QQmlVMEMetaObject::readPropertyAsUrl(int id)
+{
+ if (!ensurePropertiesAllocated())
+ return QUrl();
+
+ 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::Url) {
+ writeProperty(id, QUrl());
+ return QUrl();
+ }
+ return v->d()->data.value<QUrl>();
+}
+
QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id)
{
if (!ensurePropertiesAllocated())
@@ -711,6 +749,23 @@ QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id)
return v->d()->data.value<QSizeF>();
}
+QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id)
+{
+ if (!ensurePropertiesAllocated())
+ return QPointF();
+
+ 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::PointF) {
+ writeProperty(id, QPointF());
+ return QPointF();
+ }
+ return v->d()->data.value<QPointF>();
+}
+
+
int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
{
int id = _id;
@@ -829,7 +884,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
*reinterpret_cast<QString *>(a[0]) = readPropertyAsString(id);
break;
case QVariant::Url:
- *reinterpret_cast<QUrl *>(a[0]) = data[id].asQUrl();
+ *reinterpret_cast<QUrl *>(a[0]) = readPropertyAsUrl(id);
break;
case QVariant::Date:
*reinterpret_cast<QDate *>(a[0]) = data[id].asQDate();
@@ -844,7 +899,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
*reinterpret_cast<QSizeF *>(a[0]) = readPropertyAsSizeF(id);
break;
case QVariant::PointF:
- *reinterpret_cast<QPointF *>(a[0]) = data[id].asQPointF();
+ *reinterpret_cast<QPointF *>(a[0]) = readPropertyAsPointF(id);
break;
case QMetaType::QObjectStar:
*reinterpret_cast<QObject **>(a[0]) = data[id].asQObject();
@@ -885,8 +940,8 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
writeProperty(id, *reinterpret_cast<QString *>(a[0]));
break;
case QVariant::Url:
- needActivate = *reinterpret_cast<QUrl *>(a[0]) != data[id].asQUrl();
- data[id].setValue(*reinterpret_cast<QUrl *>(a[0]));
+ needActivate = *reinterpret_cast<QUrl *>(a[0]) != readPropertyAsUrl(id);
+ writeProperty(id, *reinterpret_cast<QUrl *>(a[0]));
break;
case QVariant::Date:
needActivate = *reinterpret_cast<QDate *>(a[0]) != data[id].asQDate();
@@ -905,8 +960,8 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
writeProperty(id, *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]));
+ needActivate = *reinterpret_cast<QPointF *>(a[0]) != readPropertyAsPointF(id);
+ writeProperty(id, *reinterpret_cast<QPointF *>(a[0]));
break;
case QMetaType::QObjectStar:
needActivate = *reinterpret_cast<QObject **>(a[0]) != data[id].asQObject();
diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h
index c4ca128e87..445b54e61c 100644
--- a/src/qml/qml/qqmlvmemetaobject_p.h
+++ b/src/qml/qml/qqmlvmemetaobject_p.h
@@ -209,12 +209,16 @@ public:
double readPropertyAsDouble(int id);
QString readPropertyAsString(int id);
QSizeF readPropertyAsSizeF(int id);
+ QPointF readPropertyAsPointF(int id);
+ QUrl readPropertyAsUrl(int id);
void writeProperty(int id, int v);
void writeProperty(int id, bool v);
void writeProperty(int id, double v);
void writeProperty(int id, const QString& v);
+ void writeProperty(int id, const QPointF& v);
void writeProperty(int id, const QSizeF& v);
+ void writeProperty(int id, const QUrl& v);
void ensureQObjectWrapper();