Utils: Replace mutating FileName::appendString

... by a non-mutating .stringAppended, doing the same.

Change-Id: I7adb6cae3415942cc9a80088bd75cda9d577d4a5
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2019-05-15 08:01:06 +02:00
parent 075d674c5a
commit f99d69ee43
8 changed files with 27 additions and 41 deletions

View File

@@ -855,16 +855,11 @@ FileName &FileName::appendPath(const QString &s)
return *this; return *this;
} }
FileName &FileName::appendString(const QString &str) FileName FileName::stringAppended(const QString &str) const
{ {
m_data.append(str); FileName fn = *this;
return *this; fn.m_data.append(str);
} return fn;
FileName &FileName::appendString(QChar str)
{
m_data.append(str);
return *this;
} }
uint FileName::hash(uint seed) const uint FileName::hash(uint seed) const

View File

@@ -94,8 +94,7 @@ public:
FileName relativeChildPath(const FileName &parent) const; FileName relativeChildPath(const FileName &parent) const;
FileName &appendPath(const QString &s); FileName &appendPath(const QString &s);
FileName &appendString(const QString &str); FileName stringAppended(const QString &str) const;
FileName &appendString(QChar str);
void clear() { m_data.clear(); } void clear() { m_data.clear(); }
bool isEmpty() const { return m_data.isEmpty(); } bool isEmpty() const { return m_data.isEmpty(); }

View File

@@ -244,9 +244,7 @@ BackUpStrategy::backupName(const QVariantMap &oldData, const FileName &path, con
{ {
if (oldData == data) if (oldData == data)
return nullopt; return nullopt;
FileName backup = path; return path.stringAppended(".bak");
backup.appendString(".bak");
return backup;
} }
BackingUpSettingsAccessor::BackingUpSettingsAccessor(const QString &docType, BackingUpSettingsAccessor::BackingUpSettingsAccessor(const QString &docType,
@@ -370,13 +368,14 @@ VersionedBackUpStrategy::backupName(const QVariantMap &oldData, const FileName &
const int oldVersion = versionFromMap(oldData); const int oldVersion = versionFromMap(oldData);
if (!oldEnvironmentId.isEmpty() && oldEnvironmentId != m_accessor->settingsId()) if (!oldEnvironmentId.isEmpty() && oldEnvironmentId != m_accessor->settingsId())
backupName.appendString('.' + QString::fromLatin1(oldEnvironmentId).mid(1, 7)); backupName = backupName.stringAppended
('.' + QString::fromLatin1(oldEnvironmentId).mid(1, 7));
if (oldVersion != m_accessor->currentVersion()) { if (oldVersion != m_accessor->currentVersion()) {
VersionUpgrader *upgrader = m_accessor->upgrader(oldVersion); VersionUpgrader *upgrader = m_accessor->upgrader(oldVersion);
if (upgrader) if (upgrader)
backupName.appendString('.' + upgrader->backupExtension()); backupName = backupName.stringAppended('.' + upgrader->backupExtension());
else else
backupName.appendString('.' + QString::number(oldVersion)); backupName = backupName.stringAppended('.' + QString::number(oldVersion));
} }
if (backupName == path) if (backupName == path)
return nullopt; return nullopt;

View File

@@ -286,9 +286,9 @@ QJsonObject AndroidManager::deploymentSettings(const Target *target)
settings["useLLVM"] = true; settings["useLLVM"] = true;
settings["ndk-host"] = AndroidConfigurations::currentConfig().toolchainHost(); settings["ndk-host"] = AndroidConfigurations::currentConfig().toolchainHost();
settings["stdcpp-path"] = AndroidConfigurations::currentConfig().ndkLocation() settings["stdcpp-path"] = AndroidConfigurations::currentConfig().ndkLocation()
.appendPath("/sources/cxx-stl/llvm-libc++/libs/") .appendPath("/sources/cxx-stl/llvm-libc++/libs/"
.appendString(targetArch(target)) + targetArch(target)
.appendPath("libc++_shared.so").toString(); + "/libc++_shared.so").toString();
return settings; return settings;
} }

View File

@@ -204,8 +204,7 @@ const QList<BuildTargetInfo> CMakeBuildConfiguration::appTargets() const
BuildTargetInfo bti; BuildTargetInfo bti;
bti.displayName = ct.title; bti.displayName = ct.title;
bti.targetFilePath = ct.executable; bti.targetFilePath = ct.executable;
bti.projectFilePath = ct.sourceDirectory; bti.projectFilePath = ct.sourceDirectory.stringAppended("/");
bti.projectFilePath.appendString('/');
bti.workingDirectory = ct.workingDirectory; bti.workingDirectory = ct.workingDirectory;
bti.buildKey = CMakeTargetNode::generateId(ct.sourceDirectory, ct.title); bti.buildKey = CMakeTargetNode::generateId(ct.sourceDirectory, ct.title);
appTargetList.append(bti); appTargetList.append(bti);

View File

@@ -242,17 +242,16 @@ static QString makeRelative(QString path)
// Return complete file path of the .user file. // Return complete file path of the .user file.
static FileName externalUserFilePath(const Utils::FileName &projectFilePath, const QString &suffix) static FileName externalUserFilePath(const Utils::FileName &projectFilePath, const QString &suffix)
{ {
FileName result;
static const optional<QString> externalUserFileDir = defineExternalUserFileDir(); static const optional<QString> externalUserFileDir = defineExternalUserFileDir();
if (externalUserFileDir) { if (externalUserFileDir) {
// Recreate the relative project file hierarchy under the shared directory. // Recreate the relative project file hierarchy under the shared directory.
// PersistentSettingsWriter::write() takes care of creating the path. // PersistentSettingsWriter::write() takes care of creating the path.
result = FileName::fromString(externalUserFileDir.value()); return FileName::fromString(externalUserFileDir.value()
result.appendString('/' + makeRelative(projectFilePath.toString())); + '/' + makeRelative(projectFilePath.toString())
result.appendString(suffix); + suffix);
} }
return result; return {};
} }
} // namespace } // namespace
@@ -388,9 +387,8 @@ QVariant UserFileAccessor::retrieveSharedSettings() const
FileName UserFileAccessor::projectUserFile() const FileName UserFileAccessor::projectUserFile() const
{ {
static const QString qtcExt = QLatin1String(qgetenv("QTC_EXTENSION")); static const QString qtcExt = QLatin1String(qgetenv("QTC_EXTENSION"));
FileName projectUserFile = m_project->projectFilePath(); return m_project->projectFilePath()
projectUserFile.appendString(generateSuffix(qtcExt.isEmpty() ? FILE_EXTENSION_STR : qtcExt)); .stringAppended(generateSuffix(qtcExt.isEmpty() ? FILE_EXTENSION_STR : qtcExt));
return projectUserFile;
} }
FileName UserFileAccessor::externalUserFile() const FileName UserFileAccessor::externalUserFile() const
@@ -403,9 +401,8 @@ FileName UserFileAccessor::externalUserFile() const
FileName UserFileAccessor::sharedFile() const FileName UserFileAccessor::sharedFile() const
{ {
static const QString qtcExt = QLatin1String(qgetenv("QTC_SHARED_EXTENSION")); static const QString qtcExt = QLatin1String(qgetenv("QTC_SHARED_EXTENSION"));
FileName sharedFile = m_project->projectFilePath(); return m_project->projectFilePath()
sharedFile.appendString(generateSuffix(qtcExt.isEmpty() ? ".shared" : qtcExt)); .stringAppended(generateSuffix(qtcExt.isEmpty() ? ".shared" : qtcExt));
return sharedFile;
} }
QVariantMap UserFileAccessor::postprocessMerge(const QVariantMap &main, QVariantMap UserFileAccessor::postprocessMerge(const QVariantMap &main,

View File

@@ -1941,12 +1941,10 @@ FileNameList QmakeProFile::generatedFiles(const FileName &buildDir,
return { }; return { };
FileName location = buildDir; FileName location = buildDir;
location.appendPath(sourceFile.toFileInfo().completeBaseName()); location.appendPath(sourceFile.toFileInfo().completeBaseName());
FileName header = location; return {
header.appendString(singleVariableValue(Variable::HeaderExtension)); location.stringAppended(singleVariableValue(Variable::HeaderExtension)),
FileName cpp = location; location.stringAppended(singleVariableValue(Variable::CppExtension))
cpp.appendString(singleVariableValue(Variable::CppExtension)); };
return { header, cpp };
} }
return { }; return { };
} }

View File

@@ -71,6 +71,5 @@ Utils::FileName Settings::getPath(const QString &file)
result.appendPath(lowerFile); result.appendPath(lowerFile);
else else
result.appendPath(file); // handle arbitrary file names not known yet result.appendPath(file); // handle arbitrary file names not known yet
result.appendString(".xml"); return result.stringAppended(".xml");
return result;
} }