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.h
Go to the documentation of this file.
1// Copyright (C) 2016 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_H
5#define QQMLLISTMODEL_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 <private/qtqmlmodelsglobal_p.h>
19#include <private/qqmlcustomparser_p.h>
20
21#include <QtCore/QObject>
22#include <QtCore/QStringList>
23#include <QtCore/QHash>
24#include <QtCore/QList>
25#include <QtCore/QVariant>
26#include <QtCore/qabstractitemmodel.h>
27
28#include <private/qv4engine_p.h>
29#include <private/qpodvector_p.h>
30
31QT_REQUIRE_CONFIG(qml_list_model);
32
34
35
37class ListModel;
38class ListLayout;
39
40namespace QV4 {
41struct ModelObject;
42}
43
44class Q_QMLMODELS_EXPORT QQmlListModel : public QAbstractListModel
45{
47 Q_PROPERTY(int count READ count NOTIFY countChanged)
48 Q_PROPERTY(bool dynamicRoles READ dynamicRoles WRITE setDynamicRoles)
49 Q_PROPERTY(QObject *agent READ agent CONSTANT REVISION(2, 14))
53
54public:
55 QQmlListModel(QObject *parent=nullptr);
57
58 QModelIndex index(int row, int column, const QModelIndex &parent) const override;
59 int rowCount(const QModelIndex &parent) const override;
60 QVariant data(const QModelIndex &index, int role) const override;
61 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
62 QHash<int,QByteArray> roleNames() const override;
63
64 QVariant data(int index, int role) const;
65 int count() const;
66
67 Q_INVOKABLE void clear();
71 Q_INVOKABLE QJSValue get(int index) const;
72 Q_INVOKABLE void set(int index, const QJSValue &value);
73 Q_INVOKABLE void setProperty(int index, const QString& property, const QVariant& value);
74 Q_INVOKABLE void move(int from, int to, int count);
75 Q_INVOKABLE void sync();
76
78
79 bool dynamicRoles() const { return m_dynamicRoles; }
80 void setDynamicRoles(bool enableDynamicRoles);
81
84
85private:
86 friend class QQmlListModelParser;
88 friend class ModelObject;
89 friend struct QV4::ModelObject;
90 friend class ModelNodeMetaObject;
91 friend class ListModel;
92 friend class ListElement;
95 friend struct StringOrTranslation;
96
97 // Constructs a flat list model for a worker agent
100
102
103 inline bool canMove(int from, int to, int n) const { return !(from+n > count() || to+n > count() || from < 0 || to < 0 || n < 0); }
104
105 mutable QQmlListModelWorkerAgent *m_agent;
106 mutable QV4::ExecutionEngine *m_engine;
107 QQmlRefPointer<QV4::ExecutableCompilationUnit> m_compilationUnit;
108 bool m_mainThread;
109 bool m_primary;
110
111 bool m_dynamicRoles;
112
113 ListLayout *m_layout;
114 ListModel *m_listModel;
115 std::unique_ptr<QPropertyNotifier> translationChangeHandler;
116
117 QVector<class DynamicRoleModelNode *> m_modelObjects;
118 QVector<QString> m_roles;
119
120 struct ElementSync
121 {
122 DynamicRoleModelNode *src = nullptr;
123 DynamicRoleModelNode *target = nullptr;
124 int srcIndex = -1;
125 int targetIndex = -1;
126 QVector<int> changedRoles;
127 };
128
129 static bool sync(QQmlListModel *src, QQmlListModel *target);
130 static QQmlListModel *createWithOwner(QQmlListModel *newOwner);
131
132 void emitItemsChanged(int index, int count, const QVector<int> &roles);
133 void emitItemsAboutToBeInserted(int index, int count);
134 void emitItemsInserted();
135
136 void removeElements(int index, int removeCount);
137
138 void updateTranslations();
139};
140
141// ### FIXME
148
150{
151public:
159
160
162
163 void verifyBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) override;
164 void applyBindings(QObject *obj, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) override;
165
166private:
167 bool verifyProperty(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QV4::CompiledData::Binding *binding);
168 // returns true if a role was set
169 bool applyProperty(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QV4::CompiledData::Binding *binding, ListModel *model, int outterElementIndex);
170
171 static bool definesEmptyList(const QString &);
172
173 QString listElementTypeName;
174};
175
176template<>
181
183
184#endif // QQMLLISTMODEL_H
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qhash.h:820
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
The QQmlCustomParser class allows you to add new arbitrary types to QML.
void verifyBindings(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &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
void countChanged()
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
b clear()
list append(new Employee("Blackpool", "Stephen"))
cache insert(employee->id(), employee)
Combined button and popup list for selecting options.
Definition qcompare.h:63
static QDBusError::ErrorType get(const char *name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint index
[2]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum src
GLenum target
GLfloat n
GLenum GLenum GLsizei void GLsizei void * column
GLhandleARB obj
[2]
GLenum GLenum GLsizei void * row
#define QML_NAMED_ELEMENT(NAME)
#define QML_CUSTOMPARSER
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
QQmlCustomParser * qmlCreateCustomParser< QQmlListModel >()
#define QT_REQUIRE_CONFIG(feature)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_INVOKABLE
#define Q_SIGNALS
const char property[13]
Definition qwizard.cpp:101
QSqlQueryModel * model
[16]
QFuture< QSet< QChar > > set
[10]
settings remove("monkey")
mimeData setData("text/csv", csvData)
args<< 1<< 2;QJSValue threeAgain=fun.call(args);QString fileName="helloworld.qs";QFile scriptFile(fileName);if(!scriptFile.open(QIODevice::ReadOnly)) QTextStream stream(&scriptFile);QString contents=stream.readAll();scriptFile.close();myEngine.evaluate(contents, fileName);myEngine.globalObject().setProperty("myNumber", 123);...QJSValue myNumberPlusOne=myEngine.evaluate("myNumber + 1");QJSValue result=myEngine.evaluate(...);if(result.isError()) qDebug()<< "Uncaught exception at line"<< result.property("lineNumber").toInt()<< ":"<< result.toString();QPushButton *button=new QPushButton;QJSValue scriptButton=myEngine.newQObject(button);myEngine.globalObject().setProperty("button", scriptButton);myEngine.evaluate("button.checkable = true");qDebug()<< scriptButton.property("checkable").toBool();scriptButton.property("show").call();QJSEngine engine;QObject *myQObject=new QObject();myQObject- setProperty)("dynamicProperty", 3)
QJSValueList args
QJSEngine engine
[0]