Commit f32a1b1e authored by Tobias Hunger's avatar Tobias Hunger

ProjectExplorer: Add some more functions to buildsteplist

Use those functions instead of repeating code all over the place.

Change-Id: I03161663b4d5c538fb2ea667353ab7846373ad81
Reviewed-by: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent 385237db
......@@ -42,18 +42,13 @@ public:
template<class T> static T *buildStep(const ProjectExplorer::BuildConfiguration *dc)
{
if (!dc)
return 0;
return nullptr;
foreach (const Core::Id &id, dc->knownStepLists()) {
ProjectExplorer::BuildStepList *bsl = dc->stepList(id);
if (!bsl)
return 0;
const QList<ProjectExplorer::BuildStep *> &buildSteps = bsl->steps();
for (int i = buildSteps.count() - 1; i >= 0; --i) {
if (T * const step = qobject_cast<T *>(buildSteps.at(i)))
return step;
}
T *const step = dc->stepList(id)->firstOfType<T>();
if (step)
return step;
}
return 0;
return nullptr;
}
template<typename State> static void assertState(State expected,
......
......@@ -229,11 +229,6 @@ void AutotoolsBuildConfiguration::setBuildDirectory(const Utils::FileName &direc
if (directory == buildDirectory())
return;
BuildConfiguration::setBuildDirectory(directory);
BuildStepList *bsl = stepList(BUILDSTEPS_BUILD);
foreach (BuildStep *bs, bsl->steps()) {
ConfigureStep *cs = qobject_cast<ConfigureStep *>(bs);
if (cs) {
cs->notifyBuildDirectoryChanged();
}
}
foreach (auto bs, stepList(BUILDSTEPS_BUILD)->allOfType<ConfigureStep>())
bs->notifyBuildDirectoryChanged();
}
......@@ -113,13 +113,11 @@ RunControl *BareMetalRunControlFactory::create(
DebuggerStartParameters sp;
if (const BuildConfiguration *bc = target->activeBuildConfiguration()) {
if (const BuildStepList *bsl = bc->stepList(BareMetalGdbCommandsDeployStep::stepId())) {
foreach (const BuildStep *bs, bsl->steps()) {
if (auto ds = qobject_cast<const BareMetalGdbCommandsDeployStep *>(bs)) {
if (!sp.commandsAfterConnect.endsWith("\n"))
sp.commandsAfterConnect.append("\n");
sp.commandsAfterConnect.append(ds->gdbCommands().toLatin1());
}
if (BuildStepList *bsl = bc->stepList(BareMetalGdbCommandsDeployStep::stepId())) {
foreach (const BareMetalGdbCommandsDeployStep *bs, bsl->allOfType<BareMetalGdbCommandsDeployStep>()) {
if (!sp.commandsAfterConnect.endsWith("\n"))
sp.commandsAfterConnect.append("\n");
sp.commandsAfterConnect.append(bs->gdbCommands().toLatin1());
}
}
}
......
......@@ -84,29 +84,20 @@ QList<Core::LocatorFilterEntry> CMakeLocatorFilter::matchesFor(QFutureInterface<
void CMakeLocatorFilter::accept(Core::LocatorFilterEntry selection) const
{
// Get the project containing the target selected
CMakeProject *cmakeProject = 0;
CMakeProject *cmakeProject = nullptr;
foreach (Project *p, SessionManager::projects()) {
cmakeProject = qobject_cast<CMakeProject *>(p);
if (cmakeProject && cmakeProject->projectFilePath().toString() == selection.internalData.toString())
break;
cmakeProject = 0;
}
if (!cmakeProject)
return;
if (!cmakeProject->activeTarget())
return;
if (!cmakeProject->activeTarget()->activeBuildConfiguration())
if (!cmakeProject || !cmakeProject->activeTarget() || !cmakeProject->activeTarget()->activeBuildConfiguration())
return;
// Find the make step
ProjectExplorer::BuildStepList *buildStepList = cmakeProject->activeTarget()->activeBuildConfiguration()
->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
auto buildStep
= qobject_cast<CMakeBuildStep *>(findOrDefault(buildStepList->steps(),
[](BuildStep *s) -> bool { return qobject_cast<CMakeBuildStep *>(s); }));
auto buildStep = buildStepList->firstOfType<CMakeBuildStep>();
if (!buildStep)
return;
......
......@@ -174,19 +174,8 @@ void IosRunConfiguration::updateDisplayNames()
IosDeployStep *IosRunConfiguration::deployStep() const
{
IosDeployStep * step = 0;
DeployConfiguration *config = target()->activeDeployConfiguration();
BuildStepList *bsl = config->stepList();
if (bsl) {
const QList<BuildStep *> &buildSteps = bsl->steps();
for (int i = buildSteps.count() - 1; i >= 0; --i) {
step = qobject_cast<IosDeployStep *>(buildSteps.at(i));
if (step)
break;
}
}
Q_ASSERT_X(step, Q_FUNC_INFO, "Impossible: iOS build configuration without deploy step.");
return step;
return config ? config->stepList()->firstOfType<IosDeployStep>() : nullptr;
}
FileName IosRunConfiguration::profilePath() const
......
......@@ -553,9 +553,8 @@ bool BuildManager::buildLists(QList<BuildStepList *> bsls, const QStringList &st
QStringList names;
names.reserve(steps.size());
for (int i = 0; i < bsls.size(); ++i) {
for (int j = 0; j < bsls.at(i)->steps().size(); ++j) {
for (int j = 0; j < bsls.at(i)->count(); ++j)
names.append(stepListNames.at(i));
}
}
bool success = buildQueueAppend(steps, names, preambelMessage);
......
......@@ -168,6 +168,11 @@ QList<BuildStep *> BuildStepList::steps() const
return m_steps;
}
QList<BuildStep *> BuildStepList::steps(const std::function<bool (const BuildStep *)> &filter) const
{
return Utils::filtered(steps(), filter);
}
void BuildStepList::insertStep(int position, BuildStep *step)
{
m_steps.insert(position, step);
......
......@@ -47,6 +47,27 @@ public:
~BuildStepList() override;
QList<BuildStep *> steps() const;
QList<BuildStep *> steps(const std::function<bool(const BuildStep *)> &filter) const;
template <class BS> BS *firstOfType() {
BS *bs = nullptr;
for (int i = 0; i < count(); ++i) {
bs = qobject_cast<BS *>(at(i));
if (bs)
return bs;
}
return nullptr;
}
template <class BS> QList<BS *>allOfType() {
QList<BS *> result;
BS *bs = nullptr;
for (int i = 0; i < count(); ++i) {
bs = qobject_cast<BS *>(at(i));
if (bs)
result.append(bs);
}
return result;
}
bool isNull() const;
int count() const;
bool isEmpty() const;
......
......@@ -115,11 +115,7 @@ NamedWidget *QbsBuildConfiguration::createConfigWidget()
QbsBuildStep *QbsBuildConfiguration::qbsStep() const
{
foreach (BuildStep *bs, stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD)->steps()) {
if (QbsBuildStep *qbsBs = qobject_cast<QbsBuildStep *>(bs))
return qbsBs;
}
return 0;
return stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD)->firstOfType<QbsBuildStep>();
}
QVariantMap QbsBuildConfiguration::qbsConfiguration() const
......
......@@ -55,11 +55,7 @@ static Core::Id genericQbsDeployConfigurationId()
QbsInstallStep *QbsDeployConfiguration::qbsInstallStep() const
{
foreach (ProjectExplorer::BuildStep *bs, stepList()->steps()) {
if (QbsInstallStep *install = qobject_cast<QbsInstallStep *>(bs))
return install;
}
return 0;
return stepList()->firstOfType<QbsInstallStep>();
}
QbsDeployConfiguration::QbsDeployConfiguration(ProjectExplorer::Target *target, Core::Id id) :
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment