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(';');
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
{

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;
[[nodiscard]] FilePath operator+(const QString &s) const;
[[nodiscard]] FilePath operator/(const QString &str) const;
Qt::CaseSensitivity caseSensitivity() const;

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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()));
}

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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());

View File

@@ -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());

View File

@@ -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");

View File

@@ -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;

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);
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);

View File

@@ -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();
}

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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()),

View File

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

View File

@@ -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());
}

View File

@@ -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);
}

View File

@@ -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()) {

View File

@@ -96,8 +96,8 @@ private slots:
void onDevice_data();
void onDevice();
void plus();
void plus_data();
void stringAppended();
void stringAppended_data();
void url();
void url_data();
@@ -995,7 +995,7 @@ void tst_fileutils::onDevice()
QCOMPARE(path.onDevice(templatePath), expected);
}
void tst_fileutils::plus_data()
void tst_fileutils::stringAppended_data()
{
QTest::addColumn<FilePath>("left");
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/");
}
void tst_fileutils::plus()
void tst_fileutils::stringAppended()
{
QFETCH(FilePath, left);
QFETCH(QString, right);
QFETCH(FilePath, expected);
const FilePath result = left + right;
const FilePath result = left.stringAppended(right);
QCOMPARE(expected, result);
}