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 updateItemProperties(int index, QObject *object, bool init);
73 void destroyingItem(QObject *object);
74 Q_REVISION(2, 15) void itemPooled(int index, QObject *object);
75 Q_REVISION(2, 15) void itemReused(int index, QObject *object);
76
77protected:
78 QQmlInstanceModel(QObjectPrivate &dd, QObject *parent = nullptr)
79 : QObject(dd, parent) {}
80
81private:
82 Q_DISABLE_COPY(QQmlInstanceModel)
83};
84
87class Q_QMLMODELS_EXPORT QQmlObjectModel : public QQmlInstanceModel
88{
89 Q_OBJECT
90 Q_DECLARE_PRIVATE(QQmlObjectModel)
91
92 Q_PROPERTY(QQmlListProperty<QObject> children READ children NOTIFY childrenChanged DESIGNABLE false)
93 Q_CLASSINFO("qt_QmlJSWrapperFactoryMethod", "_q_createJSWrapper(QQmlV4ExecutionEnginePtr)")
94 Q_CLASSINFO("DefaultProperty", "children")
95 QML_NAMED_ELEMENT(ObjectModel)
96 QML_ADDED_IN_VERSION(2, 1)
97 QML_ATTACHED(QQmlObjectModelAttached)
98
99public:
100 QQmlObjectModel(QObject *parent=nullptr);
101 ~QQmlObjectModel();
102
103 int count() const override;
104 bool isValid() const override;
105 QObject *object(int index, QQmlIncubator::IncubationMode incubationMode = QQmlIncubator::AsynchronousIfNested) override;
106 ReleaseFlags release(QObject *object, ReusableFlag reusable = NotReusable) override;
107 QVariant variantValue(int index, const QString &role) override;
108 void setWatchedRoles(const QList<QByteArray> &) override {}
109 QQmlIncubator::Status incubationStatus(int index) override;
110
111 int indexOf(QObject *object, QObject *objectContext) const override;
112
113 QQmlListProperty<QObject> children();
114
115 static QQmlObjectModelAttached *qmlAttachedProperties(QObject *obj);
116
117 Q_REVISION(2, 3) Q_INVOKABLE QObject *get(int index) const;
118 Q_REVISION(2, 3) Q_INVOKABLE void append(QObject *object);
119 Q_REVISION(2, 3) Q_INVOKABLE void insert(int index, QObject *object);
120 Q_REVISION(2, 3) Q_INVOKABLE void move(int from, int to, int n = 1);
121 Q_REVISION(2, 3) Q_INVOKABLE void remove(int index, int n = 1);
122
123public Q_SLOTS:
124 Q_REVISION(2, 3) void clear();
125
126Q_SIGNALS:
127 void childrenChanged();
128
129private:
130 Q_PRIVATE_SLOT(d_func(), quint64 _q_createJSWrapper(QQmlV4ExecutionEnginePtr))
131 Q_DISABLE_COPY(QQmlObjectModel)
132};
133
135{
137
138public:
141
143 int index() const { return m_index; }
144 void setIndex(int idx) {
145 if (m_index != idx) {
146 m_index = idx;
148 }
149 }
150
153
154public:
156};
157
158
159QT_END_NAMESPACE
160
161#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)
Combined button and popup list for selecting options.
Definition qjsvalue.h:24
DEFINE_OBJECT_VTABLE(QV4::QQmlObjectModelWrapper)
QT_REQUIRE_CONFIG(qml_object_model)
static void markObjects(Base *that, MarkStack *markStack)