Utils: Use a proper class as Key

The Key encapsulates now a QByteArray.

Plan is to use QByteArray::fromRawData on literals, but that's not
active yet due to an unclear ASAN report, see the gerrit discussion.

For now we also paddle back when interfacing QSettings, instead of mimicing
writing a QVariantMap (and fail in some corners), always convert
the Store. This is meant to go away in the future when code paths
are better controled.

Change-Id: Id1206a434d511f8003903d5322c7c9bd5f5fb859
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2023-09-05 15:25:26 +02:00
parent d3b9b9b2d1
commit d6fe357d81
34 changed files with 255 additions and 159 deletions

View File

@@ -2996,7 +2996,7 @@ SettingsGroupNester::SettingsGroupNester(const QStringList &groups)
{ {
QTC_ASSERT(theSettings, return); QTC_ASSERT(theSettings, return);
for (const QString &group : groups) for (const QString &group : groups)
theSettings->beginGroup(group); theSettings->beginGroup(keyFromString(group));
} }
SettingsGroupNester::~SettingsGroupNester() SettingsGroupNester::~SettingsGroupNester()

View File

@@ -106,20 +106,20 @@ const QString keyAttribute("key");
struct ParseValueStackEntry struct ParseValueStackEntry
{ {
explicit ParseValueStackEntry(QVariant::Type t = QVariant::Invalid, const Key &k = {}) : type(t), key(k) {} explicit ParseValueStackEntry(QVariant::Type t = QVariant::Invalid, const QString &k = {}) : type(t), key(k) {}
explicit ParseValueStackEntry(const QVariant &aSimpleValue, const Key &k); explicit ParseValueStackEntry(const QVariant &aSimpleValue, const QString &k);
QVariant value() const; QVariant value() const;
void addChild(const Key &key, const QVariant &v); void addChild(const QString &key, const QVariant &v);
QVariant::Type type; QVariant::Type type;
Key key; QString key;
QVariant simpleValue; QVariant simpleValue;
QVariantList listValue; QVariantList listValue;
Store mapValue; QVariantMap mapValue;
}; };
ParseValueStackEntry::ParseValueStackEntry(const QVariant &aSimpleValue, const Key &k) ParseValueStackEntry::ParseValueStackEntry(const QVariant &aSimpleValue, const QString &k)
: type(aSimpleValue.type()), key(k), simpleValue(aSimpleValue) : type(aSimpleValue.type()), key(k), simpleValue(aSimpleValue)
{ {
QTC_ASSERT(simpleValue.isValid(), return); QTC_ASSERT(simpleValue.isValid(), return);
@@ -131,7 +131,7 @@ QVariant ParseValueStackEntry::value() const
case QVariant::Invalid: case QVariant::Invalid:
return QVariant(); return QVariant();
case QVariant::Map: case QVariant::Map:
return variantFromStore(mapValue); return QVariant(mapValue);
case QVariant::List: case QVariant::List:
return QVariant(listValue); return QVariant(listValue);
default: default:
@@ -140,7 +140,7 @@ QVariant ParseValueStackEntry::value() const
return simpleValue; return simpleValue;
} }
void ParseValueStackEntry::addChild(const Key &key, const QVariant &v) void ParseValueStackEntry::addChild(const QString &key, const QVariant &v)
{ {
switch (type) { switch (type) {
case QVariant::Map: case QVariant::Map:
@@ -159,7 +159,7 @@ void ParseValueStackEntry::addChild(const Key &key, const QVariant &v)
class ParseContext class ParseContext
{ {
public: public:
Store parse(const FilePath &file); QVariantMap parse(const FilePath &file);
private: private:
QVariant readSimpleValue(QXmlStreamReader &r, const QXmlStreamAttributes &attributes) const; QVariant readSimpleValue(QXmlStreamReader &r, const QXmlStreamAttributes &attributes) const;
@@ -170,11 +170,11 @@ private:
static QString formatWarning(const QXmlStreamReader &r, const QString &message); static QString formatWarning(const QXmlStreamReader &r, const QString &message);
QStack<ParseValueStackEntry> m_valueStack; QStack<ParseValueStackEntry> m_valueStack;
Store m_result; QVariantMap m_result;
Key m_currentVariableName; QString m_currentVariableName;
}; };
Store ParseContext::parse(const FilePath &file) QVariantMap ParseContext::parse(const FilePath &file)
{ {
QXmlStreamReader r(file.fileContents().value_or(QByteArray())); QXmlStreamReader r(file.fileContents().value_or(QByteArray()));
@@ -194,7 +194,7 @@ Store ParseContext::parse(const FilePath &file)
case QXmlStreamReader::Invalid: case QXmlStreamReader::Invalid:
qWarning("Error reading %s:%d: %s", qPrintable(file.fileName()), qWarning("Error reading %s:%d: %s", qPrintable(file.fileName()),
int(r.lineNumber()), qPrintable(r.errorString())); int(r.lineNumber()), qPrintable(r.errorString()));
return Store(); return {};
default: default:
break; break;
} // switch token } // switch token
@@ -206,13 +206,13 @@ bool ParseContext::handleStartElement(QXmlStreamReader &r)
{ {
const QStringView name = r.name(); const QStringView name = r.name();
if (name == variableElement) { if (name == variableElement) {
m_currentVariableName = keyFromString(r.readElementText()); m_currentVariableName = r.readElementText();
return false; return false;
} }
if (name == valueElement) { if (name == valueElement) {
const QXmlStreamAttributes attributes = r.attributes(); const QXmlStreamAttributes attributes = r.attributes();
const Key key = attributes.hasAttribute(keyAttribute) ? const QString key = attributes.hasAttribute(keyAttribute) ?
keyFromString(attributes.value(keyAttribute).toString()) : Key(); attributes.value(keyAttribute).toString() : QString();
// This reads away the end element, so, handle end element right here. // This reads away the end element, so, handle end element right here.
const QVariant v = readSimpleValue(r, attributes); const QVariant v = readSimpleValue(r, attributes);
if (!v.isValid()) { if (!v.isValid()) {
@@ -224,15 +224,15 @@ bool ParseContext::handleStartElement(QXmlStreamReader &r)
} }
if (name == valueListElement) { if (name == valueListElement) {
const QXmlStreamAttributes attributes = r.attributes(); const QXmlStreamAttributes attributes = r.attributes();
const Key key = attributes.hasAttribute(keyAttribute) ? const QString key = attributes.hasAttribute(keyAttribute) ?
keyFromString(attributes.value(keyAttribute).toString()) : Key(); attributes.value(keyAttribute).toString() : QString();
m_valueStack.push_back(ParseValueStackEntry(QVariant::List, key)); m_valueStack.push_back(ParseValueStackEntry(QVariant::List, key));
return false; return false;
} }
if (name == valueMapElement) { if (name == valueMapElement) {
const QXmlStreamAttributes attributes = r.attributes(); const QXmlStreamAttributes attributes = r.attributes();
const Key key = attributes.hasAttribute(keyAttribute) ? const QString key = attributes.hasAttribute(keyAttribute) ?
keyFromString(attributes.value(keyAttribute).toString()) : Key(); attributes.value(keyAttribute).toString() : QString();
m_valueStack.push_back(ParseValueStackEntry(QVariant::Map, key)); m_valueStack.push_back(ParseValueStackEntry(QVariant::Map, key));
return false; return false;
} }
@@ -293,14 +293,14 @@ PersistentSettingsReader::PersistentSettingsReader() = default;
QVariant PersistentSettingsReader::restoreValue(const Key &variable, const QVariant &defaultValue) const QVariant PersistentSettingsReader::restoreValue(const Key &variable, const QVariant &defaultValue) const
{ {
if (m_valueMap.contains(variable)) if (m_valueMap.contains(stringFromKey(variable)))
return m_valueMap.value(variable); return m_valueMap.value(stringFromKey(variable));
return defaultValue; return defaultValue;
} }
Store PersistentSettingsReader::restoreValues() const Store PersistentSettingsReader::restoreValues() const
{ {
return m_valueMap; return storeFromMap(m_valueMap);
} }
bool PersistentSettingsReader::load(const FilePath &fileName) bool PersistentSettingsReader::load(const FilePath &fileName)
@@ -331,12 +331,12 @@ FilePath PersistentSettingsReader::filePath()
*/ */
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
static QString xmlAttrFromKey(const Key &key) { return stringFromKey(key); } static QString xmlAttrFromKey(const QString &key) { return key; }
#else #else
static Key xmlAttrFromKey(const Key &key) { return key; } static QString xmlAttrFromKey(const QString &key) { return key; }
#endif #endif
static void writeVariantValue(QXmlStreamWriter &w, const QVariant &variant, const Key &key = {}) static void writeVariantValue(QXmlStreamWriter &w, const QVariant &variant, const QString &key = {})
{ {
static const int storeId = qMetaTypeId<Store>(); static const int storeId = qMetaTypeId<Store>();
@@ -355,9 +355,9 @@ static void writeVariantValue(QXmlStreamWriter &w, const QVariant &variant, cons
w.writeAttribute(typeAttribute, "QVariantMap"); w.writeAttribute(typeAttribute, "QVariantMap");
if (!key.isEmpty()) if (!key.isEmpty())
w.writeAttribute(keyAttribute, xmlAttrFromKey(key)); w.writeAttribute(keyAttribute, xmlAttrFromKey(key));
const Store varMap = storeFromVariant(variant); const QVariantMap varMap = variant.toMap();
const Store::const_iterator cend = varMap.constEnd(); const auto cend = varMap.constEnd();
for (Store::const_iterator i = varMap.constBegin(); i != cend; ++i) for (auto i = varMap.constBegin(); i != cend; ++i)
writeVariantValue(w, i.value(), i.key()); writeVariantValue(w, i.value(), i.key());
w.writeEndElement(); w.writeEndElement();
} else if (variantType == QMetaType::QObjectStar) { } else if (variantType == QMetaType::QObjectStar) {
@@ -427,11 +427,10 @@ bool PersistentSettingsWriter::write(const Store &data, QString *errorString) co
QCoreApplication::applicationVersion(), QCoreApplication::applicationVersion(),
QDateTime::currentDateTime().toString(Qt::ISODate))); QDateTime::currentDateTime().toString(Qt::ISODate)));
w.writeStartElement(qtCreatorElement); w.writeStartElement(qtCreatorElement);
const Store::const_iterator cend = data.constEnd(); const QVariantMap map = mapFromStore(data);
for (Store::const_iterator it = data.constBegin(); it != cend; ++it) { for (auto it = map.constBegin(), cend = map.constEnd(); it != cend; ++it) {
w.writeStartElement(dataElement); w.writeStartElement(dataElement);
// FIXME: stringFromKey() not needed from Qt 6.5 onward. w.writeTextElement(variableElement, it.key());
w.writeTextElement(variableElement, stringFromKey(it.key()));
writeVariantValue(w, it.value()); writeVariantValue(w, it.value());
w.writeEndElement(); w.writeEndElement();
} }

View File

@@ -26,7 +26,7 @@ public:
FilePath filePath(); FilePath filePath();
private: private:
Store m_valueMap; QVariantMap m_valueMap;
FilePath m_filePath; FilePath m_filePath;
}; };

View File

@@ -2,6 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qtcsettings.h" #include "qtcsettings.h"
#include "store.h"
namespace Utils { namespace Utils {
@@ -29,4 +30,14 @@ namespace Utils {
\sa QSettings::setValue() \sa QSettings::setValue()
*/ */
QVariant QtcSettings::value(const Key &key, const QVariant &def) const
{
return QSettings::value(stringFromKey(key), def);
}
void QtcSettings::setValue(const Key &key, const QVariant &value)
{
QSettings::setValue(stringFromKey(key), mapEntryFromStoreEntry(value));
}
} // namespace Utils } // namespace Utils

View File

@@ -5,7 +5,7 @@
#include "utils_global.h" #include "utils_global.h"
#include "store.h" #include "storekey.h"
#include <QSettings> #include <QSettings>
@@ -17,12 +17,10 @@ public:
using QSettings::QSettings; using QSettings::QSettings;
void beginGroup(const Key &prefix) { QSettings::beginGroup(stringFromKey(prefix)); } void beginGroup(const Key &prefix) { QSettings::beginGroup(stringFromKey(prefix)); }
void beginGroup(const QString &prefix) { QSettings::beginGroup(prefix); }
void beginGroup(const char *prefix) { QSettings::beginGroup(stringFromKey(prefix)); }
QVariant value(const Key &key) const { return QSettings::value(stringFromKey(key)); } QVariant value(const Key &key) const { return QSettings::value(stringFromKey(key)); }
QVariant value(const Key &key, const QVariant &def) const { return QSettings::value(stringFromKey(key), def); } QVariant value(const Key &key, const QVariant &def) const;
void setValue(const Key &key, const QVariant &value) { QSettings::setValue(stringFromKey(key), value); } void setValue(const Key &key, const QVariant &value);
void remove(const Key &key) { QSettings::remove(stringFromKey(key)); } void remove(const Key &key) { QSettings::remove(stringFromKey(key)); }
bool contains(const Key &key) const { return QSettings::contains(stringFromKey(key)); } bool contains(const Key &key) const { return QSettings::contains(stringFromKey(key)); }

View File

@@ -42,18 +42,37 @@ Store storeFromVariant(const QVariant &value)
return Store(); return Store();
} }
static QVariantList storeListFromMapList(const QVariantList &mapList);
static QVariantList mapListFromStoreList(const QVariantList &storeList);
QVariant storeEntryFromMapEntry(const QVariant &mapEntry)
{
if (mapEntry.type() == QVariant::Map)
return QVariant::fromValue(storeFromMap(mapEntry.toMap()));
if (mapEntry.type() == QVariant::List)
return QVariant::fromValue(storeListFromMapList(mapEntry.toList()));
return mapEntry;
}
QVariant mapEntryFromStoreEntry(const QVariant &storeEntry)
{
if (storeEntry.metaType() == QMetaType::fromType<Store>())
return QVariant::fromValue(mapFromStore(storeEntry.value<Store>()));
if (storeEntry.type() == QVariant::List)
return QVariant::fromValue(mapListFromStoreList(storeEntry.toList()));
return storeEntry;
}
static QVariantList storeListFromMapList(const QVariantList &mapList) static QVariantList storeListFromMapList(const QVariantList &mapList)
{ {
QVariantList storeList; QVariantList storeList;
for (const auto &mapEntry : mapList) { for (const auto &mapEntry : mapList)
if (mapEntry.type() == QVariant::Map) storeList.append(storeEntryFromMapEntry(mapEntry));
storeList.append(QVariant::fromValue(storeFromMap(mapEntry.toMap())));
else if (mapEntry.type() == QVariant::List)
storeList.append(QVariant::fromValue(storeListFromMapList(mapEntry.toList())));
else
storeList.append(mapEntry);
}
return storeList; return storeList;
} }
@@ -62,14 +81,8 @@ static QVariantList mapListFromStoreList(const QVariantList &storeList)
{ {
QVariantList mapList; QVariantList mapList;
for (const auto &storeEntry : storeList) { for (const QVariant &storeEntry : storeList)
if (storeEntry.metaType() == QMetaType::fromType<Store>()) mapList.append(mapEntryFromStoreEntry(storeEntry));
mapList.append(QVariant::fromValue(mapFromStore(storeEntry.value<Store>())));
else if (storeEntry.type() == QVariant::List)
mapList.append(QVariant::fromValue(mapListFromStoreList(storeEntry.toList())));
else
mapList.append(storeEntry);
}
return mapList; return mapList;
} }
@@ -77,30 +90,20 @@ static QVariantList mapListFromStoreList(const QVariantList &storeList)
Store storeFromMap(const QVariantMap &map) Store storeFromMap(const QVariantMap &map)
{ {
Store store; Store store;
for (auto it = map.begin(); it != map.end(); ++it) {
if (it.value().type() == QVariant::Map) { for (auto it = map.begin(); it != map.end(); ++it)
store.insert(keyFromString(it.key()), QVariant::fromValue(storeFromMap(it->toMap()))); store.insert(keyFromString(it.key()), storeEntryFromMapEntry(it.value()));
} else if (it.value().type() == QVariant::List) {
store.insert(keyFromString(it.key()),
QVariant::fromValue(storeListFromMapList(it->toList())));
} else {
store.insert(keyFromString(it.key()), it.value());
}
}
return store; return store;
} }
QVariantMap mapFromStore(const Store &store) QVariantMap mapFromStore(const Store &store)
{ {
QVariantMap map; QVariantMap map;
for (auto it = store.begin(); it != store.end(); ++it) {
if (it.value().metaType() == QMetaType::fromType<Store>()) for (auto it = store.begin(); it != store.end(); ++it)
map.insert(stringFromKey(it.key()), mapFromStore(it->value<Store>())); map.insert(stringFromKey(it.key()), mapEntryFromStoreEntry(it.value()));
else if (it.value().type() == QVariant::List)
map.insert(stringFromKey(it.key()), mapListFromStoreList(it->toList()));
else
map.insert(stringFromKey(it.key()), it.value());
}
return map; return map;
} }
@@ -110,9 +113,40 @@ bool isStore(const QVariant &value)
return typeId == QMetaType::QVariantMap || typeId == qMetaTypeId<Store>(); return typeId == QMetaType::QVariantMap || typeId == qMetaTypeId<Store>();
} }
Key::Key(const char *key, size_t n)
: data(QByteArray::fromRawData(key, n))
{}
Key::Key(const Key &base, int number)
: data(base.data + QByteArray::number(number))
{}
Key::~Key()
{}
const QByteArrayView Key::view() const
{
return data;
}
const QByteArray &Key::toByteArray() const
{
return data;
}
Key numberedKey(const Key &key, int number) Key numberedKey(const Key &key, int number)
{ {
return key + Key::number(number); return Key(key, number);
}
Key keyFromString(const QString &str)
{
return str.toUtf8();
}
QString stringFromKey(const Key &key)
{
return QString::fromLatin1(key.view());
} }
expected_str<Store> storeFromJson(const QByteArray &json) expected_str<Store> storeFromJson(const QByteArray &json)
@@ -140,7 +174,7 @@ Store storeFromSettings(const Key &groupKey, QtcSettings *s)
s->beginGroup(groupKey); s->beginGroup(groupKey);
const KeyList keys = keysFromStrings(s->allKeys()); const KeyList keys = keysFromStrings(s->allKeys());
for (const Key &key : keys) for (const Key &key : keys)
store.insert(key, s->value(key)); store.insert(key, storeEntryFromMapEntry(s->value(key)));
s->endGroup(); s->endGroup();
return store; return store;
} }
@@ -149,7 +183,7 @@ void storeToSettings(const Key &groupKey, QtcSettings *s, const Store &store)
{ {
s->beginGroup(groupKey); s->beginGroup(groupKey);
for (auto it = store.constBegin(), end = store.constEnd(); it != end; ++it) for (auto it = store.constBegin(), end = store.constEnd(); it != end; ++it)
s->setValue(it.key(), it.value()); s->setValue(it.key(), mapEntryFromStoreEntry(it.value()));
s->endGroup(); s->endGroup();
} }

View File

@@ -16,6 +16,7 @@ class QtcSettings;
using KeyList = QList<Key>; using KeyList = QList<Key>;
using Store = QMap<Key, QVariant>; using Store = QMap<Key, QVariant>;
using OldStore = QMap<QByteArray, QVariant>;
QTCREATOR_UTILS_EXPORT KeyList keysFromStrings(const QStringList &list); QTCREATOR_UTILS_EXPORT KeyList keysFromStrings(const QStringList &list);
QTCREATOR_UTILS_EXPORT QStringList stringsFromKeys(const KeyList &list); QTCREATOR_UTILS_EXPORT QStringList stringsFromKeys(const KeyList &list);
@@ -33,6 +34,9 @@ QTCREATOR_UTILS_EXPORT Key numberedKey(const Key &key, int number);
QTCREATOR_UTILS_EXPORT expected_str<Store> storeFromJson(const QByteArray &json); QTCREATOR_UTILS_EXPORT expected_str<Store> storeFromJson(const QByteArray &json);
QTCREATOR_UTILS_EXPORT QByteArray jsonFromStore(const Store &store); QTCREATOR_UTILS_EXPORT QByteArray jsonFromStore(const Store &store);
// These recursively change type.
QTCREATOR_UTILS_EXPORT QVariant storeEntryFromMapEntry(const QVariant &value);
QTCREATOR_UTILS_EXPORT QVariant mapEntryFromStoreEntry(const QVariant &value);
// Don't use in new code. // Don't use in new code.
QTCREATOR_UTILS_EXPORT Store storeFromSettings(const Key &groupKey, QtcSettings *s); QTCREATOR_UTILS_EXPORT Store storeFromSettings(const Key &groupKey, QtcSettings *s);
@@ -41,3 +45,4 @@ QTCREATOR_UTILS_EXPORT void storeToSettings(const Key &groupKey, QtcSettings *s,
} // Utils } // Utils
Q_DECLARE_METATYPE(Utils::Store) Q_DECLARE_METATYPE(Utils::Store)
Q_DECLARE_METATYPE(Utils::OldStore)

View File

@@ -5,13 +5,59 @@
#include "utils_global.h" #include "utils_global.h"
#include <QByteArrayView>
#include <QString> #include <QString>
#include <QHashFunctions>
namespace Utils { namespace Utils {
using Key = QByteArray; class QTCREATOR_UTILS_EXPORT Key
{
public:
Key() = default;
Key(const QByteArray &key) : data(key) {}
inline Key keyFromString(const QString &str) { return str.toUtf8(); } template <int N>
inline QString stringFromKey(const Key &key) { return QString::fromUtf8(key); } Key(const char (&key)[N]) : data(key) {}
// FIXME:
// The following is wanted, but not used yet due to unclear ASAN report.
// template <int N>
// Key(const char (&key)[N]) : Key(key, strlen(key)) {}
Key(const char *key, size_t n);
Key(const Key &base, int number);
~Key();
const QByteArrayView view() const;
const QByteArray &toByteArray() const;
QByteArrayView operator()() const { return data; }
bool isEmpty() const { return data.isEmpty(); }
void clear() { data.clear(); }
friend bool operator<(const Key &a, const Key &b) { return a.data < b.data; }
friend bool operator==(const Key &a, const Key &b) { return a.data == b.data; }
friend Key operator+(const Key &a, const Key &b)
{
return Key(a.data + b.data);
}
friend Key operator+(const Key &a, char b)
{
return Key(a.data + b);
}
friend size_t qHash(const Key &key, size_t seed = 0)
{
return qHash(key.data, seed);
}
private:
QByteArray data;
};
QTCREATOR_UTILS_EXPORT Key keyFromString(const QString &str);
QTCREATOR_UTILS_EXPORT QString stringFromKey(const Key &key);
} // Utils } // Utils

View File

@@ -27,7 +27,7 @@ QString UnixUtils::fileBrowser(const QSettings *settings)
void UnixUtils::setFileBrowser(QSettings *settings, const QString &term) void UnixUtils::setFileBrowser(QSettings *settings, const QString &term)
{ {
QtcSettings::setValueWithDefault(settings, "General/FileBrowser", term, defaultFileBrowser()); QtcSettings::setValueWithDefault(settings, Key("General/FileBrowser"), term, defaultFileBrowser());
} }

View File

@@ -97,9 +97,9 @@ void DebugServerProviderManager::restoreProviders()
Store map = storeFromVariant(data.value(key)); Store map = storeFromVariant(data.value(key));
const KeyList keys = map.keys(); const KeyList keys = map.keys();
for (const Key &key : keys) { for (const Key &key : keys) {
const int lastDot = key.lastIndexOf('.'); const int lastDot = key.view().lastIndexOf('.');
if (lastDot != -1) if (lastDot != -1)
map[key.mid(lastDot + 1)] = map[key]; map[key.view().mid(lastDot + 1).toByteArray()] = map[key];
} }
bool restored = false; bool restored = false;
for (IDebugServerProviderFactory *f : std::as_const(m_factories)) { for (IDebugServerProviderFactory *f : std::as_const(m_factories)) {

View File

@@ -21,7 +21,7 @@ ClangFormatSettings &ClangFormatSettings::instance()
ClangFormatSettings::ClangFormatSettings() ClangFormatSettings::ClangFormatSettings()
{ {
QtcSettings *settings = Core::ICore::settings(); QtcSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(Constants::SETTINGS_ID)); settings->beginGroup(Constants::SETTINGS_ID);
m_overrideDefaultFile = settings->value(Constants::OVERRIDE_FILE_ID, false).toBool(); m_overrideDefaultFile = settings->value(Constants::OVERRIDE_FILE_ID, false).toBool();
m_formatWhileTyping = settings->value(Constants::FORMAT_WHILE_TYPING_ID, false).toBool(); m_formatWhileTyping = settings->value(Constants::FORMAT_WHILE_TYPING_ID, false).toBool();
m_formatOnSave = settings->value(Constants::FORMAT_CODE_ON_SAVE_ID, false).toBool(); m_formatOnSave = settings->value(Constants::FORMAT_CODE_ON_SAVE_ID, false).toBool();
@@ -45,7 +45,7 @@ ClangFormatSettings::ClangFormatSettings()
void ClangFormatSettings::write() const void ClangFormatSettings::write() const
{ {
QtcSettings *settings = Core::ICore::settings(); QtcSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(Constants::SETTINGS_ID)); settings->beginGroup(Constants::SETTINGS_ID);
settings->setValue(Constants::OVERRIDE_FILE_ID, m_overrideDefaultFile); settings->setValue(Constants::OVERRIDE_FILE_ID, m_overrideDefaultFile);
settings->setValue(Constants::FORMAT_WHILE_TYPING_ID, m_formatWhileTyping); settings->setValue(Constants::FORMAT_WHILE_TYPING_ID, m_formatWhileTyping);
settings->setValue(Constants::FORMAT_CODE_ON_SAVE_ID, m_formatOnSave); settings->setValue(Constants::FORMAT_CODE_ON_SAVE_ID, m_formatOnSave);

View File

@@ -8,6 +8,7 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/qtcsettings.h> #include <utils/qtcsettings.h>
#include <utils/store.h>
using namespace Utils; using namespace Utils;

View File

@@ -81,6 +81,7 @@ CorePlugin::CorePlugin()
qRegisterMetaType<Utils::Store>(); qRegisterMetaType<Utils::Store>();
qRegisterMetaType<Utils::Key>(); qRegisterMetaType<Utils::Key>();
qRegisterMetaType<Utils::KeyList>(); qRegisterMetaType<Utils::KeyList>();
qRegisterMetaType<Utils::OldStore>();
m_instance = this; m_instance = this;
setupSystemEnvironment(); setupSystemEnvironment();
} }

View File

@@ -371,7 +371,7 @@ bool Find::hasFindFlag(FindFlag flag)
void FindPrivate::writeSettings() void FindPrivate::writeSettings()
{ {
QtcSettings *settings = ICore::settings(); QtcSettings *settings = ICore::settings();
settings->beginGroup(QLatin1String("Find")); settings->beginGroup("Find");
settings->setValueWithDefault("Backward", bool(m_findFlags & FindBackward), false); settings->setValueWithDefault("Backward", bool(m_findFlags & FindBackward), false);
settings->setValueWithDefault("CaseSensitively", bool(m_findFlags & FindCaseSensitively), false); settings->setValueWithDefault("CaseSensitively", bool(m_findFlags & FindCaseSensitively), false);
settings->setValueWithDefault("WholeWords", bool(m_findFlags & FindWholeWords), false); settings->setValueWithDefault("WholeWords", bool(m_findFlags & FindWholeWords), false);
@@ -389,18 +389,18 @@ void FindPrivate::writeSettings()
void FindPrivate::readSettings() void FindPrivate::readSettings()
{ {
QSettings *settings = ICore::settings(); QtcSettings *settings = ICore::settings();
settings->beginGroup(QLatin1String("Find")); settings->beginGroup("Find");
{ {
QSignalBlocker blocker(m_instance); QSignalBlocker blocker(m_instance);
Find::setBackward(settings->value(QLatin1String("Backward"), false).toBool()); Find::setBackward(settings->value("Backward", false).toBool());
Find::setCaseSensitive(settings->value(QLatin1String("CaseSensitively"), false).toBool()); Find::setCaseSensitive(settings->value("CaseSensitively", false).toBool());
Find::setWholeWord(settings->value(QLatin1String("WholeWords"), false).toBool()); Find::setWholeWord(settings->value("WholeWords", false).toBool());
Find::setRegularExpression(settings->value(QLatin1String("RegularExpression"), false).toBool()); Find::setRegularExpression(settings->value("RegularExpression", false).toBool());
Find::setPreserveCase(settings->value(QLatin1String("PreserveCase"), false).toBool()); Find::setPreserveCase(settings->value("PreserveCase", false).toBool());
} }
m_findCompletionModel.readSettings(settings); m_findCompletionModel.readSettings(settings);
m_replaceCompletions = settings->value(QLatin1String("ReplaceStrings")).toStringList(); m_replaceCompletions = settings->value("ReplaceStrings").toStringList();
m_replaceCompletionModel.setStringList(m_replaceCompletions); m_replaceCompletionModel.setStringList(m_replaceCompletions);
settings->endGroup(); settings->endGroup();
m_findToolBar->readSettings(); m_findToolBar->readSettings();

View File

@@ -27,6 +27,7 @@
#include <utils/navigationtreeview.h> #include <utils/navigationtreeview.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/removefiledialog.h> #include <utils/removefiledialog.h>
#include <utils/store.h>
#include <utils/stringutils.h> #include <utils/stringutils.h>
#include <utils/styledbar.h> #include <utils/styledbar.h>
#include <utils/stylehelper.h> #include <utils/stylehelper.h>

View File

@@ -2233,7 +2233,7 @@ void MainWindow::aboutToShutdown()
void MainWindowPrivate::readSettings() void MainWindowPrivate::readSettings()
{ {
QtcSettings *settings = PluginManager::settings(); QtcSettings *settings = PluginManager::settings();
settings->beginGroup(QLatin1String(settingsGroup)); settings->beginGroup(settingsGroup);
if (m_overrideColor.isValid()) { if (m_overrideColor.isValid()) {
StyleHelper::setBaseColor(m_overrideColor); StyleHelper::setBaseColor(m_overrideColor);
@@ -2278,7 +2278,7 @@ void MainWindowPrivate::readSettings()
void MainWindow::saveSettings() void MainWindow::saveSettings()
{ {
QtcSettings *settings = PluginManager::settings(); QtcSettings *settings = PluginManager::settings();
settings->beginGroup(QLatin1String(settingsGroup)); settings->beginGroup(settingsGroup);
if (!(d->m_overrideColor.isValid() && StyleHelper::baseColor() == d->m_overrideColor)) if (!(d->m_overrideColor.isValid() && StyleHelper::baseColor() == d->m_overrideColor))
settings->setValueWithDefault(colorKey, settings->setValueWithDefault(colorKey,

View File

@@ -541,7 +541,7 @@ void SessionManagerPrivate::restoreSessionValues(const PersistentSettingsReader
// restore toplevel items that are not restored by restoreValues // restore toplevel items that are not restored by restoreValues
const auto end = values.constEnd(); const auto end = values.constEnd();
for (auto it = values.constBegin(); it != end; ++it) { for (auto it = values.constBegin(); it != end; ++it) {
if (it.key() == "valueKeys" || it.key().startsWith("value-")) if (it.key() == "valueKeys" || it.key().view().startsWith("value-"))
continue; continue;
m_sessionValues.insert(it.key(), it.value()); m_sessionValues.insert(it.key(), it.value());
} }

View File

@@ -69,7 +69,7 @@ static FilePath fallbackClangdFilePath()
void CppCodeModelSettings::fromSettings(QtcSettings *s) void CppCodeModelSettings::fromSettings(QtcSettings *s)
{ {
s->beginGroup(QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP)); s->beginGroup(Constants::CPPEDITOR_SETTINGSGROUP);
setEnableLowerClazyLevels(s->value(enableLowerClazyLevelsKey(), true).toBool()); setEnableLowerClazyLevels(s->value(enableLowerClazyLevelsKey(), true).toBool());
@@ -101,7 +101,7 @@ void CppCodeModelSettings::fromSettings(QtcSettings *s)
void CppCodeModelSettings::toSettings(QtcSettings *s) void CppCodeModelSettings::toSettings(QtcSettings *s)
{ {
s->beginGroup(QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP)); s->beginGroup(Constants::CPPEDITOR_SETTINGSGROUP);
s->setValue(enableLowerClazyLevelsKey(), enableLowerClazyLevels()); s->setValue(enableLowerClazyLevelsKey(), enableLowerClazyLevels());
s->setValue(pchUsageKey(), pchUsage()); s->setValue(pchUsageKey(), pchUsage());
@@ -402,7 +402,7 @@ void ClangdSettings::loadSettings()
m_data.fromMap(Utils::storeFromSettings(clangdSettingsKey(), settings)); m_data.fromMap(Utils::storeFromSettings(clangdSettingsKey(), settings));
settings->beginGroup(QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP)); settings->beginGroup(Constants::CPPEDITOR_SETTINGSGROUP);
m_data.customDiagnosticConfigs = diagnosticConfigsFromSettings(settings); m_data.customDiagnosticConfigs = diagnosticConfigsFromSettings(settings);
// Pre-8.0 compat // Pre-8.0 compat
@@ -420,7 +420,7 @@ void ClangdSettings::saveSettings()
{ {
const auto settings = Core::ICore::settings(); const auto settings = Core::ICore::settings();
Utils::storeToSettings(clangdSettingsKey(), settings, m_data.toMap()); Utils::storeToSettings(clangdSettingsKey(), settings, m_data.toMap());
settings->beginGroup(QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP)); settings->beginGroup(Constants::CPPEDITOR_SETTINGSGROUP);
diagnosticConfigsToSettings(settings, m_data.customDiagnosticConfigs); diagnosticConfigsToSettings(settings, m_data.customDiagnosticConfigs);
settings->endGroup(); settings->endGroup();
} }

View File

@@ -290,12 +290,12 @@ QString DebuggerSettings::dump()
settings().all.forEachAspect([&msg](BaseAspect *aspect) { settings().all.forEachAspect([&msg](BaseAspect *aspect) {
Key key = aspect->settingsKey(); Key key = aspect->settingsKey();
if (!key.isEmpty()) { if (!key.isEmpty()) {
const int pos = key.indexOf('/'); const int pos = key.view().indexOf('/');
if (pos >= 0) if (pos >= 0)
key = key.mid(pos); key = key.view().mid(pos).toByteArray();
const QString current = aspect->variantValue().toString(); const QString current = aspect->variantValue().toString();
const QString default_ = aspect->defaultVariantValue().toString(); const QString default_ = aspect->defaultVariantValue().toString();
QString setting = key + ": " + current + " (default: " + default_ + ')'; QString setting = stringFromKey(key) + ": " + current + " (default: " + default_ + ')';
if (current != default_) if (current != default_)
setting += " ***"; setting += " ***";
msg << setting; msg << setting;

View File

@@ -13,10 +13,10 @@ namespace Designer::Internal {
static Key addPrefix(const QString &name) static Key addPrefix(const QString &name)
{ {
Key result = keyFromString(name); Key result;
if (Core::ICore::settings()->group().isEmpty()) if (Core::ICore::settings()->group().isEmpty())
result.prepend("Designer"); result = "Designer";
return result; return Key(result + name.toUtf8());
} }
void SettingsManager::beginGroup(const QString &prefix) void SettingsManager::beginGroup(const QString &prefix)

View File

@@ -244,7 +244,7 @@ FakeVimSettings::FakeVimSettings()
FakeVimSettings::~FakeVimSettings() = default; FakeVimSettings::~FakeVimSettings() = default;
FvBaseAspect *FakeVimSettings::item(const Key &name) FvBaseAspect *FakeVimSettings::item(const Utils::Key &name)
{ {
return m_nameToAspect.value(name, nullptr); return m_nameToAspect.value(name, nullptr);
} }
@@ -265,8 +265,8 @@ QString FakeVimSettings::trySetValue(const QString &name, const QString &value)
void FakeVimSettings::setup(FvBaseAspect *aspect, void FakeVimSettings::setup(FvBaseAspect *aspect,
const QVariant &value, const QVariant &value,
const Key &settingsKey, const Utils::Key &settingsKey,
const Key &shortName, const Utils::Key &shortName,
const QString &labelText) const QString &labelText)
{ {
aspect->setSettingsKey("FakeVim", settingsKey); aspect->setSettingsKey("FakeVim", settingsKey);
@@ -282,7 +282,7 @@ void FakeVimSettings::setup(FvBaseAspect *aspect,
Q_UNUSED(labelText) Q_UNUSED(labelText)
#endif #endif
const Key longName = settingsKey.toLower(); const Key longName = settingsKey.toByteArray().toLower();
if (!longName.isEmpty()) { if (!longName.isEmpty()) {
m_nameToAspect[longName] = aspect; m_nameToAspect[longName] = aspect;
m_aspectToName[aspect] = longName; m_aspectToName[aspect] = longName;

View File

@@ -25,8 +25,6 @@ namespace FakeVim::Internal {
#ifdef FAKEVIM_STANDALONE #ifdef FAKEVIM_STANDALONE
using Key = QByteArray;
class FvBaseAspect class FvBaseAspect
{ {
public: public:
@@ -37,15 +35,15 @@ public:
virtual void setDefaultVariantValue(const QVariant &) {} virtual void setDefaultVariantValue(const QVariant &) {}
virtual QVariant variantValue() const { return {}; } virtual QVariant variantValue() const { return {}; }
virtual QVariant defaultVariantValue() const { return {}; } virtual QVariant defaultVariantValue() const { return {}; }
void setSettingsKey(const Key &group, const Key &key); void setSettingsKey(const Utils::Key &group, const Utils::Key &key);
Key settingsKey() const; Utils::Key settingsKey() const;
void setCheckable(bool) {} void setCheckable(bool) {}
void setDisplayName(const QString &) {} void setDisplayName(const QString &) {}
void setToolTip(const QString &) {} void setToolTip(const QString &) {}
private: private:
Key m_settingsGroup; Utils::Key m_settingsGroup;
Key m_settingsKey; Utils::Key m_settingsKey;
}; };
template <class ValueType> template <class ValueType>

View File

@@ -6125,7 +6125,7 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
if (!error.isEmpty()) if (!error.isEmpty())
showMessage(MessageError, error); showMessage(MessageError, error);
} else { } else {
Utils::Key optionName = Utils::keyFromString(cmd.args); QString optionName = cmd.args;
bool toggleOption = optionName.endsWith('!'); bool toggleOption = optionName.endsWith('!');
bool printOption = !toggleOption && optionName.endsWith('?'); bool printOption = !toggleOption && optionName.endsWith('?');
@@ -6136,14 +6136,14 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
if (negateOption) if (negateOption)
optionName.remove(0, 2); optionName.remove(0, 2);
FvBaseAspect *act = s.item(optionName); FvBaseAspect *act = s.item(Utils::keyFromString(optionName));
if (!act) { if (!act) {
showMessage(MessageError, Tr::tr("Unknown option:") + ' ' + cmd.args); showMessage(MessageError, Tr::tr("Unknown option:") + ' ' + cmd.args);
} else if (act->defaultVariantValue().type() == QVariant::Bool) { } else if (act->defaultVariantValue().type() == QVariant::Bool) {
bool oldValue = act->variantValue().toBool(); bool oldValue = act->variantValue().toBool();
if (printOption) { if (printOption) {
showMessage(MessageInfo, QLatin1String(oldValue ? "" : "no") showMessage(MessageInfo, QLatin1String(oldValue ? "" : "no")
+ act->settingsKey().toLower()); + act->settingsKey().toByteArray().toLower());
} else if (toggleOption || negateOption == oldValue) { } else if (toggleOption || negateOption == oldValue) {
act->setVariantValue(!oldValue); act->setVariantValue(!oldValue);
} }
@@ -6152,7 +6152,7 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
} else if (toggleOption) { } else if (toggleOption) {
showMessage(MessageError, Tr::tr("Trailing characters:") + ' ' + cmd.args); showMessage(MessageError, Tr::tr("Trailing characters:") + ' ' + cmd.args);
} else { } else {
showMessage(MessageInfo, act->settingsKey().toLower() + "=" showMessage(MessageInfo, act->settingsKey().toByteArray().toLower() + "="
+ act->variantValue().toString()); + act->variantValue().toString());
} }
} }

View File

@@ -605,7 +605,7 @@ void LanguageClientSettings::init()
LanguageClientManager::applySettings(); LanguageClientManager::applySettings();
} }
QList<BaseSettings *> LanguageClientSettings::fromSettings(QSettings *settingsIn) QList<BaseSettings *> LanguageClientSettings::fromSettings(QtcSettings *settingsIn)
{ {
settingsIn->beginGroup(settingsGroupKey); settingsIn->beginGroup(settingsGroupKey);
QList<BaseSettings *> result; QList<BaseSettings *> result;
@@ -654,7 +654,7 @@ void LanguageClientSettings::enableSettings(const QString &id, bool enable)
settingsPage().enableSettings(id, enable); settingsPage().enableSettings(id, enable);
} }
void LanguageClientSettings::toSettings(QSettings *settings, void LanguageClientSettings::toSettings(QtcSettings *settings,
const QList<BaseSettings *> &languageClientSettings) const QList<BaseSettings *> &languageClientSettings)
{ {
settings->beginGroup(settingsGroupKey); settings->beginGroup(settingsGroupKey);

View File

@@ -135,7 +135,7 @@ class LANGUAGECLIENT_EXPORT LanguageClientSettings
{ {
public: public:
static void init(); static void init();
static QList<BaseSettings *> fromSettings(QSettings *settings); static QList<BaseSettings *> fromSettings(Utils::QtcSettings *settings);
static QList<BaseSettings *> pageSettings(); static QList<BaseSettings *> pageSettings();
static QList<BaseSettings *> changedSettings(); static QList<BaseSettings *> changedSettings();
@@ -146,7 +146,7 @@ public:
static void registerClientType(const ClientType &type); static void registerClientType(const ClientType &type);
static void addSettings(BaseSettings *settings); static void addSettings(BaseSettings *settings);
static void enableSettings(const QString &id, bool enable = true); static void enableSettings(const QString &id, bool enable = true);
static void toSettings(QSettings *settings, const QList<BaseSettings *> &languageClientSettings); static void toSettings(Utils::QtcSettings *settings, const QList<BaseSettings *> &languageClientSettings);
static bool outlineComboBoxIsSorted(); static bool outlineComboBoxIsSorted();
static void setOutlineComboBoxSorted(bool sorted); static void setOutlineComboBoxSorted(bool sorted);

View File

@@ -694,20 +694,19 @@ void McuSupportTest::test_legacy_createPackagesWithCorrespondingSettings_data()
QTest::newRow("iar_mimxrt1064_evk_freertos_json") QTest::newRow("iar_mimxrt1064_evk_freertos_json")
<< iar_mimxrt1064_evk_freertos_json << iar_mimxrt1064_evk_freertos_json
<< QSet<Key>{{"EVK_MIMXRT1064_SDK_PATH"}, << QSet<Key>{"EVK_MIMXRT1064_SDK_PATH",
{Key{Legacy::Constants::SETTINGS_KEY_FREERTOS_PREFIX}.append( Key{QByteArray(Legacy::Constants::SETTINGS_KEY_FREERTOS_PREFIX).append("IMXRT1064")},
"IMXRT1064")}, "IARToolchain"}
"IARToolchain"}
.unite(commonSettings); .unite(commonSettings);
QTest::newRow("stm32f469i") << iar_stm32f469i_discovery_baremetal_json QTest::newRow("stm32f469i") << iar_stm32f469i_discovery_baremetal_json
<< QSet<Key>{{"STM32Cube_FW_F4_SDK_PATH"}, "IARToolchain"}.unite( << QSet<Key>{{"STM32Cube_FW_F4_SDK_PATH"}, "IARToolchain"}.unite(
commonSettings); commonSettings);
QTest::newRow("nxp1050") << armgcc_mimxrt1050_evk_freertos_json QTest::newRow("nxp1050")
<< QSet<Key>{{"EVKB_IMXRT1050_SDK_PATH"}, << armgcc_mimxrt1050_evk_freertos_json
{Key{Legacy::Constants::SETTINGS_KEY_FREERTOS_PREFIX} << QSet<Key>{"EVKB_IMXRT1050_SDK_PATH",
.append("IMXRT1050")}, Key{QByteArray(Legacy::Constants::SETTINGS_KEY_FREERTOS_PREFIX).append("IMXRT1050")},
"GNUArmEmbeddedToolchain"} "GNUArmEmbeddedToolchain"}
.unite(commonSettings); .unite(commonSettings);
QTest::newRow("armgcc_stm32h750b_discovery_baremetal_json") QTest::newRow("armgcc_stm32h750b_discovery_baremetal_json")
<< armgcc_stm32h750b_discovery_baremetal_json << armgcc_stm32h750b_discovery_baremetal_json
<< QSet<Key>{{"STM32Cube_FW_H7_SDK_PATH"}, "GNUArmEmbeddedToolchain"}.unite( << QSet<Key>{{"STM32Cube_FW_H7_SDK_PATH"}, "GNUArmEmbeddedToolchain"}.unite(

View File

@@ -428,11 +428,11 @@ void PerfSettings::readGlobalSettings()
Store defaults; Store defaults;
// Read stored values // Read stored values
QSettings *settings = Core::ICore::settings(); QtcSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(Constants::AnalyzerSettingsGroupId)); settings->beginGroup(Constants::AnalyzerSettingsGroupId);
Store map = defaults; Store map = defaults;
for (Store::ConstIterator it = defaults.constBegin(); it != defaults.constEnd(); ++it) for (Store::ConstIterator it = defaults.constBegin(); it != defaults.constEnd(); ++it)
map.insert(it.key(), settings->value(stringFromKey(it.key()), it.value())); map.insert(it.key(), settings->value(it.key(), it.value()));
settings->endGroup(); settings->endGroup();
fromMap(map); fromMap(map);
@@ -440,12 +440,12 @@ void PerfSettings::readGlobalSettings()
void PerfSettings::writeGlobalSettings() const void PerfSettings::writeGlobalSettings() const
{ {
QSettings *settings = Core::ICore::settings(); QtcSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(Constants::AnalyzerSettingsGroupId)); settings->beginGroup(Constants::AnalyzerSettingsGroupId);
Store map; Store map;
toMap(map); toMap(map);
for (Store::ConstIterator it = map.constBegin(); it != map.constEnd(); ++it) for (Store::ConstIterator it = map.constBegin(); it != map.constEnd(); ++it)
settings->setValue(stringFromKey(it.key()), it.value()); settings->setValue(it.key(), it.value());
settings->endGroup(); settings->endGroup();
} }

View File

@@ -225,8 +225,8 @@ QWidget *CustomWizardFieldPage::registerPathChooser(const QString &fieldName,
pathChooser->setExpectedKind(PathChooser::Command); pathChooser->setExpectedKind(PathChooser::Command);
else if (expectedKind == QLatin1String("any")) else if (expectedKind == QLatin1String("any"))
pathChooser->setExpectedKind(PathChooser::Any); pathChooser->setExpectedKind(PathChooser::Any);
pathChooser->setHistoryCompleter("PE.Custom." + m_parameters->id.name() pathChooser->setHistoryCompleter(keyFromString("PE.Custom." + m_parameters->id.name()
+ '.' + keyFromString(field.name)); + '.' + field.name));
registerField(fieldName, pathChooser, "path", SIGNAL(rawPathChanged(QString))); registerField(fieldName, pathChooser, "path", SIGNAL(rawPathChanged(QString)));
// Connect to completeChanged() for derived classes that reimplement isComplete() // Connect to completeChanged() for derived classes that reimplement isComplete()

View File

@@ -218,8 +218,8 @@ void EditorConfiguration::fromMap(const Store &map)
Store submap; Store submap;
for (auto it = map.constBegin(), end = map.constEnd(); it != end; ++it) { for (auto it = map.constBegin(), end = map.constEnd(); it != end; ++it) {
if (it.key().startsWith(kPrefix)) if (it.key().view().startsWith(kPrefix.view()))
submap.insert(it.key().mid(kPrefix.size()), it.value()); submap.insert(it.key().view().mid(kPrefix.view().size()).toByteArray(), it.value());
} }
d->m_defaultCodeStyle->fromMap(submap); d->m_defaultCodeStyle->fromMap(submap);
d->m_typingSettings.fromMap(submap); d->m_typingSettings.fromMap(submap);

View File

@@ -62,10 +62,12 @@ void ExtraAbi::load()
std::vector<Abi::OS> oses; std::vector<Abi::OS> oses;
for (const QString &osName : osNames) { for (const QString &osName : osNames) {
Abi::OS os = Abi::osFromString(osName); Abi::OS os = Abi::osFromString(osName);
if (Abi::toString(os) != osName) if (Abi::toString(os) != osName) {
qWarning() << "Invalid OS found when registering extra abi flavor" << it.key(); qWarning() << "Invalid OS found when registering extra abi flavor"
else << it.key().toByteArray();
} else {
oses.push_back(os); oses.push_back(os);
}
} }
Abi::registerOsFlavor(oses, stringFromKey(flavor)); Abi::registerOsFlavor(oses, stringFromKey(flavor));

View File

@@ -802,7 +802,8 @@ QVariant UserFileVersion19Upgrader::process(const QVariant &entry, const KeyList
for (auto it = map.cbegin(), end = map.cend(); it != end; ++it) { for (auto it = map.cbegin(), end = map.cend(); it != end; ++it) {
Key key = it.key(); Key key = it.key();
QVariant value = it.value(); QVariant value = it.value();
if (path.size() == 2 && path.at(1).startsWith("ProjectExplorer.Target.RunConfiguration.")) { if (path.size() == 2
&& path.at(1).view().startsWith("ProjectExplorer.Target.RunConfiguration.")) {
if (argsKeys.contains(key)) if (argsKeys.contains(key))
key = "RunConfiguration.Arguments"; key = "RunConfiguration.Arguments";
else if (wdKeys.contains(key)) else if (wdKeys.contains(key))

View File

@@ -89,7 +89,7 @@ QString QtWizard::templateDir()
bool QtWizard::lowerCaseFiles() bool QtWizard::lowerCaseFiles()
{ {
Key lowerCaseSettingsKey = CppEditor::Constants::CPPEDITOR_SETTINGSGROUP; QByteArray lowerCaseSettingsKey = CppEditor::Constants::CPPEDITOR_SETTINGSGROUP;
lowerCaseSettingsKey += '/'; lowerCaseSettingsKey += '/';
lowerCaseSettingsKey += CppEditor::Constants::LOWERCASE_CPPFILES_KEY; lowerCaseSettingsKey += CppEditor::Constants::LOWERCASE_CPPFILES_KEY;
const bool lowerCaseDefault = CppEditor::Constants::LOWERCASE_CPPFILES_DEFAULT; const bool lowerCaseDefault = CppEditor::Constants::LOWERCASE_CPPFILES_DEFAULT;

View File

@@ -765,7 +765,7 @@ void QtVersion::fromMap(const Store &map, const FilePath &filePath, bool forceRe
d->m_qmakeCommand = filePath.resolvePath(d->m_qmakeCommand); d->m_qmakeCommand = filePath.resolvePath(d->m_qmakeCommand);
const expected_str<Utils::Store> persistentStore = PersistentCacheStore::byKey( const expected_str<Utils::Store> persistentStore = PersistentCacheStore::byKey(
"QtVersionData" + d->m_qmakeCommand.toString().toUtf8()); Key("QtVersionData" + d->m_qmakeCommand.toString().toUtf8()));
if (persistentStore && !forceRefreshCache) { if (persistentStore && !forceRefreshCache) {
d->m_data.fromMap(*persistentStore); d->m_data.fromMap(*persistentStore);
@@ -799,7 +799,7 @@ Store QtVersion::toMap() const
result.insert(QTVERSIONQMAKEPATH, qmakeFilePath().toSettings()); result.insert(QTVERSIONQMAKEPATH, qmakeFilePath().toSettings());
if (d->m_data.versionInfoUpToDate) if (d->m_data.versionInfoUpToDate)
PersistentCacheStore::write("QtVersionData" + d->m_qmakeCommand.toString().toUtf8(), PersistentCacheStore::write(Key("QtVersionData" + d->m_qmakeCommand.toString().toUtf8()),
d->m_data.toMap()); d->m_data.toMap());
return result; return result;
@@ -1407,7 +1407,7 @@ void QtVersionPrivate::updateVersionInfo()
m_isUpdating = false; m_isUpdating = false;
m_data.versionInfoUpToDate = true; m_data.versionInfoUpToDate = true;
PersistentCacheStore::write("QtVersionData" + m_qmakeCommand.toString().toUtf8(), PersistentCacheStore::write(Key("QtVersionData" + m_qmakeCommand.toString().toUtf8()),
m_data.toMap()); m_data.toMap());
} }

View File

@@ -213,14 +213,14 @@ bool QtVersionManagerImpl::restoreQtVersions()
if (version < 1) if (version < 1)
return false; return false;
const Key keyPrefix(QTVERSION_DATA_KEY); const QByteArray keyPrefix(QTVERSION_DATA_KEY);
const Store::ConstIterator dcend = data.constEnd(); const Store::ConstIterator dcend = data.constEnd();
for (Store::ConstIterator it = data.constBegin(); it != dcend; ++it) { for (Store::ConstIterator it = data.constBegin(); it != dcend; ++it) {
const Key &key = it.key(); const Key &key = it.key();
if (!key.startsWith(keyPrefix)) if (!key.view().startsWith(keyPrefix))
continue; continue;
bool ok; bool ok;
int count = key.mid(keyPrefix.count()).toInt(&ok); int count = key.view().mid(keyPrefix.count()).toInt(&ok);
if (!ok || count < 0) if (!ok || count < 0)
continue; continue;
@@ -287,14 +287,14 @@ void QtVersionManagerImpl::updateFromInstaller(bool emitSignal)
QStringList sdkVersions; QStringList sdkVersions;
const Key keyPrefix(QTVERSION_DATA_KEY); const QByteArray keyPrefix(QTVERSION_DATA_KEY);
const Store::ConstIterator dcend = data.constEnd(); const Store::ConstIterator dcend = data.constEnd();
for (Store::ConstIterator it = data.constBegin(); it != dcend; ++it) { for (Store::ConstIterator it = data.constBegin(); it != dcend; ++it) {
const Key &key = it.key(); const Key &key = it.key();
if (!key.startsWith(keyPrefix)) if (!key.view().startsWith(keyPrefix))
continue; continue;
bool ok; bool ok;
int count = key.mid(keyPrefix.count()).toInt(&ok); int count = key.view().mid(keyPrefix.count()).toInt(&ok);
if (!ok || count < 0) if (!ok || count < 0)
continue; continue;