diff options
author | hjk <hjk@qt.io> | 2022-11-29 15:15:12 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2022-11-30 06:57:02 +0000 |
commit | 4417c48e7b8f9564bb780b14b6ddfb9a209b7c87 (patch) | |
tree | aa45a4c9805dfcf1538ad9e5ccd0ff9eae85033b /src | |
parent | b183efc94ac0e5df2bc1c9892eedde5e499c415e (diff) | |
download | qt-creator-4417c48e7b8f9564bb780b14b6ddfb9a209b7c87.tar.gz |
Utils: Remove FilePath::operator+()
This was a alias for .stringAppended(), but can be used too easily
when .pathAppended() is meant.
Change-Id: Ia3b64d39828d4074b43d87c923ce3a6a87038948
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Diffstat (limited to 'src')
27 files changed, 53 insertions, 43 deletions
diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 57cafaba17..1680f9483e 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -586,7 +586,7 @@ static FilePaths appendExeExtensions(const Environment &env, const FilePath &exe const QStringList extensions = env.expandedValueForKey("PATHEXT").split(';'); for (const QString &ext : extensions) - execs << executable + ext.toLower(); + execs << executable.stringAppended(ext.toLower()); } } return execs; @@ -971,11 +971,6 @@ bool FilePath::operator>=(const FilePath &other) const return !(*this < other); } -FilePath FilePath::operator+(const QString &s) const -{ - return stringAppended(s); -} - /// \returns whether FilePath is a child of \a s bool FilePath::isChildOf(const FilePath &s) const { diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index cf9cf2cf1b..541a9555f7 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -137,7 +137,6 @@ public: bool operator<=(const FilePath &other) const; bool operator>(const FilePath &other) const; bool operator>=(const FilePath &other) const; - [[nodiscard]] FilePath operator+(const QString &s) const; [[nodiscard]] FilePath operator/(const QString &str) const; Qt::CaseSensitivity caseSensitivity() const; diff --git a/src/libs/utils/stringutils.cpp b/src/libs/utils/stringutils.cpp index 5012f0e00f..ccde4d474d 100644 --- a/src/libs/utils/stringutils.cpp +++ b/src/libs/utils/stringutils.cpp @@ -482,4 +482,14 @@ QTCREATOR_UTILS_EXPORT QStringView chopIfEndsWith(QStringView str, QChar c) return str; } +QTCREATOR_UTILS_EXPORT QString appendHelper(const QString &base, int n) +{ + return base + QString::number(n); +} + +QTCREATOR_UTILS_EXPORT FilePath appendHelper(const FilePath &base, int n) +{ + return base.stringAppended(QString::number(n)); +} + } // namespace Utils diff --git a/src/libs/utils/stringutils.h b/src/libs/utils/stringutils.h index fa1d4624b1..38019bf9c7 100644 --- a/src/libs/utils/stringutils.h +++ b/src/libs/utils/stringutils.h @@ -16,6 +16,8 @@ QT_END_NAMESPACE namespace Utils { +class FilePath; + // Create a usable settings key from a category, // for example Editor|C++ -> Editor_C__ QTCREATOR_UTILS_EXPORT QString settingsKey(const QString &category); @@ -68,15 +70,18 @@ QTCREATOR_UTILS_EXPORT QString expandMacros(const QString &str, AbstractMacroExp QTCREATOR_UTILS_EXPORT int parseUsedPortFromNetstatOutput(const QByteArray &line); +QTCREATOR_UTILS_EXPORT QString appendHelper(const QString &base, int n); +QTCREATOR_UTILS_EXPORT FilePath appendHelper(const FilePath &base, int n); + template<typename T> T makeUniquelyNumbered(const T &preferred, const std::function<bool(const T &)> &isOk) { if (isOk(preferred)) return preferred; int i = 2; - T tryName = preferred + QString::number(i); + T tryName = appendHelper(preferred, i); while (!isOk(tryName)) - tryName = preferred + QString::number(++i); + tryName = appendHelper(preferred, ++i); return tryName; } diff --git a/src/plugins/android/androidconfigurations.cpp b/src/plugins/android/androidconfigurations.cpp index b529d882f6..c7a1644684 100644 --- a/src/plugins/android/androidconfigurations.cpp +++ b/src/plugins/android/androidconfigurations.cpp @@ -246,7 +246,7 @@ void AndroidConfig::parseDependenciesJson() } if (sdkConfigFile.lastModified() > sdkConfigUserFile.lastModified()) { - const FilePath oldUserFile = sdkConfigUserFile + ".old"; + const FilePath oldUserFile = sdkConfigUserFile.stringAppended(".old"); oldUserFile.removeFile(); sdkConfigUserFile.renameFile(oldUserFile); sdkConfigFile.copyFile(sdkConfigUserFile); diff --git a/src/plugins/android/androidmanifesteditoriconwidget.cpp b/src/plugins/android/androidmanifesteditoriconwidget.cpp index 037ed684ca..558ecf573d 100644 --- a/src/plugins/android/androidmanifesteditoriconwidget.cpp +++ b/src/plugins/android/androidmanifesteditoriconwidget.cpp @@ -137,7 +137,7 @@ void AndroidManifestEditorIconWidget::setIconFromPath(const FilePath &iconPath) } } copyIcon(); - FilePath iconFile = baseDir + m_targetIconPath + m_targetIconFileName; + FilePath iconFile = baseDir / m_targetIconPath / m_targetIconFileName; m_button->setIcon(QIcon(iconFile.toString())); } diff --git a/src/plugins/android/androidqmlpreviewworker.cpp b/src/plugins/android/androidqmlpreviewworker.cpp index e89f87dfbc..4e58d8b53c 100644 --- a/src/plugins/android/androidqmlpreviewworker.cpp +++ b/src/plugins/android/androidqmlpreviewworker.cpp @@ -320,8 +320,8 @@ FilePath AndroidQmlPreviewWorker::createQmlrcFile(const FilePath &workFolder, const QtSupport::QtVersion *qtVersion = QtSupport::QtKitAspect::qtVersion(m_rc->kit()); const FilePath rccBinary = qtVersion->rccFilePath(); QtcProcess rccProcess; - FilePath qrcPath = FilePath::fromString(basename) + ".qrc4viewer"; - const FilePath qmlrcPath = FilePath::fromString(QDir::tempPath()) / basename + packageSuffix; + FilePath qrcPath = FilePath::fromString(basename + ".qrc4viewer"); + const FilePath qmlrcPath = FilePath::fromString(QDir::tempPath()) / (basename + packageSuffix); rccProcess.setWorkingDirectory(workFolder); diff --git a/src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp b/src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp index cbe47956d2..f28ec89338 100644 --- a/src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp +++ b/src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp @@ -109,8 +109,8 @@ void ArtisticStyleSettings::setCustomStyle(const QString &customStyle) QString ArtisticStyleSettings::documentationFilePath() const { return (Core::ICore::userResourcePath(Beautifier::Constants::SETTINGS_DIRNAME) - / Beautifier::Constants::DOCUMENTATION_DIRNAME / SETTINGS_NAME - + ".xml") + / Beautifier::Constants::DOCUMENTATION_DIRNAME / SETTINGS_NAME) + .stringAppended(".xml") .toString(); } diff --git a/src/plugins/beautifier/clangformat/clangformatsettings.cpp b/src/plugins/beautifier/clangformat/clangformatsettings.cpp index c0940b4d99..c0924b5930 100644 --- a/src/plugins/beautifier/clangformat/clangformatsettings.cpp +++ b/src/plugins/beautifier/clangformat/clangformatsettings.cpp @@ -35,8 +35,8 @@ ClangFormatSettings::ClangFormatSettings() : QString ClangFormatSettings::documentationFilePath() const { return (Core::ICore::userResourcePath() / Beautifier::Constants::SETTINGS_DIRNAME - / Beautifier::Constants::DOCUMENTATION_DIRNAME / SETTINGS_NAME - + ".xml") + / Beautifier::Constants::DOCUMENTATION_DIRNAME / SETTINGS_NAME) + .stringAppended(".xml") .toString(); } diff --git a/src/plugins/beautifier/uncrustify/uncrustifysettings.cpp b/src/plugins/beautifier/uncrustify/uncrustifysettings.cpp index 80abe53e13..4d480e2319 100644 --- a/src/plugins/beautifier/uncrustify/uncrustifysettings.cpp +++ b/src/plugins/beautifier/uncrustify/uncrustifysettings.cpp @@ -120,8 +120,8 @@ void UncrustifySettings::setFormatEntireFileFallback(bool formatEntireFileFallba QString UncrustifySettings::documentationFilePath() const { return (Core::ICore::userResourcePath() / Beautifier::Constants::SETTINGS_DIRNAME - / Beautifier::Constants::DOCUMENTATION_DIRNAME / SETTINGS_NAME - + ".xml") + / Beautifier::Constants::DOCUMENTATION_DIRNAME / SETTINGS_NAME) + .stringAppended(".xml") .toString(); } diff --git a/src/plugins/clangtools/executableinfo.cpp b/src/plugins/clangtools/executableinfo.cpp index 148411c85c..5da9cb76d0 100644 --- a/src/plugins/clangtools/executableinfo.cpp +++ b/src/plugins/clangtools/executableinfo.cpp @@ -220,7 +220,7 @@ QPair<FilePath, QString> getClangIncludeDirAndVersion(const FilePath &clangToolP const QString dynamicVersion = queryVersion(clangToolPath, QueryFailMode::Noisy); if (dynamicResourceDir.isEmpty() || dynamicVersion.isEmpty()) return {FilePath::fromString(CLANG_INCLUDE_DIR), QString(CLANG_VERSION)}; - return {dynamicResourceDir + "/include", dynamicVersion}; + return {dynamicResourceDir / "include", dynamicVersion}; } QHash<Utils::FilePath, QPair<QDateTime, ClazyStandaloneInfo>> ClazyStandaloneInfo::cache; diff --git a/src/plugins/clangtools/virtualfilesystemoverlay.cpp b/src/plugins/clangtools/virtualfilesystemoverlay.cpp index 16b3864533..e4bd3b6222 100644 --- a/src/plugins/clangtools/virtualfilesystemoverlay.cpp +++ b/src/plugins/clangtools/virtualfilesystemoverlay.cpp @@ -44,7 +44,7 @@ void VirtualFileSystemOverlay::update() QString error; saved.path = m_root.filePath(doc->filePath().fileName() + ".auto"); while (saved.path.exists()) - saved.path = saved.path + ".1"; + saved.path = saved.path.stringAppended(".1"); if (!doc->save(&error, saved.path, true)) { qCDebug(LOG) << error; continue; diff --git a/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp b/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp index 4f8d1e42cb..8af9c183db 100644 --- a/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp +++ b/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp @@ -761,13 +761,13 @@ static FilePath getUserFilePath(const QString &proposalFileName) const FilePath newFilePath = externalToolsDir / proposal.baseName(); int count = 0; - FilePath tryPath = newFilePath + suffix; + FilePath tryPath = newFilePath.stringAppended(suffix); while (tryPath.exists()) { if (++count > 15) return {}; // add random number const int number = QRandomGenerator::global()->generate() % 1000; - tryPath = newFilePath + QString::number(number) + suffix; + tryPath = newFilePath.stringAppended(QString::number(number) + suffix); } return tryPath; } diff --git a/src/plugins/debugger/shared/cdbsymbolpathlisteditor.cpp b/src/plugins/debugger/shared/cdbsymbolpathlisteditor.cpp index 7e161ac462..56d0f531f5 100644 --- a/src/plugins/debugger/shared/cdbsymbolpathlisteditor.cpp +++ b/src/plugins/debugger/shared/cdbsymbolpathlisteditor.cpp @@ -129,7 +129,7 @@ CdbSymbolPathListEditor::CdbSymbolPathListEditor(QWidget *parent) : bool CdbSymbolPathListEditor::promptCacheDirectory(QWidget *parent, FilePath *cacheDirectory) { CacheDirectoryDialog dialog(parent); - dialog.setPath(TemporaryDirectory::masterDirectoryFilePath() + "/symbolcache"); + dialog.setPath(TemporaryDirectory::masterDirectoryFilePath() / "symbolcache"); if (dialog.exec() != QDialog::Accepted) return false; *cacheDirectory = dialog.path(); @@ -155,7 +155,7 @@ void CdbSymbolPathListEditor::setupSymbolPaths() if (path.isEmpty() && indexOfSymbolCache != -1) path = FilePath::fromString(currentPaths.at(indexOfSymbolCache)); if (path.isEmpty()) - path = TemporaryDirectory::masterDirectoryFilePath() + "/symbolcache"; + path = TemporaryDirectory::masterDirectoryFilePath() / "symbolcache"; bool useSymbolServer = true; bool useSymbolCache = true; diff --git a/src/plugins/help/generalsettingspage.cpp b/src/plugins/help/generalsettingspage.cpp index 9ec864e0b8..4ad13c26c6 100644 --- a/src/plugins/help/generalsettingspage.cpp +++ b/src/plugins/help/generalsettingspage.cpp @@ -396,9 +396,9 @@ void GeneralSettingsPage::exportBookmarks() QLatin1String suffix(".xbel"); if (!filePath.endsWith(suffix)) - filePath = filePath + suffix; + filePath = filePath.stringAppended(suffix); - Utils::FileSaver saver(filePath); + FileSaver saver(filePath); if (!saver.hasError()) { XbelWriter writer(LocalHelpManager::bookmarkManager().treeBookmarkModel()); writer.writeToFile(saver.file()); diff --git a/src/plugins/perfprofiler/perfprofilertool.cpp b/src/plugins/perfprofiler/perfprofilertool.cpp index ae0b470d88..07aee796d7 100644 --- a/src/plugins/perfprofiler/perfprofilertool.cpp +++ b/src/plugins/perfprofiler/perfprofilertool.cpp @@ -624,7 +624,7 @@ void PerfProfilerTool::showSaveTraceDialog() if (filePath.isEmpty()) return; if (!filePath.endsWith(".ptq")) - filePath = filePath + ".ptq"; + filePath = filePath.stringAppended(".ptq"); setToolActionsEnabled(false); m_traceManager->saveToTraceFile(filePath.toString()); diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp index afb7eca08c..c5667920a5 100644 --- a/src/plugins/projectexplorer/project.cpp +++ b/src/plugins/projectexplorer/project.cpp @@ -1056,12 +1056,12 @@ bool Project::isEditModePreferred() const #if defined(WITH_TESTS) -static FilePath constructTestPath(const char *basePath) +static FilePath constructTestPath(const QString &basePath) { FilePath drive; if (HostOsInfo::isWindowsHost()) drive = "C:"; - return drive + QLatin1String(basePath); + return drive.stringAppended(basePath); } const FilePath TEST_PROJECT_PATH = constructTestPath("/tmp/foobar/baz.project"); diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index dc31ba12fa..75cf8aea01 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -2260,7 +2260,7 @@ void ProjectExplorerPlugin::extensionsInitialized() .searchInPath(gitBinary, gitSearchPaths); if (!fullGitPath.isEmpty()) { searchPaths << fullGitPath.parentDir() - << fullGitPath.parentDir().parentDir() + "/usr/bin"; + << fullGitPath.parentDir().parentDir().pathAppended("usr/bin"); } } return searchPaths; diff --git a/src/plugins/qmakeprojectmanager/customwidgetwizard/plugingenerator.cpp b/src/plugins/qmakeprojectmanager/customwidgetwizard/plugingenerator.cpp index d0fb9414ab..1188fb047d 100644 --- a/src/plugins/qmakeprojectmanager/customwidgetwizard/plugingenerator.cpp +++ b/src/plugins/qmakeprojectmanager/customwidgetwizard/plugingenerator.cpp @@ -293,7 +293,7 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara const QString proFileContents = processTemplate(p.templatePath + QLatin1String("/tpl_plugin.pro"), sm, errorMessage); if (proFileContents.isEmpty()) return QList<Core::GeneratedFile>(); - Core::GeneratedFile proFile(baseDir / p.fileName + QLatin1String(".pro")); + Core::GeneratedFile proFile(baseDir.pathAppended(p.fileName + ".pro")); proFile.setContents(proFileContents); proFile.setAttributes(Core::GeneratedFile::OpenProjectAttribute); rc.push_back(proFile); diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp index 56969199a9..c962bb01a8 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp @@ -1376,7 +1376,8 @@ void QmakeBuildSystem::collectLibraryData(const QmakeProFile *file, DeploymentDa targetFileName += QLatin1Char('.'); while (!versionComponents.isEmpty()) { const QString versionString = versionComponents.join(QLatin1Char('.')); - deploymentData.addFile(destDirFor(ti) / targetFileName + versionString, + deploymentData.addFile(destDirFor(ti).pathAppended(targetFileName + + versionString), targetPath); versionComponents.removeLast(); } diff --git a/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp b/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp index 01045080e2..03e8ddde28 100644 --- a/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp +++ b/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp @@ -208,7 +208,7 @@ void BaseQmakeProjectWizardDialog::generateProfileName(const QString &name, if (!m_targetSetupPage) return; - const Utils::FilePath proFile = path / name / name + ".pro"; + const Utils::FilePath proFile = path / name / (name + ".pro"); m_targetSetupPage->setProjectPath(proFile); } diff --git a/src/plugins/qmldesigner/components/componentcore/formatoperation.cpp b/src/plugins/qmldesigner/components/componentcore/formatoperation.cpp index a09ca32bcd..2858e48735 100644 --- a/src/plugins/qmldesigner/components/componentcore/formatoperation.cpp +++ b/src/plugins/qmldesigner/components/componentcore/formatoperation.cpp @@ -37,7 +37,7 @@ void readFormatConfiguration(){ if (copyableProperties.isEmpty()){ QString source = "formatconfiguration.json"; - Utils::FilePath path = Core::ICore::resourcePath() + "/qmldesigner/" + source; + Utils::FilePath path = Core::ICore::resourcePath("qmldesigner") / source; QString errorString; Utils::FileReader reader; diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index fa7b1f5255..e694f19956 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -587,7 +587,7 @@ void QmlProfilerTool::showSaveDialog() Tr::tr("QML traces (*%1 *%2)").arg(zFile).arg(tFile)); if (!filePath.isEmpty()) { if (!filePath.endsWith(zFile) && !filePath.endsWith(tFile)) - filePath = filePath + zFile; + filePath = filePath.stringAppended(zFile); saveLastTraceFile(filePath); Debugger::enableMainWindow(false); Core::ProgressManager::addTask(d->m_profilerModelManager->save(filePath.toString()), diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp index 208d2482fc..3444525437 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.cpp +++ b/src/plugins/qmlprojectmanager/qmlproject.cpp @@ -125,7 +125,7 @@ QmlProject::QmlProject(const Utils::FilePath &fileName) }); } else { Utils::FilePaths uiFiles = getUiQmlFilesForFolder(projectDirectory() - + "/content"); + / "content"); if (uiFiles.isEmpty()) uiFiles = getUiQmlFilesForFolder(projectDirectory()); diff --git a/src/plugins/remotelinux/genericlinuxdeviceconfigurationwizardpages.cpp b/src/plugins/remotelinux/genericlinuxdeviceconfigurationwizardpages.cpp index 247a78f0a7..69befe5ddd 100644 --- a/src/plugins/remotelinux/genericlinuxdeviceconfigurationwizardpages.cpp +++ b/src/plugins/remotelinux/genericlinuxdeviceconfigurationwizardpages.cpp @@ -256,7 +256,7 @@ void GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::createKey() void GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::deployKey() { - PublicKeyDeploymentDialog dlg(d->device, privateKeyFilePath() + ".pub", this); + PublicKeyDeploymentDialog dlg(d->device, privateKeyFilePath().stringAppended(".pub"), this); d->iconLabel.setPixmap((dlg.exec() == QDialog::Accepted ? Icons::OK : Icons::BROKEN).pixmap()); } diff --git a/src/plugins/studiowelcome/studiowelcomeplugin.cpp b/src/plugins/studiowelcome/studiowelcomeplugin.cpp index faf17d5f62..a819a88eb1 100644 --- a/src/plugins/studiowelcome/studiowelcomeplugin.cpp +++ b/src/plugins/studiowelcome/studiowelcomeplugin.cpp @@ -262,11 +262,11 @@ public: Q_UNUSED(explicitQmlproject) Q_UNUSED(tempFile) Q_UNUSED(completeBaseName) - const Utils::FilePath projectFile = Core::ICore::resourcePath("examples") - / example / example + ".qmlproject"; + const FilePath projectFile = Core::ICore::resourcePath("examples") + / example / (example + ".qmlproject"); ProjectExplorer::ProjectExplorerPlugin::openProjectWelcomePage(projectFile); - const Utils::FilePath qmlFile = Core::ICore::resourcePath("examples") - / example / formFile; + const FilePath qmlFile = Core::ICore::resourcePath("examples") + / example / formFile; Core::EditorManager::openEditor(qmlFile); } diff --git a/src/plugins/webassembly/webassemblyrunconfiguration.cpp b/src/plugins/webassembly/webassemblyrunconfiguration.cpp index bdbc58e7ed..3e741378ca 100644 --- a/src/plugins/webassembly/webassemblyrunconfiguration.cpp +++ b/src/plugins/webassembly/webassemblyrunconfiguration.cpp @@ -45,7 +45,7 @@ static CommandLine emrunCommand(const Target *target, const FilePath emrun = env.searchInPath("emrun"); const FilePath emrunPy = emrun.absolutePath().pathAppended(emrun.baseName() + ".py"); const FilePath targetPath = bc->buildSystem()->buildTarget(buildKey).targetFilePath; - const FilePath html = targetPath.absolutePath() / targetPath.baseName() + ".html"; + const FilePath html = targetPath.absolutePath() / (targetPath.baseName() + ".html"); QStringList args(emrunPy.path()); if (!browser.isEmpty()) { |