diff options
| -rw-r--r-- | autotests/kentrymaptest.cpp | 56 | ||||
| -rw-r--r-- | src/core/kconfig.cpp | 10 | ||||
| -rw-r--r-- | src/core/kconfigdata.cpp | 15 | ||||
| -rw-r--r-- | src/core/kconfigdata.h | 7 | 
4 files changed, 47 insertions, 41 deletions
| diff --git a/autotests/kentrymaptest.cpp b/autotests/kentrymaptest.cpp index d571f761..899fcac1 100644 --- a/autotests/kentrymaptest.cpp +++ b/autotests/kentrymaptest.cpp @@ -54,21 +54,21 @@ void KEntryMapTest::testSimple()      map.setEntry(group1, key2, value2, EntryOptions());      QCOMPARE(map.size(), 3); // the group marker & 2 keys -    QVERIFY(map.findEntry(group1) != map.end()); -    QVERIFY(map.findEntry(group1.toLower()) == map.end()); +    QVERIFY(map.constFindEntry(group1) != map.cend()); +    QCOMPARE(map.constFindEntry(group1.toLower()), map.cend()); -    QVERIFY(map.findEntry(group1, key1) != map.end()); -    QVERIFY(map.findEntry(group1, key1.toLower()) == map.end()); -    QVERIFY(map.findEntry(group1, key2) != map.end()); -    QVERIFY(map.findEntry(group1, key2.toUpper()) == map.end()); +    QVERIFY(map.constFindEntry(group1, key1) != map.cend()); +    QCOMPARE(map.constFindEntry(group1, key1.toLower()), map.cend()); +    QVERIFY(map.constFindEntry(group1, key2) != map.cend()); +    QCOMPARE(map.constFindEntry(group1, key2.toUpper()), map.cend()); -    QByteArray found = map.findEntry(group1, key1)->mValue; -    QVERIFY(found == value1); +    QByteArray found = map.constFindEntry(group1, key1)->mValue; +    QCOMPARE(found, value1);      QVERIFY(found != value2); -    found = map.findEntry(group1, key2)->mValue; +    found = map.constFindEntry(group1, key2)->mValue;      QVERIFY(found != value1); -    QVERIFY(found == value2); +    QCOMPARE(found, value2);  }  void KEntryMapTest::testDirty() @@ -93,16 +93,16 @@ void KEntryMapTest::testDefault()      map.setEntry(group1, key2, value2, EntryOptions());      QCOMPARE(map.size(), 4); // group marker, default1, entry1, entry2 -    const KEntryMap::ConstIterator defaultEntry(map.findEntry(group1, key1, SearchDefaults)); -    const KEntryMap::ConstIterator entry1(map.findEntry(group1, key1)); -    const KEntryMap::ConstIterator entry2(map.findEntry(group1, key2)); +    const auto defaultEntry(map.constFindEntry(group1, key1, SearchDefaults)); +    const auto entry1(map.constFindEntry(group1, key1)); +    const auto entry2(map.constFindEntry(group1, key2));      // default set for entry1      QVERIFY(defaultEntry != map.constEnd());      QCOMPARE(defaultEntry->mValue, entry1->mValue);      // no default set for entry2 -    QVERIFY(map.findEntry(group1, key2, SearchDefaults) == map.end()); +    QCOMPARE(map.constFindEntry(group1, key2, SearchDefaults), map.cend());      // change from default      map.setEntry(group1, key1, value2, EntryOptions()); @@ -131,7 +131,7 @@ void KEntryMapTest::testDelete()      map.setEntry(group1, key2, QByteArray(), EntryDeleted | EntryDirty);      QCOMPARE(map.size(), 5); // entry should still be in map, so it can override merged entries later -    QCOMPARE(map.findEntry(group1, key2)->mValue, QByteArray()); +    QCOMPARE(map.constFindEntry(group1, key2)->mValue, QByteArray());  }  void KEntryMapTest::testGlobal() @@ -139,11 +139,11 @@ void KEntryMapTest::testGlobal()      KEntryMap map;      map.setEntry(group1, key1, value1, EntryGlobal); -    QCOMPARE(map.findEntry(group1, key1)->bGlobal, true); +    QCOMPARE(map.constFindEntry(group1, key1)->bGlobal, true);      // this should create a new key that is not "global"      map.setEntry(group1, key1, value2, EntryOptions()); -    QVERIFY(!map.findEntry(group1, key1)->bGlobal); +    QCOMPARE(map.constFindEntry(group1, key1)->bGlobal, false);  }  void KEntryMapTest::testImmutable() @@ -151,18 +151,18 @@ void KEntryMapTest::testImmutable()      KEntryMap map;      map.setEntry(group1, key1, value1, EntryImmutable); -    QCOMPARE(map.findEntry(group1, key1)->bImmutable, true); // verify the immutable bit was set +    QCOMPARE(map.constFindEntry(group1, key1)->bImmutable, true); // verify the immutable bit was set      map.setEntry(group1, key1, value2, EntryOptions()); -    QCOMPARE(map.findEntry(group1, key1)->mValue, value1); // verify the value didn't change +    QCOMPARE(map.constFindEntry(group1, key1)->mValue, value1); // verify the value didn't change      map.clear();      map.setEntry(group1, QByteArray(), QByteArray(), EntryImmutable); -    QCOMPARE(map.findEntry(group1)->bImmutable, true); // verify the group is immutable +    QCOMPARE(map.constFindEntry(group1)->bImmutable, true); // verify the group is immutable      map.setEntry(group1, key1, value1, EntryOptions()); // should be ignored since the group is immutable -    QVERIFY(map.findEntry(group1, key1) == map.end()); +    QCOMPARE(map.constFindEntry(group1, key1), map.cend());  }  void KEntryMapTest::testLocale() @@ -173,17 +173,17 @@ void KEntryMapTest::testLocale()      KEntryMap map;      map.setEntry(group1, key1, untranslated, EntryDefault); -    QCOMPARE(map.findEntry(group1, key1)->mValue, untranslated); -    QCOMPARE(map.findEntry(group1, key1, SearchLocalized)->mValue, untranslated); // no localized value yet +    QCOMPARE(map.constFindEntry(group1, key1)->mValue, untranslated); +    QCOMPARE(map.constFindEntry(group1, key1, SearchLocalized)->mValue, untranslated); // no localized value yet      map.setEntry(group1, key1, translated, EntryLocalized); -    QCOMPARE(map.findEntry(group1, key1, SearchLocalized)->mValue, translated); // has localized value now -    QVERIFY(map.findEntry(group1, key1, SearchLocalized)->mValue != map.findEntry(group1, key1)->mValue); -    QCOMPARE(map.findEntry(group1, key1, SearchDefaults | SearchLocalized)->mValue, untranslated); // default should still be untranslated +    QCOMPARE(map.constFindEntry(group1, key1, SearchLocalized)->mValue, translated); // has localized value now +    QVERIFY(map.constFindEntry(group1, key1, SearchLocalized)->mValue != map.constFindEntry(group1, key1)->mValue); +    QCOMPARE(map.constFindEntry(group1, key1, SearchDefaults | SearchLocalized)->mValue, untranslated); // default should still be untranslated      map.setEntry(group1, key1, translatedDefault, EntryDefault | EntryLocalized); -    QCOMPARE(map.findEntry(group1, key1, SearchLocalized)->mValue, translatedDefault); +    QCOMPARE(map.constFindEntry(group1, key1, SearchLocalized)->mValue, translatedDefault);      map.setEntry(group1, key1, translated, EntryLocalized); // set the translated entry to a different locale -    QCOMPARE(map.findEntry(group1, key1, SearchLocalized)->mValue, translated); +    QCOMPARE(map.constFindEntry(group1, key1, SearchLocalized)->mValue, translated);  } diff --git a/src/core/kconfig.cpp b/src/core/kconfig.cpp index ab6ac5c5..7f53847f 100644 --- a/src/core/kconfig.cpp +++ b/src/core/kconfig.cpp @@ -332,8 +332,8 @@ QStringList KConfigPrivate::keyListImpl(const QByteArray &theGroup) const  {      QStringList keys; -    const KEntryMapConstIterator theEnd = entryMap.constEnd(); -    KEntryMapConstIterator it = entryMap.findEntry(theGroup); +    const auto theEnd = entryMap.constEnd(); +    auto it = entryMap.constFindEntry(theGroup);      if (it != theEnd) {          ++it; // advance past the special group entry marker @@ -363,8 +363,8 @@ QMap<QString, QString> KConfig::entryMap(const QString &aGroup) const      QMap<QString, QString> theMap;      const QByteArray theGroup(aGroup.isEmpty() ? "<default>" : aGroup.toUtf8()); -    const KEntryMapConstIterator theEnd = d->entryMap.constEnd(); -    KEntryMapConstIterator it = d->entryMap.findEntry(theGroup, {}, {}); +    const auto theEnd = d->entryMap.constEnd(); +    auto it = d->entryMap.constFindEntry(theGroup, {}, {});      if (it != theEnd) {          ++it; // advance past the special group entry marker @@ -981,7 +981,7 @@ QByteArray KConfigPrivate::lookupData(const QByteArray &group, const char *key,      if (bReadDefaults) {          flags |= KEntryMap::SearchDefaults;      } -    const KEntryMapConstIterator it = entryMap.findEntry(group, key, flags); +    const auto it = entryMap.constFindEntry(group, key, flags);      if (it == entryMap.constEnd()) {          return QByteArray();      } 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;      } diff --git a/src/core/kconfigdata.h b/src/core/kconfigdata.h index afa18877..dd396fc8 100644 --- a/src/core/kconfigdata.h +++ b/src/core/kconfigdata.h @@ -192,7 +192,12 @@ public:      Iterator findEntry(const QByteArray &group, const QByteArray &key = QByteArray(), SearchFlags flags = SearchFlags()); -    ConstIterator findEntry(const QByteArray &group, const QByteArray &key = QByteArray(), SearchFlags flags = SearchFlags()) const; +    ConstIterator findEntry(const QByteArray &group, const QByteArray &key = QByteArray(), SearchFlags flags = SearchFlags()) const +    { +        return constFindEntry(group, key, flags); +    } + +    ConstIterator constFindEntry(const QByteArray &group, const QByteArray &key = QByteArray(), SearchFlags flags = SearchFlags()) const;      /**       * Returns true if the entry gets dirtied or false in other case | 
