Qt 6.x
The Qt SDK
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
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
20 if (data == cachedData)
21 return;
22
23 cachedData = data;
24 static_cast<const VDMListDelegateDataType *>(QObjectPrivate::get(this)->metaObject)
25 ->emitAllSignals(this);
26}
27
29{
30 // Used only for initialization of the cached data. Does not have to emit change signals.
31 if (role == QLatin1String("modelData") || role.isEmpty())
32 cachedData = value;
33 else
34 VDMListDelegateDataType::setValue(&cachedData, role, value);
35}
36
38{
39 if (index == -1) {
40 index = idx;
41 setModelData(model.list.at(idx));
43 return true;
44 } else {
45 return false;
46 }
47}
48
50{
51 for (int i = propertyOffset, end = propertyCount(); i != end; ++i)
52 QMetaObject::activate(accessor, this, i - propertyOffset, nullptr);
53 emit accessor->modelDataChanged();
54}
55
57 QObject *object, QMetaObject::Call call, int id, void **arguments)
58{
59 Q_ASSERT(qobject_cast<QQmlDMListAccessorData *>(object));
60 QQmlDMListAccessorData *accessor = static_cast<QQmlDMListAccessorData *>(object);
61
62 switch (call) {
64 if (id < propertyOffset)
65 break;
66
67 QVariant *result = static_cast<QVariant *>(arguments[0]);
68 const QByteArray name = property(id).name();
69 const QVariant data = accessor->index == -1
70 ? accessor->modelData()
71 : model->list.at(accessor->index);
72 *result = value(&data, name);
73 return -1;
74 }
76 if (id < propertyOffset)
77 break;
78
79 const QVariant &argument = *static_cast<QVariant *>(arguments[0]);
80 const QByteArray name = property(id).name();
81 QVariant data = accessor->index == -1
82 ? accessor->modelData()
83 : model->list.at(accessor->index);
84 if (argument == value(&data, name))
85 return -1;
87 if (accessor->index == -1)
88 accessor->cachedData = data;
89 else
90 model->list.set(accessor->index, data);
91 QMetaObject::activate(accessor, this, id - propertyOffset, nullptr);
92 emit accessor->modelDataChanged();
93 return -1;
94 }
95 default:
96 break;
97 }
98
99 return accessor->qt_metacall(call, id, arguments);
100}
101
102int VDMListDelegateDataType::createProperty(const char *name, const char *)
103{
104 const int propertyIndex = propertyCount() - propertyOffset;
105
106 // We use QVariant because the types may be different in the different objects.
108 &builder, propertyIndex, name, QByteArrayLiteral("QVariant"));
109
111 *static_cast<QMetaObject *>(this) = *metaObject;
112 return propertyIndex + propertyOffset;
113}
114
116{
117 if (const QQmlRefPointer<QQmlContextData> &contextData
118 = static_cast<QQmlDMListAccessorData *>(object)->contextData) {
119 if (contextData->contextObject() == object) {
120 // We are using context properties. There should be a propertyCache so that row and
121 // column are hidden. We shall also return the static metaObject in that case.
122
123 if (!propertyCache) {
125 &QQmlDMListAccessorData::staticMetaObject, model->modelItemRevision);
126 if (QQmlData *ddata = QQmlData::get(object, true))
127 ddata->propertyCache = propertyCache;
128 }
129
130 // ### Qt 7: Return const from toDynamicMetaObject() and drop the const_cast.
131 return const_cast<QMetaObject *>(&QQmlDMListAccessorData::staticMetaObject);
132 }
133 }
134
135 // If the context object is not the model object, we are using required properties.
136 // In that case, allow the creation of extra properties.
137 return this;
138}
139
\inmodule QtCore
Definition qbytearray.h:57
QMetaObject * toMetaObject() const
Converts this meta object builder into a concrete QMetaObject.
QDynamicMetaObjectData * metaObject
Definition qobject.h:77
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:153
\inmodule QtCore
Definition qobject.h:90
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 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
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
\inmodule QtCore
Definition qvariant.h:64
void emitAllSignals(QQmlDMListAccessorData *accessor) const
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]
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:4057