Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qqmldmobjectdata_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 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 QQMLDMOBJECTDATA_P_H
5#define QQMLDMOBJECTDATA_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/qqmladaptormodelenginedata_p.h>
19#include <private/qqmldelegatemodel_p_p.h>
20#include <private/qobject_p.h>
21
23
26{
31public:
35 int index, int row, int column,
36 QObject *object);
37
39 {
40 if (modelData == object)
41 return;
42
43 object = modelData;
45 }
46
47 QObject *modelData() const { return object; }
48 QObject *proxiedObject() override { return object; }
49
51
54};
55
57 : public QQmlRefCounted<VDMObjectDelegateDataType>,
59{
60public:
63 bool shared;
65
68 , signalOffset(0)
69 , shared(true)
70 {
71 }
72
76 , shared(false)
78 | QMetaObjectBuilder::Signals
79 | QMetaObjectBuilder::SuperClass
81 {
83 }
84
85 int rowCount(const QQmlAdaptorModel &model) const override
86 {
87 return model.list.count();
88 }
89
90 int columnCount(const QQmlAdaptorModel &) const override
91 {
92 return 1;
93 }
94
95 QVariant value(const QQmlAdaptorModel &model, int index, const QString &role) const override
96 {
97 if (QObject *object = model.list.at(index).value<QObject *>())
98 return object->property(role.toUtf8());
99 return QVariant();
100 }
101
105 int index, int row, int column) override
106 {
107 if (!metaObject)
109 return index >= 0 && index < model.list.count()
110 ? new QQmlDMObjectData(metaType, this, index, row, column, qvariant_cast<QObject *>(model.list.at(index)))
111 : nullptr;
112 }
113
115 {
117 QQmlAdaptorModelEngineData::setModelDataType<QQmlDMObjectData>(&builder, this);
118
120 // Note: ATM we cannot create a shared property cache for this class, since each model
121 // object can have different properties. And to make those properties available to the
122 // delegate, QQmlDMObjectData makes use of a QAbstractDynamicMetaObject subclass
123 // (QQmlDMObjectDataMetaObject), which we cannot represent in a QQmlPropertyCache.
124 // By not having a shared property cache, revisioned properties in QQmlDelegateModelItem
125 // will always be available to the delegate, regardless of the import version.
126 }
127
128 void cleanup(QQmlAdaptorModel &) const override
129 {
130 release();
131 }
132
133 bool notify(const QQmlAdaptorModel &model, const QList<QQmlDelegateModelItem *> &items, int index, int count, const QVector<int> &) const override
134 {
135 for (auto modelItem : items) {
136 const int modelItemIndex = modelItem->index;
137 if (modelItemIndex < index || modelItemIndex >= index + count)
138 continue;
139
140 auto objectModelItem = static_cast<QQmlDMObjectData *>(modelItem);
141 QObject *updatedModelData = qvariant_cast<QObject *>(model.list.at(objectModelItem->index));
142 objectModelItem->setModelData(updatedModelData);
143 }
144 return true;
145 }
146};
147
149{
150public:
152 : m_data(data)
153 , m_type(type)
154 {
156 *static_cast<QMetaObject *>(this) = *type->metaObject;
157 op->metaObject = this;
158 m_type->addref();
159 }
160
162 {
163 m_type->release();
164 }
165
166 int metaCall(QObject *o, QMetaObject::Call call, int id, void **arguments) override
167 {
168 Q_ASSERT(o == m_data);
169 Q_UNUSED(o);
170
171 static const int objectPropertyOffset = QObject::staticMetaObject.propertyCount();
172 if (id >= m_type->propertyOffset
173 && (call == QMetaObject::ReadProperty
175 || call == QMetaObject::ResetProperty)) {
176 if (m_data->object)
177 QMetaObject::metacall(m_data->object, call, id - m_type->propertyOffset + objectPropertyOffset, arguments);
178 return -1;
179 } else if (id >= m_type->signalOffset && call == QMetaObject::InvokeMetaMethod) {
180 QMetaObject::activate(m_data, this, id - m_type->signalOffset, nullptr);
181 return -1;
182 } else {
183 return m_data->qt_metacall(call, id, arguments);
184 }
185 }
186
187 int createProperty(const char *name, const char *) override
188 {
189 if (!m_data->object)
190 return -1;
191 const QMetaObject *metaObject = m_data->object->metaObject();
192 static const int objectPropertyOffset = QObject::staticMetaObject.propertyCount();
193
194 const int previousPropertyCount = propertyCount() - propertyOffset();
195 int propertyIndex = metaObject->indexOfProperty(name);
196 if (propertyIndex == -1)
197 return -1;
198 if (previousPropertyCount + objectPropertyOffset == metaObject->propertyCount())
199 return propertyIndex + m_type->propertyOffset - objectPropertyOffset;
200
201 if (m_type->shared) {
204 type->release();
205 }
206
207 const int previousMethodCount = methodCount();
208 int notifierId = previousMethodCount - methodOffset();
209 for (int propertyId = previousPropertyCount; propertyId < metaObject->propertyCount() - objectPropertyOffset; ++propertyId) {
210 QMetaProperty property = metaObject->property(propertyId + objectPropertyOffset);
211 QMetaPropertyBuilder propertyBuilder;
212 if (property.hasNotifySignal()) {
213 m_type->builder.addSignal("__" + QByteArray::number(propertyId) + "()");
214 propertyBuilder = m_type->builder.addProperty(property.name(), property.typeName(), notifierId);
215 ++notifierId;
216 } else {
217 propertyBuilder = m_type->builder.addProperty(property.name(), property.typeName());
218 }
219 propertyBuilder.setWritable(property.isWritable());
220 propertyBuilder.setResettable(property.isResettable());
221 propertyBuilder.setConstant(property.isConstant());
222 }
223
225 *static_cast<QMetaObject *>(this) = *m_type->metaObject;
226
227 notifierId = previousMethodCount;
228 for (int i = previousPropertyCount; i < metaObject->propertyCount() - objectPropertyOffset; ++i) {
229 QMetaProperty property = metaObject->property(i + objectPropertyOffset);
230 if (property.hasNotifySignal()) {
232 m_data->object, property.notifySignalIndex(), m_data, notifierId);
233 ++notifierId;
234 }
235 }
236 return propertyIndex + m_type->propertyOffset - objectPropertyOffset;
237 }
238
241};
242
244
245#endif // QQMLDMOBJECTDATA_P_H
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
Definition qlist.h:74
QMetaObject * toMetaObject() const
Converts this meta object builder into a concrete QMetaObject.
QMetaMethodBuilder addSignal(const QByteArray &signature)
Adds a new signal to this class with the specified signature.
void setFlags(MetaObjectFlags)
Sets the flags of the class being constructed by this meta object builder.
QMetaPropertyBuilder addProperty(const QByteArray &name, const QByteArray &type, int notifierId=-1)
Adds a new readable/writable property to this class with the specified name and type.
void setConstant(bool value)
Sets the CONSTANT flag on this property to value.
void setWritable(bool value)
Sets this property to writable if value is true.
void setResettable(bool value)
Sets this property to resettable if value is true.
\inmodule QtCore
QDynamicMetaObjectData * metaObject
Definition qobject.h:77
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:153
\inmodule QtCore
Definition qobject.h:90
\inmodule QtCore
Definition qpointer.h:18
QScopedPointer< QMetaObject, QScopedPointerPodDeleter > metaObject
int metaCall(QObject *o, QMetaObject::Call call, int id, void **arguments) override
QQmlDMObjectDataMetaObject(QQmlDMObjectData *data, VDMObjectDelegateDataType *type)
int createProperty(const char *name, const char *) override
VDMObjectDelegateDataType * m_type
QObject * proxiedObject() override
void modelDataChanged()
QObject * modelData() const
void setModelData(QObject *modelData)
QPointer< QObject > object
QQmlRefPointer< QQmlDelegateModelItemMetaType > const metaType
static bool connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, int type=0, int *types=nullptr)
Connect sender signal_index to receiver method_index with the specified type and types.
void addref() const
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QByteArray toUtf8() const &
Definition qstring.h:563
\inmodule QtCore
Definition qvariant.h:64
bool notify(const QQmlAdaptorModel &model, const QList< QQmlDelegateModelItem * > &items, int index, int count, const QVector< int > &) const override
int rowCount(const QQmlAdaptorModel &model) const override
void initializeMetaType(QQmlAdaptorModel &model)
QQmlDelegateModelItem * createItem(QQmlAdaptorModel &model, const QQmlRefPointer< QQmlDelegateModelItemMetaType > &metaType, int index, int row, int column) override
VDMObjectDelegateDataType(const VDMObjectDelegateDataType &type)
int columnCount(const QQmlAdaptorModel &) const override
QVariant value(const QQmlAdaptorModel &model, int index, const QString &role) const override
void cleanup(QQmlAdaptorModel &) const override
QList< QVariant > arguments
Combined button and popup list for selecting options.
@ DynamicMetaObject
#define QT_ANONYMOUS_PROPERTY(...)
Definition qobject_p.h:38
GLuint index
[2]
GLenum GLenum GLsizei count
GLenum type
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint name
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLenum GLsizei void * row
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_INTERFACES(x)
#define Q_SIGNALS
#define emit
#define Q_UNUSED(x)
const char property[13]
Definition qwizard.cpp:101
QSqlQueryModel * model
[16]
obj metaObject() -> className()
QList< QTreeWidgetItem * > items
\inmodule QtCore
int propertyCount() const
Returns the number of properties in this class, including the number of properties provided by each b...
static int metacall(QObject *, Call, int, void **)
int methodCount() const
Returns the number of methods in this class, including the number of methods provided by each base cl...
int methodOffset() const
Returns the method offset for this class; i.e.
int propertyOffset() const
Returns the property offset for this class; i.e.
static void activate(QObject *sender, int signal_index, void **argv)
Definition qobject.cpp:4057