diff options
Diffstat (limited to 'src/qml/types/qqmllistmodel.cpp')
-rw-r--r-- | src/qml/types/qqmllistmodel.cpp | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index 062f7a2a74..1a2e4c7f6f 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -45,10 +45,12 @@ #include <private/qqmlcustomparser_p.h> #include <private/qqmlengine_p.h> +#include <private/qqmlnotifier_p.h> #include <private/qv4object_p.h> #include <private/qv4dateobject_p.h> #include <private/qv4objectiterator_p.h> +#include <private/qv4alloca_p.h> #include <qqmlcontext.h> #include <qqmlinfo.h> @@ -57,6 +59,7 @@ #include <QtCore/qstack.h> #include <QXmlStreamReader> #include <QtCore/qdatetime.h> +#include <QScopedValueRollback> QT_BEGIN_NAMESPACE @@ -502,10 +505,10 @@ void ListModel::set(int elementIndex, QV4::Object *object) break; // Add the value now - if (propertyValue->isString()) { + if (QV4::String *s = propertyValue->stringValue()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::String); if (r.type == ListLayout::Role::String) - e->setStringPropertyFast(r, propertyValue->stringValue()->toQString()); + e->setStringPropertyFast(r, s->toQString()); } else if (propertyValue->isNumber()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Number); if (r.type == ListLayout::Role::Number) { @@ -1262,9 +1265,14 @@ ModelNodeMetaObject *ModelNodeMetaObject::get(QObject *obj) void ModelNodeMetaObject::updateValues() { - if (!m_initialized) + const int roleCount = m_model->m_listModel->roleCount(); + if (!m_initialized) { + int *changedRoles = reinterpret_cast<int *>(alloca(roleCount * sizeof(int))); + for (int i = 0; i < roleCount; ++i) + changedRoles[i] = i; + emitDirectNotifies(changedRoles, roleCount); return; - int roleCount = m_model->m_listModel->roleCount(); + } for (int i=0 ; i < roleCount ; ++i) { const ListLayout::Role &role = m_model->m_listModel->getExistingRole(i); QByteArray name = role.name.toUtf8(); @@ -1275,8 +1283,10 @@ void ModelNodeMetaObject::updateValues() void ModelNodeMetaObject::updateValues(const QVector<int> &roles) { - if (!m_initialized) + if (!m_initialized) { + emitDirectNotifies(roles.constData(), roles.count()); return; + } int roleCount = roles.count(); for (int i=0 ; i < roleCount ; ++i) { int roleIndex = roles.at(i); @@ -1303,6 +1313,22 @@ void ModelNodeMetaObject::propertyWritten(int index) m_model->emitItemsChanged(m_elementIndex, 1, QVector<int>(1, roleIndex)); } +// Does the emission of the notifiers when we haven't created the meta-object yet +void ModelNodeMetaObject::emitDirectNotifies(const int *changedRoles, int roleCount) +{ + Q_ASSERT(!m_initialized); + QQmlData *ddata = QQmlData::get(object(), /*create*/false); + if (!ddata) + return; + QQmlEnginePrivate *ep = QQmlEnginePrivate::get(qmlEngine(m_model)); + if (!ep) + return; + for (int i = 0; i < roleCount; ++i) { + const int changedRole = changedRoles[i]; + QQmlNotifier::notify(ddata, changedRole); + } +} + namespace QV4 { void ModelObject::put(Managed *m, String *name, const Value &value) @@ -1329,6 +1355,18 @@ ReturnedValue ModelObject::get(const Managed *m, String *name, bool *hasProperty return QObjectWrapper::get(m, name, hasProperty); if (hasProperty) *hasProperty = true; + + if (QQmlEngine *qmlEngine = that->engine()->qmlEngine()) { + QQmlEnginePrivate *ep = QQmlEnginePrivate::get(qmlEngine); + if (ep && ep->propertyCapture) { + QObjectPrivate *op = QObjectPrivate::get(that->object()); + // Temporarily hide the dynamic meta-object, to prevent it from being created when the capture + // triggers a QObject::connectNotify() by calling obj->metaObject(). + QScopedValueRollback<QDynamicMetaObjectData*> metaObjectBlocker(op->metaObject, 0); + ep->propertyCapture->captureProperty(that->object(), -1, role->index); + } + } + const int elementIndex = that->d()->m_elementIndex; QVariant value = that->d()->m_model->data(elementIndex, role->index); return that->engine()->fromVariant(value); |