Utils: Use Key more widely in QtcSettings

And adapt user code.

Change-Id: I6efe4ebe6823de4cc862f304a57e041b02c40eac
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2023-08-30 07:39:54 +02:00
parent 922da1fbb3
commit c7710acadd
35 changed files with 141 additions and 147 deletions

View File

@@ -661,7 +661,7 @@ int main(int argc, char **argv)
QTranslator translator;
QTranslator qtTranslator;
QStringList uiLanguages = QLocale::system().uiLanguages();
QString overrideLanguage = settings->value(QLatin1String("General/OverrideLanguage")).toString();
QString overrideLanguage = settings->value("General/OverrideLanguage").toString();
if (!overrideLanguage.isEmpty())
uiLanguages.prepend(overrideLanguage);
if (!options.uiLanguage.isEmpty())

View File

@@ -1018,12 +1018,12 @@ void PluginManagerPrivate::writeSettings()
void PluginManagerPrivate::readSettings()
{
if (globalSettings) {
defaultDisabledPlugins = globalSettings->value(QLatin1String(C_IGNORED_PLUGINS)).toStringList();
defaultEnabledPlugins = globalSettings->value(QLatin1String(C_FORCEENABLED_PLUGINS)).toStringList();
defaultDisabledPlugins = globalSettings->value(C_IGNORED_PLUGINS).toStringList();
defaultEnabledPlugins = globalSettings->value(C_FORCEENABLED_PLUGINS).toStringList();
}
if (settings) {
disabledPlugins = settings->value(QLatin1String(C_IGNORED_PLUGINS)).toStringList();
forceEnabledPlugins = settings->value(QLatin1String(C_FORCEENABLED_PLUGINS)).toStringList();
disabledPlugins = settings->value(C_IGNORED_PLUGINS).toStringList();
forceEnabledPlugins = settings->value(C_FORCEENABLED_PLUGINS).toStringList();
}
}

View File

@@ -207,10 +207,10 @@ QString HistoryCompleter::historyItem() const
return d->list.at(0);
}
bool HistoryCompleter::historyExistsFor(const QString &historyKey)
bool HistoryCompleter::historyExistsFor(const Key &historyKey)
{
QTC_ASSERT(theSettings, return false);
const QString fullKey = QLatin1String("CompleterHistory/") + historyKey;
const Key fullKey = "CompleterHistory/" + historyKey;
return theSettings->value(fullKey).isValid();
}

View File

@@ -23,7 +23,7 @@ public:
bool removeHistoryItem(int index);
QString historyItem() const;
bool hasHistory() const { return historySize() > 0; }
static bool historyExistsFor(const QString &historyKey);
static bool historyExistsFor(const Key &historyKey);
void clearHistory();
void addEntry(const QString &str);

View File

@@ -16,50 +16,45 @@ class QTCREATOR_UTILS_EXPORT QtcSettings : public QSettings
public:
using QSettings::QSettings;
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); }
void remove(const Key &key) { QSettings::remove(stringFromKey(key)); }
bool contains(const Key &key) const { return QSettings::contains(stringFromKey(key)); }
template<typename T>
void setValueWithDefault(const Key &key, const T &val, const T &defaultValue);
template<typename T>
void setValueWithDefault(const Key &key, const T &val);
void setValueWithDefault(const Key &key, const T &val, const T &defaultValue)
{
setValueWithDefault(this, key, val, defaultValue);
}
template<typename T>
static void setValueWithDefault(QSettings *settings,
const Key &key,
const T &val,
const T &defaultValue);
const T &defaultValue)
{
if (val == defaultValue)
settings->remove(stringFromKey(key));
else
settings->setValue(stringFromKey(key), QVariant::fromValue(val));
}
template<typename T>
static void setValueWithDefault(QSettings *settings, const Key &key, const T &val);
void setValueWithDefault(const Key &key, const T &val)
{
setValueWithDefault(this, key, val);
}
template<typename T>
static void setValueWithDefault(QSettings *settings, const Key &key, const T &val)
{
if (val == T())
settings->remove(stringFromKey(key));
else
settings->setValue(stringFromKey(key), QVariant::fromValue(val));
}
};
template<typename T>
void QtcSettings::setValueWithDefault(const Key &key, const T &val, const T &defaultValue)
{
setValueWithDefault(this, key, val, defaultValue);
}
template<typename T>
void QtcSettings::setValueWithDefault(const Key &key, const T &val)
{
setValueWithDefault(this, key, val);
}
template<typename T>
void QtcSettings::setValueWithDefault(QSettings *settings,
const Key &key,
const T &val,
const T &defaultValue)
{
if (val == defaultValue)
settings->remove(key);
else
settings->setValue(key, QVariant::fromValue(val));
}
template<typename T>
void QtcSettings::setValueWithDefault(QSettings *settings, const Key &key, const T &val)
{
if (val == T())
settings->remove(key);
else
settings->setValue(key, QVariant::fromValue(val));
}
} // namespace Utils

View File

@@ -116,4 +116,9 @@ bool isStore(const QVariant &value)
return typeId == QMetaType::QVariantMap || typeId == qMetaTypeId<Store>();
}
Key numberedKey(const Key &key, int number)
{
return key + Key::number(number);
}
} // Utils

View File

@@ -29,6 +29,8 @@ QTCREATOR_UTILS_EXPORT QVariantMap mapFromStore(const Store &store);
QTCREATOR_UTILS_EXPORT bool isStore(const QVariant &value);
QTCREATOR_UTILS_EXPORT Key numberedKey(const Key &key, int number);
} // Utils
#ifdef QTC_USE_STORE

View File

@@ -6,8 +6,11 @@
#include <coreplugin/icore.h>
using namespace Utils;
namespace ClangFormat {
static const char FORMAT_CODE_INSTEAD_OF_INDENT_ID[] = "ClangFormat.FormatCodeInsteadOfIndent";
const char FORMAT_CODE_INSTEAD_OF_INDENT_ID[] = "ClangFormat.FormatCodeInsteadOfIndent";
ClangFormatSettings &ClangFormatSettings::instance()
{
@@ -17,43 +20,37 @@ ClangFormatSettings &ClangFormatSettings::instance()
ClangFormatSettings::ClangFormatSettings()
{
QSettings *settings = Core::ICore::settings();
QtcSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(Constants::SETTINGS_ID));
m_overrideDefaultFile = settings->value(QLatin1String(Constants::OVERRIDE_FILE_ID), false)
.toBool();
m_formatWhileTyping = settings->value(QLatin1String(Constants::FORMAT_WHILE_TYPING_ID), false)
.toBool();
m_formatOnSave = settings->value(QLatin1String(Constants::FORMAT_CODE_ON_SAVE_ID), false)
.toBool();
m_fileSizeThreshold
= settings->value(QLatin1String(Constants::FILE_SIZE_THREDSHOLD), 1024).toInt();
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();
m_fileSizeThreshold = settings->value(Constants::FILE_SIZE_THREDSHOLD, 1024).toInt();
// Convert old settings to new ones. New settings were added to QtC 8.0
bool isOldFormattingOn
= settings->value(QLatin1String(FORMAT_CODE_INSTEAD_OF_INDENT_ID), false).toBool();
Core::ICore::settings()->remove(QLatin1String(FORMAT_CODE_INSTEAD_OF_INDENT_ID));
bool isOldFormattingOn = settings->value(FORMAT_CODE_INSTEAD_OF_INDENT_ID, false).toBool();
Core::ICore::settings()->remove(FORMAT_CODE_INSTEAD_OF_INDENT_ID);
if (isOldFormattingOn) {
settings->setValue(QLatin1String(Constants::MODE_ID),
settings->setValue(Constants::MODE_ID,
static_cast<int>(ClangFormatSettings::Mode::Formatting));
m_mode = ClangFormatSettings::Mode::Formatting;
} else
m_mode = static_cast<ClangFormatSettings::Mode>(
settings->value(QLatin1String(Constants::MODE_ID), ClangFormatSettings::Mode::Indenting)
.toInt());
settings->value(Constants::MODE_ID, ClangFormatSettings::Mode::Indenting).toInt());
settings->endGroup();
}
void ClangFormatSettings::write() const
{
QSettings *settings = Core::ICore::settings();
QtcSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(Constants::SETTINGS_ID));
settings->setValue(QLatin1String(Constants::OVERRIDE_FILE_ID), m_overrideDefaultFile);
settings->setValue(QLatin1String(Constants::FORMAT_WHILE_TYPING_ID), m_formatWhileTyping);
settings->setValue(QLatin1String(Constants::FORMAT_CODE_ON_SAVE_ID), m_formatOnSave);
settings->setValue(QLatin1String(Constants::MODE_ID), static_cast<int>(m_mode));
settings->setValue(QLatin1String(Constants::FILE_SIZE_THREDSHOLD), m_fileSizeThreshold);
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);
settings->setValue(Constants::MODE_ID, static_cast<int>(m_mode));
settings->setValue(Constants::FILE_SIZE_THREDSHOLD, m_fileSizeThreshold);
settings->endGroup();
}

View File

@@ -9,7 +9,7 @@
#include <utils/qtcassert.h>
#include <utils/qtcsettings.h>
#include <QSettings>
using namespace Utils;
namespace ClassView {
namespace Internal {
@@ -42,32 +42,30 @@ Core::NavigationView NavigationWidgetFactory::createWidget()
/*!
Returns a settings prefix for \a position.
*/
static QString settingsPrefix(int position)
static Key settingsPrefix(int position)
{
return QString::fromLatin1("ClassView.Treewidget.%1.FlatMode").arg(position);
return numberedKey("ClassView.Treewidget.", position) + ".FlatMode";
}
//! Flat mode settings
void NavigationWidgetFactory::saveSettings(Utils::QtcSettings *settings,
int position,
QWidget *widget)
void NavigationWidgetFactory::saveSettings(QtcSettings *settings, int position, QWidget *widget)
{
auto pw = qobject_cast<NavigationWidget *>(widget);
QTC_ASSERT(pw, return);
// .beginGroup is not used - to prevent simultaneous access
QString settingsGroup = settingsPrefix(position);
Key settingsGroup = settingsPrefix(position);
settings->setValue(settingsGroup, pw->flatMode());
}
void NavigationWidgetFactory::restoreSettings(Utils::QtcSettings *settings, int position, QWidget *widget)
void NavigationWidgetFactory::restoreSettings(QtcSettings *settings, int position, QWidget *widget)
{
auto pw = qobject_cast<NavigationWidget *>(widget);
QTC_ASSERT(pw, return);
// .beginGroup is not used - to prevent simultaneous access
QString settingsGroup = settingsPrefix(position);
Key settingsGroup = settingsPrefix(position);
pw->setFlatMode(settings->value(settingsGroup, false).toBool());
}

View File

@@ -490,8 +490,8 @@ void ActionManagerPrivate::readUserSettings(Id id, Command *cmd)
void ActionManagerPrivate::saveSettings(Command *cmd)
{
const QString id = cmd->id().toString();
const QString settingsKey = QLatin1String(kKeyboardSettingsKeyV2) + '/' + id;
const Key id = cmd->id().toKey();
const Key settingsKey = kKeyboardSettingsKeyV2 + '/' + id;
const QList<QKeySequence> keys = cmd->keySequences();
const QList<QKeySequence> defaultKeys = cmd->defaultKeySequences();
if (keys != defaultKeys) {

View File

@@ -327,8 +327,8 @@ void NewDialogWidget::showDialog()
{
QModelIndex idx;
QString lastPlatform = ICore::settings()->value(QLatin1String(LAST_PLATFORM_KEY)).toString();
QString lastCategory = ICore::settings()->value(QLatin1String(LAST_CATEGORY_KEY)).toString();
QString lastPlatform = ICore::settings()->value(LAST_PLATFORM_KEY).toString();
QString lastCategory = ICore::settings()->value(LAST_CATEGORY_KEY).toString();
if (!lastPlatform.isEmpty()) {
int index = m_comboBox->findData(lastPlatform);

View File

@@ -861,7 +861,7 @@ void FolderNavigationWidgetFactory::restoreSettings(QtcSettings *settings, int p
{
auto fnw = qobject_cast<FolderNavigationWidget *>(widget);
QTC_ASSERT(fnw, return);
const QString base = kSettingsBase + QString::number(position);
const Key base = kSettingsBase + Key::number(position);
fnw->setHiddenFilesFilter(settings->value(base + kHiddenFilesKey, kHiddenFilesDefault).toBool());
fnw->setAutoSynchronization(settings->value(base + kSyncKey, kAutoSyncDefault).toBool());
fnw->setShowBreadCrumbs(

View File

@@ -263,7 +263,7 @@ QString GeneralSettingsWidget::language()
void GeneralSettingsWidget::setLanguage(const QString &locale)
{
QtcSettings *settings = ICore::settings();
if (settings->value(QLatin1String("General/OverrideLanguage")).toString() != locale) {
if (settings->value("General/OverrideLanguage").toString() != locale) {
RestartDialog dialog(ICore::dialogParent(),
Tr::tr("The language change will take effect after restart."));
dialog.exec();

View File

@@ -1477,12 +1477,12 @@ void DebuggerPluginPrivate::parseCommandLineArguments()
QTimer::singleShot(0, this, &DebuggerPluginPrivate::runScheduled);
}
static void setConfigValue(const QString &name, const QVariant &value)
static void setConfigValue(const Key &name, const QVariant &value)
{
ICore::settings()->setValue("DebugMode/" + name, value);
}
static QVariant configValue(const QString &name)
static QVariant configValue(const Key &name)
{
return ICore::settings()->value("DebugMode/" + name);
}
@@ -1658,7 +1658,7 @@ void DebuggerPluginPrivate::reloadDebuggingHelpers()
void DebuggerPluginPrivate::startRemoteCdbSession()
{
const QString connectionKey = "CdbRemoteConnection";
const Key connectionKey = "CdbRemoteConnection";
Kit *kit = findUniversalCdbKit();
QTC_ASSERT(kit, return);

View File

@@ -4,12 +4,20 @@
#include "settingsmanager.h"
#include <coreplugin/icore.h>
#include <utils/qtcassert.h>
#include <QSettings>
#include <QDebug>
using namespace Utils;
using namespace Designer::Internal;
namespace Designer::Internal {
static Key addPrefix(const QString &name)
{
Key result = keyFromString(name);
if (Core::ICore::settings()->group().isEmpty())
result.prepend("Designer");
return result;
}
void SettingsManager::beginGroup(const QString &prefix)
{
@@ -41,10 +49,4 @@ void SettingsManager::remove(const QString &key)
Core::ICore::settings()->remove(addPrefix(key));
}
QString SettingsManager::addPrefix(const QString &name) const
{
QString result = name;
if (Core::ICore::settings()->group().isEmpty())
result.prepend("Designer");
return result;
}
} // Designer::Internal

View File

@@ -21,9 +21,6 @@ public:
void setValue(const QString &key, const QVariant &value) override;
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const override;
void remove(const QString &key) override;
private:
QString addPrefix(const QString &name) const;
};
} // namespace Internal

View File

@@ -29,13 +29,14 @@
#include <QtHelp/QHelpLink>
using namespace Core;
static const char kUserDocumentationKey[] = "Help/UserDocumentation";
static const char kUpdateDocumentationTask[] = "UpdateDocumentationTask";
using namespace Utils;
namespace Help {
namespace Internal {
const char kUserDocumentationKey[] = "Help/UserDocumentation";
const char kUpdateDocumentationTask[] = "UpdateDocumentationTask";
struct HelpManagerPrivate
{
HelpManagerPrivate() = default;
@@ -357,8 +358,8 @@ HelpManagerPrivate::~HelpManagerPrivate()
const QStringList HelpManagerPrivate::documentationFromInstaller()
{
QSettings *installSettings = ICore::settings();
const QStringList documentationPaths = installSettings->value(QLatin1String("Help/InstalledDocumentation"))
QtcSettings *installSettings = ICore::settings();
const QStringList documentationPaths = installSettings->value("Help/InstalledDocumentation")
.toStringList();
QStringList documentationFiles;
for (const QString &path : documentationPaths) {
@@ -377,8 +378,7 @@ const QStringList HelpManagerPrivate::documentationFromInstaller()
void HelpManagerPrivate::readSettings()
{
m_userRegisteredFiles = Utils::toSet(ICore::settings()->value(QLatin1String(kUserDocumentationKey))
.toStringList());
m_userRegisteredFiles = Utils::toSet(ICore::settings()->value(kUserDocumentationKey).toStringList());
}
void HelpManagerPrivate::writeSettings()

View File

@@ -249,7 +249,7 @@ HelpPluginPrivate::HelpPluginPrivate()
Core::HelpManager::HelpModeAlways);
});
const QString qdsStandaloneEntry = "QML/Designer/StandAloneMode"; //entry from designer settings
const Key qdsStandaloneEntry = "QML/Designer/StandAloneMode"; //entry from designer settings
const bool isDesigner = Core::ICore::settings()->value(qdsStandaloneEntry, false).toBool();
action = new QAction(Tr::tr("Report Bug..."), this);

View File

@@ -221,8 +221,7 @@ DeviceSettingsWidget::DeviceSettingsWidget()
addButton->setEnabled(hasDeviceFactories);
int lastIndex = ICore::settings()
->value(QLatin1String(LastDeviceIndexKey), 0).toInt();
int lastIndex = ICore::settings()->value(LastDeviceIndexKey, 0).toInt();
if (lastIndex == -1)
lastIndex = 0;
if (lastIndex < m_configurationComboBox->count())

View File

@@ -76,6 +76,11 @@ static void warnAboutUnsupportedKeys(const QVariantMap &map, const QString &name
}
}
static Key fullSettingsKey(const QString &fieldKey)
{
return "Wizards/" + keyFromString(fieldKey);
}
// --------------------------------------------------------------------
// Helper:
@@ -1413,9 +1418,4 @@ JsonFieldPage::Field *JsonFieldPage::createFieldData(const QString &type)
return nullptr;
}
QString JsonFieldPage::fullSettingsKey(const QString &fieldKey)
{
return "Wizards/" + fieldKey;
}
} // namespace ProjectExplorer

View File

@@ -126,7 +126,6 @@ private:
static QHash<QString, FieldFactory> m_factories;
static Field *createFieldData(const QString &type);
static QString fullSettingsKey(const QString &fieldKey);
QFormLayout *m_formLayout;
QLabel *m_errorLabel;

View File

@@ -2216,7 +2216,7 @@ void ProjectExplorerPluginPrivate::savePersistentSettings()
}
QtcSettings *s = ICore::settings();
s->remove(QLatin1String("ProjectExplorer/RecentProjects/Files"));
s->remove("ProjectExplorer/RecentProjects/Files");
QStringList fileNames;
QStringList displayNames;

View File

@@ -661,7 +661,7 @@ void ProjectTreeWidgetFactory::restoreSettings(QtcSettings *settings, int positi
{
auto ptw = qobject_cast<ProjectTreeWidget *>(widget);
Q_ASSERT(ptw);
const QString baseKey = kBaseKey + QString::number(position);
const Key baseKey = kBaseKey + Key::number(position);
ptw->setProjectFilter(
settings->value(baseKey + kProjectFilterKey, kProjectFilterDefault).toBool());
ptw->setGeneratedFilesFilter(

View File

@@ -62,7 +62,7 @@ using namespace Internal;
const char DETECT_X64_AS_X32_KEY[] = "ProjectExplorer/Toolchains/DetectX64AsX32";
static QString badToolchainsKey() { return {"BadToolChains"}; }
static Key badToolchainsKey() { return "BadToolChains"; }
// --------------------------------------------------------------------------
// ToolChainManager

View File

@@ -29,6 +29,7 @@
using namespace ProjectExplorer;
using namespace QtSupport;
using namespace Utils;
namespace QmakeProjectManager {
namespace Internal {
@@ -88,9 +89,9 @@ QString QtWizard::templateDir()
bool QtWizard::lowerCaseFiles()
{
QString lowerCaseSettingsKey = QLatin1String(CppEditor::Constants::CPPEDITOR_SETTINGSGROUP);
lowerCaseSettingsKey += QLatin1Char('/');
lowerCaseSettingsKey += QLatin1String(CppEditor::Constants::LOWERCASE_CPPFILES_KEY);
Key lowerCaseSettingsKey = CppEditor::Constants::CPPEDITOR_SETTINGSGROUP;
lowerCaseSettingsKey += '/';
lowerCaseSettingsKey += CppEditor::Constants::LOWERCASE_CPPFILES_KEY;
const bool lowerCaseDefault = CppEditor::Constants::LOWERCASE_CPPFILES_DEFAULT;
return Core::ICore::settings()->value(lowerCaseSettingsKey, QVariant(lowerCaseDefault)).toBool();
}

View File

@@ -178,15 +178,15 @@ void StudioSettingsPage::apply()
QSettings *s = Core::ICore::settings();
const QString value = m_pathChooserExamples->filePath().toString();
if (s->value(Paths::exampleDownloadPath.toString(), false).toString() != value) {
s->setValue(Paths::exampleDownloadPath.toString(), value);
if (s->value(Paths::exampleDownloadPath, false).toString() != value) {
s->setValue(Paths::exampleDownloadPath, value);
emit examplesDownloadPathChanged(value);
}
const QString bundlesPath = m_pathChooserBundles->filePath().toString();
if (s->value(Paths::bundlesDownloadPath.toString()).toString() != bundlesPath) {
s->setValue(Paths::bundlesDownloadPath.toString(), bundlesPath);
if (s->value(Paths::bundlesDownloadPath).toString() != bundlesPath) {
s->setValue(Paths::bundlesDownloadPath, bundlesPath);
emit bundlesDownloadPathChanged(bundlesPath);
const QString restartText = tr("Changing bundle path will take effect after restart.");

View File

@@ -30,15 +30,13 @@ Utils::FilePath defaultBundlesPath()
QString examplesPathSetting()
{
return Core::ICore::settings()
->value(exampleDownloadPath.toString(), defaultExamplesPath().toString())
return Core::ICore::settings()->value(exampleDownloadPath, defaultExamplesPath().toString())
.toString();
}
QString bundlesPathSetting()
{
return Core::ICore::settings()
->value(bundlesDownloadPath.toString(), defaultBundlesPath().toString())
return Core::ICore::settings()->value(bundlesDownloadPath, defaultBundlesPath().toString())
.toString();
}

View File

@@ -9,8 +9,8 @@
namespace QmlDesigner::Paths {
inline constexpr QStringView exampleDownloadPath = u"StudioConfig/ExamplesDownloadPath";
inline constexpr QStringView bundlesDownloadPath = u"StudioConfig/BundlesDownloadPath";
constexpr char exampleDownloadPath[] = "StudioConfig/ExamplesDownloadPath";
constexpr char bundlesDownloadPath[] = "StudioConfig/BundlesDownloadPath";
QMLDESIGNERBASE_EXPORT Utils::FilePath defaultExamplesPath();
QMLDESIGNERBASE_EXPORT Utils::FilePath defaultBundlesPath();

View File

@@ -49,13 +49,13 @@ Q_GLOBAL_STATIC_WITH_ARGS(QVersionNumber, minQtVersionForCategories, (6, 5, 1));
void ExampleSetModel::writeCurrentIdToSettings(int currentIndex) const
{
QSettings *settings = Core::ICore::settings();
settings->setValue(QLatin1String(kSelectedExampleSetKey), getId(currentIndex));
QtcSettings *settings = Core::ICore::settings();
settings->setValue(kSelectedExampleSetKey, getId(currentIndex));
}
int ExampleSetModel::readCurrentIndexFromSettings() const
{
QVariant id = Core::ICore::settings()->value(QLatin1String(kSelectedExampleSetKey));
QVariant id = Core::ICore::settings()->value(kSelectedExampleSetKey);
for (int i=0; i < rowCount(); i++) {
if (id == getId(i))
return i;

View File

@@ -12,7 +12,9 @@
#include <QHBoxLayout>
#include <QToolButton>
using namespace ScxmlEditor::Common;
using namespace Utils;
namespace ScxmlEditor::Common {
const char C_SETTINGS_COLORPICKER_LASTUSEDCOLORS[] = "ScxmlEditor/ColorPickerLastUsedColors_%1";
constexpr int C_BUTTON_COLUMNS_COUNT = 5;
@@ -55,15 +57,15 @@ ColorPicker::ColorPicker(const QString &key, QWidget *parent)
}.attachTo(this);
const QStringList lastColors = Core::ICore::settings()->value(
QString::fromLatin1(C_SETTINGS_COLORPICKER_LASTUSEDCOLORS).arg(m_key), QStringList()).toStringList();
C_SETTINGS_COLORPICKER_LASTUSEDCOLORS + keyFromString(m_key), QStringList()).toStringList();
for (int i = lastColors.count(); i--;)
setLastUsedColor(lastColors[i]);
}
ColorPicker::~ColorPicker()
{
Core::ICore::settings()->setValue(QString::fromLatin1(C_SETTINGS_COLORPICKER_LASTUSEDCOLORS).arg(m_key),
m_lastUsedColorNames);
Core::ICore::settings()->setValue(
C_SETTINGS_COLORPICKER_LASTUSEDCOLORS + keyFromString(m_key), m_lastUsedColorNames);
}
void ColorPicker::setLastUsedColor(const QString &colorName)
@@ -99,3 +101,5 @@ QToolButton *ColorPicker::createButton(const QColor &color)
return button;
}
} // ScxmlEditor::Common

View File

@@ -10,9 +10,7 @@ class QHBoxLayout;
class QToolButton;
QT_END_NAMESPACE
namespace ScxmlEditor {
namespace Common {
namespace ScxmlEditor::Common {
class ColorPicker : public QFrame
{
@@ -37,5 +35,4 @@ private:
QHBoxLayout *m_lastUsedColorContainer;
};
} // namespace Common
} // namespace ScxmlEditor
} // namespace ScxmlEditor::Common

View File

@@ -57,7 +57,7 @@ void DataModelDownloader::usageStatisticsDownloadExample(const QString &name)
bool DataModelDownloader::downloadEnabled() const
{
const QString lastQDSVersionEntry = "QML/Designer/EnableWelcomePageDownload";
const Key lastQDSVersionEntry = "QML/Designer/EnableWelcomePageDownload";
return Core::ICore::settings()->value(lastQDSVersionEntry, false).toBool();
}

View File

@@ -516,7 +516,7 @@ void StudioWelcomePlugin::initialize()
static bool forceDownLoad()
{
const QString lastQDSVersionEntry = "QML/Designer/ForceWelcomePageDownload";
const Key lastQDSVersionEntry = "QML/Designer/ForceWelcomePageDownload";
return Core::ICore::settings()->value(lastQDSVersionEntry, false).toBool();
}

View File

@@ -143,10 +143,10 @@ QWidget *FindInFiles::createConfigWidget()
[this] { setSearchDir(m_directory->filePath()); });
connect(this, &BaseFileFind::searchDirChanged, m_directory, &PathChooser::setFilePath);
m_directory->setHistoryCompleter(HistoryKey, /*restoreLastItemFromHistory=*/ true);
if (!HistoryCompleter::historyExistsFor(QLatin1String(HistoryKey))) {
if (!HistoryCompleter::historyExistsFor(HistoryKey)) {
auto completer = static_cast<HistoryCompleter *>(m_directory->lineEdit()->completer());
const QStringList legacyHistory = ICore::settings()->value(
QLatin1String("Find/FindInFiles/directories")).toStringList();
"Find/FindInFiles/directories").toStringList();
for (const QString &dir: legacyHistory)
completer->addEntry(dir);
}

View File

@@ -600,7 +600,7 @@ void BookmarkManager::saveBookmarks()
QDataStream stream(&bookmarks, QIODevice::WriteOnly);
readBookmarksRecursive(treeModel->invisibleRootItem(), stream, 0);
Core::ICore::settings()->setValue(QLatin1String(kBookmarksKey), bookmarks);
Core::ICore::settings()->setValue(kBookmarksKey, bookmarks);
}
QStringList BookmarkManager::bookmarkFolders() const