From 898053533a54ccdceb568d5efa80c24d1ad64b43 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 30 Sep 2022 15:57:27 +0200 Subject: [PATCH] ProjectExplorer: Limit the usage of qMakePair Make the code less verbose. Change-Id: If9fe08a6a7538d34c80ca97a2aec21a2bd6e5d22 Reviewed-by: Christian Kandeler --- src/libs/utils/settingsaccessor.h | 2 +- src/plugins/projectexplorer/customparser.cpp | 5 +- .../devicesupport/devicefilesystemmodel.cpp | 2 +- src/plugins/projectexplorer/gcctoolchain.cpp | 4 +- .../projectexplorer/kitinformation.cpp | 3 +- src/plugins/projectexplorer/msvcparser.cpp | 4 +- .../projectexplorer/projectexplorer.cpp | 8 +- .../runsettingspropertiespage.cpp | 2 +- src/plugins/projectexplorer/session.cpp | 2 +- .../projectexplorer/targetsetupwidget.cpp | 4 +- src/plugins/projectexplorer/taskwindow.cpp | 2 +- src/plugins/projectexplorer/toolchain.cpp | 2 +- .../projectexplorer/toolchainoptionspage.cpp | 2 +- .../projectexplorer/userfileaccessor.cpp | 75 +++++++++---------- 14 files changed, 56 insertions(+), 61 deletions(-) diff --git a/src/libs/utils/settingsaccessor.h b/src/libs/utils/settingsaccessor.h index bf8b15ce943..f5965626de9 100644 --- a/src/libs/utils/settingsaccessor.h +++ b/src/libs/utils/settingsaccessor.h @@ -207,7 +207,7 @@ public: virtual QVariantMap upgrade(const QVariantMap &data) = 0; protected: - using Change = QPair; + using Change = QPair; QVariantMap renameKeys(const QList &changes, QVariantMap map) const; private: diff --git a/src/plugins/projectexplorer/customparser.cpp b/src/plugins/projectexplorer/customparser.cpp index 946b4074e8a..7bcc18a6210 100644 --- a/src/plugins/projectexplorer/customparser.cpp +++ b/src/plugins/projectexplorer/customparser.cpp @@ -306,9 +306,8 @@ private: parserCheckBoxes.clear(); for (const CustomParserSettings &s : ProjectExplorerPlugin::customParsers()) { const auto checkBox = new QCheckBox(s.displayName, this); - connect(checkBox, &QCheckBox::stateChanged, - this, &SelectionWidget::selectionChanged); - parserCheckBoxes << qMakePair(checkBox, s.id); + connect(checkBox, &QCheckBox::stateChanged, this, &SelectionWidget::selectionChanged); + parserCheckBoxes.push_back({checkBox, s.id}); layout->addWidget(checkBox); } setSelectedParsers(parsers); diff --git a/src/plugins/projectexplorer/devicesupport/devicefilesystemmodel.cpp b/src/plugins/projectexplorer/devicesupport/devicefilesystemmodel.cpp index f1eff39a521..29858efe3e2 100644 --- a/src/plugins/projectexplorer/devicesupport/devicefilesystemmodel.cpp +++ b/src/plugins/projectexplorer/devicesupport/devicefilesystemmodel.cpp @@ -236,7 +236,7 @@ static void dirEntries(QFutureInterface &futureInterface, const File for (const FilePath &entry : entries) { if (futureInterface.isCanceled()) return; - result.append(qMakePair(entry, fileType(entry))); + result.push_back({entry, fileType(entry)}); } futureInterface.reportResult(result); } diff --git a/src/plugins/projectexplorer/gcctoolchain.cpp b/src/plugins/projectexplorer/gcctoolchain.cpp index 3461b7e7c4e..0b2b37fbcf5 100644 --- a/src/plugins/projectexplorer/gcctoolchain.cpp +++ b/src/plugins/projectexplorer/gcctoolchain.cpp @@ -616,7 +616,7 @@ HeaderPaths GccToolChain::builtInHeaderPaths(const Utils::Environment &env, if (!originalTargetTriple.isEmpty()) arguments << "-target" << originalTargetTriple; - const std::optional cachedPaths = headerCache->check(qMakePair(env, arguments)); + const std::optional cachedPaths = headerCache->check({env, arguments}); if (cachedPaths) return cachedPaths.value(); @@ -624,7 +624,7 @@ HeaderPaths GccToolChain::builtInHeaderPaths(const Utils::Environment &env, arguments, env); extraHeaderPathsFunction(paths); - headerCache->insert(qMakePair(env, arguments), paths); + headerCache->insert({env, arguments}, paths); qCDebug(gccLog) << "Reporting header paths to code model:"; for (const HeaderPath &hp : qAsConst(paths)) { diff --git a/src/plugins/projectexplorer/kitinformation.cpp b/src/plugins/projectexplorer/kitinformation.cpp index 556cade2299..22675f4e672 100644 --- a/src/plugins/projectexplorer/kitinformation.cpp +++ b/src/plugins/projectexplorer/kitinformation.cpp @@ -1532,8 +1532,7 @@ KitAspectWidget *EnvironmentKitAspect::createConfigWidget(Kit *k) const KitAspect::ItemList EnvironmentKitAspect::toUserOutput(const Kit *k) const { - return { qMakePair(tr("Environment"), - EnvironmentItem::toStringList(environmentChanges(k)).join("
")) }; + return {{tr("Environment"), EnvironmentItem::toStringList(environmentChanges(k)).join("
")}}; } Id EnvironmentKitAspect::id() diff --git a/src/plugins/projectexplorer/msvcparser.cpp b/src/plugins/projectexplorer/msvcparser.cpp index 3d1c4511e43..bf9c731ce16 100644 --- a/src/plugins/projectexplorer/msvcparser.cpp +++ b/src/plugins/projectexplorer/msvcparser.cpp @@ -19,7 +19,7 @@ static QPair parseFileName(const QString &input) { QString fileName = input; if (fileName.startsWith("LINK") || fileName.startsWith("cl")) - return qMakePair(FilePath(), -1); + return {{}, -1}; // Extract linenumber (if it is there): int linenumber = -1; @@ -39,7 +39,7 @@ static QPair parseFileName(const QString &input) } } const QString normalized = FileUtils::normalizedPathName(fileName); - return qMakePair(FilePath::fromUserInput(normalized), linenumber); + return {FilePath::fromUserInput(normalized), linenumber}; } using namespace ProjectExplorer; diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 030e92da3cf..8ef24d8ed30 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -3247,7 +3247,7 @@ QList> ProjectExplorerPlugin::runningRunContro const QList runControls = allRunControls(); for (RunControl *rc : runControls) { if (rc->isRunning()) - processes << qMakePair(rc->commandLine(), rc->applicationProcessHandle()); + processes.push_back({rc->commandLine(), rc->applicationProcessHandle()}); } return processes; } @@ -3420,7 +3420,7 @@ void ProjectExplorerPluginPrivate::addToRecentProjects(const FilePath &filePath, if (m_recentProjects.count() > m_maxRecentProjects) m_recentProjects.removeLast(); - m_recentProjects.prepend(qMakePair(filePath, displayName)); + m_recentProjects.push_front({filePath, displayName}); m_lastOpenDirectory = filePath.absolutePath(); emit m_instance->recentProjectsChanged(); } @@ -3947,10 +3947,10 @@ void ProjectExplorerPluginPrivate::removeFile() const FilePath filePath = currentNode->filePath(); using NodeAndPath = QPair; - QList filesToRemove{qMakePair(currentNode, currentNode->filePath())}; + QList filesToRemove{{currentNode, currentNode->filePath()}}; QList siblings; for (const Node * const n : ProjectTree::siblingsWithSameBaseName(currentNode)) - siblings << qMakePair(n, n->filePath()); + siblings.push_back({n, n->filePath()}); RemoveFileDialog removeFileDialog(filePath, ICore::dialogParent()); if (removeFileDialog.exec() != QDialog::Accepted) diff --git a/src/plugins/projectexplorer/runsettingspropertiespage.cpp b/src/plugins/projectexplorer/runsettingspropertiespage.cpp index 5a3ba7f6507..354440b4baf 100644 --- a/src/plugins/projectexplorer/runsettingspropertiespage.cpp +++ b/src/plugins/projectexplorer/runsettingspropertiespage.cpp @@ -486,7 +486,7 @@ void RunSettingsWidget::addSubWidget(QWidget *widget, QLabel *label) l->addWidget(label, l->rowCount(), 0, 1, -1); l->addWidget(widget, l->rowCount(), 0, 1, -1); - m_subWidgets.append(qMakePair(widget, label)); + m_subWidgets.push_back({widget, label}); } void RunSettingsWidget::removeSubWidgets() diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp index 051fb287aa0..12a6bcf5452 100644 --- a/src/plugins/projectexplorer/session.cpp +++ b/src/plugins/projectexplorer/session.cpp @@ -635,7 +635,7 @@ QStringList SessionManagerPrivate::dependenciesOrder() const return p->projectFilePath().toString() == proPath; }); }); - unordered << qMakePair(proName, depList); + unordered.push_back({proName, depList}); } while (!unordered.isEmpty()) { diff --git a/src/plugins/projectexplorer/targetsetupwidget.cpp b/src/plugins/projectexplorer/targetsetupwidget.cpp index 78888d2aba4..12c7880b65e 100644 --- a/src/plugins/projectexplorer/targetsetupwidget.cpp +++ b/src/plugins/projectexplorer/targetsetupwidget.cpp @@ -338,7 +338,7 @@ void TargetSetupWidget::reportIssues(int index) QPair TargetSetupWidget::findIssues(const BuildInfo &info) { if (m_projectPath.isEmpty() || !info.factory) - return qMakePair(Task::Unknown, QString()); + return {Task::Unknown, {}}; QString buildDir = info.buildDirectory.toString(); Tasks issues; @@ -364,7 +364,7 @@ QPair TargetSetupWidget::findIssues(const BuildInfo &in } if (!text.isEmpty()) text = QLatin1String("") + text; - return qMakePair(highestType, text); + return {highestType, text}; } TargetSetupWidget::BuildInfoStore::~BuildInfoStore() diff --git a/src/plugins/projectexplorer/taskwindow.cpp b/src/plugins/projectexplorer/taskwindow.cpp index 4570161c112..977b494d525 100644 --- a/src/plugins/projectexplorer/taskwindow.cpp +++ b/src/plugins/projectexplorer/taskwindow.cpp @@ -930,7 +930,7 @@ void TaskDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, + startOffset, positions.top() + linePos.y()); const QSize linkSize(endOffset - startOffset, linkLine.height()); const QRectF linkRect(linkPos, linkSize); - m_hrefs << qMakePair(linkRect, range.format.anchorHref()); + m_hrefs.push_back({linkRect, range.format.anchorHref()}); } } diff --git a/src/plugins/projectexplorer/toolchain.cpp b/src/plugins/projectexplorer/toolchain.cpp index 0776ef7ce0f..d0b9d92e86f 100644 --- a/src/plugins/projectexplorer/toolchain.cpp +++ b/src/plugins/projectexplorer/toolchain.cpp @@ -596,7 +596,7 @@ static QPair rawIdData(const QVariantMap &data) const QString raw = data.value(QLatin1String(ID_KEY)).toString(); const int pos = raw.indexOf(QLatin1Char(':')); QTC_ASSERT(pos > 0, return qMakePair(QString::fromLatin1("unknown"), QString::fromLatin1("unknown"))); - return qMakePair(raw.mid(0, pos), raw.mid(pos + 1)); + return {raw.mid(0, pos), raw.mid(pos + 1)}; } QByteArray ToolChainFactory::idFromMap(const QVariantMap &data) diff --git a/src/plugins/projectexplorer/toolchainoptionspage.cpp b/src/plugins/projectexplorer/toolchainoptionspage.cpp index 5f261888785..33a564c8b88 100644 --- a/src/plugins/projectexplorer/toolchainoptionspage.cpp +++ b/src/plugins/projectexplorer/toolchainoptionspage.cpp @@ -157,7 +157,7 @@ public: autoRoot->appendChild(autoNode); manualRoot->appendChild(manualNode); - m_languageMap.insert(l, qMakePair(autoNode, manualNode)); + m_languageMap.insert(l, {autoNode, manualNode}); } m_model.rootItem()->appendChild(autoRoot); diff --git a/src/plugins/projectexplorer/userfileaccessor.cpp b/src/plugins/projectexplorer/userfileaccessor.cpp index f1057fe9628..86814054895 100644 --- a/src/plugins/projectexplorer/userfileaccessor.cpp +++ b/src/plugins/projectexplorer/userfileaccessor.cpp @@ -27,6 +27,8 @@ using namespace Utils; using namespace ProjectExplorer; using namespace ProjectExplorer::Internal; +using StringVariantPair = std::pair; + namespace { const char OBSOLETE_VERSION_KEY[] = "ProjectExplorer.Project.Updater.FileVersion"; @@ -331,13 +333,13 @@ UserFileAccessor::merge(const MergingSettingsAccessor::SettingsMergeData &global return std::nullopt; if (isHouseKeepingKey(key) || global.key == USER_STICKY_KEYS_KEY) - return qMakePair(key, mainValue); + return {{key, mainValue}}; if (!stickyKeys.contains(global.key) && secondaryValue != mainValue && !secondaryValue.isNull()) - return qMakePair(key, secondaryValue); + return {{key, secondaryValue}}; if (!mainValue.isNull()) - return qMakePair(key, mainValue); - return qMakePair(key, secondaryValue); + return {{key, mainValue}}; + return {{key, secondaryValue}}; } // When saving settings... @@ -360,7 +362,7 @@ SettingsMergeFunction UserFileAccessor::userStickyTrackerFunction(QStringList &s return std::nullopt; if (isHouseKeepingKey(key)) - return qMakePair(key, main); + return {{key, main}}; // Ignore house keeping keys: if (key == USER_STICKY_KEYS_KEY) @@ -369,7 +371,7 @@ SettingsMergeFunction UserFileAccessor::userStickyTrackerFunction(QStringList &s // Track keys that changed in main from the value in secondary: if (main != secondary && !secondary.isNull() && !stickyKeys.contains(global.key)) stickyKeys.append(global.key); - return qMakePair(key, main); + return {{key, main}}; }; } @@ -471,15 +473,10 @@ QVariantMap UserFileVersion14Upgrader::upgrade(const QVariantMap &map) QVariantMap UserFileVersion15Upgrader::upgrade(const QVariantMap &map) { - QList changes; - changes.append(qMakePair(QLatin1String("ProjectExplorer.Project.Updater.EnvironmentId"), - QLatin1String("EnvironmentId"))); - // This is actually handled in the SettingsAccessor itself: - // changes.append(qMakePair(QLatin1String("ProjectExplorer.Project.Updater.FileVersion"), - // QLatin1String("Version"))); - changes.append(qMakePair(QLatin1String("ProjectExplorer.Project.UserStickyKeys"), - QLatin1String("UserStickyKeys"))); - + const QList changes{{QLatin1String("ProjectExplorer.Project.Updater.EnvironmentId"), + QLatin1String("EnvironmentId")}, + {QLatin1String("ProjectExplorer.Project.UserStickyKeys"), + QLatin1String("UserStickyKeys")}}; return renameKeys(changes, QVariantMap(map)); } @@ -744,12 +741,12 @@ QVariant UserFileVersion18Upgrader::process(const QVariant &entry) return Utils::transform(entry.toList(), &UserFileVersion18Upgrader::process); case QVariant::Map: return Utils::transform>( - entry.toMap().toStdMap(), [](const std::pair &item) { + entry.toMap().toStdMap(), [](const StringVariantPair &item) -> StringVariantPair { const QString key = (item.first == "AutotoolsProjectManager.MakeStep.AdditionalArguments" ? QString("AutotoolsProjectManager.MakeStep.MakeArguments") : item.first); - return qMakePair(key, UserFileVersion18Upgrader::process(item.second)); + return {key, UserFileVersion18Upgrader::process(item.second)}; }); default: return entry; @@ -798,24 +795,24 @@ QVariant UserFileVersion19Upgrader::process(const QVariant &entry, const QString return Utils::transform(entry.toList(), std::bind(&UserFileVersion19Upgrader::process, std::placeholders::_1, path)); case QVariant::Map: - return Utils::transform( - entry.toMap().toStdMap(), [&](const std::pair &item) { - if (path.size() == 2 && path.at(1).startsWith("ProjectExplorer.Target.RunConfiguration.")) { - if (argsKeys.contains(item.first)) - return qMakePair(QString("RunConfiguration.Arguments"), item.second); - if (wdKeys.contains(item.first)) - return qMakePair(QString("RunConfiguration.WorkingDirectory"), item.second); - if (termKeys.contains(item.first)) - return qMakePair(QString("RunConfiguration.UseTerminal"), item.second); - if (libsKeys.contains(item.first)) - return qMakePair(QString("RunConfiguration.UseLibrarySearchPath"), item.second); - if (dyldKeys.contains(item.first)) - return qMakePair(QString("RunConfiguration.UseDyldImageSuffix"), item.second); - } - QStringList newPath = path; - newPath.append(item.first); - return qMakePair(item.first, UserFileVersion19Upgrader::process(item.second, newPath)); - }); + return Utils::transform(entry.toMap().toStdMap(), + [&](const StringVariantPair &item) -> StringVariantPair { + if (path.size() == 2 && path.at(1).startsWith("ProjectExplorer.Target.RunConfiguration.")) { + if (argsKeys.contains(item.first)) + return {"RunConfiguration.Arguments", item.second}; + if (wdKeys.contains(item.first)) + return {"RunConfiguration.WorkingDirectory", item.second}; + if (termKeys.contains(item.first)) + return {"RunConfiguration.UseTerminal", item.second}; + if (libsKeys.contains(item.first)) + return {"RunConfiguration.UseLibrarySearchPath", item.second}; + if (dyldKeys.contains(item.first)) + return {"RunConfiguration.UseDyldImageSuffix", item.second}; + } + QStringList newPath = path; + newPath.append(item.first); + return {item.first, UserFileVersion19Upgrader::process(item.second, newPath)}; + }); default: return entry; } @@ -833,8 +830,8 @@ QVariant UserFileVersion20Upgrader::process(const QVariant &entry) return Utils::transform(entry.toList(), &UserFileVersion20Upgrader::process); case QVariant::Map: return Utils::transform>( - entry.toMap().toStdMap(), [](const std::pair &item) { - auto res = qMakePair(item.first, item.second); + entry.toMap().toStdMap(), [](const StringVariantPair &item) { + StringVariantPair res = {item.first, item.second}; if (item.first == "ProjectExplorer.ProjectConfiguration.Id" && item.second == "Qbs.Deploy") res.second = QVariant("ProjectExplorer.DefaultDeployConfiguration"); @@ -865,8 +862,8 @@ QVariant UserFileVersion21Upgrader::process(const QVariant &entry) return entryMap; } return Utils::transform( - entryMap.toStdMap(), [](const std::pair &item) { - return qMakePair(item.first, UserFileVersion21Upgrader::process(item.second)); + entryMap.toStdMap(), [](const StringVariantPair &item) -> StringVariantPair{ + return {item.first, UserFileVersion21Upgrader::process(item.second)}; }); } default: