summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-12-22 21:31:02 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-01-21 11:23:43 +0100
commit914c5eb36a2515714b90c375449bee060db5f4f5 (patch)
tree75e573930e59ab4260ff8f14c1509a62e9229982 /src/corelib
parentb9365aed6a6699e4ae1c1638217565a18ebf6de6 (diff)
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')
-rw-r--r--src/corelib/kernel/qvariant.cpp20
-rw-r--r--src/corelib/kernel/qvariant.h8
2 files changed, 13 insertions, 15 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;
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;