summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qvariant.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-09-10 18:25:02 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-09-19 11:14:30 +0200
commit5c808073af5b8f1290602fcccf60666c9a3682f8 (patch)
tree97545220e79498a2dc2bb95f41da14ecce75cbd0 /src/corelib/kernel/qvariant.cpp
parentb30801f64db5211bfb4392f13a6ff06d30288cb5 (diff)
Extend QSequentialIterable and add QAssociativeIterable
And add mutable iterators. This requires some refactoring of the existing iterators. Task-number: QTBUG-81716 Change-Id: I61b3a3e8c0df5fd449679257a29d9f0c3d19c4f0 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/kernel/qvariant.cpp')
-rw-r--r--src/corelib/kernel/qvariant.cpp355
1 files changed, 13 insertions, 342 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index d0a548bc74..603c49ebfe 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -2617,348 +2617,6 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p)
*/
/*!
- \class QAssociativeIterable
- \since 5.2
- \inmodule QtCore
- \brief The QAssociativeIterable class is an iterable interface for an associative container in a QVariant.
-
- 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.
-
- \snippet code/src_corelib_kernel_qvariant.cpp 10
-
- The container itself is not copied before iterating over it.
-
- \sa QVariant
-*/
-
-/*!
- \internal
-*/
-QAssociativeIterable::QAssociativeIterable(const QtMetaTypePrivate::QAssociativeIterableImpl &impl)
- : m_impl(impl)
-{
-}
-
-QAssociativeIterable::const_iterator::const_iterator(const QAssociativeIterable &iter, QAtomicInt *ref_)
- : m_impl(iter.m_impl), ref(ref_)
-{
- ref->ref();
-}
-
-QAssociativeIterable::const_iterator::const_iterator(const QtMetaTypePrivate::QAssociativeIterableImpl &impl, QAtomicInt *ref_)
- : m_impl(impl), ref(ref_)
-{
- ref->ref();
-}
-
-void QAssociativeIterable::const_iterator::begin()
-{
- m_impl.begin();
-}
-
-void QAssociativeIterable::const_iterator::end()
-{
- m_impl.end();
-}
-
-void QAssociativeIterable::const_iterator::find(const QVariant &key)
-{
- Q_ASSERT(key.metaType() == m_impl._metaType_key);
- m_impl.find(key.constData());
-}
-
-/*!
- Returns a QAssociativeIterable::const_iterator for the beginning of the container. This
- can be used in stl-style iteration.
-
- \sa end()
-*/
-QAssociativeIterable::const_iterator QAssociativeIterable::begin() const
-{
- const_iterator it(*this, new QAtomicInt(0));
- it.begin();
- return it;
-}
-
-/*!
- Returns a QAssociativeIterable::const_iterator for the end of the container. This
- can be used in stl-style iteration.
-
- \sa begin()
-*/
-QAssociativeIterable::const_iterator QAssociativeIterable::end() const
-{
- const_iterator it(*this, new QAtomicInt(0));
- it.end();
- return it;
-}
-
-/*!
- \since 5.5
-
- Returns a QAssociativeIterable::const_iterator for the given key \a key
- in the container, if the types are convertible.
-
- If the key is not found, returns end().
-
- This can be used in stl-style iteration.
-
- \sa begin(), end(), value()
-*/
-QAssociativeIterable::const_iterator QAssociativeIterable::find(const QVariant &key) const
-{
- const_iterator it(*this, new QAtomicInt(0));
- QVariant key_ = key;
- if (key_.canConvert(m_impl._metaType_key) && key_.convert(m_impl._metaType_key))
- it.find(key_);
- else
- it.end();
- return it;
-}
-
-/*!
- Returns the value for the given \a key in the container, if the types are convertible.
-
- \sa find()
-*/
-QVariant QAssociativeIterable::value(const QVariant &key) const
-{
- const const_iterator it = find(key);
- if (it == end())
- return QVariant();
- return *it;
-}
-
-/*!
- Returns the number of elements in the container.
-*/
-int QAssociativeIterable::size() const
-{
- return m_impl.size();
-}
-
-/*!
- \class QAssociativeIterable::const_iterator
- \since 5.2
- \inmodule QtCore
- \brief The QAssociativeIterable::const_iterator allows iteration over a container in a QVariant.
-
- A QAssociativeIterable::const_iterator can only be created by a QAssociativeIterable instance,
- and can be used in a way similar to other stl-style iterators.
-
- \snippet code/src_corelib_kernel_qvariant.cpp 10
-
- \sa QAssociativeIterable
-*/
-
-
-/*!
- Destroys the QAssociativeIterable::const_iterator.
-*/
-QAssociativeIterable::const_iterator::~const_iterator()
-{
- if (!ref->deref()) {
- m_impl.destroyIter();
- delete ref;
- }
-}
-
-/*!
- Creates a copy of \a other.
-*/
-QAssociativeIterable::const_iterator::const_iterator(const const_iterator &other)
- : m_impl(other.m_impl), ref(other.ref)
-{
- ref->ref();
-}
-
-/*!
- Assigns \a other to this.
-*/
-QAssociativeIterable::const_iterator&
-QAssociativeIterable::const_iterator::operator=(const const_iterator &other)
-{
- other.ref->ref();
- if (!ref->deref()) {
- m_impl.destroyIter();
- delete ref;
- }
- m_impl = other.m_impl;
- ref = other.ref;
- return *this;
-}
-
-/*!
- Returns the current value, converted to a QVariant.
-*/
-const QVariant QAssociativeIterable::const_iterator::operator*() const
-{
- QVariant v(m_impl._metaType_value);
- void *dataPtr;
- if (m_impl._metaType_value == QMetaType::fromType<QVariant>())
- dataPtr = &v;
- else
- dataPtr = v.data();
- m_impl.getCurrentValue(dataPtr);
- return v;
-}
-
-/*!
- Returns the current key, converted to a QVariant.
-*/
-const QVariant QAssociativeIterable::const_iterator::key() const
-{
- QVariant v(m_impl._metaType_key);
- void *dataPtr;
- if (m_impl._metaType_key == QMetaType::fromType<QVariant>())
- dataPtr = &v;
- else
- dataPtr = v.data();
- m_impl.getCurrentKey(dataPtr);
- return v;
-}
-
-/*!
- Returns the current value, converted to a QVariant.
-*/
-const QVariant QAssociativeIterable::const_iterator::value() const
-{
- return operator*();
-}
-
-/*!
- Returns \c true if \a other points to the same item as this
- iterator; otherwise returns \c false.
-
- \sa operator!=()
-*/
-bool QAssociativeIterable::const_iterator::operator==(const const_iterator &other) const
-{
- return m_impl.equal(other.m_impl);
-}
-
-/*!
- Returns \c true if \a other points to a different item than this
- iterator; otherwise returns \c false.
-
- \sa operator==()
-*/
-bool QAssociativeIterable::const_iterator::operator!=(const const_iterator &other) const
-{
- return !m_impl.equal(other.m_impl);
-}
-
-/*!
- The prefix ++ operator (\c{++it}) advances the iterator to the
- next item in the container and returns an iterator to the new current
- item.
-
- Calling this function on QAssociativeIterable::end() leads to undefined results.
-
- \sa operator--()
-*/
-QAssociativeIterable::const_iterator &QAssociativeIterable::const_iterator::operator++()
-{
- m_impl.advance(1);
- return *this;
-}
-
-/*!
- \overload
-
- The postfix ++ operator (\c{it++}) advances the iterator to the
- next item in the container and returns an iterator to the previously
- current item.
-*/
-QAssociativeIterable::const_iterator QAssociativeIterable::const_iterator::operator++(int)
-{
- QtMetaTypePrivate::QAssociativeIterableImpl impl;
- impl.copy(m_impl);
- m_impl.advance(1);
- return const_iterator(impl, new QAtomicInt(0));
-}
-
-/*!
- The prefix -- operator (\c{--it}) makes the preceding item
- current and returns an iterator to the new current item.
-
- Calling this function on QAssociativeIterable::begin() leads to undefined results.
-
- \sa operator++()
-*/
-QAssociativeIterable::const_iterator &QAssociativeIterable::const_iterator::operator--()
-{
- m_impl.advance(-1);
- return *this;
-}
-
-/*!
- \overload
-
- The postfix -- operator (\c{it--}) makes the preceding item
- current and returns an iterator to the previously current item.
-*/
-QAssociativeIterable::const_iterator QAssociativeIterable::const_iterator::operator--(int)
-{
- QtMetaTypePrivate::QAssociativeIterableImpl impl;
- impl.copy(m_impl);
- m_impl.advance(-1);
- return const_iterator(impl, new QAtomicInt(0));
-}
-
-/*!
- Advances the iterator by \a j items.
-
- \sa operator-=(), operator+()
-*/
-QAssociativeIterable::const_iterator &QAssociativeIterable::const_iterator::operator+=(int j)
-{
- m_impl.advance(j);
- return *this;
-}
-
-/*!
- Makes the iterator go back by \a j items.
-
- \sa operator+=(), operator-()
-*/
-QAssociativeIterable::const_iterator &QAssociativeIterable::const_iterator::operator-=(int j)
-{
- m_impl.advance(-j);
- return *this;
-}
-
-/*!
- Returns an iterator to the item at \a j positions forward from
- this iterator.
-
- \sa operator-(), operator+=()
-*/
-QAssociativeIterable::const_iterator QAssociativeIterable::const_iterator::operator+(int j) const
-{
- QtMetaTypePrivate::QAssociativeIterableImpl impl;
- impl.copy(m_impl);
- impl.advance(j);
- return const_iterator(impl, new QAtomicInt(0));
-}
-
-/*!
- Returns an iterator to the item at \a j positions backward from
- this iterator.
-
- \sa operator+(), operator-=()
-*/
-QAssociativeIterable::const_iterator QAssociativeIterable::const_iterator::operator-(int j) const
-{
- QtMetaTypePrivate::QAssociativeIterableImpl impl;
- impl.copy(m_impl);
- impl.advance(-j);
- return const_iterator(impl, new QAtomicInt(0));
-}
-
-/*!
\class QVariantRef
\since 6.0
\inmodule QtCore
@@ -2979,6 +2637,13 @@ QAssociativeIterable::const_iterator QAssociativeIterable::const_iterator::opera
*/
/*!
+ \fn QVariantRef &QVariantRef::operator=(const QVariant &value)
+
+ Assigns a new \a value to the value pointed to by the pointer this
+ QVariantRef refers to.
+ */
+
+/*!
\fn QVariantRef &QVariantRef::operator=(const QVariantRef &value)
Assigns a new \a value to the value pointed to by the pointer this
@@ -2993,6 +2658,12 @@ QAssociativeIterable::const_iterator QAssociativeIterable::const_iterator::opera
*/
/*!
+ \fn QVariantRef::operator QVariant() const
+
+ Resolves the QVariantRef to an actual QVariant.
+*/
+
+/*!
\fn void swap(QVariantRef a, QVariantRef b)
Swaps the values pointed to by the pointers the QVariantRefs