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
qqmllist.cpp
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#include "qqmllist.h"
5#include "qqmllist_p.h"
6#include <QtQml/private/qqmlproperty_p.h>
7
9
11{
12 if (object) {
13 const QQmlMetaObject elementType = d->elementType();
14 if (elementType.isNull() || !QQmlMetaObject::canConvert(object, elementType))
15 return false;
16 }
17 return true;
18}
19
24
26 const QQmlListProperty<QObject> &prop, QMetaType propType)
27{
29
30 if (!prop.object) return rv;
31
32 rv.d = new QQmlListReferencePrivate;
33 rv.d->object = prop.object;
34 rv.d->property = prop;
35 rv.d->propertyType = propType;
36
37 return rv;
38}
39
45
47{
48 Q_ASSERT(refCount > 0);
49 --refCount;
50 if (!refCount)
51 delete this;
52}
53
89
90#if QT_DEPRECATED_SINCE(6, 4)
105{}
106
118 [[maybe_unused]] QQmlEngine *engine)
120{}
121#endif
122
133 : d(nullptr)
134{
135 const QMetaType t = variant.metaType();
136 if (!(t.flags() & QMetaType::IsQmlList))
137 return;
138
140 d->propertyType = t;
141
142 d->property.~QQmlListProperty();
143 t.construct(&d->property, variant.constData());
144
145 d->object = d->property.object;
146}
147
155 : d(nullptr)
156{
157 if (!object || !property) return;
158
159 QQmlPropertyData local;
160 const QQmlPropertyData *data =
161 QQmlPropertyCache::property(object, QLatin1String(property), nullptr, &local);
162
163 if (!data || !data->isQList()) return;
164
166 d->object = object;
167 d->propertyType = data->propType();
168
169 void *args[] = { &d->property, nullptr };
171}
172
175: d(o.d)
176{
177 if (d) d->addref();
178}
179
182{
183 if (o.d) o.d->addref();
184 if (d) d->release();
185 d = o.d;
186 return *this;
187}
188
194
199{
200 return d && d->object;
201}
202
207{
208 if (isValid()) return d->object;
209 else return nullptr;
210}
211
220{
221 return isValid() ? d->elementType() : nullptr;
222}
223
231{
232 return (isValid() && d->property.append);
233}
234
242{
243 return (isValid() && d->property.at);
244}
245
253{
254 return (isValid() && d->property.clear);
255}
256
264{
265 return (isValid() && d->property.count);
266}
267
275{
276 return (isValid() && d->property.replace);
277}
278
286{
287 return (isValid() && d->property.removeLast);
288}
289
302{
303 return (isValid()
304 && d->property.append
305 && d->property.count
306 && d->property.at
307 && d->property.clear);
308}
309
310
317{
318 return (isValid() && d->property.count && d->property.at);
319}
320
327{
328 if (!canAppend()) return false;
329
330 if (!isObjectCompatible(object, d))
331 return false;
332
333 d->property.append(&d->property, object);
334
335 return true;
336}
337
344{
345 if (!canAt()) return nullptr;
346
347 return d->property.at(&d->property, index);
348}
349
356{
357 if (!canClear()) return false;
358
359 d->property.clear(&d->property);
360
361 return true;
362}
363
368{
369 if (!canCount()) return 0;
370
371 return d->property.count(&d->property);
372}
373
387{
388 if (!canReplace())
389 return false;
390
391 if (!isObjectCompatible(object, d))
392 return false;
393
394 d->property.replace(&d->property, index, object);
395 return true;
396}
397
405{
406 if (!canRemoveLast())
407 return false;
408
410 return true;
411}
412
\inmodule QtCore
Definition qmetatype.h:341
\inmodule QtCore
Definition qobject.h:103
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
ClearFunction clear
Definition qqmllist.h:87
AtFunction at
Definition qqmllist.h:86
QObject * object
Definition qqmllist.h:81
RemoveLastFunction removeLast
Definition qqmllist.h:89
CountFunction count
Definition qqmllist.h:85
AppendFunction append
Definition qqmllist.h:84
ReplaceFunction replace
Definition qqmllist.h:88
static QQmlListReference init(const QQmlListProperty< QObject > &, QMetaType)
Definition qqmllist.cpp:25
const QMetaObject * elementType()
Definition qqmllist_p.h:46
QPointer< QObject > object
Definition qqmllist_p.h:34
QQmlListProperty< QObject > property
Definition qqmllist_p.h:35
The QQmlListReference class allows the manipulation of QQmlListProperty properties.
Definition qqmllist.h:183
QQmlListReference()
Constructs an invalid instance.
Definition qqmllist.cpp:85
bool canAppend() const
Returns true if the list property can be appended to, otherwise false.
Definition qqmllist.cpp:230
qsizetype count() const
Returns the number of objects in the list, or 0 if the operation failed.
Definition qqmllist.cpp:367
bool canRemoveLast() const
Returns true if the last item can be removed from the list property, otherwise false.
Definition qqmllist.cpp:285
bool replace(qsizetype, QObject *) const
Replaces the item at index in the list with object.
Definition qqmllist.cpp:386
friend class QQmlListReferencePrivate
Definition qqmllist.h:226
bool append(QObject *) const
Appends object to the list.
Definition qqmllist.cpp:326
bool isReadable() const
Definition qqmllist.cpp:316
bool isValid() const
Returns true if the instance refers to a valid list property, otherwise false.
Definition qqmllist.cpp:198
bool canClear() const
Returns true if the list property can be cleared, otherwise false.
Definition qqmllist.cpp:252
QObject * object() const
Returns the list property's object.
Definition qqmllist.cpp:206
bool removeLast() const
Removes the last item in the list.
Definition qqmllist.cpp:404
const QMetaObject * listElementType() const
Returns the QMetaObject for the elements stored in the list property, or \nullptr if the reference is...
Definition qqmllist.cpp:219
bool isManipulable() const
Definition qqmllist.cpp:301
bool canReplace() const
Returns true if items in the list property can be replaced, otherwise false.
Definition qqmllist.cpp:274
QObject * at(qsizetype) const
Returns the list element at index, or 0 if the operation failed.
Definition qqmllist.cpp:343
bool canAt() const
Returns true if the list property can queried by index, otherwise false.
Definition qqmllist.cpp:241
bool clear() const
Clears the list.
Definition qqmllist.cpp:355
QQmlListReference & operator=(const QQmlListReference &)
Definition qqmllist.cpp:181
bool canCount() const
Returns true if the list property can be queried for its element count, otherwise false.
Definition qqmllist.cpp:263
bool isNull() const
static bool canConvert(const QQmlMetaObject &from, const QQmlMetaObject &to)
const QQmlPropertyData * property(const K &key, QObject *object, const QQmlRefPointer< QQmlContextData > &context) const
\inmodule QtCore
Definition qvariant.h:65
QMetaType metaType() const
const void * constData() const
Definition qvariant.h:451
Combined button and popup list for selecting options.
GLuint index
[2]
GLuint object
[3]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble t
Definition qopenglext.h:243
static QT_BEGIN_NAMESPACE bool isObjectCompatible(QObject *object, QQmlListReferencePrivate *d)
Definition qqmllist.cpp:10
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
ptrdiff_t qsizetype
Definition qtypes.h:165
const char property[13]
Definition qwizard.cpp:101
QObject::connect nullptr
QVariant variant
[1]
QJSValueList args
QJSEngine engine
[0]
\inmodule QtCore
static int metacall(QObject *, Call, int, void **)