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
qsequentialiterable.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 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 <QtCore/qsequentialiterable.h>
5#include <QtCore/qvariant.h>
6
7#include <QtCore/private/qiterable_p.h>
8
10
72{
74 const void *valuePtr = coercer.coerce(value, metaContainer().valueMetaType());
75
76 switch (position) {
77 case AtBegin:
78 if (metaContainer().canAddValueAtBegin())
80 break;
81 case AtEnd:
82 if (metaContainer().canAddValueAtEnd())
84 break;
85 case Unspecified:
86 if (metaContainer().canAddValue())
88 break;
89 }
90}
91
96{
97 switch (position) {
98 case AtBegin:
99 if (metaContainer().canRemoveValueAtBegin())
101 break;
102 case AtEnd:
103 if (metaContainer().canRemoveValueAtEnd())
105 break;
106 case Unspecified:
107 if (metaContainer().canRemoveValue())
109 break;
110 }
111}
112
117
122{
124 void *dataPtr;
125 if (valueMetaType() == QMetaType::fromType<QVariant>())
126 dataPtr = &v;
127 else
128 dataPtr = v.data();
129
130 const QMetaSequence meta = metaContainer();
131 if (meta.canGetValueAtIndex()) {
132 meta.valueAtIndex(m_iterable.constPointer(), idx, dataPtr);
133 } else if (meta.canGetValueAtConstIterator()) {
136 meta.valueAtConstIterator(iterator, dataPtr);
138 }
139
140 return v;
141}
142
147{
149 const void *dataPtr = coercer.coerce(value, metaContainer().valueMetaType());
150
151 const QMetaSequence meta = metaContainer();
152 if (meta.canSetValueAtIndex()) {
153 meta.setValueAtIndex(m_iterable.mutablePointer(), idx, dataPtr);
154 } else if (meta.canSetValueAtIterator()) {
155 void *iterator = meta.begin(m_iterable.mutablePointer());
156 meta.advanceIterator(iterator, idx);
157 meta.setValueAtIterator(iterator, dataPtr);
159 }
160}
161
184QVariantRef<QSequentialIterator> QSequentialIterator::operator*() const
185{
186 return QVariantRef<QSequentialIterator>(this);
187}
188
192QVariantPointer<QSequentialIterator> QSequentialIterator::operator->() const
193{
194 return QVariantPointer<QSequentialIterator>(this);
195}
196
201{
202 return QIterablePrivate::retrieveElement(metaContainer().valueMetaType(), [this](void *dataPtr) {
203 metaContainer().valueAtConstIterator(constIterator(), dataPtr);
204 });
205}
206
214
const void * constIterator() const
Returns a const pointer to the internal native iterator.
Definition qiterable.h:213
Container metaContainer() const
Definition qiterable.h:214
QMetaSequence metaContainer() const
Definition qiterable.h:508
QtPrivate::QConstPreservingPointer< void, quint16 > m_iterable
Definition qiterable.h:417
void advanceConstIterator(void *iterator, qsizetype step) const
Advances the const iterator by step steps.
void destroyConstIterator(const void *iterator) const
Destroys a const iterator previously created using \l constBegin() or \l constEnd().
void advanceIterator(void *iterator, qsizetype step) const
Advances the non-const iterator by step steps.
void * constBegin(const void *container) const
Creates and returns a const iterator pointing to the beginning of container.
void destroyIterator(const void *iterator) const
Destroys a non-const iterator previously created using \l begin() or \l end().
void * begin(void *container) const
Creates and returns a non-const iterator pointing to the beginning of container.
\inmodule QtCore
bool canSetValueAtIndex() const
Returns true if an value can be written to the container by index, otherwise false.
void setValueAtIndex(void *container, qsizetype index, const void *value) const
Overwrites the value at index in the container using the value passed as parameter if that is possibl...
bool canGetValueAtIndex() const
Returns true if values can be retrieved from the container by index, otherwise false.
void removeValue(void *container) const
Removes an value from the container if possible.
void valueAtConstIterator(const void *iterator, void *result) const
Retrieves the value pointed to by the const iterator and stores it in the memory location pointed to ...
void addValueAtEnd(void *container, const void *value) const
Adds value to the end of container if possible.
void setValueAtIterator(const void *iterator, const void *value) const
Writes value to the value pointed to by the non-const iterator, if possible.
void addValue(void *container, const void *value) const
Adds value to the container if possible.
void removeValueAtEnd(void *container) const
Removes a value from the end of container if possible.
bool canSetValueAtIterator() const
Returns true if the underlying container can write to the value pointed to by a non-const iterator,...
bool canGetValueAtConstIterator() const
Returns true if the underlying container can retrieve the value pointed to by a const iterator,...
void removeValueAtBegin(void *container) const
Removes a value from the beginning of container if possible.
void valueAtIndex(const void *container, qsizetype index, void *result) const
Retrieves the value at index in the container and places it in the memory location pointed to by resu...
void addValueAtBegin(void *container, const void *value) const
Adds value to the beginning of container if possible.
\inmodule QtCore
Definition qmetatype.h:341
QVariant operator*() const
Returns the current item, converted to a QVariant.
QVariantConstPointer operator->() const
Returns the current item, converted to a QVariantConstPointer.
QMetaType valueMetaType() const
void set(qsizetype idx, const QVariant &value)
Sets the element at position idx in the container to value.
QVariant at(qsizetype idx) const
Returns the value at position idx in the container.
void addValue(const QVariant &value, Position position=Unspecified)
Adds value to the container, at position, if possible.
void removeValue(Position position=Unspecified)
Removes a value from the container, at position, if possible.
QTaggedIterator< QSequentialIterator, void > iterator
QVariantRef< QSequentialIterator > operator*() const
\typealias QSequentialIterable::const_iterator
QVariantPointer< QSequentialIterator > operator->() const
Returns the current item, converted to a QVariantPointer.
Emulated const pointer to QVariant based on a pointer.
Definition qvariant.h:859
\inmodule QtCore
Definition qvariant.h:65
const Type * constPointer() const
Definition qiterable.h:54
const void * coerce(const QVariant &value, const QMetaType &type)
static QVariant retrieveElement(QMetaType type, Callback callback)
Definition qiterable_p.h:26
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLsizei const GLfloat * v
[13]
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
ptrdiff_t qsizetype
Definition qtypes.h:165