Utils: Use numberedKey(Key, int) more wildly

Will ease transition to a key class that doen's have ::number()

Change-Id: Ib2f2957c916f41b0731a2033422bfbf7e429bcc8
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2023-08-30 09:18:19 +02:00
parent 9dc9a43f40
commit 41184bc9fc
18 changed files with 53 additions and 53 deletions

View File

@@ -90,7 +90,7 @@ void DebugServerProviderManager::restoreProviders()
const int count = data.value(countKeyC, 0).toInt();
for (int i = 0; i < count; ++i) {
const Key key = dataKeyC + Key::number(i);
const Key key = numberedKey(dataKeyC, i);
if (!data.contains(key))
break;
@@ -132,8 +132,8 @@ void DebugServerProviderManager::saveProviders()
p->toMap(tmp);
if (tmp.isEmpty())
continue;
const Key key = dataKeyC + Key::number(count);
data.insert(key, QVariant::fromValue(tmp));
const Key key = numberedKey(dataKeyC, count);
data.insert(key, variantFromStore(tmp));
++count;
}
}

View File

@@ -186,7 +186,7 @@ void CMakeToolSettingsAccessor::saveCMakeTools(const QList<CMakeTool *> &cmakeTo
Store tmp = item->toMap();
if (tmp.isEmpty())
continue;
data.insert(CMAKE_TOOL_DATA_KEY + Key::number(count), variantFromStore(tmp));
data.insert(numberedKey(CMAKE_TOOL_DATA_KEY, count), variantFromStore(tmp));
++count;
}
}
@@ -202,7 +202,7 @@ CMakeToolSettingsAccessor::cmakeTools(const Store &data, bool fromSdk) const
int count = data.value(CMAKE_TOOL_COUNT_KEY, 0).toInt();
for (int i = 0; i < count; ++i) {
const Key key = CMAKE_TOOL_DATA_KEY + Key::number(i);
const Key key = numberedKey(CMAKE_TOOL_DATA_KEY, i);
if (!data.contains(key))
continue;

View File

@@ -835,13 +835,13 @@ const bool kShowBreadCrumbsDefault = true;
const bool kRootAutoSyncDefault = true;
const bool kShowFoldersOnTopDefault = true;
void FolderNavigationWidgetFactory::saveSettings(Utils::QtcSettings *settings,
void FolderNavigationWidgetFactory::saveSettings(QtcSettings *settings,
int position,
QWidget *widget)
{
auto fnw = qobject_cast<FolderNavigationWidget *>(widget);
QTC_ASSERT(fnw, return);
const Key base = kSettingsBase + Key::number(position);
const Key base = numberedKey(kSettingsBase, position);
settings->setValueWithDefault(base + kHiddenFilesKey,
fnw->hiddenFilesFilter(),
kHiddenFilesDefault);
@@ -861,7 +861,7 @@ void FolderNavigationWidgetFactory::restoreSettings(QtcSettings *settings, int p
{
auto fnw = qobject_cast<FolderNavigationWidget *>(widget);
QTC_ASSERT(fnw, return);
const Key base = kSettingsBase + Key::number(position);
const Key base = numberedKey(kSettingsBase, position);
fnw->setHiddenFilesFilter(settings->value(base + kHiddenFilesKey, kHiddenFilesDefault).toBool());
fnw->setAutoSynchronization(settings->value(base + kSyncKey, kAutoSyncDefault).toBool());
fnw->setShowBreadCrumbs(

View File

@@ -756,7 +756,7 @@ void DebuggerItemModel::readDebuggers(const FilePath &fileName, bool isSystem)
int count = data.value(DEBUGGER_COUNT_KEY, 0).toInt();
for (int i = 0; i < count; ++i) {
const Key key = DEBUGGER_DATA_KEY + Key::number(i);
const Key key = numberedKey(DEBUGGER_DATA_KEY, i);
if (!data.contains(key))
continue;
const Store dbMap = storeFromVariant(data.value(key));
@@ -813,7 +813,7 @@ void DebuggerItemModel::saveDebuggers()
if (item.isValid() && item.engineType() != NoEngineType) {
Store tmp = item.toMap();
if (!tmp.isEmpty()) {
data.insert(DEBUGGER_DATA_KEY + Key::number(count), variantFromStore(tmp));
data.insert(numberedKey(DEBUGGER_DATA_KEY, count), variantFromStore(tmp));
++count;
}
}

View File

@@ -23,7 +23,7 @@ namespace Internal {
static Key entryName(int index)
{
return Constants::ToolsSettings::ENTRY_KEY + Key::number(index);
return numberedKey(Constants::ToolsSettings::ENTRY_KEY, index);
}
ToolsSettingsAccessor::ToolsSettingsAccessor()

View File

@@ -381,8 +381,8 @@ void BuildConfiguration::toMap(Store &map) const
EnvironmentItem::toStringList(d->m_userEnvironmentChanges));
map.insert(BUILD_STEP_LIST_COUNT, 2);
map.insert(BUILD_STEP_LIST_PREFIX + Key::number(0), variantFromStore(d->m_buildSteps.toMap()));
map.insert(BUILD_STEP_LIST_PREFIX + Key::number(1), variantFromStore(d->m_cleanSteps.toMap()));
map.insert(numberedKey(BUILD_STEP_LIST_PREFIX, 0), variantFromStore(d->m_buildSteps.toMap()));
map.insert(numberedKey(BUILD_STEP_LIST_PREFIX, 1), variantFromStore(d->m_cleanSteps.toMap()));
map.insert(PARSE_STD_OUT_KEY, d->m_parseStdOut);
map.insert(CUSTOM_PARSERS_KEY, transform(d->m_customParsers, &Id::toSetting));
@@ -401,7 +401,7 @@ void BuildConfiguration::fromMap(const Store &map)
int maxI = map.value(BUILD_STEP_LIST_COUNT, 0).toInt();
for (int i = 0; i < maxI; ++i) {
Store data = storeFromVariant(map.value(BUILD_STEP_LIST_PREFIX + Key::number(i)));
Store data = storeFromVariant(map.value(numberedKey(BUILD_STEP_LIST_PREFIX, i)));
if (data.isEmpty()) {
qWarning() << "No data for build step list" << i << "found!";
continue;

View File

@@ -62,7 +62,7 @@ Store BuildStepList::toMap() const
for (int i = 0; i < m_steps.count(); ++i) {
Store data;
m_steps.at(i)->toMap(data);
map.insert(STEPS_PREFIX + Key::number(i), variantFromStore(data));
map.insert(numberedKey(STEPS_PREFIX, i), variantFromStore(data));
}
return map;
@@ -111,7 +111,7 @@ bool BuildStepList::fromMap(const Store &map)
int maxSteps = map.value(STEPS_COUNT_KEY, 0).toInt();
for (int i = 0; i < maxSteps; ++i) {
Store bsData = storeFromVariant(map.value(STEPS_PREFIX + Key::number(i)));
Store bsData = storeFromVariant(map.value(numberedKey(STEPS_PREFIX, i)));
if (bsData.isEmpty()) {
qWarning() << "No step data found for" << i << "(continuing).";
continue;

View File

@@ -181,7 +181,7 @@ Store EditorConfiguration::toMap() const
{"language", QVariant::fromValue(itCodeStyle.key().toSetting())},
{"value", QVariant::fromValue(itCodeStyle.value()->toMap())}
};
map.insert(kCodeStylePrefix + Key::number(i), variantFromStore(settingsIdMap));
map.insert(numberedKey(kCodeStylePrefix, i), variantFromStore(settingsIdMap));
i++;
}
@@ -204,7 +204,7 @@ void EditorConfiguration::fromMap(const Store &map)
const int codeStyleCount = map.value(kCodeStyleCount, 0).toInt();
for (int i = 0; i < codeStyleCount; ++i) {
Store settingsIdMap = storeFromVariant(map.value(kCodeStylePrefix + Key::number(i)));
Store settingsIdMap = storeFromVariant(map.value(numberedKey(kCodeStylePrefix, i)));
if (settingsIdMap.isEmpty()) {
qWarning() << "No data for code style settings list" << i << "found!";
continue;

View File

@@ -448,7 +448,7 @@ void KitManager::saveKits()
Store tmp = k->toMap();
if (tmp.isEmpty())
continue;
data.insert(KIT_DATA_KEY + Key::number(count), variantFromStore(tmp));
data.insert(numberedKey(KIT_DATA_KEY, count), variantFromStore(tmp));
++count;
}
data.insert(KIT_COUNT_KEY, count);
@@ -514,7 +514,7 @@ static KitList restoreKitsHelper(const FilePath &fileName)
const int count = data.value(KIT_COUNT_KEY, 0).toInt();
for (int i = 0; i < count; ++i) {
const Key key = KIT_DATA_KEY + Key::number(i);
const Key key = numberedKey(KIT_DATA_KEY, i);
if (!data.contains(key))
break;

View File

@@ -698,7 +698,7 @@ void Project::toMap(Store &map) const
map.insert(ACTIVE_TARGET_KEY, ts.indexOf(d->m_activeTarget));
map.insert(TARGET_COUNT_KEY, ts.size());
for (int i = 0; i < ts.size(); ++i)
map.insert(TARGET_KEY_PREFIX + Key::number(i), variantFromStore(ts.at(i)->toMap()));
map.insert(numberedKey(TARGET_KEY_PREFIX, i), variantFromStore(ts.at(i)->toMap()));
map.insert(EDITOR_SETTINGS_KEY, variantFromStore(d->m_editorConfiguration.toMap()));
if (!d->m_pluginSettings.isEmpty())
@@ -801,7 +801,7 @@ Project::RestoreResult Project::fromMap(const Store &map, QString *errorMessage)
void Project::createTargetFromMap(const Store &map, int index)
{
const Key key = TARGET_KEY_PREFIX + Key::number(index);
const Key key = numberedKey(TARGET_KEY_PREFIX, index);
if (!map.contains(key))
return;

View File

@@ -1703,7 +1703,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
for (int i = 0; i < customParserCount; ++i) {
CustomParserSettings settings;
settings.fromMap(storeFromVariant(
s->value(Constants::CUSTOM_PARSER_PREFIX_KEY + Key::number(i))));
s->value(numberedKey(Constants::CUSTOM_PARSER_PREFIX_KEY, i))));
dd->m_customParsers << settings;
}
@@ -2278,7 +2278,7 @@ void ProjectExplorerPluginPrivate::savePersistentSettings()
s->setValueWithDefault(Constants::CUSTOM_PARSER_COUNT_KEY, int(dd->m_customParsers.count()), 0);
for (int i = 0; i < dd->m_customParsers.count(); ++i) {
s->setValue(Constants::CUSTOM_PARSER_PREFIX_KEY + Key::number(i),
s->setValue(numberedKey(Constants::CUSTOM_PARSER_PREFIX_KEY, i),
variantFromStore(dd->m_customParsers.at(i).toMap()));
}
}

View File

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

View File

@@ -605,7 +605,7 @@ Store Target::toMap() const
for (int i = 0; i < bcs.size(); ++i) {
Store data;
bcs.at(i)->toMap(data);
map.insert(BC_KEY_PREFIX + Key::number(i), variantFromStore(data));
map.insert(numberedKey(BC_KEY_PREFIX, i), variantFromStore(data));
}
const QList<DeployConfiguration *> dcs = deployConfigurations();
@@ -614,7 +614,7 @@ Store Target::toMap() const
for (int i = 0; i < dcs.size(); ++i) {
Store data;
dcs.at(i)->toMap(data);
map.insert(DC_KEY_PREFIX + Key::number(i), variantFromStore(data));
map.insert(numberedKey(DC_KEY_PREFIX, i), variantFromStore(data));
}
const QList<RunConfiguration *> rcs = runConfigurations();
@@ -623,7 +623,7 @@ Store Target::toMap() const
for (int i = 0; i < rcs.size(); ++i) {
Store data;
rcs.at(i)->toMap(data);
map.insert(RC_KEY_PREFIX + Key::number(i), variantFromStore(data));
map.insert(numberedKey(RC_KEY_PREFIX, i), variantFromStore(data));
}
if (!d->m_pluginSettings.isEmpty())
@@ -900,7 +900,7 @@ bool Target::fromMap(const Store &map)
activeConfiguration = 0;
for (int i = 0; i < bcCount; ++i) {
const Key key = BC_KEY_PREFIX + Key::number(i);
const Key key = numberedKey(BC_KEY_PREFIX, i);
if (!map.contains(key))
return false;
const Store valueMap = storeFromVariant(map.value(key));
@@ -927,7 +927,7 @@ bool Target::fromMap(const Store &map)
activeConfiguration = 0;
for (int i = 0; i < dcCount; ++i) {
const Key key = DC_KEY_PREFIX + Key::number(i);
const Key key = numberedKey(DC_KEY_PREFIX, i);
if (!map.contains(key))
return false;
Store valueMap = storeFromVariant(map.value(key));
@@ -954,7 +954,7 @@ bool Target::fromMap(const Store &map)
activeConfiguration = 0;
for (int i = 0; i < rcCount; ++i) {
const Key key = RC_KEY_PREFIX + Key::number(i);
const Key key = numberedKey(RC_KEY_PREFIX, i);
if (!map.contains(key))
return false;

View File

@@ -224,7 +224,7 @@ void ToolChainSettingsAccessor::saveToolChains(const Toolchains &toolchains, QWi
tc->toMap(tmp);
if (tmp.isEmpty())
continue;
data.insert(TOOLCHAIN_DATA_KEY + Key::number(count), variantFromStore(tmp));
data.insert(numberedKey(TOOLCHAIN_DATA_KEY, count), variantFromStore(tmp));
++count;
}
data.insert(TOOLCHAIN_COUNT_KEY, count);
@@ -241,7 +241,7 @@ Toolchains ToolChainSettingsAccessor::toolChains(const Store &data) const
const int count = data.value(TOOLCHAIN_COUNT_KEY, 0).toInt();
for (int i = 0; i < count; ++i) {
const Key key = TOOLCHAIN_DATA_KEY + Key::number(i);
const Key key = numberedKey(TOOLCHAIN_DATA_KEY, i);
if (!data.contains(key))
break;

View File

@@ -494,7 +494,7 @@ UserFileVersion16Upgrader::OldStepMaps UserFileVersion16Upgrader::extractStepMap
int stepCount = stepListMap.value("ProjectExplorer.BuildStepList.StepsCount", 0).toInt();
Key stepKey = "ProjectExplorer.BuildStepList.Step.";
for (int i = 0; i < stepCount; ++i) {
Store stepMap = storeFromVariant(stepListMap.value(stepKey + Key::number(i)));
Store stepMap = storeFromVariant(stepListMap.value(numberedKey(stepKey, i)));
const QString id = stepMap.value("ProjectExplorer.ProjectConfiguration.Id").toString();
if (id == "Qt4ProjectManager.AndroidDeployQtStep")
result.androidDeployQt = stepMap;
@@ -516,10 +516,10 @@ Store UserFileVersion16Upgrader::removeAndroidPackageStep(Store deployMap)
Key stepKey = "ProjectExplorer.BuildStepList.Step.";
int targetPosition = 0;
for (int sourcePosition = 0; sourcePosition < stepCount; ++sourcePosition) {
Store stepMap = storeFromVariant(stepListMap.value(stepKey + Key::number(sourcePosition)));
Store stepMap = storeFromVariant(stepListMap.value(numberedKey(stepKey, sourcePosition)));
if (stepMap.value("ProjectExplorer.ProjectConfiguration.Id").toString()
!= "Qt4ProjectManager.AndroidPackageInstallationStep") {
stepListMap.insert(stepKey + Key::number(targetPosition), variantFromStore(stepMap));
stepListMap.insert(numberedKey(stepKey, targetPosition), variantFromStore(stepMap));
++targetPosition;
}
}
@@ -527,7 +527,7 @@ Store UserFileVersion16Upgrader::removeAndroidPackageStep(Store deployMap)
stepListMap.insert(stepCountKey, targetPosition);
for (int i = targetPosition; i < stepCount; ++i)
stepListMap.remove(stepKey + Key::number(i));
stepListMap.remove(numberedKey(stepKey, i));
deployMap.insert(stepListKey, variantFromStore(stepListMap));
return deployMap;
@@ -543,7 +543,7 @@ Store UserFileVersion16Upgrader::insertSteps(Store buildConfigurationMap,
const Key bslKey = "ProjectExplorer.BuildConfiguration.BuildStepList.";
const Key bslTypeKey = "ProjectExplorer.ProjectConfiguration.Id";
for (int bslNumber = 0; bslNumber < stepListCount; ++bslNumber) {
Store buildStepListMap = buildConfigurationMap.value(bslKey + Key::number(bslNumber)).value<Store>();
Store buildStepListMap = buildConfigurationMap.value(numberedKey(bslKey, bslNumber)).value<Store>();
if (buildStepListMap.value(bslTypeKey) != "ProjectExplorer.BuildSteps.Build")
continue;
@@ -565,7 +565,7 @@ Store UserFileVersion16Upgrader::insertSteps(Store buildConfigurationMap,
QString defaultDisplayName = oldStepMap.androidPackageInstall.value(defaultDisplayNameKey).toString();
bool enabled = oldStepMap.androidPackageInstall.value(enabledKey).toBool();
androidPackageInstallStep.insert(idKey, Utils::Id("Qt4ProjectManager.AndroidPackageInstallationStep").toSetting());
androidPackageInstallStep.insert(idKey, Id("Qt4ProjectManager.AndroidPackageInstallationStep").toSetting());
androidPackageInstallStep.insert(displayNameKey, displayName);
androidPackageInstallStep.insert(defaultDisplayNameKey, defaultDisplayName);
androidPackageInstallStep.insert(enabledKey, enabled);
@@ -574,7 +574,7 @@ Store UserFileVersion16Upgrader::insertSteps(Store buildConfigurationMap,
defaultDisplayName = oldStepMap.androidDeployQt.value(defaultDisplayNameKey).toString();
enabled = oldStepMap.androidDeployQt.value(enabledKey).toBool();
androidBuildApkStep.insert(idKey, Utils::Id("QmakeProjectManager.AndroidBuildApkStep").toSetting());
androidBuildApkStep.insert(idKey, Id("QmakeProjectManager.AndroidBuildApkStep").toSetting());
androidBuildApkStep.insert(displayNameKey, displayName);
androidBuildApkStep.insert(defaultDisplayNameKey, defaultDisplayName);
androidBuildApkStep.insert(enabledKey, enabled);
@@ -598,10 +598,10 @@ Store UserFileVersion16Upgrader::insertSteps(Store buildConfigurationMap,
androidBuildApkStep.insert(VerboseOutputKey, verbose);
const Key buildStepKey = "ProjectExplorer.BuildStepList.Step.";
buildStepListMap.insert(buildStepKey + Key::number(stepCount), variantFromStore(androidPackageInstallStep));
buildStepListMap.insert(buildStepKey + Key::number(stepCount + 1), variantFromStore(androidBuildApkStep));
buildStepListMap.insert(numberedKey(buildStepKey, stepCount), variantFromStore(androidPackageInstallStep));
buildStepListMap.insert(numberedKey(buildStepKey, stepCount + 1), variantFromStore(androidBuildApkStep));
buildConfigurationMap.insert(bslKey + Key::number(bslNumber), variantFromStore(buildStepListMap));
buildConfigurationMap.insert(numberedKey(bslKey, bslNumber), variantFromStore(buildStepListMap));
}
if (policy == RenameBuildConfiguration) {
@@ -637,7 +637,7 @@ Store UserFileVersion16Upgrader::upgrade(const Store &data)
Store result = data;
for (int i = 0; i < targetCount; ++i) {
Key targetKey = "ProjectExplorer.Project.Target." + Key::number(i);
Key targetKey = numberedKey("ProjectExplorer.Project.Target.", i);
Store targetMap = storeFromVariant(data.value(targetKey));
const Key dcCountKey = "ProjectExplorer.Target.DeployConfigurationCount";
@@ -651,12 +651,12 @@ Store UserFileVersion16Upgrader::upgrade(const Store &data)
Key deployKey = "ProjectExplorer.Target.DeployConfiguration.";
for (int j = 0; j < deployconfigurationCount; ++j) {
Store deployConfigurationMap
= storeFromVariant(targetMap.value(deployKey + Key::number(j)));
= storeFromVariant(targetMap.value(numberedKey(deployKey, j)));
OldStepMaps oldStep = extractStepMaps(deployConfigurationMap);
if (!oldStep.isEmpty()) {
oldSteps.append(oldStep);
deployConfigurationMap = removeAndroidPackageStep(deployConfigurationMap);
targetMap.insert(deployKey + Key::number(j), QVariant::fromValue(deployConfigurationMap));
targetMap.insert(numberedKey(deployKey, j), QVariant::fromValue(deployConfigurationMap));
}
}
@@ -672,7 +672,7 @@ Store UserFileVersion16Upgrader::upgrade(const Store &data)
Key bcKey = "ProjectExplorer.Target.BuildConfiguration.";
for (int j = 0; j < buildConfigurationCount; ++j) {
Store oldBuildConfigurationMap = storeFromVariant(targetMap.value(bcKey + Key::number(j)));
Store oldBuildConfigurationMap = storeFromVariant(targetMap.value(numberedKey(bcKey, j)));
oldBuildConfigurations.append(oldBuildConfigurationMap);
}
@@ -691,7 +691,7 @@ Store UserFileVersion16Upgrader::upgrade(const Store &data)
targetMap.insert(bcCountKey, newBuildConfigurations.size());
for (int j = 0; j < newBuildConfigurations.size(); ++j)
targetMap.insert(bcKey + Key::number(j), variantFromStore(newBuildConfigurations.at(j)));
targetMap.insert(numberedKey(bcKey, j), variantFromStore(newBuildConfigurations.at(j)));
result.insert(targetKey, variantFromStore(targetMap));
}

View File

@@ -442,7 +442,7 @@ public:
if (tmp.isEmpty())
continue;
data.insert(QNXConfigDataKey + Key::number(count), variantFromStore(tmp));
data.insert(numberedKey(QNXConfigDataKey, count), variantFromStore(tmp));
++count;
}
@@ -459,7 +459,7 @@ public:
Store data = reader.restoreValues();
int count = data.value(QNXConfigCountKey, 0).toInt();
for (int i = 0; i < count; ++i) {
const Key key = QNXConfigDataKey + Key::number(i);
const Key key = numberedKey(QNXConfigDataKey, i);
if (!data.contains(key))
continue;

View File

@@ -358,7 +358,7 @@ static void saveQtVersions()
if (tmp.isEmpty())
continue;
tmp.insert(QTVERSION_TYPE_KEY, qtv->type());
data.insert(QTVERSION_DATA_KEY + Key::number(count), QVariant::fromValue(tmp));
data.insert(numberedKey(QTVERSION_DATA_KEY, count), variantFromStore(tmp));
++count;
}
m_writer->save(data, Core::ICore::dialogParent());

View File

@@ -35,7 +35,7 @@ public:
Store upgrade(const Store &data) final
{
Store result = data;
result.insert("VERSION_" + Key::number(version()), version());
result.insert(numberedKey("VERSION_", version()), version());
return result;
}
};