Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmllistmodel_p_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQMLLISTMODEL_P_P_H
5#define QQMLLISTMODEL_P_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qqmllistmodel_p.h"
19#include <private/qtqmlmodelsglobal_p.h>
20#include <private/qqmlengine_p.h>
21#include <private/qqmlopenmetaobject_p.h>
22#include <private/qv4qobjectwrapper_p.h>
23#include <qqml.h>
24
25QT_REQUIRE_CONFIG(qml_list_model);
26
28
29
31
33{
34public:
37
39
40protected:
41 void propertyWrite(int index) override;
42 void propertyWritten(int index) override;
43
44private:
45 DynamicRoleModelNode *m_owner;
46};
47
49{
51public:
52 DynamicRoleModelNode(QQmlListModel *owner, int uid);
53
55
56 void updateValues(const QVariantMap &object, QVector<int> &roles);
57
59 {
60 return m_meta->value(name.toUtf8());
61 }
62
63 bool setValue(const QByteArray &name, const QVariant &val)
64 {
65 return m_meta->setValue(name, val);
66 }
67
69 {
70 m_meta->m_enabled = enable;
71 }
72
73 int getUid() const
74 {
75 return m_uid;
76 }
77
79
80private:
81 QQmlListModel *m_owner;
82 int m_uid;
84
86};
87
89{
90public:
91 ModelNodeMetaObject(QObject *object, QQmlListModel *model, int elementIndex);
93
94 QMetaObject *toDynamicMetaObject(QObject *object) override;
95
97
101
102 void updateValues();
103 void updateValues(const QVector<int> &roles);
104
105 bool initialized() const { return m_initialized; }
106
107protected:
108 void propertyWritten(int index) override;
109
110private:
112
113 void emitDirectNotifies(const int *changedRoles, int roleCount);
114
115 void initialize();
116 bool m_initialized;
117};
118
119namespace QV4 {
120
121namespace Heap {
122
136
137}
138
140{
143
144 ListModel *listModel() const { return d()->m_model->m_listModel; }
145
146protected:
147 static bool virtualPut(Managed *m, PropertyKey id, const Value& value, Value *receiver);
148 static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty);
152};
153
154} // namespace QV4
155
157{
158public:
159 ListLayout() : currentBlock(0), currentBlockOffset(0) {}
161 ~ListLayout();
162
163 class Role
164 {
165 public:
166
168 explicit Role(const Role *other);
169 ~Role();
170
171 // This enum must be kept in sync with the roleTypeNames variable in qqmllistmodel.cpp
188
193 int index;
195 };
196
197 const Role *getRoleOrCreate(const QString &key, const QVariant &data);
200
201 const Role &getExistingRole(int index) const { return *roles.at(index); }
202 const Role *getExistingRole(const QString &key) const;
203 const Role *getExistingRole(QV4::String *key) const;
204
205 int roleCount() const { return roles.size(); }
206
207 static void sync(ListLayout *src, ListLayout *target);
208
209private:
210 const Role &createRole(const QString &key, Role::DataType type);
211
212 int currentBlock;
213 int currentBlockOffset;
214 QVector<Role *> roles;
215 QStringHash<Role *> roleHash;
216};
217
219{
221 bool isSet() const { return binding || arrayData; }
222 bool isTranslation() const { return binding && !arrayData; }
223 void setString(const QString &s);
225 QString toString(const QQmlListModel *owner) const;
226 QString asString() const;
227private:
228 void clear();
229
230 union {
231 char16_t *stringData = nullptr;
233 };
234
235 QTypedArrayData<char16_t> *arrayData = nullptr;
236 uint stringSize = 0;
237};
238
243{
244public:
246 enum { BLOCK_SIZE = 64 - sizeof(int) - sizeof(ListElement *) - sizeof(ModelNodeMetaObject *) };
247
248 ListElement();
249 ListElement(int existingUid);
250 ~ListElement();
251
252 static QVector<int> sync(ListElement *src, ListLayout *srcLayout, ListElement *target, ListLayout *targetLayout);
253
254private:
255
256 void destroy(ListLayout *layout);
257
258 int setVariantProperty(const ListLayout::Role &role, const QVariant &d);
259
260 int setJsProperty(const ListLayout::Role &role, const QV4::Value &d, QV4::ExecutionEngine *eng);
261
262 int setStringProperty(const ListLayout::Role &role, const QString &s);
263 int setDoubleProperty(const ListLayout::Role &role, double n);
264 int setBoolProperty(const ListLayout::Role &role, bool b);
265 int setListProperty(const ListLayout::Role &role, ListModel *m);
266 int setQObjectProperty(const ListLayout::Role &role, QV4::QObjectWrapper *o);
267 int setVariantMapProperty(const ListLayout::Role &role, QV4::Object *o);
268 int setVariantMapProperty(const ListLayout::Role &role, QVariantMap *m);
269 int setDateTimeProperty(const ListLayout::Role &role, const QDateTime &dt);
270 int setUrlProperty(const ListLayout::Role &role, const QUrl &url);
271 int setFunctionProperty(const ListLayout::Role &role, const QJSValue &f);
272 int setTranslationProperty(const ListLayout::Role &role, const QV4::CompiledData::Binding *b);
273
274 void setStringPropertyFast(const ListLayout::Role &role, const QString &s);
275 void setDoublePropertyFast(const ListLayout::Role &role, double n);
276 void setBoolPropertyFast(const ListLayout::Role &role, bool b);
277 void setQObjectPropertyFast(const ListLayout::Role &role, QV4::QObjectWrapper *o);
278 void setListPropertyFast(const ListLayout::Role &role, ListModel *m);
279 void setVariantMapFast(const ListLayout::Role &role, QV4::Object *o);
280 void setDateTimePropertyFast(const ListLayout::Role &role, const QDateTime &dt);
281 void setUrlPropertyFast(const ListLayout::Role &role, const QUrl &url);
282 void setFunctionPropertyFast(const ListLayout::Role &role, const QJSValue &f);
283
284 void clearProperty(const ListLayout::Role &role);
285
286 QVariant getProperty(const ListLayout::Role &role, const QQmlListModel *owner, QV4::ExecutionEngine *eng);
287 ListModel *getListProperty(const ListLayout::Role &role);
288 StringOrTranslation *getStringProperty(const ListLayout::Role &role);
289 QV4::QObjectWrapper *getQObjectProperty(const ListLayout::Role &role);
290 QV4::PersistentValue *getGuardProperty(const ListLayout::Role &role);
291 QVariantMap *getVariantMapProperty(const ListLayout::Role &role);
292 QDateTime *getDateTimeProperty(const ListLayout::Role &role);
293 QUrl *getUrlProperty(const ListLayout::Role &role);
294 QJSValue *getFunctionProperty(const ListLayout::Role &role);
295
296 inline char *getPropertyMemory(const ListLayout::Role &role);
297
298 int getUid() const { return uid; }
299
300 ModelNodeMetaObject *objectCache();
301
302 char data[BLOCK_SIZE];
303 ListElement *next;
304
305 int uid;
306 QObject *m_objectCache;
307
308 friend class ListModel;
309};
310
315{
316public:
317
320
321 void destroy();
322
323 int setOrCreateProperty(int elementIndex, const QString &key, const QVariant &data);
324 int setExistingProperty(int uid, const QString &key, const QV4::Value &data, QV4::ExecutionEngine *eng);
325
326 QVariant getProperty(int elementIndex, int roleIndex, const QQmlListModel *owner, QV4::ExecutionEngine *eng);
327 ListModel *getListProperty(int elementIndex, const ListLayout::Role &role);
328
329 void updateTranslations();
330
331 int roleCount() const
332 {
333 return m_layout->roleCount();
334 }
335
337 {
338 return m_layout->getExistingRole(index);
339 }
340
342 {
343 return m_layout->getExistingRole(key);
344 }
345
350
351 int elementCount() const
352 {
353 return elements.count();
354 }
355
357
358 void set(int elementIndex, QV4::Object *object, QVector<int> *roles);
359 void set(int elementIndex, QV4::Object *object, SetElement reason = SetElement::IsCurrentlyUpdated);
360
361 int append(QV4::Object *object);
362 void insert(int elementIndex, QV4::Object *object);
363
364 Q_REQUIRED_RESULT QVector<std::function<void()>> remove(int index, int count);
365
366 int appendElement();
367 void insertElement(int index);
368
369 void move(int from, int to, int n);
370
371 static bool sync(ListModel *src, ListModel *target);
372
374
375private:
376 QPODVector<ListElement *, 4> elements;
377 ListLayout *m_layout;
378
379 QQmlListModel *m_modelCache;
380
381 struct ElementSync
382 {
383 ListElement *src = nullptr;
384 ListElement *target = nullptr;
385 int srcIndex = -1;
386 int targetIndex = -1;
387 QVector<int> changedRoles;
388 };
389
390 void newElement(int index);
391
392 void updateCacheIndices(int start = 0, int end = -1);
393
394 template<typename ArrayLike>
395 void setArrayLike(QV4::ScopedObject *o, QV4::String *propertyName, ListElement *e, ArrayLike *a)
396 {
397 const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::List);
398 if (r.type == ListLayout::Role::List) {
399 ListModel *subModel = new ListModel(r.subLayout, nullptr);
400
401 int arrayLength = a->getLength();
402 for (int j=0 ; j < arrayLength ; ++j) {
403 *o = a->get(j);
404 subModel->append(*o);
405 }
406
407 e->setListPropertyFast(r, subModel);
408 }
409 }
410
411 friend class ListElement;
414};
415
417
419
420#endif // QQUICKLISTMODEL_P_P_H
DynamicRoleModelNodeMetaObject(DynamicRoleModelNode *object)
void propertyWritten(int index) override
void propertyWrite(int index) override
static QVector< int > sync(DynamicRoleModelNode *src, DynamicRoleModelNode *target)
QVariant getValue(const QString &name) const
DynamicRoleModelNode(QQmlListModel *owner, int uid)
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)
int roleCount() const
const Role * getRoleOrCreate(const QString &key, const QVariant &data)
static void sync(ListLayout *src, ListLayout *target)
const Role & getExistingRole(int index) const
Q_REQUIRED_RESULT QVector< std::function< void()> > remove(int index, int count)
static bool sync(ListModel *src, ListModel *target)
int append(QV4::Object *object)
QVariant getProperty(int elementIndex, int roleIndex, const QQmlListModel *owner, QV4::ExecutionEngine *eng)
int elementCount() const
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)
int appendElement()
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)
ListModel * getListProperty(int elementIndex, const ListLayout::Role &role)
int roleCount() const
int setOrCreateProperty(int elementIndex, const QString &key, const QVariant &data)
const ListLayout::Role & getOrCreateListRole(const QString &name)
const ListLayout::Role & getExistingRole(int index) const
QQmlListModel * m_model
void propertyWritten(int index) override
static ModelNodeMetaObject * get(QObject *obj)
QMetaObject * toDynamicMetaObject(QObject *object) override
ModelNodeMetaObject(QObject *object, QQmlListModel *model, int elementIndex)
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qdatetime.h:283
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
Definition qlist.h:75
QDynamicMetaObjectData * metaObject
Definition qobject.h:90
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:150
\inmodule QtCore
Definition qobject.h:103
int count() const
bool setValue(const QByteArray &, const QVariant &, bool force=false)
QVariant value(const QByteArray &) const
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
quint64 ReturnedValue
static int arrayLength(const QString &rawType)
Definition provider.cpp:52
#define Q_REQUIRED_RESULT
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_DECLARE_METATYPE(TYPE)
Definition qmetatype.h:1525
GLboolean GLboolean GLboolean b
const GLfloat * m
GLuint64 key
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLboolean r
[2]
GLuint GLuint end
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat f
GLenum src
GLenum type
GLenum target
GLboolean enable
GLuint start
GLuint name
GLfloat n
GLhandleARB obj
[2]
GLdouble s
[6]
Definition qopenglext.h:235
GLuint GLfloat * val
#define QT_REQUIRE_CONFIG(feature)
#define Q_OBJECT
unsigned int uint
Definition qtypes.h:34
#define V4_NEEDS_DESTROY
#define V4_OBJECT2(DataClass, superClass)
QSqlQueryModel * model
[16]
QFuture< QSet< QChar > > set
[10]
QUrl url("example.com")
[constructor-url-reference]
QVBoxLayout * layout
QSharedPointer< T > other(t)
[5]
view create()
\inmodule QtCore
void init(QObject *object, QQmlListModel *model)
ModelNodeMetaObject * m_nodeModelMetaObject
void init(QObject *object)
ExecutionEngine * engine() const
static ReturnedValue lookupGetter(Lookup *l, ExecutionEngine *engine, const Value &object)
V4_NEEDS_DESTROY ListModel * listModel() const
bool hasProperty(PropertyKey id) const
static constexpr VTable::OwnPropertyKeys virtualOwnPropertyKeys
static constexpr VTable::Get virtualGet
static constexpr VTable::Put virtualPut
static constexpr VTable::ResolveLookupGetter virtualResolveLookupGetter
const QV4::CompiledData::Binding * binding
void setString(const QString &s)
QString toString(const QQmlListModel *owner) const
QString asString() const
void setTranslation(const QV4::CompiledData::Binding *binding)