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
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
4#ifndef QQMLINSTANCEMODEL_P_H
5#define QQMLINSTANCEMODEL_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 <private/qtqmlmodelsglobal_p.h>
19#include <private/qqmlincubator_p.h>
20#include <QtQml/qqml.h>
21#include <QtCore/qobject.h>
22
23QT_REQUIRE_CONFIG(qml_object_model);
24
26
27class QObject;
28class QQmlChangeSet;
30
31class Q_QMLMODELS_EXPORT QQmlInstanceModel : public QObject
32{
34
35 Q_PROPERTY(int count READ count NOTIFY countChanged)
38
39public:
42 Reusable
43 };
44
45 enum ReleaseFlag { Referenced = 0x01, Destroyed = 0x02, Pooled = 0x04 };
46 Q_DECLARE_FLAGS(ReleaseFlags, ReleaseFlag)
47
48 virtual int count() const = 0;
49 virtual bool isValid() const = 0;
50 virtual QObject *object(int index, QQmlIncubator::IncubationMode incubationMode = QQmlIncubator::AsynchronousIfNested) = 0;
51 virtual ReleaseFlags release(QObject *object, ReusableFlag reusableFlag = NotReusable) = 0;
52 virtual void cancel(int) {}
53 QString stringValue(int index, const QString &role) { return variantValue(index, role).toString(); }
54 virtual QVariant variantValue(int, const QString &) = 0;
55 virtual void setWatchedRoles(const QList<QByteArray> &roles) = 0;
57
58 virtual void drainReusableItemsPool(int maxPoolTime) { Q_UNUSED(maxPoolTime); }
59 virtual int poolSize() { return 0; }
60
61 virtual int indexOf(QObject *object, QObject *objectContext) const = 0;
62 virtual const QAbstractItemModel *abstractItemModel() const { return nullptr; }
63
64 virtual bool setRequiredProperty(int index, const QString &name, const QVariant &value);
65
68 void modelUpdated(const QQmlChangeSet &changeSet, bool reset);
69 void createdItem(int index, QObject *object);
70 void initItem(int index, QObject *object);
71 void destroyingItem(QObject *object);
72 Q_REVISION(2, 15) void itemPooled(int index, QObject *object);
73 Q_REVISION(2, 15) void itemReused(int index, QObject *object);
74
75protected:
77 : QObject(dd, parent) {}
78
79private:
80 Q_DISABLE_COPY(QQmlInstanceModel)
81};
82
85class Q_QMLMODELS_EXPORT QQmlObjectModel : public QQmlInstanceModel
86{
88 Q_DECLARE_PRIVATE(QQmlObjectModel)
89
90 Q_PROPERTY(QQmlListProperty<QObject> children READ children NOTIFY childrenChanged DESIGNABLE false)
91 Q_CLASSINFO("DefaultProperty", "children")
92 QML_NAMED_ELEMENT(ObjectModel)
95
96public:
97 QQmlObjectModel(QObject *parent=nullptr);
99
100 int count() const override;
101 bool isValid() const override;
103 ReleaseFlags release(QObject *object, ReusableFlag reusable = NotReusable) override;
104 QVariant variantValue(int index, const QString &role) override;
105 void setWatchedRoles(const QList<QByteArray> &) override {}
106 QQmlIncubator::Status incubationStatus(int index) override;
107
108 int indexOf(QObject *object, QObject *objectContext) const override;
109
110 QQmlListProperty<QObject> children();
111
112 static QQmlObjectModelAttached *qmlAttachedProperties(QObject *obj);
113
116 Q_REVISION(2, 3) Q_INVOKABLE void insert(int index, QObject *object);
117 Q_REVISION(2, 3) Q_INVOKABLE void move(int from, int to, int n = 1);
118 Q_REVISION(2, 3) Q_INVOKABLE void remove(int index, int n = 1);
119
120public Q_SLOTS:
121 Q_REVISION(2, 3) void clear();
122
124 void childrenChanged();
125
126private:
127 Q_DISABLE_COPY(QQmlObjectModel)
128};
129
131{
133
134public:
136 : QObject(parent), m_index(-1) {}
138 attachedProperties.remove(parent());
139 }
140
141 Q_PROPERTY(int index READ index NOTIFY indexChanged FINAL)
142 int index() const { return m_index; }
143 void setIndex(int idx) {
144 if (m_index != idx) {
145 m_index = idx;
146 Q_EMIT indexChanged();
147 }
148 }
149
151 QQmlObjectModelAttached *rv = attachedProperties.value(obj);
152 if (!rv) {
154 attachedProperties.insert(obj, rv);
155 }
156 return rv;
157 }
158
161
162public:
164
165 static QHash<QObject*, QQmlObjectModelAttached*> attachedProperties;
166};
167
168
170
171#endif // QQMLINSTANCEMODEL_P_H
\inmodule QtCore
Definition qobject.h:103
The QQmlChangeSet class stores an ordered list of notifications about changes to a linear data set.
The QQmlIncubator class allows QML objects to be created asynchronously.
IncubationMode
Specifies the mode the incubator operates in.
Status
Specifies the status of the QQmlIncubator.
virtual void setWatchedRoles(const QList< QByteArray > &roles)=0
void createdItem(int index, QObject *object)
virtual int poolSize()
void modelUpdated(const QQmlChangeSet &changeSet, bool reset)
virtual const QAbstractItemModel * abstractItemModel() const
virtual QQmlIncubator::Status incubationStatus(int index)=0
void destroyingItem(QObject *object)
virtual int indexOf(QObject *object, QObject *objectContext) const =0
void initItem(int index, QObject *object)
QString stringValue(int index, const QString &role)
virtual void drainReusableItemsPool(int maxPoolTime)
virtual QVariant variantValue(int, const QString &)=0
The QQmlListProperty class allows applications to expose list-like properties of QObject-derived clas...
Definition qqmllist.h:24
static QHash< QObject *, QQmlObjectModelAttached * > attachedProperties
QQmlObjectModelAttached(QObject *parent)
static QQmlObjectModelAttached * properties(QObject *obj)
Q_REVISION(2, 3) Q_INVOKABLE QObject *get(int index) const
QQmlListProperty< QObject > children()
void setWatchedRoles(const QList< QByteArray > &) override
QObject * object(int index, QQmlIncubator::IncubationMode incubationMode=QQmlIncubator::AsynchronousIfNested) override
\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.
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
static QDBusError::ErrorType get(const char *name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
GLuint index
[2]
GLenum GLenum GLsizei count
GLuint name
GLfloat n
GLhandleARB obj
[2]
GLboolean reset
#define QML_ANONYMOUS
#define QML_NAMED_ELEMENT(NAME)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
#define QML_ATTACHED(ATTACHED_TYPE)
#define QT_REQUIRE_CONFIG(feature)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_REVISION(...)
#define Q_CLASSINFO(name, value)
#define Q_EMIT
#define Q_INVOKABLE
#define Q_SLOTS
#define Q_SIGNALS
#define Q_UNUSED(x)
future cancel()
settings remove("monkey")
sem release()
list indexOf("B")