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
qqmldmlistaccessordata.cpp
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#include <private/qqmldmlistaccessordata_p.h>
5
7
9 const QQmlRefPointer<QQmlDelegateModelItemMetaType> &metaType,
11 int index, int row, int column, const QVariant &value)
12 : QQmlDelegateModelItem(metaType, dataType, index, row, column)
13 , cachedData(value)
14{
15 QObjectPrivate::get(this)->metaObject = dataType;
16 dataType->addref();
17}
18
25
27 if (data == cachedData)
28 return;
29
30 cachedData = data;
31 cachedDataClean = false;
32 static_cast<const VDMListDelegateDataType *>(QObjectPrivate::get(this)->metaObject)
33 ->emitAllSignals(this);
34}
35
37{
38 // Used only for initialization of the cached data. Does not have to emit change signals.
39 Q_ASSERT(!cachedDataClean);
40
41 if (role == QLatin1String("modelData") || role.isEmpty())
42 cachedData = value;
43 else
44 VDMListDelegateDataType::setValue(&cachedData, role, value);
45}
46
48{
49 if (index == -1) {
50 index = idx;
51 setModelData(model.list.at(idx));
53 return true;
54 } else {
55 return false;
56 }
57}
58
60{
61 for (int i = propertyOffset, end = propertyCount(); i != end; ++i)
62 QMetaObject::activate(accessor, this, i - propertyOffset, nullptr);
63 emit accessor->modelDataChanged();
64}
65
67 QObject *object, QMetaObject::Call call, int id, void **arguments)
68{
69 Q_ASSERT(qobject_cast<QQmlDMListAccessorData *>(object));
70 QQmlDMListAccessorData *accessor = static_cast<QQmlDMListAccessorData *>(object);
71
72 switch (call) {
74 if (id < propertyOffset)
75 break;
76
77 QVariant *result = static_cast<QVariant *>(arguments[0]);
78 const QByteArray name = property(id).name();
79 const QVariant data = accessor->index == -1
80 ? accessor->modelData()
81 : model->list.at(accessor->index);
82 *result = value(&data, name);
83 return -1;
84 }
86 if (id < propertyOffset)
87 break;
88
89 const QVariant &argument = *static_cast<QVariant *>(arguments[0]);
90 const QByteArray name = property(id).name();
91 QVariant data = accessor->index == -1
92 ? accessor->modelData()
93 : model->list.at(accessor->index);
94 if (argument == value(&data, name))
95 return -1;
97 if (accessor->index == -1) {
98 accessor->cachedData = data;
99 accessor->cachedDataClean = false;
100 } else {
101 model->list.set(accessor->index, data);
102 }
103 QMetaObject::activate(accessor, this, id - propertyOffset, nullptr);
104 emit accessor->modelDataChanged();
105 return -1;
106 }
107 default:
108 break;
109 }
110
111 return accessor->qt_metacall(call, id, arguments);
112}
113
114int VDMListDelegateDataType::createProperty(const char *name, const char *)
115{
116 const int propertyIndex = propertyCount() - propertyOffset;
117
118 // We use QVariant because the types may be different in the different objects.
120 &builder, propertyIndex, name, QByteArrayLiteral("QVariant"));
121
123 *static_cast<QMetaObject *>(this) = *metaObject;
124 return propertyIndex + propertyOffset;
125}
126
128{
129 if (const QQmlRefPointer<QQmlContextData> &contextData
130 = static_cast<QQmlDMListAccessorData *>(object)->contextData) {
131 if (contextData->contextObject() == object) {
132 // We are using context properties. There should be a propertyCache so that row and
133 // column are hidden. We shall also return the static metaObject in that case.
134
135 if (!propertyCache) {
137 &QQmlDMListAccessorData::staticMetaObject, model->modelItemRevision);
138 if (QQmlData *ddata = QQmlData::get(object, true))
139 ddata->propertyCache = propertyCache;
140 }
141
142 // ### Qt 7: Return const from toDynamicMetaObject() and drop the const_cast.
143 return const_cast<QMetaObject *>(&QQmlDMListAccessorData::staticMetaObject);
144 }
145 }
146
147 // If the context object is not the model object, we are using required properties.
148 // In that case, create any extra properties.
150 if (!data->cachedDataClean) {
151 createMissingProperties(&data->cachedData);
152 data->cachedDataClean = true;
153 }
154 return this;
155}
156
\inmodule QtCore
Definition qbytearray.h:57
QMetaObject * toMetaObject() const
Converts this meta object builder into a concrete QMetaObject.
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:150
\inmodule QtCore
Definition qobject.h:103
static void addProperty(QMetaObjectBuilder *builder, int propertyId, const QByteArray &propertyName, const QByteArray &propertyType)
QQmlPropertyCache::ConstPtr propertyCache
QScopedPointer< QMetaObject, QScopedPointerPodDeleter > metaObject
QTypeRevision modelItemRevision
QQmlListAccessor list
void setModelData(const QVariant &data)
QQmlDMListAccessorData(const QQmlRefPointer< QQmlDelegateModelItemMetaType > &metaType, VDMListDelegateDataType *dataType, int index, int row, int column, const QVariant &value)
bool resolveIndex(const QQmlAdaptorModel &model, int idx) override
void setValue(const QString &role, const QVariant &value) override
static QQmlData * get(QObjectPrivate *priv, bool create)
Definition qqmldata_p.h:199
QVariant at(qsizetype) const
void set(qsizetype, const QVariant &)
static Ptr createStandalone(const QMetaObject *, QTypeRevision metaObjectRevision=QTypeRevision::zero())
Creates a standalone QQmlPropertyCache of metaObject.
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
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
\inmodule QtCore
Definition qvariant.h:65
void emitAllSignals(QQmlDMListAccessorData *accessor) const
void createMissingProperties(const QVariant *row)
int createProperty(const char *name, const char *) final
QMetaObject * toDynamicMetaObject(QObject *accessors) final
int metaCall(QObject *object, QMetaObject::Call call, int id, void **arguments) final
static void setValue(QVariant *row, const String &role, const QVariant &value)
QList< QVariant > arguments
Combined button and popup list for selecting options.
#define QByteArrayLiteral(str)
Definition qbytearray.h:52
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint index
[2]
GLuint GLuint end
GLuint object
[3]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint name
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLenum GLsizei void * row
GLuint64EXT * result
[6]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define emit
const char property[13]
Definition qwizard.cpp:101
QSqlQueryModel * model
[16]
sem release()
QDBusArgument argument
\inmodule QtCore
int propertyCount() const
Returns the number of properties in this class, including the number of properties provided by each b...
static void activate(QObject *sender, int signal_index, void **argv)
Definition qobject.cpp:4193