Utils: Introduce a FilePath::absolutePath() function

... and start using it.

Change-Id: I44c74005a4deee72d0332106a4ce3582e0b66191
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2019-12-18 18:55:27 +01:00
parent 84d0e3dda8
commit 711daa3803
3 changed files with 11 additions and 5 deletions

View File

@@ -800,6 +800,13 @@ FilePath FilePath::parentDir() const
return FilePath::fromString(parent);
}
FilePath FilePath::absolutePath() const
{
FilePath result = *this;
result.m_data = QFileInfo(m_data).absolutePath();
return result;
}
/// Constructs a FilePath from \a filename
/// \a filename is not checked for validity.
FilePath FilePath::fromString(const QString &filename)

View File

@@ -86,6 +86,7 @@ public:
bool isWritablePath() const;
FilePath parentDir() const;
FilePath absolutePath() const;
bool operator==(const FilePath &other) const;
bool operator!=(const FilePath &other) const;

View File

@@ -119,11 +119,9 @@ void DesktopRunConfiguration::updateTargetInformation()
aspect<ExecutableAspect>()->setExecutable(executable);
if (!executable.isEmpty()) {
QString defaultWorkingDir = QFileInfo(executable.toString()).absolutePath();
if (!defaultWorkingDir.isEmpty()) {
auto wdAspect = aspect<WorkingDirectoryAspect>();
wdAspect->setDefaultWorkingDirectory(FilePath::fromString(defaultWorkingDir));
}
const FilePath defaultWorkingDir = executable.absolutePath();
if (!defaultWorkingDir.isEmpty())
aspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(defaultWorkingDir);
}
emit enabledChanged();