Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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.

mapping.insert(7, "Seven");
mapping.insert(11, "Eleven");
mapping.insert(42, "Forty-two");
if (variant.canConvert<QVariantHash>()) {
// 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 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

using QAssociativeIterable::BidirectionalIterator = QTaggedIterator<iterator, std::bidirectional_iterator_tag>

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

using QAssociativeIterable::ForwardIterator = QTaggedIterator<iterator, std::forward_iterator_tag>

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

using QAssociativeIterable::RandomAccessIterator = QTaggedIterator<iterator, std::random_access_iterator_tag>

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.

◆ constEnd()

const_iterator QAssociativeIterable::constEnd ( ) const
inline

Definition at line 115 of file qassociativeiterable.h.

◆ 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.

◆ 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.

◆ 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.

◆ mutableBegin()

iterator QAssociativeIterable::mutableBegin ( )
inline

Definition at line 117 of file qassociativeiterable.h.

◆ mutableEnd()

iterator QAssociativeIterable::mutableEnd ( )
inline

Definition at line 118 of file qassociativeiterable.h.

◆ 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.

◆ operator=()

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

Definition at line 105 of file qassociativeiterable.h.

◆ 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.

◆ 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.

◆ 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.


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