ProjectExplorer: Use less indirection for BuildConfiguration aspects

Change-Id: I6c219bc35edccd723f39e71d52b246060c1c424e
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2023-07-07 17:33:56 +02:00
parent f1a6135c1e
commit a8a68b024a
4 changed files with 31 additions and 29 deletions

View File

@@ -79,7 +79,7 @@ public:
void setInitialCMakeArguments(const QStringList &args); void setInitialCMakeArguments(const QStringList &args);
void setCMakeBuildType(const QString &cmakeBuildType, bool quiet = false); void setCMakeBuildType(const QString &cmakeBuildType, bool quiet = false);
ProjectExplorer::BuildDirectoryAspect buildDir{this}; ProjectExplorer::BuildDirectoryAspect buildDir{this, this};
Internal::InitialCMakeArgumentsAspect initialCMakeArguments{this}; Internal::InitialCMakeArgumentsAspect initialCMakeArguments{this};
Utils::StringAspect additionalCMakeOptions{this}; Utils::StringAspect additionalCMakeOptions{this};
Utils::FilePathAspect sourceDirectory{this}; Utils::FilePathAspect sourceDirectory{this};

View File

@@ -36,8 +36,9 @@ public:
QPointer<InfoLabel> problemLabel; QPointer<InfoLabel> problemLabel;
}; };
BuildDirectoryAspect::BuildDirectoryAspect(const BuildConfiguration *bc) BuildDirectoryAspect::BuildDirectoryAspect(AspectContainer *container, const BuildConfiguration *bc)
: d(new Private(bc->target())) : FilePathAspect(container),
d(new Private(bc->target()))
{ {
setSettingsKey("ProjectExplorer.BuildConfiguration.BuildDirectory"); setSettingsKey("ProjectExplorer.BuildConfiguration.BuildDirectory");
setLabelText(Tr::tr("Build directory:")); setLabelText(Tr::tr("Build directory:"));

View File

@@ -14,8 +14,9 @@ class BuildConfiguration;
class PROJECTEXPLORER_EXPORT BuildDirectoryAspect : public Utils::FilePathAspect class PROJECTEXPLORER_EXPORT BuildDirectoryAspect : public Utils::FilePathAspect
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit BuildDirectoryAspect(const BuildConfiguration *bc); explicit BuildDirectoryAspect(Utils::AspectContainer *container, const BuildConfiguration *bc);
~BuildDirectoryAspect() override; ~BuildDirectoryAspect() override;
void allowInSourceBuilds(const Utils::FilePath &sourceDir); void allowInSourceBuilds(const Utils::FilePath &sourceDir);

View File

@@ -128,15 +128,17 @@ class BuildConfigurationPrivate
public: public:
BuildConfigurationPrivate(BuildConfiguration *bc) BuildConfigurationPrivate(BuildConfiguration *bc)
: m_buildSteps(bc, Constants::BUILDSTEPS_BUILD), : m_buildSteps(bc, Constants::BUILDSTEPS_BUILD),
m_cleanSteps(bc, Constants::BUILDSTEPS_CLEAN) m_cleanSteps(bc, Constants::BUILDSTEPS_CLEAN),
m_buildDirectoryAspect(bc, bc),
m_tooltipAspect(bc)
{} {}
bool m_clearSystemEnvironment = false; bool m_clearSystemEnvironment = false;
EnvironmentItems m_userEnvironmentChanges; EnvironmentItems m_userEnvironmentChanges;
BuildStepList m_buildSteps; BuildStepList m_buildSteps;
BuildStepList m_cleanSteps; BuildStepList m_cleanSteps;
BuildDirectoryAspect *m_buildDirectoryAspect = nullptr; BuildDirectoryAspect m_buildDirectoryAspect;
StringAspect *m_tooltipAspect = nullptr; StringAspect m_tooltipAspect;
FilePath m_lastEmittedBuildDirectory; FilePath m_lastEmittedBuildDirectory;
mutable Environment m_cachedEnvironment; mutable Environment m_cachedEnvironment;
QString m_configWidgetDisplayName; QString m_configWidgetDisplayName;
@@ -190,24 +192,22 @@ BuildConfiguration::BuildConfiguration(Target *target, Utils::Id id)
connect(ProjectTree::instance(), &ProjectTree::currentProjectChanged, connect(ProjectTree::instance(), &ProjectTree::currentProjectChanged,
this, &BuildConfiguration::updateCacheAndEmitEnvironmentChanged); this, &BuildConfiguration::updateCacheAndEmitEnvironmentChanged);
d->m_buildDirectoryAspect = addAspect<BuildDirectoryAspect>(this); d->m_buildDirectoryAspect.setBaseFileName(target->project()->projectDirectory());
d->m_buildDirectoryAspect->setBaseFileName(target->project()->projectDirectory()); d->m_buildDirectoryAspect.setEnvironment(environment());
d->m_buildDirectoryAspect->setEnvironment(environment()); d->m_buildDirectoryAspect.setMacroExpanderProvider([this] { return macroExpander(); });
d->m_buildDirectoryAspect->setMacroExpanderProvider([this] { return macroExpander(); }); connect(&d->m_buildDirectoryAspect, &StringAspect::changed,
connect(d->m_buildDirectoryAspect, &StringAspect::changed,
this, &BuildConfiguration::emitBuildDirectoryChanged); this, &BuildConfiguration::emitBuildDirectoryChanged);
connect(this, &BuildConfiguration::environmentChanged, this, [this] { connect(this, &BuildConfiguration::environmentChanged, this, [this] {
d->m_buildDirectoryAspect->setEnvironment(environment()); d->m_buildDirectoryAspect.setEnvironment(environment());
emit this->target()->buildEnvironmentChanged(this); emit this->target()->buildEnvironmentChanged(this);
}); });
d->m_tooltipAspect = addAspect<StringAspect>(); d->m_tooltipAspect.setLabelText(Tr::tr("Tooltip in target selector:"));
d->m_tooltipAspect->setLabelText(Tr::tr("Tooltip in target selector:")); d->m_tooltipAspect.setToolTip(Tr::tr("Appears as a tooltip when hovering the build configuration"));
d->m_tooltipAspect->setToolTip(Tr::tr("Appears as a tooltip when hovering the build configuration")); d->m_tooltipAspect.setDisplayStyle(StringAspect::LineEditDisplay);
d->m_tooltipAspect->setDisplayStyle(StringAspect::LineEditDisplay); d->m_tooltipAspect.setSettingsKey("ProjectExplorer.BuildConfiguration.Tooltip");
d->m_tooltipAspect->setSettingsKey("ProjectExplorer.BuildConfiguration.Tooltip"); connect(&d->m_tooltipAspect, &StringAspect::changed, this, [this] {
connect(d->m_tooltipAspect, &StringAspect::changed, this, [this] { setToolTip(d->m_tooltipAspect());
setToolTip(d->m_tooltipAspect->value());
}); });
connect(target, &Target::parsingStarted, this, &BuildConfiguration::enabledChanged); connect(target, &Target::parsingStarted, this, &BuildConfiguration::enabledChanged);
@@ -228,7 +228,7 @@ BuildConfiguration::~BuildConfiguration()
FilePath BuildConfiguration::buildDirectory() const FilePath BuildConfiguration::buildDirectory() const
{ {
FilePath path = FilePath::fromUserInput( FilePath path = FilePath::fromUserInput(
environment().expandVariables(d->m_buildDirectoryAspect->value().trimmed())); environment().expandVariables(d->m_buildDirectoryAspect.value().trimmed()));
// FIXME: If the macro expander is expected to be able to do some // FIXME: If the macro expander is expected to be able to do some
// structual changes, the fromUserInput() above might already have // structual changes, the fromUserInput() above might already have
// mis-parsed. Should this here be encapsulated in the FilePathAspect? // mis-parsed. Should this here be encapsulated in the FilePathAspect?
@@ -242,17 +242,17 @@ FilePath BuildConfiguration::buildDirectory() const
FilePath BuildConfiguration::rawBuildDirectory() const FilePath BuildConfiguration::rawBuildDirectory() const
{ {
return d->m_buildDirectoryAspect->filePath(); return d->m_buildDirectoryAspect();
} }
void BuildConfiguration::setBuildDirectory(const FilePath &dir) void BuildConfiguration::setBuildDirectory(const FilePath &dir)
{ {
if (dir == d->m_buildDirectoryAspect->filePath()) if (dir == d->m_buildDirectoryAspect())
return; return;
d->m_buildDirectoryAspect->setValue(dir); d->m_buildDirectoryAspect.setValue(dir);
const FilePath fixedDir = BuildDirectoryAspect::fixupDir(buildDirectory()); const FilePath fixedDir = BuildDirectoryAspect::fixupDir(buildDirectory());
if (!fixedDir.isEmpty()) if (!fixedDir.isEmpty())
d->m_buildDirectoryAspect->setValue(fixedDir); d->m_buildDirectoryAspect.setValue(fixedDir);
emitBuildDirectoryChanged(); emitBuildDirectoryChanged();
} }
@@ -425,7 +425,7 @@ bool BuildConfiguration::fromMap(const QVariantMap &map)
d->m_customParsers = transform(map.value(CUSTOM_PARSERS_KEY).toList(), &Utils::Id::fromSetting); d->m_customParsers = transform(map.value(CUSTOM_PARSERS_KEY).toList(), &Utils::Id::fromSetting);
const bool res = ProjectConfiguration::fromMap(map); const bool res = ProjectConfiguration::fromMap(map);
setToolTip(d->m_tooltipAspect->value()); setToolTip(d->m_tooltipAspect());
return res; return res;
} }
@@ -449,7 +449,7 @@ void BuildConfiguration::emitBuildDirectoryChanged()
ProjectExplorer::BuildDirectoryAspect *BuildConfiguration::buildDirectoryAspect() const ProjectExplorer::BuildDirectoryAspect *BuildConfiguration::buildDirectoryAspect() const
{ {
return d->m_buildDirectoryAspect; return &d->m_buildDirectoryAspect;
} }
void BuildConfiguration::setConfigWidgetDisplayName(const QString &display) void BuildConfiguration::setConfigWidgetDisplayName(const QString &display)
@@ -459,7 +459,7 @@ void BuildConfiguration::setConfigWidgetDisplayName(const QString &display)
void BuildConfiguration::setBuildDirectoryHistoryCompleter(const QString &history) void BuildConfiguration::setBuildDirectoryHistoryCompleter(const QString &history)
{ {
d->m_buildDirectoryAspect->setHistoryCompleter(history); d->m_buildDirectoryAspect.setHistoryCompleter(history);
} }
void BuildConfiguration::setConfigWidgetHasFrame(bool configWidgetHasFrame) void BuildConfiguration::setConfigWidgetHasFrame(bool configWidgetHasFrame)
@@ -469,7 +469,7 @@ void BuildConfiguration::setConfigWidgetHasFrame(bool configWidgetHasFrame)
void BuildConfiguration::setBuildDirectorySettingsKey(const QString &key) void BuildConfiguration::setBuildDirectorySettingsKey(const QString &key)
{ {
d->m_buildDirectoryAspect->setSettingsKey(key); d->m_buildDirectoryAspect.setSettingsKey(key);
} }
Environment BuildConfiguration::baseEnvironment() const Environment BuildConfiguration::baseEnvironment() const