5#ifndef QQMLLISTMODEL_P_P_H
6#define QQMLLISTMODEL_P_P_H
20#include <private/qtqmlmodelsglobal_p.h>
21#include <private/qqmlengine_p.h>
22#include <private/qqmlopenmetaobject_p.h>
23#include <private/qv4qobjectwrapper_p.h>
31class DynamicRoleModelNode;
57 void updateValues(
const QVariantMap &object, QVector<
int> &roles);
61 return m_meta->value(name.toUtf8());
64 bool setValue(
const QByteArray &name,
const QVariant &val)
66 return m_meta->setValue(name, val);
82 QQmlListModel *m_owner;
92 ModelNodeMetaObject(QObject *object, QQmlListModel *model,
int elementIndex);
95#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
)
98 QMetaObject *toDynamicMetaObject(QObject *object)
override;
118 void emitDirectNotifies(
const int *changedRoles,
int roleCount);
121 mutable bool m_initialized;
129 void init(QObject *object, QQmlListModel *model)
131 QObjectWrapper::init(object);
138 QObjectWrapper::destroy();
142 if (
const QObject *o = object()) {
143 const QObjectPrivate *op = QObjectPrivate::get(o);
226 int currentBlockOffset;
227 QVector<Role *> roles;
228 QStringHash<Role *> roleHash;
234 bool isSet()
const {
return binding || arrayData; }
238 QString toString(
const QQmlListModel *owner)
const;
248 QTypedArrayData<
char16_t> *arrayData =
nullptr;
253
254
271 int setVariantProperty(
const ListLayout::
Role &role,
const QVariant &d);
273 int setJsProperty(
const ListLayout::
Role &role,
const QV4::Value &d, QV4::ExecutionEngine *eng);
275 int setStringProperty(
const ListLayout::
Role &role,
const QString &s);
279 int setQObjectProperty(
const ListLayout::
Role &role, QV4::QObjectWrapper *o);
280 int setVariantMapProperty(
const ListLayout::
Role &role, QV4::Object *o);
281 int setVariantMapProperty(
const ListLayout::
Role &role, QVariantMap *m);
282 int setDateTimeProperty(
const ListLayout::
Role &role,
const QDateTime &dt);
283 int setUrlProperty(
const ListLayout::
Role &role,
const QUrl &url);
284 int setFunctionProperty(
const ListLayout::
Role &role,
const QJSValue &f);
285 int setTranslationProperty(
const ListLayout::
Role &role,
const QV4::CompiledData::Binding *b);
287 void setStringPropertyFast(
const ListLayout::
Role &role,
const QString &s);
288 void setDoublePropertyFast(
const ListLayout::
Role &role,
double n);
290 void setQObjectPropertyFast(
const ListLayout::
Role &role, QV4::QObjectWrapper *o);
292 void setVariantMapFast(
const ListLayout::
Role &role, QV4::Object *o);
293 void setDateTimePropertyFast(
const ListLayout::
Role &role,
const QDateTime &dt);
294 void setUrlPropertyFast(
const ListLayout::
Role &role,
const QUrl &url);
295 void setFunctionPropertyFast(
const ListLayout::
Role &role,
const QJSValue &f);
299 QVariant getProperty(
const ListLayout::
Role &role,
const QQmlListModel *owner, QV4::ExecutionEngine *eng);
302 QV4::QObjectWrapper *getQObjectProperty(
const ListLayout::
Role &role);
303 QV4::PersistentValue *getGuardProperty(
const ListLayout::
Role &role);
311 int getUid()
const {
return uid; }
319 QObject *m_objectCache;
325
326
331 ListModel(
ListLayout *layout, QQmlListModel *modelCache);
336 int setExistingProperty(
int uid,
const QString &key,
const QV4::Value &data, QV4::ExecutionEngine *eng);
338 QVariant getProperty(
int elementIndex,
int roleIndex,
const QQmlListModel *owner, QV4::ExecutionEngine *eng);
365 return elements.count();
370 void set(
int elementIndex, QV4::Object *object, QVector<
int> *roles);
373 int append(QV4::Object *object);
374 void insert(
int elementIndex, QV4::Object *object);
381 void move(
int from,
int to,
int n);
385 QObject *getOrCreateModelObject(QQmlListModel *model,
int elementIndex);
388 QPODVector<ListElement *, 4> elements;
391 QQmlListModel *m_modelCache;
398 int targetIndex = -1;
399 QVector<
int> changedRoles;
402 void newElement(
int index);
404 void updateCacheIndices(
int start = 0,
int end = -1);
406 template<
typename ArrayLike>
409 ListModel *subModel =
new ListModel(r.subLayout,
nullptr);
411 for (qint64 j = 0, arrayLength = a->getLength(); j < arrayLength; ++j) {
413 subModel->append(*o);
419 template<
typename ArrayLike>
420 void setArrayLikeFast(
421 QV4::ScopedObject *o, QV4::String *propertyName,
ListElement *e, ArrayLike *a)
425 e->setListPropertyFast(r, resolveSubModel(o, r, a));
428 template<
typename ArrayLike>
430 QV4::ScopedObject *o, QV4::String *propertyName,
ListElement *e, ArrayLike *a)
433 return e->setListProperty(r, resolveSubModel(o, r, a));
static QVector< int > sync(DynamicRoleModelNode *src, DynamicRoleModelNode *target)
QVariant getValue(const QString &name) const
bool setValue(const QByteArray &name, const QVariant &val)
void setNodeUpdatesEnabled(bool enable)
void updateValues(const QVariantMap &object, QVector< int > &roles)
static QVector< int > sync(ListElement *src, ListLayout *srcLayout, ListElement *target, ListLayout *targetLayout)
ListElement(int existingUid)
ListLayout(const ListLayout *other)
const Role * getRoleOrCreate(const QString &key, const QVariant &data)
const Role * getExistingRole(QV4::String *key) const
static void sync(ListLayout *src, ListLayout *target)
const Role & getExistingRole(int index) const
const Role & getRoleOrCreate(const QString &key, Role::DataType type)
const Role & getRoleOrCreate(QV4::String *key, Role::DataType type)
const Role * getExistingRole(const QString &key) const
void set(int elementIndex, QV4::Object *object, SetElement reason=SetElement::IsCurrentlyUpdated)
static bool sync(ListModel *src, ListModel *target)
int append(QV4::Object *object)
QVariant getProperty(int elementIndex, int roleIndex, const QQmlListModel *owner, QV4::ExecutionEngine *eng)
void move(int from, int to, int n)
const ListLayout::Role * getExistingRole(QV4::String *key) const
void insertElement(int index)
ListModel(ListLayout *layout, QQmlListModel *modelCache)
void insert(int elementIndex, QV4::Object *object)
int setExistingProperty(int uid, const QString &key, const QV4::Value &data, QV4::ExecutionEngine *eng)
void updateTranslations()
QObject * getOrCreateModelObject(QQmlListModel *model, int elementIndex)
void set(int elementIndex, QV4::Object *object, QVector< int > *roles)
ListModel * getListProperty(int elementIndex, const ListLayout::Role &role)
int setOrCreateProperty(int elementIndex, const QString &key, const QVariant &data)
const ListLayout::Role & getOrCreateListRole(const QString &name)
const ListLayout::Role & getExistingRole(int index) const
void verifyBindings(const QQmlRefPointer< QV4::CompiledData::CompilationUnit > &compilationUnit, const QList< const QV4::CompiledData::Binding * > &bindings) override
DEFINE_OBJECT_VTABLE(ModelObject)
QT_REQUIRE_CONFIG(animation)
static QAtomicInt uidCounter(MIN_LISTMODEL_UID)
Q_DECLARE_METATYPE(const QV4::CompiledData::Binding *)
static bool isMemoryUsed(const char *mem)
static QString roleTypeName(ListLayout::Role::DataType t)
QT_END_NAMESPACE Q_DECLARE_METATYPE(ListModel *)
QT_REQUIRE_CONFIG(qml_list_model)
QV4QPointer< QQmlListModel > m_model
PropertyKey next(const Object *o, Property *pd=nullptr, PropertyAttributes *attrs=nullptr) override
~ModelObjectOwnPropertyKeyIterator() override=default
static OwnPropertyKeyIterator * virtualOwnPropertyKeys(const Object *m, Value *target)
static ReturnedValue lookupGetter(Lookup *l, ExecutionEngine *engine, const Value &object)
static ReturnedValue virtualResolveLookupGetter(const Object *object, ExecutionEngine *engine, Lookup *lookup)
static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty)
const QV4::CompiledData::Binding * binding
bool isTranslation() const
void setString(const QString &s)
QString toString(const QQmlListModel *owner) const
void setTranslation(const QV4::CompiledData::Binding *binding)