ProjectExplorer: Make ProjectConfiguration an AspectContainer

... instead of having one. AspectContainer are de-factor (q)objects
with "fat" properties, conceptionally not much different from QObject
itself, so there's not real need to differentiate between the QObject
interface and the (forwarded) aspectcontainer interface.

As a side-effect, this saves one QObject base object per instance.

Change-Id: I6eefe739b3aebcef1ece196ff8d70aa36738997b
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2023-05-22 13:30:11 +02:00
parent 79dd2a8c8b
commit b41f7e87ae
5 changed files with 12 additions and 30 deletions

View File

@@ -147,7 +147,7 @@ QWidget *BuildStep::doCreateConfigWidget()
setSummaryText(m_summaryUpdater());
};
for (BaseAspect *aspect : std::as_const(m_aspects))
for (BaseAspect *aspect : std::as_const(*this))
connect(aspect, &BaseAspect::changed, widget, recreateSummary);
connect(buildConfiguration(), &BuildConfiguration::buildDirectoryChanged,
@@ -161,7 +161,7 @@ QWidget *BuildStep::doCreateConfigWidget()
QWidget *BuildStep::createConfigWidget()
{
Layouting::Form form;
for (BaseAspect *aspect : std::as_const(m_aspects)) {
for (BaseAspect *aspect : std::as_const(*this)) {
if (aspect->isVisible())
form.addItem(aspect);
}

View File

@@ -19,10 +19,10 @@ const char DISPLAY_NAME_KEY[] = "ProjectExplorer.ProjectConfiguration.DisplayNam
// ProjectConfiguration
ProjectConfiguration::ProjectConfiguration(QObject *parent, Utils::Id id)
: QObject(parent)
: AspectContainer(parent)
, m_id(id)
{
m_aspects.setOwnsSubAspects(true);
setOwnsSubAspects(true);
QTC_CHECK(parent);
QTC_CHECK(id.isValid());
@@ -89,7 +89,7 @@ QVariantMap ProjectConfiguration::toMap() const
QVariantMap map;
map.insert(QLatin1String(CONFIGURATION_ID_KEY), m_id.toSetting());
m_displayName.toMap(map, DISPLAY_NAME_KEY);
m_aspects.toMap(map);
AspectContainer::toMap(map);
return map;
}
@@ -106,15 +106,10 @@ bool ProjectConfiguration::fromMap(const QVariantMap &map)
QTC_ASSERT(id.toString().startsWith(m_id.toString()), return false);
m_displayName.fromMap(map, DISPLAY_NAME_KEY);
m_aspects.fromMap(map);
AspectContainer::fromMap(map);
return true;
}
BaseAspect *ProjectConfiguration::aspect(Id id) const
{
return m_aspects.aspect(id);
}
FilePath ProjectConfiguration::mapFromBuildDeviceToGlobalPath(const FilePath &path) const
{
IDevice::ConstPtr dev = BuildDeviceKitAspect::device(kit());

View File

@@ -21,7 +21,7 @@ class Kit;
class Project;
class Target;
class PROJECTEXPLORER_EXPORT ProjectConfiguration : public QObject
class PROJECTEXPLORER_EXPORT ProjectConfiguration : public Utils::AspectContainer
{
Q_OBJECT
@@ -54,26 +54,12 @@ public:
static QString settingsIdKey();
template<class Aspect, typename ...Args>
Aspect *addAspect(Args && ...args)
{
return m_aspects.addAspect<Aspect>(std::forward<Args>(args)...);
}
const Utils::AspectContainer &aspects() const { return m_aspects; }
Utils::BaseAspect *aspect(Utils::Id id) const;
template <typename T> T *aspect() const { return m_aspects.aspect<T>(); }
Utils::FilePath mapFromBuildDeviceToGlobalPath(const Utils::FilePath &path) const;
signals:
void displayNameChanged();
void toolTipChanged();
protected:
Utils::AspectContainer m_aspects;
private:
QPointer<Target> m_target;
const Utils::Id m_id;

View File

@@ -217,7 +217,7 @@ bool RunConfiguration::isEnabled() const
QWidget *RunConfiguration::createConfigurationWidget()
{
Layouting::Form form;
for (BaseAspect *aspect : std::as_const(m_aspects)) {
for (BaseAspect *aspect : std::as_const(*this)) {
if (aspect->isVisible()) {
form.addItem(aspect);
form.addItem(Layouting::br);
@@ -247,7 +247,7 @@ void RunConfiguration::addAspectFactory(const AspectFactory &aspectFactory)
QMap<Utils::Id, QVariantMap> RunConfiguration::settingsData() const
{
QMap<Utils::Id, QVariantMap> data;
for (BaseAspect *aspect : m_aspects)
for (BaseAspect *aspect : *this)
aspect->toActiveMap(data[aspect->id()]);
return data;
}
@@ -255,7 +255,7 @@ QMap<Utils::Id, QVariantMap> RunConfiguration::settingsData() const
AspectContainerData RunConfiguration::aspectData() const
{
AspectContainerData data;
for (BaseAspect *aspect : m_aspects)
for (BaseAspect *aspect : *this)
data.append(aspect->extractData());
return data;
}
@@ -566,7 +566,7 @@ RunConfiguration *RunConfigurationFactory::create(Target *target) const
// Add the universal aspects.
for (const RunConfiguration::AspectFactory &factory : theAspectFactories)
rc->m_aspects.registerAspect(factory(target));
rc->registerAspect(factory(target));
return rc;
}

View File

@@ -138,6 +138,7 @@ public:
return nullptr;
}
using ProjectConfiguration::registerAspect;
using AspectFactory = std::function<Utils::BaseAspect *(Target *)>;
template <class T> static void registerAspect()
{