aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlopenmetaobject.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2015-08-15 01:31:13 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-08-19 05:03:50 +0000
commit4876ea6a18ccdfd72014582aa5d50ab9f6b6ec9e (patch)
tree73e9a9ce3ed28b817c77d3d48475c76a7d54c9cf /src/qml/qml/qqmlopenmetaobject.cpp
parent7fccfc4663c362d717383493732849237562f0c7 (diff)
Fix performance of ListModel::get()
When called, the function would return a full-fledged QObject that maps the list element addressed. It would contain a _copy_ of all values in the list item and it would create a new meta-object for each list element. This function exists for the JavaScript API, and therefore we now return a much more lightweight object. For compatbility reasons it still has to be a QObject, but the meta-object of it is created on-demand, i.e. only when accessing properties from the C++ side or when connecting to the changed signal of a property. Otherwise the JavaScript wrapper will return the live values from the model without copying them. Change-Id: Iabf3ca22192d2aee06ae9d4b4cfb2fcde2a021b1 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com> Reviewed-by: Michael Brasser <michael.brasser@live.com> Reviewed-by: Spencer Schumann <spencer.schumann@echostar.com>
Diffstat (limited to 'src/qml/qml/qqmlopenmetaobject.cpp')
-rw-r--r--src/qml/qml/qqmlopenmetaobject.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlopenmetaobject.cpp b/src/qml/qml/qqmlopenmetaobject.cpp
index c6d2d44ee1..777bb0c5e1 100644
--- a/src/qml/qml/qqmlopenmetaobject.cpp
+++ b/src/qml/qml/qqmlopenmetaobject.cpp
@@ -106,6 +106,28 @@ QMetaObject *QQmlOpenMetaObjectType::metaObject() const
return d->mem;
}
+void QQmlOpenMetaObjectType::createProperties(const QVector<QByteArray> &names)
+{
+ for (int i = 0; i < names.count(); ++i) {
+ const QByteArray &name = names.at(i);
+ const int id = d->mob.propertyCount();
+ d->mob.addSignal("__" + QByteArray::number(id) + "()");
+ QMetaPropertyBuilder build = d->mob.addProperty(name, "QVariant", id);
+ propertyCreated(id, build);
+ d->names.insert(name, id);
+ }
+ free(d->mem);
+ d->mem = d->mob.toMetaObject();
+ QSet<QQmlOpenMetaObject*>::iterator it = d->referers.begin();
+ while (it != d->referers.end()) {
+ QQmlOpenMetaObject *omo = *it;
+ *static_cast<QMetaObject *>(omo) = *d->mem;
+ if (d->cache)
+ d->cache->update(omo);
+ ++it;
+ }
+}
+
int QQmlOpenMetaObjectType::createProperty(const QByteArray &name)
{
int id = d->mob.propertyCount();
@@ -230,6 +252,14 @@ QQmlOpenMetaObjectType *QQmlOpenMetaObject::type() const
return d->type;
}
+void QQmlOpenMetaObject::emitPropertyNotification(const QByteArray &propertyName)
+{
+ QHash<QByteArray, int>::ConstIterator iter = d->type->d->names.constFind(propertyName);
+ if (iter == d->type->d->names.constEnd())
+ return;
+ activate(d->object, *iter + d->type->d->signalOffset, 0);
+}
+
int QQmlOpenMetaObject::metaCall(QMetaObject::Call c, int id, void **a)
{
if (( c == QMetaObject::ReadProperty || c == QMetaObject::WriteProperty)