diff options
Diffstat (limited to 'src/qml/types')
-rw-r--r-- | src/qml/types/qqmllistmodel.cpp | 38 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodel_p_p.h | 3 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index 1b64a38bd6..c6597b49f3 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -1633,6 +1633,44 @@ void ModelObject::virtualAdvanceIterator(Managed *m, ObjectIterator *it, Value * QV4::Object::virtualAdvanceIterator(m, it, name, index, p, attributes); } +struct ModelObjectOwnPropertyKeyIterator : ObjectOwnPropertyKeyIterator +{ + int roleNameIndex = 0; + ~ModelObjectOwnPropertyKeyIterator() override = default; + PropertyKey next(const Object *o, Property *pd = nullptr, PropertyAttributes *attrs = nullptr) override; + +}; + +PropertyKey ModelObjectOwnPropertyKeyIterator::next(const Object *o, Property *pd, PropertyAttributes *attrs) +{ + const ModelObject *that = static_cast<const ModelObject *>(o); + + ExecutionEngine *v4 = that->engine(); + if (roleNameIndex < that->listModel()->roleCount()) { + Scope scope(that->engine()); + const ListLayout::Role &role = that->listModel()->getExistingRole(roleNameIndex); + ++roleNameIndex; + ScopedString roleName(scope, v4->newString(role.name)); + if (attrs) + *attrs = QV4::Attr_Data; + if (pd) { + QVariant value = that->d()->m_model->data(that->d()->elementIndex(), role.index); + pd->value = v4->fromVariant(value); + } + return roleName->toPropertyKey(); + } + + // Fall back to QV4::Object as opposed to QV4::QObjectWrapper otherwise it will add + // unnecessary entries that relate to the roles used. These just create extra work + // later on as they will just be ignored. + return ObjectOwnPropertyKeyIterator::next(o, pd, attrs); +} + +OwnPropertyKeyIterator *ModelObject::virtualOwnPropertyKeys(const Object *) +{ + return new ModelObjectOwnPropertyKeyIterator; +} + DEFINE_OBJECT_VTABLE(ModelObject); } // namespace QV4 diff --git a/src/qml/types/qqmllistmodel_p_p.h b/src/qml/types/qqmllistmodel_p_p.h index e4a850e8a5..dbd0b0a2a2 100644 --- a/src/qml/types/qqmllistmodel_p_p.h +++ b/src/qml/types/qqmllistmodel_p_p.h @@ -176,10 +176,13 @@ struct ModelObject : public QObjectWrapper V4_OBJECT2(ModelObject, QObjectWrapper) V4_NEEDS_DESTROY + ListModel *listModel() const { return d()->m_model->m_listModel; } + protected: static bool virtualPut(Managed *m, PropertyKey id, const Value& value, Value *receiver); static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty); static void virtualAdvanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes); + static OwnPropertyKeyIterator *virtualOwnPropertyKeys(const Object *m); }; } // namespace QV4 |