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 Class Reference

The QAssociativeIterable class is an iterable interface for an associative container in a QVariant. More...

#include <qassociativeiterable.h>

+ Inheritance diagram for QAssociativeIterable:
+ Collaboration diagram for QAssociativeIterable:

Public Types

using iterator = QTaggedIterator<QAssociativeIterator, void>
 
using const_iterator = QTaggedIterator<QAssociativeConstIterator, void>
 
using RandomAccessIterator = QTaggedIterator<iterator, std::random_access_iterator_tag>
 Exposes an iterator using std::random_access_iterator_tag.
 
using BidirectionalIterator = QTaggedIterator<iterator, std::bidirectional_iterator_tag>
 Exposes an iterator using std::bidirectional_iterator_tag.
 
using ForwardIterator = QTaggedIterator<iterator, std::forward_iterator_tag>
 Exposes an iterator using std::forward_iterator_tag.
 
using InputIterator = QTaggedIterator<iterator, std::input_iterator_tag>
 Exposes an iterator using std::input_iterator_tag.
 
using RandomAccessConstIterator = QTaggedIterator<const_iterator, std::random_access_iterator_tag>
 Exposes a const_iterator using std::random_access_iterator_tag.
 
using BidirectionalConstIterator = QTaggedIterator<const_iterator, std::bidirectional_iterator_tag>
 Exposes a const_iterator using std::bidirectional_iterator_tag.
 
using ForwardConstIterator = QTaggedIterator<const_iterator, std::forward_iterator_tag>
 Exposes a const_iterator using std::forward_iterator_tag.
 
using InputConstIterator = QTaggedIterator<const_iterator, std::input_iterator_tag>
 Exposes a const_iterator using std::input_iterator_tag.
 

Public Member Functions

template<class T >
 QAssociativeIterable (const T *p)
 
template<class T >
 QAssociativeIterable (T *p)
 
 QAssociativeIterable ()
 
template<typename Pointer >
 QAssociativeIterable (const QMetaAssociation &metaAssociation, Pointer iterable)
 
 QAssociativeIterable (const QMetaAssociation &metaAssociation, const QMetaType &metaType, void *iterable)
 
 QAssociativeIterable (const QMetaAssociation &metaAssociation, const QMetaType &metaType, const void *iterable)
 
 QAssociativeIterable (QIterable< QMetaAssociation > &&other)
 
QAssociativeIterableoperator= (QIterable< QMetaAssociation > &&other)
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator constBegin () const
 
const_iterator constEnd () const
 
iterator mutableBegin ()
 
iterator mutableEnd ()
 
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 that key does not exist.
 
const_iterator constFind (const QVariant &key) const
 
iterator mutableFind (const QVariant &key)
 Retrieves an iterator pointing to the element at the given key, or the end of the container if that key does not exist.
 
bool containsKey (const QVariant &key)
 Returns true if the container has an entry with the given key, or false otherwise.
 
void insertKey (const QVariant &key)
 Inserts a new entry with the given key, or resets the mapped value of any existing entry with the given key to the default constructed mapped value.
 
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, if the key does not exist.
 
void setValue (const QVariant &key, const QVariant &mapped)
 Sets the mapped value associated with key to mapped, if possible.
 
- Public Member Functions inherited from QIterable< QMetaAssociation >
 QIterable (const QMetaAssociation &metaContainer, const T *p)
 
 QIterable (const QMetaAssociation &metaContainer, T *p)
 
 QIterable (const QMetaAssociation &metaContainer, Pointer iterable)
 
 QIterable (const QMetaAssociation &metaContainer, qsizetype alignment, const void *p)
 
 QIterable (const QMetaAssociation &metaContainer, qsizetype alignment, void *p)
 
bool canInputIterate () const
 Returns whether the container has an input iterator.
 
bool canForwardIterate () const
 Returns whether it is possible to iterate over the container in forward direction.
 
bool canReverseIterate () const
 Returns whether it is possible to iterate over the container in reverse.
 
bool canRandomAccessIterate () const
 Returns whether it is possible to efficiently skip over multiple values using and iterator.
 
const voidconstIterable () const
 
voidmutableIterable ()
 
QConstIterator< QMetaAssociationconstBegin () const
 Returns a QConstIterator for the beginning of the container.
 
QConstIterator< QMetaAssociationconstEnd () const
 Returns a Qterable::QConstIterator for the end of the container.
 
QIterator< QMetaAssociationmutableBegin ()
 Returns a QIterator for the beginning of the container.
 
QIterator< QMetaAssociationmutableEnd ()
 Returns a QSequentialIterable::iterator for the end of the container.
 
qsizetype size () const
 Returns the number of values in the container.
 
QMetaAssociation metaContainer () const
 

Additional Inherited Members

- Protected Attributes inherited from QIterable< QMetaAssociation >
uint m_revision
 
QtPrivate::QConstPreservingPointer< void, quint16m_iterable
 
QMetaAssociation m_metaContainer
 

Detailed Description

The QAssociativeIterable class is an iterable interface for an associative container in a QVariant.

Since
5.2 \inmodule QtCore

This class allows several methods of accessing the elements of an associative container held within a QVariant. An instance of QAssociativeIterable can be extracted from a QVariant if it can be converted to a QVariantHash or QVariantMap or if a custom mutable view has been registered.

QHash<int, QString> mapping;
mapping.insert(7, "Seven");
mapping.insert(11, "Eleven");
mapping.insert(42, "Forty-two");
// Can use foreach over the values:
foreach (const QVariant &v, iterable) {
qDebug() << v;
}
// Can use C++11 range-for over the values:
for (const QVariant &v : iterable) {
qDebug() << v;
}
// Can use iterators:
const QAssociativeIterable::const_iterator end = iterable.end();
for ( ; it != end; ++it) {
qDebug() << *it; // The current value
qDebug() << it.key();
qDebug() << it.value();
}
}
The QAssociativeIterable class is an iterable interface for an associative container in a QVariant.
QTaggedIterator< QAssociativeConstIterator, void > const_iterator
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtCore\reentrant
Definition qdatastream.h:46
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1303
The QSequentialIterable class is an iterable interface for a container in a QVariant.
QTaggedIterator< QSequentialConstIterator, void > const_iterator
iterator begin()
Definition qset.h:136
T value() const &
Definition qvariant.h:516
void setValue(T &&avalue)
Definition qvariant.h:493
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Definition qvariant.h:536
bool canConvert(QMetaType targetType) const
Definition qvariant.h:345
QSet< QString >::iterator it
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLuint GLuint end
GLuint color
[2]
GLenum GLenum GLenum GLenum mapping
QVariant v(123)
[3]
QVariant variant
[1]
QDataStream out(...)
[0]
QList< int > intList
[7]
MyCustomStruct c
QColor color
[2]
QHash< int, QString > mapping
[9]
MyCustomStruct c2

The container itself is not copied before iterating over it.

See also
QVariant

Definition at line 50 of file qassociativeiterable.h.

Member Typedef Documentation

◆ BidirectionalConstIterator

Exposes a const_iterator using std::bidirectional_iterator_tag.

Definition at line 62 of file qassociativeiterable.h.

◆ BidirectionalIterator

Exposes an iterator using std::bidirectional_iterator_tag.

Definition at line 57 of file qassociativeiterable.h.

◆ const_iterator

◆ ForwardConstIterator

Exposes a const_iterator using std::forward_iterator_tag.

Definition at line 63 of file qassociativeiterable.h.

◆ ForwardIterator

Exposes an iterator using std::forward_iterator_tag.

Definition at line 58 of file qassociativeiterable.h.

◆ InputConstIterator

Exposes a const_iterator using std::input_iterator_tag.

Definition at line 64 of file qassociativeiterable.h.

◆ InputIterator

Exposes an iterator using std::input_iterator_tag.

Definition at line 59 of file qassociativeiterable.h.

◆ iterator

◆ RandomAccessConstIterator

Exposes a const_iterator using std::random_access_iterator_tag.

Definition at line 61 of file qassociativeiterable.h.

◆ RandomAccessIterator

Exposes an iterator using std::random_access_iterator_tag.

Definition at line 56 of file qassociativeiterable.h.

Constructor & Destructor Documentation

◆ QAssociativeIterable() [1/7]

template<class T >
QAssociativeIterable::QAssociativeIterable ( const T * p)
inline

Definition at line 67 of file qassociativeiterable.h.

◆ QAssociativeIterable() [2/7]

template<class T >
QAssociativeIterable::QAssociativeIterable ( T * p)
inline

Definition at line 73 of file qassociativeiterable.h.

◆ QAssociativeIterable() [3/7]

QAssociativeIterable::QAssociativeIterable ( )
inline

Definition at line 78 of file qassociativeiterable.h.

◆ QAssociativeIterable() [4/7]

template<typename Pointer >
QAssociativeIterable::QAssociativeIterable ( const QMetaAssociation & metaAssociation,
Pointer iterable )
inline

Definition at line 84 of file qassociativeiterable.h.

◆ QAssociativeIterable() [5/7]

QAssociativeIterable::QAssociativeIterable ( const QMetaAssociation & metaAssociation,
const QMetaType & metaType,
void * iterable )
inline

Definition at line 90 of file qassociativeiterable.h.

◆ QAssociativeIterable() [6/7]

QAssociativeIterable::QAssociativeIterable ( const QMetaAssociation & metaAssociation,
const QMetaType & metaType,
const void * iterable )
inline

Definition at line 97 of file qassociativeiterable.h.

◆ QAssociativeIterable() [7/7]

QAssociativeIterable::QAssociativeIterable ( QIterable< QMetaAssociation > && other)
inline

Definition at line 103 of file qassociativeiterable.h.

Member Function Documentation

◆ begin()

const_iterator QAssociativeIterable::begin ( ) const
inline

Definition at line 111 of file qassociativeiterable.h.

◆ constBegin()

const_iterator QAssociativeIterable::constBegin ( ) const
inline

Definition at line 114 of file qassociativeiterable.h.

References QIterable< Container >::constBegin().

+ Here is the call graph for this function:

◆ constEnd()

const_iterator QAssociativeIterable::constEnd ( ) const
inline

Definition at line 115 of file qassociativeiterable.h.

References QIterable< Container >::constEnd().

Referenced by find().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ constFind()

const_iterator QAssociativeIterable::constFind ( const QVariant & key) const
inline

Definition at line 121 of file qassociativeiterable.h.

◆ containsKey()

bool QAssociativeIterable::containsKey ( const QVariant & key)

Returns true if the container has an entry with the given key, or false otherwise.

If the key isn't convertible to the expected type, false is returned.

Definition at line 187 of file qassociativeiterable.cpp.

References QIterable< QMetaAssociation >::constIterable(), QMetaAssociation::containsKey(), QMetaAssociation::keyMetaType(), and QIterable< QMetaAssociation >::metaContainer().

+ Here is the call graph for this function:

◆ end()

const_iterator QAssociativeIterable::end ( ) const
inline

Definition at line 112 of file qassociativeiterable.h.

◆ find()

QAssociativeIterable::const_iterator QAssociativeIterable::find ( const QVariant & key) const

Retrieves a const_iterator pointing to the element at the given key, or the end of the container if that key does not exist.

If the key isn't convertible to the expected type, the end of the container is returned.

Definition at line 157 of file qassociativeiterable.cpp.

References constEnd(), QIterable< QMetaAssociation >::constIterable(), QMetaAssociation::createConstIteratorAtKey(), QMetaAssociation::keyMetaType(), and QIterable< QMetaAssociation >::metaContainer().

+ Here is the call graph for this function:

◆ insertKey()

void QAssociativeIterable::insertKey ( const QVariant & key)

Inserts a new entry with the given key, or resets the mapped value of any existing entry with the given key to the default constructed mapped value.

The key is coerced to the expected type: If it isn't convertible, a default value is inserted.

Definition at line 202 of file qassociativeiterable.cpp.

References QMetaAssociation::insertKey(), QMetaAssociation::keyMetaType(), QIterable< QMetaAssociation >::metaContainer(), and QIterable< QMetaAssociation >::mutableIterable().

+ Here is the call graph for this function:

◆ mutableBegin()

iterator QAssociativeIterable::mutableBegin ( )
inline

Definition at line 117 of file qassociativeiterable.h.

References QIterable< Container >::mutableBegin().

+ Here is the call graph for this function:

◆ mutableEnd()

iterator QAssociativeIterable::mutableEnd ( )
inline

Definition at line 118 of file qassociativeiterable.h.

References QIterable< Container >::mutableEnd().

Referenced by mutableFind().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutableFind()

QAssociativeIterable::iterator QAssociativeIterable::mutableFind ( const QVariant & key)

Retrieves an iterator pointing to the element at the given key, or the end of the container if that key does not exist.

If the key isn't convertible to the expected type, the end of the container is returned.

Definition at line 173 of file qassociativeiterable.cpp.

References QMetaAssociation::createIteratorAtKey(), QMetaAssociation::keyMetaType(), QIterable< QMetaAssociation >::metaContainer(), mutableEnd(), and QIterable< QMetaAssociation >::mutableIterable().

+ Here is the call graph for this function:

◆ operator=()

QAssociativeIterable & QAssociativeIterable::operator= ( QIterable< QMetaAssociation > && other)
inline

Definition at line 105 of file qassociativeiterable.h.

References other().

+ Here is the call graph for this function:

◆ removeKey()

void QAssociativeIterable::removeKey ( const QVariant & key)

Removes the entry with the given key from the container.

The key is coerced to the expected type: If it isn't convertible, the default value is removed.

Definition at line 214 of file qassociativeiterable.cpp.

References QMetaAssociation::keyMetaType(), QIterable< QMetaAssociation >::metaContainer(), QIterable< QMetaAssociation >::mutableIterable(), and QMetaAssociation::removeKey().

+ Here is the call graph for this function:

◆ setValue()

void QAssociativeIterable::setValue ( const QVariant & key,
const QVariant & mapped )

Sets the mapped value associated with key to mapped, if possible.

Inserts a new entry if none exists yet, for the given key. If the key is not convertible to the key type, the value for the default-constructed key type is overwritten.

Definition at line 253 of file qassociativeiterable.cpp.

References QMetaAssociation::keyMetaType(), QMetaAssociation::mappedMetaType(), QIterable< QMetaAssociation >::metaContainer(), QIterable< QMetaAssociation >::mutableIterable(), and QMetaAssociation::setMappedAtKey().

+ Here is the call graph for this function:

◆ value()

QVariant QAssociativeIterable::value ( const QVariant & key) const

Retrieves the mapped value at the given key, or a default-constructed QVariant of the mapped type, if the key does not exist.

If the key is not convertible to the key type, the mapped value associated with the default-constructed key is returned.

Definition at line 228 of file qassociativeiterable.cpp.

References QtPrivate::QVariantTypeCoercer::coerce(), QIterable< QMetaAssociation >::constIterable(), QMetaAssociation::keyMetaType(), QMetaAssociation::mappedAtKey(), QMetaAssociation::mappedMetaType(), and QIterable< QMetaAssociation >::metaContainer().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: