Utils: Introduce a FilePathAspect::expandedValue()

Currently and long-term synonym for operator(), to be used in
cases where (*this)() or such looks ugly.

Change-Id: I3f70ecd3298a1df394a0e3cc593917b4c7d36d82
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2023-07-18 09:09:11 +02:00
parent e8de9d44c9
commit 635e8c1614
5 changed files with 16 additions and 10 deletions

View File

@@ -1325,12 +1325,17 @@ FilePathAspect::FilePathAspect(AspectContainer *container)
FilePath FilePathAspect::operator()() const FilePath FilePathAspect::operator()() const
{ {
return filePath(); return FilePath::fromUserInput(StringAspect::value());
} }
FilePath FilePathAspect::value() const FilePath FilePathAspect::value() const
{ {
return filePath(); return FilePath::fromUserInput(StringAspect::value());
}
FilePath FilePathAspect::expandedValue() const
{
return FilePath::fromUserInput(StringAspect::value());
} }
QString FilePathAspect::stringValue() const QString FilePathAspect::stringValue() const

View File

@@ -537,6 +537,7 @@ public:
FilePath operator()() const; FilePath operator()() const;
FilePath value() const; FilePath value() const;
FilePath expandedValue() const;
QString stringValue() const; QString stringValue() const;
void setValue(const FilePath &filePath); void setValue(const FilePath &filePath);
void setDefaultValue(const FilePath &filePath); void setDefaultValue(const FilePath &filePath);

View File

@@ -74,12 +74,12 @@ void BuildDirectoryAspect::allowInSourceBuilds(const FilePath &sourceDir)
{ {
d->sourceDir = sourceDir; d->sourceDir = sourceDir;
makeCheckable(CheckBoxPlacement::Top, Tr::tr("Shadow build:"), QString()); makeCheckable(CheckBoxPlacement::Top, Tr::tr("Shadow build:"), QString());
setChecked(d->sourceDir != filePath()); setChecked(d->sourceDir != expandedValue());
} }
bool BuildDirectoryAspect::isShadowBuild() const bool BuildDirectoryAspect::isShadowBuild() const
{ {
return !d->sourceDir.isEmpty() && d->sourceDir != filePath(); return !d->sourceDir.isEmpty() && d->sourceDir != expandedValue();
} }
void BuildDirectoryAspect::setProblem(const QString &description) void BuildDirectoryAspect::setProblem(const QString &description)
@@ -92,7 +92,7 @@ void BuildDirectoryAspect::toMap(QVariantMap &map) const
{ {
FilePathAspect::toMap(map); FilePathAspect::toMap(map);
if (!d->sourceDir.isEmpty()) { if (!d->sourceDir.isEmpty()) {
const FilePath shadowDir = isChecked() ? filePath() : d->savedShadowBuildDir; const FilePath shadowDir = isChecked() ? expandedValue() : d->savedShadowBuildDir;
saveToMap(map, shadowDir.toSettings(), QString(), settingsKey() + ".shadowDir"); saveToMap(map, shadowDir.toSettings(), QString(), settingsKey() + ".shadowDir");
} }
} }
@@ -104,7 +104,7 @@ void BuildDirectoryAspect::fromMap(const QVariantMap &map)
d->savedShadowBuildDir = FilePath::fromSettings(map.value(settingsKey() + ".shadowDir")); d->savedShadowBuildDir = FilePath::fromSettings(map.value(settingsKey() + ".shadowDir"));
if (d->savedShadowBuildDir.isEmpty()) if (d->savedShadowBuildDir.isEmpty())
setValue(d->sourceDir); setValue(d->sourceDir);
setChecked(d->sourceDir != filePath()); setChecked(d->sourceDir != expandedValue()); // FIXME: Check.
} }
} }
@@ -121,7 +121,7 @@ void BuildDirectoryAspect::addToLayout(Layouting::LayoutItem &parent)
setValue(d->savedShadowBuildDir.isEmpty() setValue(d->savedShadowBuildDir.isEmpty()
? d->sourceDir : d->savedShadowBuildDir); ? d->sourceDir : d->savedShadowBuildDir);
} else { } else {
d->savedShadowBuildDir = filePath(); d->savedShadowBuildDir = expandedValue(); // FIXME: Check.
setValue(d->sourceDir); setValue(d->sourceDir);
} }
}); });

View File

@@ -632,8 +632,8 @@ void ExecutableAspect::makeOverridable(const QString &overridingKey, const QStri
FilePath ExecutableAspect::executable() const FilePath ExecutableAspect::executable() const
{ {
FilePath exe = m_alternativeExecutable && m_alternativeExecutable->isChecked() FilePath exe = m_alternativeExecutable && m_alternativeExecutable->isChecked()
? m_alternativeExecutable->filePath() ? (*m_alternativeExecutable)()
: m_executable.filePath(); : m_executable();
if (const IDevice::ConstPtr dev = executionDevice(m_target, m_selector)) if (const IDevice::ConstPtr dev = executionDevice(m_target, m_selector))
exe = dev->rootPath().withNewMappedPath(exe); exe = dev->rootPath().withNewMappedPath(exe);

View File

@@ -230,7 +230,7 @@ void showAttachToProcessDialog()
FilePath localExecutable = dlg.localExecutable(); FilePath localExecutable = dlg.localExecutable();
if (localExecutable.isEmpty()) { if (localExecutable.isEmpty()) {
if (auto aspect = runConfig->aspect<SymbolFileAspect>()) if (auto aspect = runConfig->aspect<SymbolFileAspect>())
localExecutable = aspect->filePath(); localExecutable = aspect->expandedValue();
} }
auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);