From 914c5eb36a2515714b90c375449bee060db5f4f5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 22 Dec 2014 21:31:02 +0100 Subject: QAssociativeIterable: add find() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) Reviewed-by: Jędrzej Nowacki --- src/corelib/kernel/qvariant.cpp | 20 +++++++++++--------- src/corelib/kernel/qvariant.h | 8 ++------ 2 files changed, 13 insertions(+), 15 deletions(-) (limited to 'src/corelib/kernel') 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; diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 3701144438..c9513a837b 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -631,9 +631,7 @@ public: void begin(); void end(); - // ### Qt 5.5: make find() (1st one) a member function - friend void find(const_iterator &it, const QVariant &key); - friend const_iterator find(const QAssociativeIterable &iterable, const QVariant &key); + void find(const QVariant &key); public: ~const_iterator(); const_iterator(const const_iterator &other); @@ -663,9 +661,7 @@ public: const_iterator begin() const; const_iterator end() const; -private: // ### Qt 5.5: make it a public find() member function: - friend const_iterator find(const QAssociativeIterable &iterable, const QVariant &key); -public: + const_iterator find(const QVariant &key) const; QVariant value(const QVariant &key) const; -- cgit v1.2.3