forked from qt-creator/qt-creator
ProjectExplorer: Add a ProjectConfiguration::target()
... with a suitable default implementation accessing a member populated at construction time instead of walking the parent chains on each access. Change-Id: I58dae6da80ed0b023cc603fca13a5a205b123672 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -65,6 +65,7 @@ namespace ProjectExplorer {
|
||||
BuildConfiguration::BuildConfiguration(Target *target, Core::Id id)
|
||||
: ProjectConfiguration(target, id)
|
||||
{
|
||||
QTC_CHECK(target && target == this->target());
|
||||
Utils::MacroExpander *expander = macroExpander();
|
||||
expander->setDisplayName(tr("Build Settings"));
|
||||
expander->setAccumulating(true);
|
||||
@@ -271,16 +272,6 @@ void BuildConfiguration::setBuildDirectorySettingsKey(const QString &key)
|
||||
m_buildDirectoryAspect->setSettingsKey(key);
|
||||
}
|
||||
|
||||
Target *BuildConfiguration::target() const
|
||||
{
|
||||
return static_cast<Target *>(parent());
|
||||
}
|
||||
|
||||
Project *BuildConfiguration::project() const
|
||||
{
|
||||
return target()->project();
|
||||
}
|
||||
|
||||
Utils::Environment BuildConfiguration::baseEnvironment() const
|
||||
{
|
||||
Utils::Environment result;
|
||||
|
@@ -75,9 +75,6 @@ public:
|
||||
bool fromMap(const QVariantMap &map) override;
|
||||
QVariantMap toMap() const override;
|
||||
|
||||
Target *target() const;
|
||||
Project *project() const override;
|
||||
|
||||
virtual bool isEnabled() const;
|
||||
virtual QString disabledReason() const;
|
||||
|
||||
|
@@ -126,6 +126,7 @@ static QList<BuildStepFactory *> g_buildStepFactories;
|
||||
BuildStep::BuildStep(BuildStepList *bsl, Core::Id id) :
|
||||
ProjectConfiguration(bsl, id)
|
||||
{
|
||||
QTC_CHECK(bsl->target() && bsl->target() == this->target());
|
||||
Utils::MacroExpander *expander = macroExpander();
|
||||
expander->setDisplayName(tr("Build Step"));
|
||||
expander->setAccumulating(true);
|
||||
@@ -204,16 +205,6 @@ ProjectConfiguration *BuildStep::projectConfiguration() const
|
||||
return static_cast<ProjectConfiguration *>(parent()->parent());
|
||||
}
|
||||
|
||||
Target *BuildStep::target() const
|
||||
{
|
||||
return qobject_cast<Target *>(parent()->parent()->parent());
|
||||
}
|
||||
|
||||
Project *BuildStep::project() const
|
||||
{
|
||||
return target()->project();
|
||||
}
|
||||
|
||||
void BuildStep::reportRunResult(QFutureInterface<bool> &fi, bool success)
|
||||
{
|
||||
fi.reportResult(success);
|
||||
|
@@ -72,8 +72,6 @@ public:
|
||||
BuildConfiguration *buildConfiguration() const;
|
||||
DeployConfiguration *deployConfiguration() const;
|
||||
ProjectConfiguration *projectConfiguration() const;
|
||||
Target *target() const;
|
||||
Project *project() const override;
|
||||
|
||||
enum class OutputFormat {
|
||||
Stdout, Stderr, // These are for forwarded output from external tools
|
||||
|
@@ -46,6 +46,7 @@ const char STEPS_PREFIX[] = "ProjectExplorer.BuildStepList.Step.";
|
||||
BuildStepList::BuildStepList(QObject *parent, Core::Id id)
|
||||
: ProjectConfiguration(parent, id)
|
||||
{
|
||||
QTC_CHECK(parent && parent->parent() && parent->parent() == target());
|
||||
if (id == Constants::BUILDSTEPS_BUILD) {
|
||||
//: Display name of the build build step list. Used as part of the labels in the project window.
|
||||
setDefaultDisplayName(tr("Build"));
|
||||
@@ -192,20 +193,3 @@ BuildStep *BuildStepList::at(int position)
|
||||
{
|
||||
return m_steps.at(position);
|
||||
}
|
||||
|
||||
Target *BuildStepList::target() const
|
||||
{
|
||||
Q_ASSERT(parent());
|
||||
auto bc = qobject_cast<BuildConfiguration *>(parent());
|
||||
if (bc)
|
||||
return bc->target();
|
||||
auto dc = qobject_cast<DeployConfiguration *>(parent());
|
||||
if (dc)
|
||||
return dc->target();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Project *BuildStepList::project() const
|
||||
{
|
||||
return target()->project();
|
||||
}
|
||||
|
@@ -77,9 +77,6 @@ public:
|
||||
void moveStepUp(int position);
|
||||
BuildStep *at(int position);
|
||||
|
||||
Target *target() const;
|
||||
Project *project() const override;
|
||||
|
||||
QVariantMap toMap() const override;
|
||||
bool fromMap(const QVariantMap &map) override;
|
||||
|
||||
|
@@ -44,6 +44,7 @@ DeployConfiguration::DeployConfiguration(Target *target, Core::Id id)
|
||||
: ProjectConfiguration(target, id),
|
||||
m_stepList(this, Constants::BUILDSTEPS_DEPLOY)
|
||||
{
|
||||
QTC_CHECK(target && target == this->target());
|
||||
Utils::MacroExpander *expander = macroExpander();
|
||||
expander->setDisplayName(tr("Deploy Settings"));
|
||||
expander->setAccumulating(true);
|
||||
@@ -108,16 +109,6 @@ bool DeployConfiguration::fromMap(const QVariantMap &map)
|
||||
return true;
|
||||
}
|
||||
|
||||
Target *DeployConfiguration::target() const
|
||||
{
|
||||
return static_cast<Target *>(parent());
|
||||
}
|
||||
|
||||
Project *DeployConfiguration::project() const
|
||||
{
|
||||
return target()->project();
|
||||
}
|
||||
|
||||
bool DeployConfiguration::isActive() const
|
||||
{
|
||||
return target()->isActive() && target()->activeDeployConfiguration() == this;
|
||||
|
@@ -56,9 +56,6 @@ public:
|
||||
bool fromMap(const QVariantMap &map) override;
|
||||
QVariantMap toMap() const override;
|
||||
|
||||
Target *target() const;
|
||||
Project *project() const override;
|
||||
|
||||
bool isActive() const override;
|
||||
|
||||
private:
|
||||
|
@@ -24,6 +24,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "projectconfiguration.h"
|
||||
#include "target.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -86,10 +87,25 @@ ProjectConfiguration::ProjectConfiguration(QObject *parent, Core::Id id)
|
||||
{
|
||||
QTC_CHECK(id.isValid());
|
||||
setObjectName(id.toString());
|
||||
for (QObject *obj = this; obj; obj = obj->parent()) {
|
||||
m_target = qobject_cast<Target *>(obj);
|
||||
if (m_target != nullptr)
|
||||
break;
|
||||
}
|
||||
|
||||
// FIXME: Below triggers on 'real' Targets with this here a base class as it's
|
||||
// not a real Target at this point of time. Plan is to cut this dependency and
|
||||
// enable the check, for now the item is set manually in the Target ctor.
|
||||
// QTC_CHECK(m_target);
|
||||
}
|
||||
|
||||
ProjectConfiguration::~ProjectConfiguration() = default;
|
||||
|
||||
Project *ProjectConfiguration::project() const
|
||||
{
|
||||
return m_target->project();
|
||||
}
|
||||
|
||||
Core::Id ProjectConfiguration::id() const
|
||||
{
|
||||
return m_id;
|
||||
@@ -159,6 +175,12 @@ QVariantMap ProjectConfiguration::toMap() const
|
||||
return map;
|
||||
}
|
||||
|
||||
Target *ProjectConfiguration::target() const
|
||||
{
|
||||
return m_target;
|
||||
|
||||
}
|
||||
|
||||
bool ProjectConfiguration::fromMap(const QVariantMap &map)
|
||||
{
|
||||
Core::Id id = Core::Id::fromSetting(map.value(QLatin1String(CONFIGURATION_ID_KEY)));
|
||||
|
@@ -42,6 +42,7 @@ namespace ProjectExplorer {
|
||||
|
||||
class Project;
|
||||
class ProjectConfigurationAspects;
|
||||
class Target;
|
||||
|
||||
class PROJECTEXPLORER_EXPORT ProjectConfigurationAspect : public QObject
|
||||
{
|
||||
@@ -153,7 +154,8 @@ public:
|
||||
Utils::MacroExpander *macroExpander() { return &m_macroExpander; }
|
||||
const Utils::MacroExpander *macroExpander() const { return &m_macroExpander; }
|
||||
|
||||
virtual Project *project() const = 0;
|
||||
Target *target() const;
|
||||
Project *project() const;
|
||||
|
||||
virtual bool isActive() const = 0;
|
||||
|
||||
@@ -180,6 +182,8 @@ protected:
|
||||
ProjectConfigurationAspects m_aspects;
|
||||
|
||||
private:
|
||||
friend class Target; // FIXME: Remove
|
||||
Target *m_target = nullptr;
|
||||
const Core::Id m_id;
|
||||
QString m_displayName;
|
||||
QString m_defaultDisplayName;
|
||||
|
@@ -160,6 +160,7 @@ static std::vector<RunConfiguration::AspectFactory> theAspectFactories;
|
||||
RunConfiguration::RunConfiguration(Target *target, Core::Id id)
|
||||
: ProjectConfiguration(target, id)
|
||||
{
|
||||
QTC_CHECK(target && target == this->target());
|
||||
connect(target->project(), &Project::parsingStarted,
|
||||
this, [this]() { updateEnabledState(); });
|
||||
connect(target->project(), &Project::parsingFinished,
|
||||
@@ -308,16 +309,6 @@ BuildConfiguration *RunConfiguration::activeBuildConfiguration() const
|
||||
return target()->activeBuildConfiguration();
|
||||
}
|
||||
|
||||
Target *RunConfiguration::target() const
|
||||
{
|
||||
return static_cast<Target *>(parent());
|
||||
}
|
||||
|
||||
Project *RunConfiguration::project() const
|
||||
{
|
||||
return target()->project();
|
||||
}
|
||||
|
||||
QVariantMap RunConfiguration::toMap() const
|
||||
{
|
||||
QVariantMap map = ProjectConfiguration::toMap();
|
||||
|
@@ -152,9 +152,6 @@ public:
|
||||
// TODO rename function
|
||||
virtual ConfigurationState ensureConfigured(QString *errorMessage = nullptr);
|
||||
|
||||
Target *target() const;
|
||||
Project *project() const override;
|
||||
|
||||
Utils::OutputFormatter *createOutputFormatter() const;
|
||||
|
||||
bool fromMap(const QVariantMap &map) override;
|
||||
|
@@ -116,6 +116,9 @@ Target::Target(Project *project, Kit *k, _constructor_tag) :
|
||||
ProjectConfiguration(project, k->id()),
|
||||
d(std::make_unique<TargetPrivate>(k))
|
||||
{
|
||||
// FIXME: Remove, see comment in ProjectConfiguration ctor.
|
||||
m_target = this;
|
||||
|
||||
QTC_CHECK(d->m_kit);
|
||||
connect(DeviceManager::instance(), &DeviceManager::updated, this, &Target::updateDeviceState);
|
||||
connect(project, &Project::parsingFinished, this, [this](bool success) {
|
||||
|
@@ -57,10 +57,10 @@ public:
|
||||
Target(Project *parent, Kit *k, _constructor_tag);
|
||||
~Target() override;
|
||||
|
||||
Project *project() const override;
|
||||
|
||||
bool isActive() const final;
|
||||
|
||||
Project *project() const;
|
||||
|
||||
// Kit:
|
||||
Kit *kit() const;
|
||||
|
||||
|
@@ -158,21 +158,21 @@ QVariantMap QbsBuildConfiguration::qbsConfiguration() const
|
||||
return config;
|
||||
}
|
||||
|
||||
Internal::QbsProject *QbsBuildConfiguration::project() const
|
||||
Internal::QbsProject *QbsBuildConfiguration::qbsProject() const
|
||||
{
|
||||
return qobject_cast<Internal::QbsProject *>(BuildConfiguration::project());
|
||||
return qobject_cast<Internal::QbsProject *>(project());
|
||||
}
|
||||
|
||||
bool QbsBuildConfiguration::isEnabled() const
|
||||
{
|
||||
return !project()->isParsing() && project()->hasParseResult();
|
||||
return !project()->isParsing() && qbsProject()->hasParseResult();
|
||||
}
|
||||
|
||||
QString QbsBuildConfiguration::disabledReason() const
|
||||
{
|
||||
if (project()->isParsing())
|
||||
return tr("Parsing the Qbs project.");
|
||||
if (!project()->hasParseResult())
|
||||
if (!qbsProject()->hasParseResult())
|
||||
return tr("Parsing of Qbs project has failed.");
|
||||
return QString();
|
||||
}
|
||||
|
@@ -53,7 +53,7 @@ public:
|
||||
QbsBuildStep *qbsStep() const;
|
||||
QVariantMap qbsConfiguration() const;
|
||||
|
||||
Internal::QbsProject *project() const override;
|
||||
Internal::QbsProject *qbsProject() const;
|
||||
|
||||
bool isEnabled() const override;
|
||||
QString disabledReason() const override;
|
||||
|
Reference in New Issue
Block a user