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>
This commit is contained in:
hjk
2022-11-29 15:15:12 +01:00
parent b183efc94a
commit 4417c48e7b
28 changed files with 58 additions and 48 deletions

View File

@@ -586,7 +586,7 @@ static FilePaths appendExeExtensions(const Environment &env, const FilePath &exe
const QStringList extensions = env.expandedValueForKey("PATHEXT").split(';'); const QStringList extensions = env.expandedValueForKey("PATHEXT").split(';');
for (const QString &ext : extensions) for (const QString &ext : extensions)
execs << executable + ext.toLower(); execs << executable.stringAppended(ext.toLower());
} }
} }
return execs; return execs;
@@ -971,11 +971,6 @@ bool FilePath::operator>=(const FilePath &other) const
return !(*this < other); return !(*this < other);
} }
FilePath FilePath::operator+(const QString &s) const
{
return stringAppended(s);
}
/// \returns whether FilePath is a child of \a s /// \returns whether FilePath is a child of \a s
bool FilePath::isChildOf(const FilePath &s) const bool FilePath::isChildOf(const FilePath &s) const
{ {

View File

@@ -137,7 +137,6 @@ public:
bool operator<=(const FilePath &other) const; bool operator<=(const FilePath &other) const;
bool operator>(const FilePath &other) const; 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; [[nodiscard]] FilePath operator/(const QString &str) const;
Qt::CaseSensitivity caseSensitivity() const; Qt::CaseSensitivity caseSensitivity() const;

View File

@@ -482,4 +482,14 @@ QTCREATOR_UTILS_EXPORT QStringView chopIfEndsWith(QStringView str, QChar c)
return str; 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 } // namespace Utils

View File

@@ -16,6 +16,8 @@ QT_END_NAMESPACE
namespace Utils { namespace Utils {
class FilePath;
// Create a usable settings key from a category, // Create a usable settings key from a category,
// for example Editor|C++ -> Editor_C__ // for example Editor|C++ -> Editor_C__
QTCREATOR_UTILS_EXPORT QString settingsKey(const QString &category); 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 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> template<typename T>
T makeUniquelyNumbered(const T &preferred, const std::function<bool(const T &)> &isOk) T makeUniquelyNumbered(const T &preferred, const std::function<bool(const T &)> &isOk)
{ {
if (isOk(preferred)) if (isOk(preferred))
return preferred; return preferred;
int i = 2; int i = 2;
T tryName = preferred + QString::number(i); T tryName = appendHelper(preferred, i);
while (!isOk(tryName)) while (!isOk(tryName))
tryName = preferred + QString::number(++i); tryName = appendHelper(preferred, ++i);
return tryName; return tryName;
} }

View File

@@ -246,7 +246,7 @@ void AndroidConfig::parseDependenciesJson()
} }
if (sdkConfigFile.lastModified() > sdkConfigUserFile.lastModified()) { if (sdkConfigFile.lastModified() > sdkConfigUserFile.lastModified()) {
const FilePath oldUserFile = sdkConfigUserFile + ".old"; const FilePath oldUserFile = sdkConfigUserFile.stringAppended(".old");
oldUserFile.removeFile(); oldUserFile.removeFile();
sdkConfigUserFile.renameFile(oldUserFile); sdkConfigUserFile.renameFile(oldUserFile);
sdkConfigFile.copyFile(sdkConfigUserFile); sdkConfigFile.copyFile(sdkConfigUserFile);

View File

@@ -137,7 +137,7 @@ void AndroidManifestEditorIconWidget::setIconFromPath(const FilePath &iconPath)
} }
} }
copyIcon(); copyIcon();
FilePath iconFile = baseDir + m_targetIconPath + m_targetIconFileName; FilePath iconFile = baseDir / m_targetIconPath / m_targetIconFileName;
m_button->setIcon(QIcon(iconFile.toString())); m_button->setIcon(QIcon(iconFile.toString()));
} }

View File

@@ -320,8 +320,8 @@ FilePath AndroidQmlPreviewWorker::createQmlrcFile(const FilePath &workFolder,
const QtSupport::QtVersion *qtVersion = QtSupport::QtKitAspect::qtVersion(m_rc->kit()); const QtSupport::QtVersion *qtVersion = QtSupport::QtKitAspect::qtVersion(m_rc->kit());
const FilePath rccBinary = qtVersion->rccFilePath(); const FilePath rccBinary = qtVersion->rccFilePath();
QtcProcess rccProcess; QtcProcess rccProcess;
FilePath qrcPath = FilePath::fromString(basename) + ".qrc4viewer"; FilePath qrcPath = FilePath::fromString(basename + ".qrc4viewer");
const FilePath qmlrcPath = FilePath::fromString(QDir::tempPath()) / basename + packageSuffix; const FilePath qmlrcPath = FilePath::fromString(QDir::tempPath()) / (basename + packageSuffix);
rccProcess.setWorkingDirectory(workFolder); rccProcess.setWorkingDirectory(workFolder);

View File

@@ -109,8 +109,8 @@ void ArtisticStyleSettings::setCustomStyle(const QString &customStyle)
QString ArtisticStyleSettings::documentationFilePath() const QString ArtisticStyleSettings::documentationFilePath() const
{ {
return (Core::ICore::userResourcePath(Beautifier::Constants::SETTINGS_DIRNAME) return (Core::ICore::userResourcePath(Beautifier::Constants::SETTINGS_DIRNAME)
/ Beautifier::Constants::DOCUMENTATION_DIRNAME / SETTINGS_NAME / Beautifier::Constants::DOCUMENTATION_DIRNAME / SETTINGS_NAME)
+ ".xml") .stringAppended(".xml")
.toString(); .toString();
} }

View File

@@ -35,8 +35,8 @@ ClangFormatSettings::ClangFormatSettings() :
QString ClangFormatSettings::documentationFilePath() const QString ClangFormatSettings::documentationFilePath() const
{ {
return (Core::ICore::userResourcePath() / Beautifier::Constants::SETTINGS_DIRNAME return (Core::ICore::userResourcePath() / Beautifier::Constants::SETTINGS_DIRNAME
/ Beautifier::Constants::DOCUMENTATION_DIRNAME / SETTINGS_NAME / Beautifier::Constants::DOCUMENTATION_DIRNAME / SETTINGS_NAME)
+ ".xml") .stringAppended(".xml")
.toString(); .toString();
} }

View File

@@ -120,8 +120,8 @@ void UncrustifySettings::setFormatEntireFileFallback(bool formatEntireFileFallba
QString UncrustifySettings::documentationFilePath() const QString UncrustifySettings::documentationFilePath() const
{ {
return (Core::ICore::userResourcePath() / Beautifier::Constants::SETTINGS_DIRNAME return (Core::ICore::userResourcePath() / Beautifier::Constants::SETTINGS_DIRNAME
/ Beautifier::Constants::DOCUMENTATION_DIRNAME / SETTINGS_NAME / Beautifier::Constants::DOCUMENTATION_DIRNAME / SETTINGS_NAME)
+ ".xml") .stringAppended(".xml")
.toString(); .toString();
} }

View File

@@ -220,7 +220,7 @@ QPair<FilePath, QString> getClangIncludeDirAndVersion(const FilePath &clangToolP
const QString dynamicVersion = queryVersion(clangToolPath, QueryFailMode::Noisy); const QString dynamicVersion = queryVersion(clangToolPath, QueryFailMode::Noisy);
if (dynamicResourceDir.isEmpty() || dynamicVersion.isEmpty()) if (dynamicResourceDir.isEmpty() || dynamicVersion.isEmpty())
return {FilePath::fromString(CLANG_INCLUDE_DIR), QString(CLANG_VERSION)}; 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; QHash<Utils::FilePath, QPair<QDateTime, ClazyStandaloneInfo>> ClazyStandaloneInfo::cache;

View File

@@ -44,7 +44,7 @@ void VirtualFileSystemOverlay::update()
QString error; QString error;
saved.path = m_root.filePath(doc->filePath().fileName() + ".auto"); saved.path = m_root.filePath(doc->filePath().fileName() + ".auto");
while (saved.path.exists()) while (saved.path.exists())
saved.path = saved.path + ".1"; saved.path = saved.path.stringAppended(".1");
if (!doc->save(&error, saved.path, true)) { if (!doc->save(&error, saved.path, true)) {
qCDebug(LOG) << error; qCDebug(LOG) << error;
continue; continue;

View File

@@ -761,13 +761,13 @@ static FilePath getUserFilePath(const QString &proposalFileName)
const FilePath newFilePath = externalToolsDir / proposal.baseName(); const FilePath newFilePath = externalToolsDir / proposal.baseName();
int count = 0; int count = 0;
FilePath tryPath = newFilePath + suffix; FilePath tryPath = newFilePath.stringAppended(suffix);
while (tryPath.exists()) { while (tryPath.exists()) {
if (++count > 15) if (++count > 15)
return {}; return {};
// add random number // add random number
const int number = QRandomGenerator::global()->generate() % 1000; const int number = QRandomGenerator::global()->generate() % 1000;
tryPath = newFilePath + QString::number(number) + suffix; tryPath = newFilePath.stringAppended(QString::number(number) + suffix);
} }
return tryPath; return tryPath;
} }

View File

@@ -129,7 +129,7 @@ CdbSymbolPathListEditor::CdbSymbolPathListEditor(QWidget *parent) :
bool CdbSymbolPathListEditor::promptCacheDirectory(QWidget *parent, FilePath *cacheDirectory) bool CdbSymbolPathListEditor::promptCacheDirectory(QWidget *parent, FilePath *cacheDirectory)
{ {
CacheDirectoryDialog dialog(parent); CacheDirectoryDialog dialog(parent);
dialog.setPath(TemporaryDirectory::masterDirectoryFilePath() + "/symbolcache"); dialog.setPath(TemporaryDirectory::masterDirectoryFilePath() / "symbolcache");
if (dialog.exec() != QDialog::Accepted) if (dialog.exec() != QDialog::Accepted)
return false; return false;
*cacheDirectory = dialog.path(); *cacheDirectory = dialog.path();
@@ -155,7 +155,7 @@ void CdbSymbolPathListEditor::setupSymbolPaths()
if (path.isEmpty() && indexOfSymbolCache != -1) if (path.isEmpty() && indexOfSymbolCache != -1)
path = FilePath::fromString(currentPaths.at(indexOfSymbolCache)); path = FilePath::fromString(currentPaths.at(indexOfSymbolCache));
if (path.isEmpty()) if (path.isEmpty())
path = TemporaryDirectory::masterDirectoryFilePath() + "/symbolcache"; path = TemporaryDirectory::masterDirectoryFilePath() / "symbolcache";
bool useSymbolServer = true; bool useSymbolServer = true;
bool useSymbolCache = true; bool useSymbolCache = true;

View File

@@ -396,9 +396,9 @@ void GeneralSettingsPage::exportBookmarks()
QLatin1String suffix(".xbel"); QLatin1String suffix(".xbel");
if (!filePath.endsWith(suffix)) if (!filePath.endsWith(suffix))
filePath = filePath + suffix; filePath = filePath.stringAppended(suffix);
Utils::FileSaver saver(filePath); FileSaver saver(filePath);
if (!saver.hasError()) { if (!saver.hasError()) {
XbelWriter writer(LocalHelpManager::bookmarkManager().treeBookmarkModel()); XbelWriter writer(LocalHelpManager::bookmarkManager().treeBookmarkModel());
writer.writeToFile(saver.file()); writer.writeToFile(saver.file());

View File

@@ -624,7 +624,7 @@ void PerfProfilerTool::showSaveTraceDialog()
if (filePath.isEmpty()) if (filePath.isEmpty())
return; return;
if (!filePath.endsWith(".ptq")) if (!filePath.endsWith(".ptq"))
filePath = filePath + ".ptq"; filePath = filePath.stringAppended(".ptq");
setToolActionsEnabled(false); setToolActionsEnabled(false);
m_traceManager->saveToTraceFile(filePath.toString()); m_traceManager->saveToTraceFile(filePath.toString());

View File

@@ -1056,12 +1056,12 @@ bool Project::isEditModePreferred() const
#if defined(WITH_TESTS) #if defined(WITH_TESTS)
static FilePath constructTestPath(const char *basePath) static FilePath constructTestPath(const QString &basePath)
{ {
FilePath drive; FilePath drive;
if (HostOsInfo::isWindowsHost()) if (HostOsInfo::isWindowsHost())
drive = "C:"; drive = "C:";
return drive + QLatin1String(basePath); return drive.stringAppended(basePath);
} }
const FilePath TEST_PROJECT_PATH = constructTestPath("/tmp/foobar/baz.project"); const FilePath TEST_PROJECT_PATH = constructTestPath("/tmp/foobar/baz.project");

View File

@@ -2260,7 +2260,7 @@ void ProjectExplorerPlugin::extensionsInitialized()
.searchInPath(gitBinary, gitSearchPaths); .searchInPath(gitBinary, gitSearchPaths);
if (!fullGitPath.isEmpty()) { if (!fullGitPath.isEmpty()) {
searchPaths << fullGitPath.parentDir() searchPaths << fullGitPath.parentDir()
<< fullGitPath.parentDir().parentDir() + "/usr/bin"; << fullGitPath.parentDir().parentDir().pathAppended("usr/bin");
} }
} }
return searchPaths; return searchPaths;

View File

@@ -293,7 +293,7 @@ QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationPara
const QString proFileContents = processTemplate(p.templatePath + QLatin1String("/tpl_plugin.pro"), sm, errorMessage); const QString proFileContents = processTemplate(p.templatePath + QLatin1String("/tpl_plugin.pro"), sm, errorMessage);
if (proFileContents.isEmpty()) if (proFileContents.isEmpty())
return QList<Core::GeneratedFile>(); return QList<Core::GeneratedFile>();
Core::GeneratedFile proFile(baseDir / p.fileName + QLatin1String(".pro")); Core::GeneratedFile proFile(baseDir.pathAppended(p.fileName + ".pro"));
proFile.setContents(proFileContents); proFile.setContents(proFileContents);
proFile.setAttributes(Core::GeneratedFile::OpenProjectAttribute); proFile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
rc.push_back(proFile); rc.push_back(proFile);

View File

@@ -1376,7 +1376,8 @@ void QmakeBuildSystem::collectLibraryData(const QmakeProFile *file, DeploymentDa
targetFileName += QLatin1Char('.'); targetFileName += QLatin1Char('.');
while (!versionComponents.isEmpty()) { while (!versionComponents.isEmpty()) {
const QString versionString = versionComponents.join(QLatin1Char('.')); const QString versionString = versionComponents.join(QLatin1Char('.'));
deploymentData.addFile(destDirFor(ti) / targetFileName + versionString, deploymentData.addFile(destDirFor(ti).pathAppended(targetFileName
+ versionString),
targetPath); targetPath);
versionComponents.removeLast(); versionComponents.removeLast();
} }

View File

@@ -208,7 +208,7 @@ void BaseQmakeProjectWizardDialog::generateProfileName(const QString &name,
if (!m_targetSetupPage) if (!m_targetSetupPage)
return; return;
const Utils::FilePath proFile = path / name / name + ".pro"; const Utils::FilePath proFile = path / name / (name + ".pro");
m_targetSetupPage->setProjectPath(proFile); m_targetSetupPage->setProjectPath(proFile);
} }

View File

@@ -37,7 +37,7 @@ void readFormatConfiguration(){
if (copyableProperties.isEmpty()){ if (copyableProperties.isEmpty()){
QString source = "formatconfiguration.json"; QString source = "formatconfiguration.json";
Utils::FilePath path = Core::ICore::resourcePath() + "/qmldesigner/" + source; Utils::FilePath path = Core::ICore::resourcePath("qmldesigner") / source;
QString errorString; QString errorString;
Utils::FileReader reader; Utils::FileReader reader;

View File

@@ -587,7 +587,7 @@ void QmlProfilerTool::showSaveDialog()
Tr::tr("QML traces (*%1 *%2)").arg(zFile).arg(tFile)); Tr::tr("QML traces (*%1 *%2)").arg(zFile).arg(tFile));
if (!filePath.isEmpty()) { if (!filePath.isEmpty()) {
if (!filePath.endsWith(zFile) && !filePath.endsWith(tFile)) if (!filePath.endsWith(zFile) && !filePath.endsWith(tFile))
filePath = filePath + zFile; filePath = filePath.stringAppended(zFile);
saveLastTraceFile(filePath); saveLastTraceFile(filePath);
Debugger::enableMainWindow(false); Debugger::enableMainWindow(false);
Core::ProgressManager::addTask(d->m_profilerModelManager->save(filePath.toString()), Core::ProgressManager::addTask(d->m_profilerModelManager->save(filePath.toString()),

View File

@@ -125,7 +125,7 @@ QmlProject::QmlProject(const Utils::FilePath &fileName)
}); });
} else { } else {
Utils::FilePaths uiFiles = getUiQmlFilesForFolder(projectDirectory() Utils::FilePaths uiFiles = getUiQmlFilesForFolder(projectDirectory()
+ "/content"); / "content");
if (uiFiles.isEmpty()) if (uiFiles.isEmpty())
uiFiles = getUiQmlFilesForFolder(projectDirectory()); uiFiles = getUiQmlFilesForFolder(projectDirectory());

View File

@@ -256,7 +256,7 @@ void GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::createKey()
void GenericLinuxDeviceConfigurationWizardKeyDeploymentPage::deployKey() 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()); d->iconLabel.setPixmap((dlg.exec() == QDialog::Accepted ? Icons::OK : Icons::BROKEN).pixmap());
} }

View File

@@ -262,11 +262,11 @@ public:
Q_UNUSED(explicitQmlproject) Q_UNUSED(explicitQmlproject)
Q_UNUSED(tempFile) Q_UNUSED(tempFile)
Q_UNUSED(completeBaseName) Q_UNUSED(completeBaseName)
const Utils::FilePath projectFile = Core::ICore::resourcePath("examples") const FilePath projectFile = Core::ICore::resourcePath("examples")
/ example / example + ".qmlproject"; / example / (example + ".qmlproject");
ProjectExplorer::ProjectExplorerPlugin::openProjectWelcomePage(projectFile); ProjectExplorer::ProjectExplorerPlugin::openProjectWelcomePage(projectFile);
const Utils::FilePath qmlFile = Core::ICore::resourcePath("examples") const FilePath qmlFile = Core::ICore::resourcePath("examples")
/ example / formFile; / example / formFile;
Core::EditorManager::openEditor(qmlFile); Core::EditorManager::openEditor(qmlFile);
} }

View File

@@ -45,7 +45,7 @@ static CommandLine emrunCommand(const Target *target,
const FilePath emrun = env.searchInPath("emrun"); const FilePath emrun = env.searchInPath("emrun");
const FilePath emrunPy = emrun.absolutePath().pathAppended(emrun.baseName() + ".py"); const FilePath emrunPy = emrun.absolutePath().pathAppended(emrun.baseName() + ".py");
const FilePath targetPath = bc->buildSystem()->buildTarget(buildKey).targetFilePath; 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()); QStringList args(emrunPy.path());
if (!browser.isEmpty()) { if (!browser.isEmpty()) {

View File

@@ -96,8 +96,8 @@ private slots:
void onDevice_data(); void onDevice_data();
void onDevice(); void onDevice();
void plus(); void stringAppended();
void plus_data(); void stringAppended_data();
void url(); void url();
void url_data(); void url_data();
@@ -995,7 +995,7 @@ void tst_fileutils::onDevice()
QCOMPARE(path.onDevice(templatePath), expected); QCOMPARE(path.onDevice(templatePath), expected);
} }
void tst_fileutils::plus_data() void tst_fileutils::stringAppended_data()
{ {
QTest::addColumn<FilePath>("left"); QTest::addColumn<FilePath>("left");
QTest::addColumn<QString>("right"); QTest::addColumn<QString>("right");
@@ -1011,13 +1011,13 @@ void tst_fileutils::plus_data()
QTest::newRow("slash-trailing-slash") << FilePath::fromString("/a/") << QString("b/") << FilePath("/a/b/"); QTest::newRow("slash-trailing-slash") << FilePath::fromString("/a/") << QString("b/") << FilePath("/a/b/");
} }
void tst_fileutils::plus() void tst_fileutils::stringAppended()
{ {
QFETCH(FilePath, left); QFETCH(FilePath, left);
QFETCH(QString, right); QFETCH(QString, right);
QFETCH(FilePath, expected); QFETCH(FilePath, expected);
const FilePath result = left + right; const FilePath result = left.stringAppended(right);
QCOMPARE(expected, result); QCOMPARE(expected, result);
} }