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;
}
FileName &FileName::appendString(const QString &str)
FileName FileName::stringAppended(const QString &str) const
{
m_data.append(str);
return *this;
}
FileName &FileName::appendString(QChar str)
{
m_data.append(str);
return *this;
FileName fn = *this;
fn.m_data.append(str);
return fn;
}
uint FileName::hash(uint seed) const

View File

@@ -94,8 +94,7 @@ public:
FileName relativeChildPath(const FileName &parent) const;
FileName &appendPath(const QString &s);
FileName &appendString(const QString &str);
FileName &appendString(QChar str);
FileName stringAppended(const QString &str) const;
void clear() { m_data.clear(); }
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)
return nullopt;
FileName backup = path;
backup.appendString(".bak");
return backup;
return path.stringAppended(".bak");
}
BackingUpSettingsAccessor::BackingUpSettingsAccessor(const QString &docType,
@@ -370,13 +368,14 @@ VersionedBackUpStrategy::backupName(const QVariantMap &oldData, const FileName &
const int oldVersion = versionFromMap(oldData);
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()) {
VersionUpgrader *upgrader = m_accessor->upgrader(oldVersion);
if (upgrader)
backupName.appendString('.' + upgrader->backupExtension());
backupName = backupName.stringAppended('.' + upgrader->backupExtension());
else
backupName.appendString('.' + QString::number(oldVersion));
backupName = backupName.stringAppended('.' + QString::number(oldVersion));
}
if (backupName == path)
return nullopt;

View File

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

View File

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

View File

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

View File

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

View File

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