aboutsummaryrefslogtreecommitdiff
path: root/src/core/kconfigdata.cpp
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2021-02-23 13:08:15 +0200
committerAhmad Samir <a.samirh78@gmail.com>2021-02-24 05:38:32 +0000
commitcae1e9b6d2ec957f8bc4643b898308a404d00a5f (patch)
tree1524789c5d560ff21af3fd54e4bec2007571965c /src/core/kconfigdata.cpp
parent48c132be8aa983165126b0641a083848dd5c6620 (diff)
downloadkconfig-cae1e9b6d2ec957f8bc4643b898308a404d00a5f.tar.gz
kconfig-cae1e9b6d2ec957f8bc4643b898308a404d00a5f.tar.bz2
Add KEntryMap::constFindEntry() method
- This has the same logic as QMap::constFind(); less detaching and now we can use auto keyword when creating iterators and always get a const_iterator even when calling constFindEntry() on a non-const map. - Use QCOMPARE() where appropriate in the unit tests.
Diffstat (limited to 'src/core/kconfigdata.cpp')
-rw-r--r--src/core/kconfigdata.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/core/kconfigdata.cpp b/src/core/kconfigdata.cpp
index accf869b..5a785c45 100644
--- a/src/core/kconfigdata.cpp
+++ b/src/core/kconfigdata.cpp
@@ -48,7 +48,7 @@ QMap<KEntryKey, KEntry>::Iterator KEntryMap::findEntry(const QByteArray &group,
return find(theKey);
}
-QMap<KEntryKey, KEntry>::ConstIterator KEntryMap::findEntry(const QByteArray &group, const QByteArray &key, KEntryMap::SearchFlags flags) const
+QMap<KEntryKey, KEntry>::ConstIterator KEntryMap::constFindEntry(const QByteArray &group, const QByteArray &key, SearchFlags flags) const
{
KEntryKey theKey(group, key, false, bool(flags & SearchDefaults));
@@ -56,14 +56,15 @@ QMap<KEntryKey, KEntry>::ConstIterator KEntryMap::findEntry(const QByteArray &gr
if (flags & SearchLocalized) {
theKey.bLocal = true;
- ConstIterator it = find(theKey);
- if (it != constEnd()) {
+ auto it = constFind(theKey);
+ if (it != cend()) {
return it;
}
theKey.bLocal = false;
}
- return find(theKey);
+
+ return constFind(theKey);
}
bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const QByteArray &value, KEntryMap::EntryOptions options)
@@ -105,7 +106,7 @@ bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const Q
} else {
// make sure the group marker is in the map
KEntryMap const *that = this;
- ConstIterator cit = that->findEntry(group);
+ auto cit = that->constFindEntry(group);
if (cit == constEnd()) {
insert(KEntryKey(group), KEntry());
} else if (cit->bImmutable) {
@@ -212,7 +213,7 @@ bool KEntryMap::setEntry(const QByteArray &group, const QByteArray &key, const Q
QString KEntryMap::getEntry(const QByteArray &group, const QByteArray &key, const QString &defaultValue, KEntryMap::SearchFlags flags, bool *expand) const
{
- const ConstIterator it = findEntry(group, key, flags);
+ const auto it = constFindEntry(group, key, flags);
QString theValue = defaultValue;
if (it != constEnd() && !it->bDeleted) {
@@ -230,7 +231,7 @@ QString KEntryMap::getEntry(const QByteArray &group, const QByteArray &key, cons
bool KEntryMap::hasEntry(const QByteArray &group, const QByteArray &key, KEntryMap::SearchFlags flags) const
{
- const ConstIterator it = findEntry(group, key, flags);
+ const auto it = constFindEntry(group, key, flags);
if (it == constEnd()) {
return false;
}