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
qassociativeiterable.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/qassociativeiterable.h>
5#include <QtCore/qvariant.h>
6
7#include <QtCore/private/qiterable_p.h>
8
10
15{
17 metaContainer().keyMetaType(), [this](void *dataPtr) {
18 metaContainer().keyAtIterator(constIterator(), dataPtr);
19 });
20}
21
26QVariantRef<QAssociativeIterator> QAssociativeIterator::value() const
27{
28 const QMetaType mappedMetaType(metaContainer().mappedMetaType());
29 return QVariantRef<QAssociativeIterator>(mappedMetaType.isValid() ? this : nullptr);
30}
31
37QVariantRef<QAssociativeIterator> QAssociativeIterator::operator*() const
38{
39 return QVariantRef<QAssociativeIterator>(this);
40}
41
47QVariantPointer<QAssociativeIterator> QAssociativeIterator::operator->() const
48{
49 return QVariantPointer<QAssociativeIterator>(this);
50}
51
56{
58 metaContainer().keyMetaType(), [this](void *dataPtr) {
59 metaContainer().keyAtConstIterator(constIterator(), dataPtr);
60 });
61}
62
68{
70 metaContainer().mappedMetaType(), [this](void *dataPtr) {
71 metaContainer().mappedAtConstIterator(constIterator(), dataPtr);
72 });
73}
74
80{
81 const QMetaType mappedMetaType(metaContainer().mappedMetaType());
82 return mappedMetaType.isValid() ? value() : key();
83}
84
94
158{
159 const QMetaAssociation meta = metaContainer();
161 if (const void *keyData = coercer.convert(key, meta.keyMetaType())) {
163 constIterable(), keyData)));
164 }
165 return constEnd();
166}
167
174{
175 const QMetaAssociation meta = metaContainer();
177 if (const void *keyData = coercer.convert(key, meta.keyMetaType()))
178 return iterator(QIterator(this, meta.createIteratorAtKey(mutableIterable(), keyData)));
179 return mutableEnd();
180}
181
188{
191 if (const void *keyData = keyCoercer.convert(key, meta.keyMetaType()))
192 return meta.containsKey(constIterable(), keyData);
193 return false;
194}
195
203{
206 meta.insertKey(mutableIterable(), keyCoercer.coerce(key, meta.keyMetaType()));
207}
208
215{
218 meta.removeKey(mutableIterable(), keyCoercer.coerce(key, meta.keyMetaType()));
219}
220
221
229{
230 const QMetaAssociation meta = metaContainer();
231 const QMetaType mappedMetaType = meta.mappedMetaType();
232
234 const void *keyData = coercer.coerce(key, meta.keyMetaType());
235
236 if (mappedMetaType == QMetaType::fromType<QVariant>()) {
238 meta.mappedAtKey(constIterable(), keyData, &result);
239 return result;
240 }
241
242 QVariant result(mappedMetaType);
243 meta.mappedAtKey(constIterable(), keyData, result.data());
244 return result;
245}
246
254{
256 QtPrivate::QVariantTypeCoercer mappedCoercer;
258 meta.setMappedAtKey(mutableIterable(), keyCoercer.coerce(key, meta.keyMetaType()),
259 mappedCoercer.coerce(mapped, meta.mappedMetaType()));
260}
261
QVariant operator*() const
Returns the current item, converted to a QVariant.
QVariantConstPointer operator->() const
Returns the current item, converted to a QVariantConstPointer.
QVariant value() const
Returns the mapped value this iterator points to, or an invalid QVariant if there is no mapped value.
QVariant key() const
Returns the key this iterator points to.
QTaggedIterator< QAssociativeConstIterator, void > const_iterator
bool containsKey(const QVariant &key)
Returns true if the container has an entry with the given key, or false otherwise.
void setValue(const QVariant &key, const QVariant &mapped)
Sets the mapped value associated with key to mapped, if possible.
const_iterator constEnd() const
void insertKey(const QVariant &key)
Inserts a new entry with the given key, or resets the mapped value of any existing entry with the giv...
QTaggedIterator< QAssociativeIterator, void > iterator
iterator mutableFind(const QVariant &key)
Retrieves an iterator pointing to the element at the given key, or the end of the container if that k...
const_iterator find(const QVariant &key) const
Retrieves a const_iterator pointing to the element at the given key, or the end of the container if t...
void removeKey(const QVariant &key)
Removes the entry with the given key from the container.
QVariant value(const QVariant &key) const
Retrieves the mapped value at the given key, or a default-constructed QVariant of the mapped type,...
QVariantRef< QAssociativeIterator > operator*() const
Returns the current item, converted to a QVariantRef.
QVariantPointer< QAssociativeIterator > operator->() const
Returns the current item, converted to a QVariantPointer.
QVariant key() const
Returns the key this iterator points to.
QVariantRef< QAssociativeIterator > value() const
Returns the mapped value this iterator points to.
const void * constIterator() const
Returns a const pointer to the internal native iterator.
Definition qiterable.h:213
Container metaContainer() const
Definition qiterable.h:214
const void * constIterable() const
Definition qiterable.h:469
QMetaAssociation metaContainer() const
Definition qiterable.h:508
void insertKey(void *container, const void *key) const
void setMappedAtKey(void *container, const void *key, const void *mapped) const
void * createConstIteratorAtKey(const void *container, const void *key) const
QMetaType keyMetaType() const
Returns the meta type for keys in the container.
void mappedAtKey(const void *container, const void *key, void *mapped) const
void * createIteratorAtKey(void *container, const void *key) const
QMetaType mappedMetaType() const
Returns the meta type for mapped values in the container.
void removeKey(void *container, const void *key) const
bool containsKey(const void *container, const void *key) const
\inmodule QtCore
Definition qmetatype.h:341
bool isValid() const
Emulated const pointer to QVariant based on a pointer.
Definition qvariant.h:859
\inmodule QtCore
Definition qvariant.h:65
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.
GLuint64 key
GLuint64EXT * result
[6]
The QConstIterator allows iteration over a container in a QVariant.
Definition qiterable.h:313
The QIterator is a template class that allows iteration over a container in a QVariant.
Definition qiterable.h:219