19#include <private/qtqmlmodelsglobal_p.h>
20#include <private/qqmlcustomparser_p.h>
22#include <QtCore/QObject>
23#include <QtCore/QStringList>
24#include <QtCore/QHash>
25#include <QtCore/QList>
26#include <QtCore/QVariant>
27#include <QtCore/qabstractitemmodel.h>
29#include <private/qv4engine_p.h>
30#include <private/qpodvector_p.h>
37class QQmlListModelWorkerAgent;
48 Q_PROPERTY(
int count READ count NOTIFY countChanged)
49 Q_PROPERTY(
bool dynamicRoles READ dynamicRoles WRITE setDynamicRoles)
50 Q_PROPERTY(QObject *agent READ agent CONSTANT REVISION(2, 14))
51 QML_NAMED_ELEMENT(ListModel)
52 QML_ADDED_IN_VERSION(2, 0)
56 QQmlListModel(QObject *parent=
nullptr);
59 QModelIndex index(
int row,
int column,
const QModelIndex &parent)
const override;
60 int rowCount(
const QModelIndex &parent)
const override;
61 QVariant data(
const QModelIndex &index,
int role)
const override;
62 bool setData(
const QModelIndex &index,
const QVariant &value,
int role = Qt::EditRole) override;
63 QHash<
int,QByteArray> roleNames()
const override;
65 QVariant data(
int index,
int role)
const;
68 Q_INVOKABLE
void clear();
69 Q_INVOKABLE
void remove(QQmlV4FunctionPtr args);
70 Q_INVOKABLE
void append(QQmlV4FunctionPtr args);
71 Q_INVOKABLE
void insert(QQmlV4FunctionPtr args);
72 Q_INVOKABLE QJSValue get(
int index)
const;
73 Q_INVOKABLE
void set(
int index,
const QJSValue &value);
74 Q_INVOKABLE
void setProperty(
int index,
const QString& property,
const QVariant& value);
75 Q_INVOKABLE
void move(
int from,
int to,
int count);
76 Q_INVOKABLE
void sync();
78 QQmlListModelWorkerAgent *agent();
80 bool dynamicRoles()
const {
return m_dynamicRoles; }
81 void setDynamicRoles(
bool enableDynamicRoles);
83 ListModel *listModel()
const {
return m_listModel; }
89 friend class QQmlListModelParser;
90 friend class QQmlListModelWorkerAgent;
91 friend class ModelObject;
92 friend struct QV4::ModelObject;
93 friend class ModelNodeMetaObject;
94 friend class ListModel;
95 friend class ListElement;
96 friend class DynamicRoleModelNode;
97 friend class DynamicRoleModelNodeMetaObject;
98 friend struct StringOrTranslation;
101 QQmlListModel(QQmlListModel *orig, QQmlListModelWorkerAgent *agent);
102 QQmlListModel(
const QQmlListModel *owner, ListModel *data, QV4::ExecutionEngine *engine, QObject *parent=
nullptr);
104 QV4::ExecutionEngine *engine()
const;
106 inline bool canMove(
int from,
int to,
int n)
const {
return !(from+n > count() || to+n > count() || from < 0 || to < 0 || n < 0); }
108 mutable QQmlListModelWorkerAgent *m_agent;
109 mutable QV4::ExecutionEngine *m_engine;
110 QQmlRefPointer<QV4::ExecutableCompilationUnit> m_compilationUnit;
116 ListLayout *m_layout;
117 ListModel *m_listModel;
118 std::unique_ptr<QPropertyNotifier> translationChangeHandler;
120 QVector<
class DynamicRoleModelNode *> m_modelObjects;
121 QVector<QString> m_roles;
125 DynamicRoleModelNode *src =
nullptr;
126 DynamicRoleModelNode *target =
nullptr;
128 int targetIndex = -1;
129 QVector<
int> changedRoles;
132 static bool sync(QQmlListModel *src, QQmlListModel *target);
133 static QQmlListModel *createWithOwner(QQmlListModel *newOwner);
135 void emitItemsChanged(
int index,
int count,
const QVector<
int> &roles);
136 void emitItemsAboutToBeInserted(
int index,
int count);
137 void emitItemsInserted();
139 void removeElements(
int index,
int removeCount);
141 void updateTranslations();
147 QML_NAMED_ELEMENT(ListElement)
166 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit,
167 const QList<
const QV4::CompiledData::Binding *> &bindings)
override;
169 QObject *obj,
const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
170 const QList<
const QV4::CompiledData::Binding *> &bindings)
override;
174 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit,
175 const QV4::CompiledData::Binding *binding);
178 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
179 const QV4::CompiledData::Binding *binding,
ListModel *model,
int outterElementIndex);
181 static bool definesEmptyList(
const QString &);
183 QString listElementTypeName;
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
void applyBindings(QObject *obj, const QQmlRefPointer< QV4::ExecutableCompilationUnit > &compilationUnit, const QList< const QV4::CompiledData::Binding * > &bindings) override
DEFINE_OBJECT_VTABLE(ModelObject)
QT_REQUIRE_CONFIG(animation)
QQmlCustomParser * qmlCreateCustomParser< QQmlConnections >()
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)