Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlobjectmodel_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// Qt-Security score:significant
4
5#ifndef QQMLINSTANCEMODEL_P_H
6#define QQMLINSTANCEMODEL_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <private/qtqmlmodelsglobal_p.h>
20#include <private/qqmlincubator_p.h>
21#include <QtQml/qqml.h>
22#include <QtCore/qobject.h>
23
25
26QT_BEGIN_NAMESPACE
27
28class QObject;
29class QQmlChangeSet;
30class QAbstractItemModel;
31
32class Q_QMLMODELS_EXPORT QQmlInstanceModel : public QObject
33{
34 Q_OBJECT
35
36 Q_PROPERTY(int count READ count NOTIFY countChanged)
37 QML_ANONYMOUS
38 QML_ADDED_IN_VERSION(2, 0)
39
40public:
41 enum ReusableFlag {
42 NotReusable,
43 Reusable
44 };
45
46 enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02, Pooled = 0x04 };
47 Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag)
48
49 virtual int count() const = 0;
50 virtual bool isValid() const = 0;
51 virtual QObject *object(int index, QQmlIncubator::IncubationMode incubationMode = QQmlIncubator::AsynchronousIfNested) = 0;
52 virtual ReleaseFlags release(QObject *object, ReusableFlag reusableFlag = NotReusable) = 0;
53 virtual void cancel(int) {}
54 QString stringValue(int index, const QString &role) { return variantValue(index, role).toString(); }
55 virtual QVariant variantValue(int, const QString &) = 0;
56 virtual void setWatchedRoles(const QList<QByteArray> &roles) = 0;
57 virtual QQmlIncubator::Status incubationStatus(int index) = 0;
58
59 virtual void drainReusableItemsPool(int maxPoolTime) { Q_UNUSED(maxPoolTime); }
60 virtual int poolSize() { return 0; }
61
62 virtual int indexOf(QObject *object, QObject *objectContext) const = 0;
63 virtual const QAbstractItemModel *abstractItemModel() const { return nullptr; }
64
65 virtual bool setRequiredProperty(int index, const QString &name, const QVariant &value);
66
67Q_SIGNALS:
68 void countChanged();
69 void modelUpdated(const QQmlChangeSet &changeSet, bool reset);
70 void createdItem(int index, QObject *object);
71 void initItem(int index, QObject *object);
72 void destroyingItem(QObject *object);
73 Q_REVISION(2, 15) void itemPooled(int index, QObject *object);
74 Q_REVISION(2, 15) void itemReused(int index, QObject *object);
75
76protected:
77 QQmlInstanceModel(QObjectPrivate &dd, QObject *parent = nullptr)
78 : QObject(dd, parent) {}
79
80private:
81 Q_DISABLE_COPY(QQmlInstanceModel)
82};
83
86class Q_QMLMODELS_EXPORT QQmlObjectModel : public QQmlInstanceModel
87{
88 Q_OBJECT
89 Q_DECLARE_PRIVATE(QQmlObjectModel)
90
91 Q_PROPERTY(QQmlListProperty<QObject> children READ children NOTIFY childrenChanged DESIGNABLE false)
92 Q_CLASSINFO("qt_QmlJSWrapperFactoryMethod", "_q_createJSWrapper(QQmlV4ExecutionEnginePtr)")
93 Q_CLASSINFO("DefaultProperty", "children")
94 QML_NAMED_ELEMENT(ObjectModel)
95 QML_ADDED_IN_VERSION(2, 1)
96 QML_ATTACHED(QQmlObjectModelAttached)
97
98public:
99 QQmlObjectModel(QObject *parent=nullptr);
100 ~QQmlObjectModel();
101
102 int count() const override;
103 bool isValid() const override;
104 QObject *object(int index, QQmlIncubator::IncubationMode incubationMode = QQmlIncubator::AsynchronousIfNested) override;
105 ReleaseFlags release(QObject *object, ReusableFlag reusable = NotReusable) override;
106 QVariant variantValue(int index, const QString &role) override;
107 void setWatchedRoles(const QList<QByteArray> &) override {}
108 QQmlIncubator::Status incubationStatus(int index) override;
109
110 int indexOf(QObject *object, QObject *objectContext) const override;
111
112 QQmlListProperty<QObject> children();
113
114 static QQmlObjectModelAttached *qmlAttachedProperties(QObject *obj);
115
116 Q_REVISION(2, 3) Q_INVOKABLE QObject *get(int index) const;
117 Q_REVISION(2, 3) Q_INVOKABLE void append(QObject *object);
118 Q_REVISION(2, 3) Q_INVOKABLE void insert(int index, QObject *object);
119 Q_REVISION(2, 3) Q_INVOKABLE void move(int from, int to, int n = 1);
120 Q_REVISION(2, 3) Q_INVOKABLE void remove(int index, int n = 1);
121
122public Q_SLOTS:
123 Q_REVISION(2, 3) void clear();
124
125Q_SIGNALS:
126 void childrenChanged();
127
128private:
129 Q_PRIVATE_SLOT(d_func(), quint64 _q_createJSWrapper(QQmlV4ExecutionEnginePtr))
130 Q_DISABLE_COPY(QQmlObjectModel)
131};
132
134{
136
137public:
140
142 int index() const { return m_index; }
143 void setIndex(int idx) {
144 if (m_index != idx) {
145 m_index = idx;
147 }
148 }
149
152
153public:
155};
156
157
158QT_END_NAMESPACE
159
160#endif // QQMLINSTANCEMODEL_P_H
static void children_replace(QQmlListProperty< QObject > *prop, qsizetype index, QObject *item)
static QObject * children_at(QQmlListProperty< QObject > *prop, qsizetype index)
int indexOf(QObject *item) const
void move(int from, int to, int n)
void replace(int index, QObject *item)
static void children_append(QQmlListProperty< QObject > *prop, QObject *item)
static void children_clear(QQmlListProperty< QObject > *prop)
static qsizetype children_count(QQmlListProperty< QObject > *prop)
static void children_removeLast(QQmlListProperty< QObject > *prop)
void insert(int index, QObject *item)
static QQmlObjectModelPrivate * get(QQmlObjectModel *q)
void remove(int index, int n)
void markChildren(QV4::MarkStack *markStack) const
void markNewChild(QQmlObjectModel *q, QObject *item)
quint64 _q_createJSWrapper(QQmlV4ExecutionEnginePtr engine)
Definition qjsvalue.h:23
DEFINE_OBJECT_VTABLE(QV4::QQmlObjectModelWrapper)
QT_REQUIRE_CONFIG(qml_object_model)
static void markObjects(Base *that, MarkStack *markStack)