RunConfiguration: Simplify adding of ExtraAspects

This makes the code a bit simpler, at the cost of the factories not
having access to the fully specialized RunConfiguration anymore. This
is apparently never used and the factories can still use the Id to decide
what to do if they really need to.

Change-Id: I7d94f85e984ac87e62c6d341c1038e1538aa15df
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Tobias Hunger
2017-01-05 12:49:45 +01:00
parent f3e3d395e5
commit 87c8839202
5 changed files with 9 additions and 23 deletions

View File

@@ -50,7 +50,6 @@ public:
: ProjectExplorer::RunConfiguration(parent, "AutoTest.TestRunConfig")
{
setDefaultDisplayName(tr("AutoTest Debug"));
addExtraAspects();
// disable QmlDebugger that is enabled by default
// might change if debugging QuickTest gets enabled

View File

@@ -69,7 +69,6 @@ public:
: RunConfiguration(parent, "ClangStaticAnalyzer.DummyRunConfig")
{
setDefaultDisplayName(tr("Clang Static Analyzer"));
addExtraAspects();
}
private:

View File

@@ -33,6 +33,7 @@
#include "kitinformation.h"
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/outputformatter.h>
#include <utils/checkablemessagebox.h>
@@ -204,16 +205,16 @@ void IRunConfigurationAspect::resetProjectToGlobalSettings()
*/
RunConfiguration::RunConfiguration(Target *target, Core::Id id) :
ProjectConfiguration(target, id),
m_aspectsInitialized(false)
ProjectConfiguration(target, id)
{
Q_ASSERT(target);
ctor();
addExtraAspects();
}
RunConfiguration::RunConfiguration(Target *target, RunConfiguration *source) :
ProjectConfiguration(target, source),
m_aspectsInitialized(true)
ProjectConfiguration(target, source)
{
Q_ASSERT(target);
ctor();
@@ -231,12 +232,8 @@ RunConfiguration::~RunConfiguration()
void RunConfiguration::addExtraAspects()
{
if (m_aspectsInitialized)
return;
foreach (IRunControlFactory *factory, ExtensionSystem::PluginManager::getObjects<IRunControlFactory>())
addExtraAspect(factory->createRunConfigurationAspect(this));
m_aspectsInitialized = true;
}
void RunConfiguration::addExtraAspect(IRunConfigurationAspect *aspect)
@@ -326,8 +323,6 @@ Abi RunConfiguration::abi() const
bool RunConfiguration::fromMap(const QVariantMap &map)
{
addExtraAspects();
foreach (IRunConfigurationAspect *aspect, m_aspects)
aspect->fromMap(map);
@@ -354,16 +349,12 @@ bool RunConfiguration::fromMap(const QVariantMap &map)
QList<IRunConfigurationAspect *> RunConfiguration::extraAspects() const
{
QTC_ASSERT(m_aspectsInitialized, return QList<IRunConfigurationAspect *>());
return m_aspects;
}
IRunConfigurationAspect *RunConfiguration::extraAspect(Core::Id id) const
{
QTC_ASSERT(m_aspectsInitialized, return nullptr);
foreach (IRunConfigurationAspect *aspect, m_aspects)
if (aspect->id() == id)
return aspect;
return nullptr;
return Utils::findOrDefault(m_aspects, Utils::equal(&IRunConfigurationAspect::id, id));
}
/*!
@@ -443,7 +434,6 @@ RunConfiguration *IRunConfigurationFactory::create(Target *parent, Core::Id id)
RunConfiguration *rc = doCreate(parent, id);
if (!rc)
return nullptr;
rc->addExtraAspects();
return rc;
}

View File

@@ -276,7 +276,6 @@ public:
template <typename T> T *extraAspect() const
{
QTC_ASSERT(m_aspectsInitialized, return nullptr);
foreach (IRunConfigurationAspect *aspect, m_aspects)
if (T *result = qobject_cast<T *>(aspect))
return result;
@@ -286,7 +285,6 @@ public:
virtual Runnable runnable() const;
virtual Abi abi() const;
void addExtraAspects();
void addExtraAspect(IRunConfigurationAspect *aspect);
signals:
@@ -304,8 +302,9 @@ protected:
private:
void ctor();
void addExtraAspects();
QList<IRunConfigurationAspect *> m_aspects;
bool m_aspectsInitialized;
};
class PROJECTEXPLORER_EXPORT IRunConfigurationFactory : public QObject

View File

@@ -398,7 +398,6 @@ void Target::addRunConfiguration(RunConfiguration *rc)
{
QTC_ASSERT(rc && !d->m_runConfigurations.contains(rc), return);
Q_ASSERT(rc->target() == this);
rc->addExtraAspects();
// Check that we don't have a configuration with the same displayName
QString configurationDisplayName = rc->displayName();