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);
for (const QString &group : groups)
theSettings->beginGroup(group);
theSettings->beginGroup(keyFromString(group));
}
SettingsGroupNester::~SettingsGroupNester()

View File

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

View File

@@ -26,7 +26,7 @@ public:
FilePath filePath();
private:
Store m_valueMap;
QVariantMap m_valueMap;
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
#include "qtcsettings.h"
#include "store.h"
namespace Utils {
@@ -29,4 +30,14 @@ namespace Utils {
\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

View File

@@ -5,7 +5,7 @@
#include "utils_global.h"
#include "store.h"
#include "storekey.h"
#include <QSettings>
@@ -17,12 +17,10 @@ public:
using QSettings::QSettings;
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 QVariant &def) const { return QSettings::value(stringFromKey(key), def); }
void setValue(const Key &key, const QVariant &value) { QSettings::setValue(stringFromKey(key), value); }
QVariant value(const Key &key, const QVariant &def) const;
void setValue(const Key &key, const QVariant &value);
void remove(const Key &key) { QSettings::remove(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();
}
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)
{
QVariantList storeList;
for (const auto &mapEntry : mapList) {
if (mapEntry.type() == QVariant::Map)
storeList.append(QVariant::fromValue(storeFromMap(mapEntry.toMap())));
else if (mapEntry.type() == QVariant::List)
storeList.append(QVariant::fromValue(storeListFromMapList(mapEntry.toList())));
else
storeList.append(mapEntry);
}
for (const auto &mapEntry : mapList)
storeList.append(storeEntryFromMapEntry(mapEntry));
return storeList;
}
@@ -62,14 +81,8 @@ static QVariantList mapListFromStoreList(const QVariantList &storeList)
{
QVariantList mapList;
for (const auto &storeEntry : storeList) {
if (storeEntry.metaType() == QMetaType::fromType<Store>())
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);
}
for (const QVariant &storeEntry : storeList)
mapList.append(mapEntryFromStoreEntry(storeEntry));
return mapList;
}
@@ -77,30 +90,20 @@ static QVariantList mapListFromStoreList(const QVariantList &storeList)
Store storeFromMap(const QVariantMap &map)
{
Store store;
for (auto it = map.begin(); it != map.end(); ++it) {
if (it.value().type() == QVariant::Map) {
store.insert(keyFromString(it.key()), QVariant::fromValue(storeFromMap(it->toMap())));
} 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());
}
}
for (auto it = map.begin(); it != map.end(); ++it)
store.insert(keyFromString(it.key()), storeEntryFromMapEntry(it.value()));
return store;
}
QVariantMap mapFromStore(const Store &store)
{
QVariantMap map;
for (auto it = store.begin(); it != store.end(); ++it) {
if (it.value().metaType() == QMetaType::fromType<Store>())
map.insert(stringFromKey(it.key()), mapFromStore(it->value<Store>()));
else if (it.value().type() == QVariant::List)
map.insert(stringFromKey(it.key()), mapListFromStoreList(it->toList()));
else
map.insert(stringFromKey(it.key()), it.value());
}
for (auto it = store.begin(); it != store.end(); ++it)
map.insert(stringFromKey(it.key()), mapEntryFromStoreEntry(it.value()));
return map;
}
@@ -110,9 +113,40 @@ bool isStore(const QVariant &value)
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)
{
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)
@@ -140,7 +174,7 @@ Store storeFromSettings(const Key &groupKey, QtcSettings *s)
s->beginGroup(groupKey);
const KeyList keys = keysFromStrings(s->allKeys());
for (const Key &key : keys)
store.insert(key, s->value(key));
store.insert(key, storeEntryFromMapEntry(s->value(key)));
s->endGroup();
return store;
}
@@ -149,7 +183,7 @@ void storeToSettings(const Key &groupKey, QtcSettings *s, const Store &store)
{
s->beginGroup(groupKey);
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();
}

View File

@@ -16,6 +16,7 @@ class QtcSettings;
using KeyList = QList<Key>;
using Store = QMap<Key, QVariant>;
using OldStore = QMap<QByteArray, QVariant>;
QTCREATOR_UTILS_EXPORT KeyList keysFromStrings(const QStringList &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 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.
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
Q_DECLARE_METATYPE(Utils::Store)
Q_DECLARE_METATYPE(Utils::OldStore)

View File

@@ -5,13 +5,59 @@
#include "utils_global.h"
#include <QByteArrayView>
#include <QString>
#include <QHashFunctions>
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(); }
inline QString stringFromKey(const Key &key) { return QString::fromUtf8(key); }
template <int N>
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

View File

@@ -27,7 +27,7 @@ QString UnixUtils::fileBrowser(const QSettings *settings)
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));
const KeyList keys = map.keys();
for (const Key &key : keys) {
const int lastDot = key.lastIndexOf('.');
const int lastDot = key.view().lastIndexOf('.');
if (lastDot != -1)
map[key.mid(lastDot + 1)] = map[key];
map[key.view().mid(lastDot + 1).toByteArray()] = map[key];
}
bool restored = false;
for (IDebugServerProviderFactory *f : std::as_const(m_factories)) {

View File

@@ -21,7 +21,7 @@ ClangFormatSettings &ClangFormatSettings::instance()
ClangFormatSettings::ClangFormatSettings()
{
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_formatWhileTyping = settings->value(Constants::FORMAT_WHILE_TYPING_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
{
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::FORMAT_WHILE_TYPING_ID, m_formatWhileTyping);
settings->setValue(Constants::FORMAT_CODE_ON_SAVE_ID, m_formatOnSave);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -541,7 +541,7 @@ void SessionManagerPrivate::restoreSessionValues(const PersistentSettingsReader
// restore toplevel items that are not restored by restoreValues
const auto end = values.constEnd();
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;
m_sessionValues.insert(it.key(), it.value());
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -135,7 +135,7 @@ class LANGUAGECLIENT_EXPORT LanguageClientSettings
{
public:
static void init();
static QList<BaseSettings *> fromSettings(QSettings *settings);
static QList<BaseSettings *> fromSettings(Utils::QtcSettings *settings);
static QList<BaseSettings *> pageSettings();
static QList<BaseSettings *> changedSettings();
@@ -146,7 +146,7 @@ public:
static void registerClientType(const ClientType &type);
static void addSettings(BaseSettings *settings);
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 void setOutlineComboBoxSorted(bool sorted);

View File

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

View File

@@ -428,11 +428,11 @@ void PerfSettings::readGlobalSettings()
Store defaults;
// Read stored values
QSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(Constants::AnalyzerSettingsGroupId));
QtcSettings *settings = Core::ICore::settings();
settings->beginGroup(Constants::AnalyzerSettingsGroupId);
Store map = defaults;
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();
fromMap(map);
@@ -440,12 +440,12 @@ void PerfSettings::readGlobalSettings()
void PerfSettings::writeGlobalSettings() const
{
QSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(Constants::AnalyzerSettingsGroupId));
QtcSettings *settings = Core::ICore::settings();
settings->beginGroup(Constants::AnalyzerSettingsGroupId);
Store map;
toMap(map);
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();
}

View File

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

View File

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

View File

@@ -62,11 +62,13 @@ void ExtraAbi::load()
std::vector<Abi::OS> oses;
for (const QString &osName : osNames) {
Abi::OS os = Abi::osFromString(osName);
if (Abi::toString(os) != osName)
qWarning() << "Invalid OS found when registering extra abi flavor" << it.key();
else
if (Abi::toString(os) != osName) {
qWarning() << "Invalid OS found when registering extra abi flavor"
<< it.key().toByteArray();
} else {
oses.push_back(os);
}
}
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) {
Key key = it.key();
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))
key = "RunConfiguration.Arguments";
else if (wdKeys.contains(key))

View File

@@ -89,7 +89,7 @@ QString QtWizard::templateDir()
bool QtWizard::lowerCaseFiles()
{
Key lowerCaseSettingsKey = CppEditor::Constants::CPPEDITOR_SETTINGSGROUP;
QByteArray lowerCaseSettingsKey = CppEditor::Constants::CPPEDITOR_SETTINGSGROUP;
lowerCaseSettingsKey += '/';
lowerCaseSettingsKey += CppEditor::Constants::LOWERCASE_CPPFILES_KEY;
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);
const expected_str<Utils::Store> persistentStore = PersistentCacheStore::byKey(
"QtVersionData" + d->m_qmakeCommand.toString().toUtf8());
Key("QtVersionData" + d->m_qmakeCommand.toString().toUtf8()));
if (persistentStore && !forceRefreshCache) {
d->m_data.fromMap(*persistentStore);
@@ -799,7 +799,7 @@ Store QtVersion::toMap() const
result.insert(QTVERSIONQMAKEPATH, qmakeFilePath().toSettings());
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());
return result;
@@ -1407,7 +1407,7 @@ void QtVersionPrivate::updateVersionInfo()
m_isUpdating = false;
m_data.versionInfoUpToDate = true;
PersistentCacheStore::write("QtVersionData" + m_qmakeCommand.toString().toUtf8(),
PersistentCacheStore::write(Key("QtVersionData" + m_qmakeCommand.toString().toUtf8()),
m_data.toMap());
}

View File

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