From 487bfed67256b7c4b8862716965905439c745216 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 24 Jun 2020 14:51:26 +0400 Subject: [PATCH] Use QMultiMap instead of QMap --- components/config/gamesettings.cpp | 11 ++++------- components/config/gamesettings.hpp | 14 ++++++++------ components/config/launchersettings.cpp | 6 +++--- components/config/launchersettings.hpp | 2 +- components/config/settingsbase.hpp | 7 ++++--- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/components/config/gamesettings.cpp b/components/config/gamesettings.cpp index fc1d813685..b771b7fc8e 100644 --- a/components/config/gamesettings.cpp +++ b/components/config/gamesettings.cpp @@ -2,11 +2,8 @@ #include "launchersettings.hpp" #include -#include #include -#include #include -#include #include @@ -105,9 +102,9 @@ bool Config::GameSettings::readUserFile(QTextStream &stream) return readFile(stream, mUserSettings); } -bool Config::GameSettings::readFile(QTextStream &stream, QMap &settings) +bool Config::GameSettings::readFile(QTextStream &stream, QMultiMap &settings) { - QMap cache; + QMultiMap cache; QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$"); while (!stream.atEnd()) { @@ -151,7 +148,7 @@ bool Config::GameSettings::readFile(QTextStream &stream, QMap values.append(settings.values(key)); if (!values.contains(value)) { - cache.insertMulti(key, value); + cache.insert(key, value); } } } @@ -368,7 +365,7 @@ bool Config::GameSettings::writeFileWithComments(QFile &file) *iter = QString(); // assume no match QString key = settingRegex.cap(1); QString keyVal = settingRegex.cap(1)+"="+settingRegex.cap(2); - QMap::const_iterator i = mUserSettings.find(key); + QMultiMap::const_iterator i = mUserSettings.find(key); while (i != mUserSettings.end() && i.key() == key) { QString settingLine = i.key() + "=" + i.value(); diff --git a/components/config/gamesettings.hpp b/components/config/gamesettings.hpp index eeac893c23..a6876b83d4 100644 --- a/components/config/gamesettings.hpp +++ b/components/config/gamesettings.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include @@ -31,7 +31,9 @@ namespace Config inline void setValue(const QString &key, const QString &value) { + mSettings.remove(key); mSettings.insert(key, value); + mUserSettings.remove(key); mUserSettings.insert(key, value); } @@ -39,11 +41,11 @@ namespace Config { QStringList values = mSettings.values(key); if (!values.contains(value)) - mSettings.insertMulti(key, value); + mSettings.insert(key, value); values = mUserSettings.values(key); if (!values.contains(value)) - mUserSettings.insertMulti(key, value); + mUserSettings.insert(key, value); } inline void remove(const QString &key) @@ -63,7 +65,7 @@ namespace Config QStringList values(const QString &key, const QStringList &defaultValues = QStringList()) const; bool readFile(QTextStream &stream); - bool readFile(QTextStream &stream, QMap &settings); + bool readFile(QTextStream &stream, QMultiMap &settings); bool readUserFile(QTextStream &stream); bool writeFile(QTextStream &stream); @@ -78,8 +80,8 @@ namespace Config Files::ConfigurationManager &mCfgMgr; void validatePaths(); - QMap mSettings; - QMap mUserSettings; + QMultiMap mSettings; + QMultiMap mUserSettings; QStringList mDataDirs; QString mDataLocal; diff --git a/components/config/launchersettings.cpp b/components/config/launchersettings.cpp index 91bf450f49..ae591ef581 100644 --- a/components/config/launchersettings.cpp +++ b/components/config/launchersettings.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include @@ -22,7 +22,7 @@ Config::LauncherSettings::~LauncherSettings() QStringList Config::LauncherSettings::subKeys(const QString &key) { - QMap settings = SettingsBase::getSettings(); + QMultiMap settings = SettingsBase::getSettings(); QStringList keys = settings.uniqueKeys(); QRegExp keyRe("(.+)/"); @@ -54,7 +54,7 @@ bool Config::LauncherSettings::writeFile(QTextStream &stream) { QString sectionPrefix; QRegExp sectionRe("([^/]+)/(.+)$"); - QMap settings = SettingsBase::getSettings(); + QMultiMap settings = SettingsBase::getSettings(); QMapIterator i(settings); i.toBack(); diff --git a/components/config/launchersettings.hpp b/components/config/launchersettings.hpp index c5eefb22a5..1483052bbc 100644 --- a/components/config/launchersettings.hpp +++ b/components/config/launchersettings.hpp @@ -6,7 +6,7 @@ namespace Config { - class LauncherSettings : public SettingsBase > + class LauncherSettings : public SettingsBase > { public: LauncherSettings(); diff --git a/components/config/settingsbase.hpp b/components/config/settingsbase.hpp index 08cd0bfc6f..1199717167 100644 --- a/components/config/settingsbase.hpp +++ b/components/config/settingsbase.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include namespace Config { @@ -33,7 +33,7 @@ namespace Config { QStringList values = mSettings.values(key); if (!values.contains(value)) - mSettings.insertMulti(key, value); + mSettings.insert(key, value); } inline void setMultiValueEnabled(bool enable) @@ -83,8 +83,9 @@ namespace Config if (!values.contains(value)) { if (mMultiValue) { - cache.insertMulti(key, value); + cache.insert(key, value); } else { + cache.remove(key); cache.insert(key, value); } }