diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-12-22 21:31:02 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-01-21 11:23:43 +0100 |
commit | 914c5eb36a2515714b90c375449bee060db5f4f5 (patch) | |
tree | 75e573930e59ab4260ff8f14c1509a62e9229982 /src/corelib/kernel/qvariant.cpp | |
parent | b9365aed6a6699e4ae1c1638217565a18ebf6de6 (diff) | |
download | qtbase-914c5eb36a2515714b90c375449bee060db5f4f5.tar.gz |
QAssociativeIterable: add find()
This is like value(), but returns an iterator instead of the value().
[ChangeLog][QtCore][QAssociativeIterable] Added find().
Change-Id: I029fc8f91cef78f718d419587a2a50ffd2bf7632
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
Diffstat (limited to 'src/corelib/kernel/qvariant.cpp')
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index f7b8fe5ca5..df1b4ed872 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -4001,11 +4001,11 @@ void QAssociativeIterable::const_iterator::end() m_impl.end(); } -void find(QAssociativeIterable::const_iterator &it, const QVariant &key) +void QAssociativeIterable::const_iterator::find(const QVariant &key) { - Q_ASSERT(key.userType() == it.m_impl._metaType_id_key); + Q_ASSERT(key.userType() == m_impl._metaType_id_key); const QtMetaTypePrivate::VariantData dkey(key.userType(), key.constData(), 0 /*key.flags()*/); - it.m_impl.find(dkey); + m_impl.find(dkey); } /*! @@ -4035,7 +4035,7 @@ QAssociativeIterable::const_iterator QAssociativeIterable::end() const } /*! - \internal + \since 5.5 Returns a QAssociativeIterable::const_iterator for the given key \a key in the container, if the types are convertible. @@ -4046,12 +4046,12 @@ QAssociativeIterable::const_iterator QAssociativeIterable::end() const \sa begin(), end(), value() */ -QAssociativeIterable::const_iterator find(const QAssociativeIterable &iterable, const QVariant &key) +QAssociativeIterable::const_iterator QAssociativeIterable::find(const QVariant &key) const { - QAssociativeIterable::const_iterator it(iterable, new QAtomicInt(0)); + const_iterator it(*this, new QAtomicInt(0)); QVariant key_ = key; - if (key_.canConvert(iterable.m_impl._metaType_id_key) && key_.convert(iterable.m_impl._metaType_id_key)) - find(it, key_); + if (key_.canConvert(m_impl._metaType_id_key) && key_.convert(m_impl._metaType_id_key)) + it.find(key_); else it.end(); return it; @@ -4059,10 +4059,12 @@ QAssociativeIterable::const_iterator find(const QAssociativeIterable &iterable, /*! 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(*this, key); + const const_iterator it = find(key); if (it == end()) return QVariant(); return *it; |