Utils etc: More use of Key and Store

Change-Id: Idd2d70617f775d783aee93a2fe82544ad335a739
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2023-08-23 18:18:46 +02:00
parent 0490266723
commit 621a2850d0
19 changed files with 137 additions and 95 deletions

View File

@@ -156,7 +156,7 @@ bool SessionManager::isDefaultSession(const QString &session)
void SessionManager::saveActiveMode(Id mode)
{
if (mode != Core::Constants::MODE_WELCOME)
setValue(QLatin1String("ActiveMode"), mode.toString());
setValue("ActiveMode", mode.toString());
}
bool SessionManager::isLoadingSession()
@@ -169,25 +169,25 @@ bool SessionManager::isLoadingSession()
within the session file.
*/
void SessionManager::setValue(const QString &name, const QVariant &value)
void SessionManager::setValue(const Key &name, const QVariant &value)
{
if (sb_d->m_values.value(name) == value)
return;
sb_d->m_values.insert(name, value);
}
QVariant SessionManager::value(const QString &name)
QVariant SessionManager::value(const Key &name)
{
auto it = sb_d->m_values.constFind(name);
return (it == sb_d->m_values.constEnd()) ? QVariant() : *it;
}
void SessionManager::setSessionValue(const QString &name, const QVariant &value)
void SessionManager::setSessionValue(const Key &name, const QVariant &value)
{
sb_d->m_sessionValues.insert(name, value);
}
QVariant SessionManager::sessionValue(const QString &name, const QVariant &defaultValue)
QVariant SessionManager::sessionValue(const Key &name, const QVariant &defaultValue)
{
auto it = sb_d->m_sessionValues.constFind(name);
return (it == sb_d->m_sessionValues.constEnd()) ? defaultValue : *it;
@@ -488,16 +488,16 @@ void SessionManagerPrivate::updateSessionMenu()
void SessionManagerPrivate::restoreValues(const PersistentSettingsReader &reader)
{
const QStringList keys = reader.restoreValue(QLatin1String("valueKeys")).toStringList();
for (const QString &key : keys) {
QVariant value = reader.restoreValue(QLatin1String("value-") + key);
const KeyList keys = keyListFromStringList(reader.restoreValue("valueKeys").toStringList());
for (const Key &key : keys) {
QVariant value = reader.restoreValue("value-" + key);
m_values.insert(key, value);
}
}
void SessionManagerPrivate::restoreSessionValues(const PersistentSettingsReader &reader)
{
const QVariantMap values = reader.restoreValues();
const Store values = reader.restoreValues();
// restore toplevel items that are not restored by restoreValues
const auto end = values.constEnd();
for (auto it = values.constBegin(); it != end; ++it) {
@@ -680,7 +680,7 @@ bool SessionManager::saveSession()
emit SessionManager::instance()->aboutToSaveSession();
const FilePath filePath = SessionManager::sessionNameToFileName(sb_d->m_sessionName);
QVariantMap data;
Store data;
// See the explanation at loadSession() for how we handle the implicit default session.
if (SessionManager::isDefaultVirgin()) {
@@ -712,12 +712,12 @@ bool SessionManager::saveSession()
}
const auto end = sb_d->m_values.constEnd();
QStringList keys;
KeyList keys;
for (auto it = sb_d->m_values.constBegin(); it != end; ++it) {
data.insert("value-" + it.key(), it.value());
keys << it.key();
}
data.insert("valueKeys", keys);
data.insert("valueKeys", QVariant::fromValue(keys));
if (!sb_d->m_writer || sb_d->m_writer->fileName() != filePath) {
delete sb_d->m_writer;

View File

@@ -50,13 +50,13 @@ public:
// Let other plugins store persistent values within the session file
// These are settings that are also saved and loaded at startup, and are taken over
// to the default session when switching from implicit to explicit default session
static void setValue(const QString &name, const QVariant &value);
static QVariant value(const QString &name);
static void setValue(const Utils::Key &name, const QVariant &value);
static QVariant value(const Utils::Key &name);
// These are settings that are specific to a session and are not loaded
// at startup and also not taken over to the default session when switching from implicit
static void setSessionValue(const QString &name, const QVariant &value);
static QVariant sessionValue(const QString &name, const QVariant &defaultValue = {});
static void setSessionValue(const Utils::Key &name, const QVariant &value);
static QVariant sessionValue(const Utils::Key &name, const QVariant &defaultValue = {});
static bool isLoadingSession();
static void markSessionFileDirty();

View File

@@ -2,6 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <utils/persistentsettings.h>
#include <utils/store.h>
#include <QFutureInterface>
@@ -43,8 +44,8 @@ public:
mutable QHash<QString, QDateTime> m_sessionDateTimes;
QHash<QString, QDateTime> m_lastActiveTimes;
QMap<QString, QVariant> m_values;
QMap<QString, QVariant> m_sessionValues;
QMap<Utils::Key, QVariant> m_values;
QMap<Utils::Key, QVariant> m_sessionValues;
QFutureInterface<void> m_future;
PersistentSettingsWriter *m_writer = nullptr;