![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QQmlListReference class allows the manipulation of \l QQmlListProperty properties. More...
#include <qqmllist.h>
Public Member Functions | |
QQmlListReference () | |
Constructs an invalid instance. | |
QQmlListReference (const QVariant &variant) | |
QQmlListReference (QObject *o, const char *property) | |
Constructs a QQmlListReference for object's property. | |
QQmlListReference (const QQmlListReference &) | |
QQmlListReference & | operator= (const QQmlListReference &) |
~QQmlListReference () | |
bool | isValid () const |
Returns true if the instance refers to a valid list property, otherwise false. | |
QObject * | object () const |
Returns the list property's object. | |
const QMetaObject * | listElementType () const |
Returns the QMetaObject for the elements stored in the list property, or \nullptr if the reference is invalid. | |
bool | canAppend () const |
Returns true if the list property can be appended to, otherwise false. | |
bool | canAt () const |
Returns true if the list property can queried by index, otherwise false. | |
bool | canClear () const |
Returns true if the list property can be cleared, otherwise false. | |
bool | canCount () const |
Returns true if the list property can be queried for its element count, otherwise false. | |
bool | canReplace () const |
Returns true if items in the list property can be replaced, otherwise false. | |
bool | canRemoveLast () const |
Returns true if the last item can be removed from the list property, otherwise false. | |
bool | isManipulable () const |
Return true if at(), count(), append(), and either clear() or removeLast() are implemented, so you can manipulate the list. | |
bool | isReadable () const |
Return true if at() and count() are implemented, so you can access the elements. | |
bool | append (QObject *) const |
Appends object to the list. | |
QObject * | at (qsizetype) const |
Returns the list element at index, or \nullptr if the operation failed. | |
bool | clear () const |
Clears the list. | |
qsizetype | count () const |
Returns the number of items in the list, or 0 if the operation failed. | |
qsizetype | size () const |
bool | replace (qsizetype, QObject *) const |
Replaces the item at index in the list with object. | |
bool | removeLast () const |
Removes the last item in the list. | |
bool | operator== (const QQmlListReference &other) const |
Compares this QQmlListReference to other, and returns true if they are equal. | |
Friends | |
class | QQmlListReferencePrivate |
The QQmlListReference class allows the manipulation of \l QQmlListProperty properties.
QQmlListReference allows C++ programs to read from, and assign values to a QML list property in a simple and type-safe way. The main advantage over using \l QQmlListProperty itself is its type erasure: QQmlListReference is not a template, but can be used for QQmlListProperties of any type. Furthermore it watches the owner object for deletion and does not allow the \l QQmlListProperty to be accessed anymore if its owner has been deleted.
You can create a QQmlListReference from either an object and a property name or from a QVariant. These two are equivalent:
Not all QQmlListReferences support all operations. Methods like canAppend(), canAt(), canClear(), and canCount() allow programs to query whether an operation is supported on a given property. The availability of the methods depends on the methods implemented by the underlying \l QQmlListProperty. When constructing a \l QQmlListProperty by manually passing the accessor functions you can restrict access to the list by passing nullptr to some of them. QQmlListReference will recognize those and report them as unavailable.
\l{QQmlListReference}s are type-safe. Only \l{QObject}s that derive of the correct base class can be added to the list. The listElementType() method can be used to query the \l QMetaObject of the \l QObject type that can be added. Attempting to add objects of an incorrect type to a list property will fail.
Like with other lists, when accessing a list element by index, it is the callers responsibility to ensure that it does not request an out of range element. Use the count() method before calling at() to this effect.
Definition at line 182 of file qqmllist.h.
QQmlListReference::QQmlListReference | ( | ) |
Constructs an invalid instance.
Definition at line 108 of file qqmllist.cpp.
|
explicit |
Constructs a QQmlListReference from a QVariant variant containing a QQmlListProperty. If variant does not contain a list property, an invalid QQmlListReference is created. If the object owning the list property is destroyed after the reference is constructed, it will automatically become invalid. That is, it is safe to hold QQmlListReference instances even after the object is deleted.
Definition at line 155 of file qqmllist.cpp.
QQmlListReference::QQmlListReference | ( | QObject * | object, |
const char * | property ) |
Constructs a QQmlListReference for object's property.
If property is not a list property, an invalid QQmlListReference is created. If object is destroyed after the reference is constructed, it will automatically become invalid. That is, it is safe to hold QQmlListReference instances even after object is deleted.
Definition at line 177 of file qqmllist.cpp.
QQmlListReference::QQmlListReference | ( | const QQmlListReference & | o | ) |
Definition at line 197 of file qqmllist.cpp.
QQmlListReference::~QQmlListReference | ( | ) |
Definition at line 213 of file qqmllist.cpp.
bool QQmlListReference::append | ( | QObject * | object | ) | const |
Appends object to the list.
Returns true if the operation succeeded, otherwise false.
Definition at line 349 of file qqmllist.cpp.
Returns the list element at index, or \nullptr if the operation failed.
Definition at line 366 of file qqmllist.cpp.
bool QQmlListReference::canAppend | ( | ) | const |
Returns true if the list property can be appended to, otherwise false.
Returns false if the reference is invalid.
Definition at line 253 of file qqmllist.cpp.
bool QQmlListReference::canAt | ( | ) | const |
Returns true if the list property can queried by index, otherwise false.
Returns false if the reference is invalid.
Definition at line 264 of file qqmllist.cpp.
bool QQmlListReference::canClear | ( | ) | const |
Returns true if the list property can be cleared, otherwise false.
Returns false if the reference is invalid.
Definition at line 275 of file qqmllist.cpp.
bool QQmlListReference::canCount | ( | ) | const |
Returns true if the list property can be queried for its element count, otherwise false.
Returns false if the reference is invalid.
Definition at line 286 of file qqmllist.cpp.
bool QQmlListReference::canRemoveLast | ( | ) | const |
Returns true if the last item can be removed from the list property, otherwise false.
Returns false if the reference is invalid.
Definition at line 308 of file qqmllist.cpp.
bool QQmlListReference::canReplace | ( | ) | const |
Returns true if items in the list property can be replaced, otherwise false.
Returns false if the reference is invalid.
Definition at line 297 of file qqmllist.cpp.
bool QQmlListReference::clear | ( | ) | const |
Clears the list.
Returns true if the operation succeeded, otherwise false.
Definition at line 378 of file qqmllist.cpp.
qsizetype QQmlListReference::count | ( | ) | const |
Returns the number of items in the list, or 0 if the operation failed.
Definition at line 390 of file qqmllist.cpp.
bool QQmlListReference::isManipulable | ( | ) | const |
Return true if at(), count(), append(), and either clear() or removeLast() are implemented, so you can manipulate the list.
Mind that replace() and removeLast() can be emulated by stashing all items and rebuilding the list using clear() and append(). Therefore, they are not required for the list to be manipulable. Furthermore, clear() can be emulated using removeLast().
Definition at line 324 of file qqmllist.cpp.
bool QQmlListReference::isReadable | ( | ) | const |
Return true if at() and count() are implemented, so you can access the elements.
Definition at line 339 of file qqmllist.cpp.
bool QQmlListReference::isValid | ( | ) | const |
Returns true if the instance refers to a valid list property, otherwise false.
Definition at line 221 of file qqmllist.cpp.
const QMetaObject * QQmlListReference::listElementType | ( | ) | const |
Returns the QMetaObject for the elements stored in the list property, or \nullptr if the reference is invalid.
The QMetaObject can be used ahead of time to determine whether a given instance can be added to a list. If you didn't pass an engine on construction this may return nullptr.
Definition at line 242 of file qqmllist.cpp.
QObject * QQmlListReference::object | ( | ) | const |
Returns the list property's object.
Returns \nullptr if the reference is invalid.
Definition at line 229 of file qqmllist.cpp.
QQmlListReference & QQmlListReference::operator= | ( | const QQmlListReference & | o | ) |
Definition at line 204 of file qqmllist.cpp.
|
inline |
Compares this QQmlListReference to other, and returns true
if they are equal.
The two are only considered equal if one was created from the other via copy assignment or copy construction.
Definition at line 223 of file qqmllist.h.
bool QQmlListReference::removeLast | ( | ) | const |
Removes the last item in the list.
Returns true if the operation succeeded, otherwise false.
Definition at line 427 of file qqmllist.cpp.
Replaces the item at index in the list with object.
Returns true if the operation succeeded, otherwise false.
Definition at line 409 of file qqmllist.cpp.
|
inline |
Definition at line 220 of file qqmllist.h.
|
friend |
Definition at line 226 of file qqmllist.h.