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
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
21#include <private/qobject_p.h>
22#include <QtCore/qpointer.h>
23
25
28{
33public:
35 const QQmlRefPointer<QQmlDelegateModelItemMetaType> &metaType,
37 int index, int row, int column,
38 QObject *object);
39
41 {
42 if (modelData == object)
43 return;
44
45 object = modelData;
47 }
48
49 QObject *modelData() const { return object; }
50 QObject *proxiedObject() override { return object; }
51
52 QPointer<QObject> object;
53
56};
57
59 : public QQmlRefCounted<VDMObjectDelegateDataType>,
61{
62public:
65 bool shared;
67
70 , signalOffset(0)
71 , shared(true)
72 {
73 }
74
86
87 int rowCount(const QQmlAdaptorModel &model) const override
88 {
89 return model.list.count();
90 }
91
92 int columnCount(const QQmlAdaptorModel &) const override
93 {
94 return 1;
95 }
96
97 QVariant value(const QQmlAdaptorModel &model, int index, const QString &role) const override
98 {
99 if (QObject *object = model.list.at(index).value<QObject *>())
100 return object->property(role.toUtf8());
101 return QVariant();
102 }
103
106 const QQmlRefPointer<QQmlDelegateModelItemMetaType> &metaType,
107 int index, int row, int column) override
108 {
109 if (!metaObject)
111 return index >= 0 && index < model.list.count()
112 ? new QQmlDMObjectData(metaType, this, index, row, column, qvariant_cast<QObject *>(model.list.at(index)))
113 : nullptr;
114 }
115
117 {
119 QQmlAdaptorModelEngineData::setModelDataType<QQmlDMObjectData>(&builder, this);
120
122 // Note: ATM we cannot create a shared property cache for this class, since each model
123 // object can have different properties. And to make those properties available to the
124 // delegate, QQmlDMObjectData makes use of a QAbstractDynamicMetaObject subclass
125 // (QQmlDMObjectDataMetaObject), which we cannot represent in a QQmlPropertyCache.
126 // By not having a shared property cache, revisioned properties in QQmlDelegateModelItem
127 // will always be available to the delegate, regardless of the import version.
128 }
129
130 void cleanup(QQmlAdaptorModel &) const override
131 {
132 release();
133 }
134
135 bool notify(const QQmlAdaptorModel &model, const QList<QQmlDelegateModelItem *> &items, int index, int count, const QVector<int> &) const override
136 {
137 for (auto modelItem : items) {
138 const int modelItemIndex = modelItem->index;
139 if (modelItemIndex < index || modelItemIndex >= index + count)
140 continue;
141
142 auto objectModelItem = static_cast<QQmlDMObjectData *>(modelItem);
143 QObject *updatedModelData = qvariant_cast<QObject *>(model.list.at(objectModelItem->index));
144 objectModelItem->setModelData(updatedModelData);
145 }
146 return true;
147 }
148};
149
151{
152public:
154 : m_data(data)
155 , m_type(type)
156 {
158 *static_cast<QMetaObject *>(this) = *type->metaObject;
159 op->metaObject = this;
160 m_type->addref();
161 }
162
167
168 int metaCall(QObject *o, QMetaObject::Call call, int id, void **arguments) override
169 {
170 Q_ASSERT(o == m_data);
171 Q_UNUSED(o);
172
173 static const int objectPropertyOffset = QObject::staticMetaObject.propertyCount();
174 if (id >= m_type->propertyOffset
175 && (call == QMetaObject::ReadProperty
177 || call == QMetaObject::ResetProperty)) {
178 if (m_data->object)
179 QMetaObject::metacall(m_data->object, call, id - m_type->propertyOffset + objectPropertyOffset, arguments);
180 return -1;
181 } else if (id >= m_type->signalOffset && call == QMetaObject::InvokeMetaMethod) {
182 QMetaObject::activate(m_data, this, id - m_type->signalOffset, nullptr);
183 return -1;
184 } else {
185 return m_data->qt_metacall(call, id, arguments);
186 }
187 }
188
189 int createProperty(const char *name, const char *) override
190 {
191 if (!m_data->object)
192 return -1;
193 const QMetaObject *metaObject = m_data->object->metaObject();
194 static const int objectPropertyOffset = QObject::staticMetaObject.propertyCount();
195
196 const int previousPropertyCount = propertyCount() - propertyOffset();
197 int propertyIndex = metaObject->indexOfProperty(name);
198 if (propertyIndex == -1)
199 return -1;
200 if (previousPropertyCount + objectPropertyOffset == metaObject->propertyCount())
201 return propertyIndex + m_type->propertyOffset - objectPropertyOffset;
202
203 if (m_type->shared) {
206 type->release();
207 }
208
209 const int previousMethodCount = methodCount();
210 int notifierId = previousMethodCount - methodOffset();
211 for (int propertyId = previousPropertyCount; propertyId < metaObject->propertyCount() - objectPropertyOffset; ++propertyId) {
212 QMetaProperty property = metaObject->property(propertyId + objectPropertyOffset);
213 QMetaPropertyBuilder propertyBuilder;
214 if (property.hasNotifySignal()) {
215 m_type->builder.addSignal("__" + QByteArray::number(propertyId) + "()");
216 propertyBuilder = m_type->builder.addProperty(property.name(), property.typeName(), notifierId);
217 ++notifierId;
218 } else {
219 propertyBuilder = m_type->builder.addProperty(property.name(), property.typeName());
220 }
221 propertyBuilder.setWritable(property.isWritable());
222 propertyBuilder.setResettable(property.isResettable());
223 propertyBuilder.setConstant(property.isConstant());
224 }
225
227 *static_cast<QMetaObject *>(this) = *m_type->metaObject;
228
229 notifierId = previousMethodCount;
230 for (int i = previousPropertyCount; i < metaObject->propertyCount() - objectPropertyOffset; ++i) {
231 QMetaProperty property = metaObject->property(i + objectPropertyOffset);
232 if (property.hasNotifySignal()) {
234 m_data->object, property.notifySignalIndex(), m_data, notifierId);
235 ++notifierId;
236 }
237 }
238 return propertyIndex + m_type->propertyOffset - objectPropertyOffset;
239 }
240
243};
244
246
247#endif // QQMLDMOBJECTDATA_P_H
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
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 setWritable(bool value)
Sets this property to writable if value is true.
\inmodule QtCore
QDynamicMetaObjectData * metaObject
Definition qobject.h:90
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:150
\inmodule QtCore
Definition qobject.h:103
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
QQmlDMObjectData(const QQmlRefPointer< QQmlDelegateModelItemMetaType > &metaType, VDMObjectDelegateDataType *dataType, int index, int row, int column, QObject *object)
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:129
QByteArray toUtf8() const &
Definition qstring.h:634
\inmodule QtCore
Definition qvariant.h:65
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
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum type
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:4193