Commit 519cc8de authored by hjk's avatar hjk

ProjectExplorer: De-duplicate code in IBuildStepFactory derived classes

This removes 900 lines of duplicated code, some duplicated checks at
runtime and some (minor) quadratic behavior when gathering display names.

canClone(), canRestore() and canCreate() and restore() use the same
pattern. Handle that on the core side once. Leave retore() virtual to let
the ios code unmodified (which is likely not needed, later...). Introduce
'Unclonable' and 'Uncreatable' flags to keep Android package installation
and WinRT deployment (non-)functionality unchanged.

Change-Id: I0325479aff818a4038b2f241ca733b8d8cd66f2f
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 4ce04942
......@@ -56,6 +56,7 @@
#include <QMessageBox>
using namespace ProjectExplorer;
using namespace Android;
using namespace Android::Internal;
......@@ -73,60 +74,24 @@ AndroidDeployQtStepFactory::AndroidDeployQtStepFactory(QObject *parent)
{
}
QList<Core::Id> AndroidDeployQtStepFactory::availableCreationIds(ProjectExplorer::BuildStepList *parent) const
QList<BuildStepInfo> AndroidDeployQtStepFactory::availableSteps(BuildStepList *parent) const
{
if (parent->id() != ProjectExplorer::Constants::BUILDSTEPS_DEPLOY)
return QList<Core::Id>();
if (!AndroidManager::supportsAndroid(parent->target()))
return QList<Core::Id>();
if (parent->contains(AndroidDeployQtStep::Id))
return QList<Core::Id>();
return QList<Core::Id>() << AndroidDeployQtStep::Id;
}
QString AndroidDeployQtStepFactory::displayNameForId(Core::Id id) const
{
if (id == AndroidDeployQtStep::Id)
return tr("Deploy to Android device or emulator");
return QString();
}
if (parent->id() != ProjectExplorer::Constants::BUILDSTEPS_DEPLOY
|| !AndroidManager::supportsAndroid(parent->target())
|| parent->contains(AndroidDeployQtStep::Id))
return {};
bool AndroidDeployQtStepFactory::canCreate(ProjectExplorer::BuildStepList *parent, Core::Id id) const
{
return availableCreationIds(parent).contains(id);
return {{ AndroidDeployQtStep::Id, tr("Deploy to Android device or emulator") }};
}
ProjectExplorer::BuildStep *AndroidDeployQtStepFactory::create(ProjectExplorer::BuildStepList *parent, Core::Id id)
{
Q_ASSERT(canCreate(parent, id));
Q_UNUSED(id);
return new AndroidDeployQtStep(parent);
}
bool AndroidDeployQtStepFactory::canRestore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) const
{
return canCreate(parent, ProjectExplorer::idFromMap(map));
}
ProjectExplorer::BuildStep *AndroidDeployQtStepFactory::restore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map)
{
Q_ASSERT(canRestore(parent, map));
AndroidDeployQtStep * const step = new AndroidDeployQtStep(parent);
if (!step->fromMap(map)) {
delete step;
return 0;
}
return step;
}
bool AndroidDeployQtStepFactory::canClone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *product) const
{
return canCreate(parent, product->id());
}
ProjectExplorer::BuildStep *AndroidDeployQtStepFactory::clone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *product)
{
Q_ASSERT(canClone(parent, product));
return new AndroidDeployQtStep(parent, static_cast<AndroidDeployQtStep *>(product));
}
......
......@@ -47,17 +47,10 @@ class AndroidDeployQtStepFactory : public ProjectExplorer::IBuildStepFactory
public:
explicit AndroidDeployQtStepFactory(QObject *parent = 0);
QList<Core::Id> availableCreationIds(ProjectExplorer::BuildStepList *parent) const override;
QString displayNameForId(Core::Id id) const override;
QList<ProjectExplorer::BuildStepInfo>
availableSteps(ProjectExplorer::BuildStepList *parent) const override;
bool canCreate(ProjectExplorer::BuildStepList *parent, Core::Id id) const override;
ProjectExplorer::BuildStep *create(ProjectExplorer::BuildStepList *parent, Core::Id id) override;
bool canRestore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) const override;
ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) override;
bool canClone(ProjectExplorer::BuildStepList *parent,
ProjectExplorer::BuildStep *product) const override;
ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStepList *parent,
ProjectExplorer::BuildStep *product) override;
};
......
......@@ -56,67 +56,27 @@ const char AUTOGEN_STEP_ID[] = "AutotoolsProjectManager.AutogenStep";
AutogenStepFactory::AutogenStepFactory(QObject *parent) : IBuildStepFactory(parent)
{ }
QList<Core::Id> AutogenStepFactory::availableCreationIds(BuildStepList *parent) const
QList<BuildStepInfo> AutogenStepFactory::availableSteps(BuildStepList *parent) const
{
if (!canHandle(parent))
return QList<Core::Id>();
return QList<Core::Id>() << Core::Id(AUTOGEN_STEP_ID);
}
if (parent->target()->project()->id() != Constants::AUTOTOOLS_PROJECT_ID
|| parent->id() != ProjectExplorer::Constants::BUILDSTEPS_BUILD)
return {};
QString AutogenStepFactory::displayNameForId(Core::Id id) const
{
if (id == AUTOGEN_STEP_ID)
return tr("Autogen", "Display name for AutotoolsProjectManager::AutogenStep id.");
return QString();
}
bool AutogenStepFactory::canCreate(BuildStepList *parent, Core::Id id) const
{
return canHandle(parent) && Core::Id(AUTOGEN_STEP_ID) == id;
QString display = tr("Autogen", "Display name for AutotoolsProjectManager::AutogenStep id.");
return {{ AUTOGEN_STEP_ID, display }};
}
BuildStep *AutogenStepFactory::create(BuildStepList *parent, Core::Id id)
{
if (!canCreate(parent, id))
return 0;
Q_UNUSED(id)
return new AutogenStep(parent);
}
bool AutogenStepFactory::canClone(BuildStepList *parent, BuildStep *source) const
{
return canCreate(parent, source->id());
}
BuildStep *AutogenStepFactory::clone(BuildStepList *parent, BuildStep *source)
{
if (!canClone(parent, source))
return 0;
return new AutogenStep(parent, static_cast<AutogenStep *>(source));
}
bool AutogenStepFactory::canRestore(BuildStepList *parent, const QVariantMap &map) const
{
return canCreate(parent, idFromMap(map));
}
BuildStep *AutogenStepFactory::restore(BuildStepList *parent, const QVariantMap &map)
{
if (!canRestore(parent, map))
return 0;
AutogenStep *bs = new AutogenStep(parent);
if (bs->fromMap(map))
return bs;
delete bs;
return 0;
}
bool AutogenStepFactory::canHandle(BuildStepList *parent) const
{
if (parent->target()->project()->id() == Constants::AUTOTOOLS_PROJECT_ID)
return parent->id() == ProjectExplorer::Constants::BUILDSTEPS_BUILD;
return false;
}
////////////////////////
// AutogenStep class
////////////////////////
......
......@@ -55,16 +55,11 @@ class AutogenStepFactory : public ProjectExplorer::IBuildStepFactory
public:
AutogenStepFactory(QObject *parent = 0);
QList<Core::Id> availableCreationIds(ProjectExplorer::BuildStepList *bc) const override;
QString displayNameForId(Core::Id id) const override;
bool canCreate(ProjectExplorer::BuildStepList *parent, Core::Id id) const override;
QList<ProjectExplorer::BuildStepInfo>
availableSteps(ProjectExplorer::BuildStepList *parent) const override;
ProjectExplorer::BuildStep *create(ProjectExplorer::BuildStepList *parent, Core::Id id) override;
bool canClone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *source) const override;
ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *source) override;
bool canRestore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) const override;
ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) override;
bool canHandle(ProjectExplorer::BuildStepList *parent) const;
};
///////////////////////
......
......@@ -55,67 +55,27 @@ const char AUTORECONF_ADDITIONAL_ARGUMENTS_KEY[] = "AutotoolsProjectManager.Auto
AutoreconfStepFactory::AutoreconfStepFactory(QObject *parent) : IBuildStepFactory(parent)
{ }
QList<Core::Id> AutoreconfStepFactory::availableCreationIds(BuildStepList *parent) const
QList<BuildStepInfo> AutoreconfStepFactory::availableSteps(BuildStepList *parent) const
{
if (!canHandle(parent))
return QList<Core::Id>();
return QList<Core::Id>() << Core::Id(AUTORECONF_STEP_ID);
}
if (parent->target()->project()->id() != Constants::AUTOTOOLS_PROJECT_ID
|| parent->id() != ProjectExplorer::Constants::BUILDSTEPS_BUILD)
return {};
QString AutoreconfStepFactory::displayNameForId(Core::Id id) const
{
if (id == AUTORECONF_STEP_ID)
return tr("Autoreconf", "Display name for AutotoolsProjectManager::AutoreconfStep id.");
return QString();
}
bool AutoreconfStepFactory::canCreate(BuildStepList *parent, Core::Id id) const
{
return canHandle(parent) && Core::Id(AUTORECONF_STEP_ID) == id;
QString display = tr("Autoreconf", "Display name for AutotoolsProjectManager::AutoreconfStep id.");
return {{ AUTORECONF_STEP_ID, display }};
}
BuildStep *AutoreconfStepFactory::create(BuildStepList *parent, Core::Id id)
{
if (!canCreate(parent, id))
return 0;
Q_UNUSED(id);
return new AutoreconfStep(parent);
}
bool AutoreconfStepFactory::canClone(BuildStepList *parent, BuildStep *source) const
{
return canCreate(parent, source->id());
}
BuildStep *AutoreconfStepFactory::clone(BuildStepList *parent, BuildStep *source)
{
if (!canClone(parent, source))
return 0;
return new AutoreconfStep(parent, static_cast<AutoreconfStep *>(source));
}
bool AutoreconfStepFactory::canRestore(BuildStepList *parent, const QVariantMap &map) const
{
return canCreate(parent, idFromMap(map));
}
BuildStep *AutoreconfStepFactory::restore(BuildStepList *parent, const QVariantMap &map)
{
if (!canRestore(parent, map))
return 0;
AutoreconfStep *bs = new AutoreconfStep(parent);
if (bs->fromMap(map))
return bs;
delete bs;
return 0;
}
bool AutoreconfStepFactory::canHandle(BuildStepList *parent) const
{
if (parent->target()->project()->id() == Constants::AUTOTOOLS_PROJECT_ID)
return parent->id() == ProjectExplorer::Constants::BUILDSTEPS_BUILD;
return false;
}
/////////////////////////
// AutoreconfStep class
/////////////////////////
......
......@@ -54,17 +54,11 @@ class AutoreconfStepFactory : public ProjectExplorer::IBuildStepFactory
public:
AutoreconfStepFactory(QObject *parent = 0);
QList<Core::Id> availableCreationIds(ProjectExplorer::BuildStepList *bc) const override;
QString displayNameForId(Core::Id id) const override;
QList<ProjectExplorer::BuildStepInfo>
availableSteps(ProjectExplorer::BuildStepList *parent) const override;
bool canCreate(ProjectExplorer::BuildStepList *parent, Core::Id id) const override;
ProjectExplorer::BuildStep *create(ProjectExplorer::BuildStepList *parent, Core::Id id) override;
bool canClone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *source) const override;
ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *source) override;
bool canRestore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) const override;
ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) override;
bool canHandle(ProjectExplorer::BuildStepList *parent) const;
};
/////////////////////////
......
......@@ -70,66 +70,27 @@ static QString projectDirRelativeToBuildDir(BuildConfiguration *bc) {
ConfigureStepFactory::ConfigureStepFactory(QObject *parent) : IBuildStepFactory(parent)
{ }
QList<Core::Id> ConfigureStepFactory::availableCreationIds(BuildStepList *parent) const
QList<BuildStepInfo> ConfigureStepFactory::availableSteps(BuildStepList *parent) const
{
if (!canHandle(parent))
return QList<Core::Id>();
return QList<Core::Id>() << Core::Id(CONFIGURE_STEP_ID);
}
if (parent->target()->project()->id() != Constants::AUTOTOOLS_PROJECT_ID
|| parent->id() != ProjectExplorer::Constants::BUILDSTEPS_BUILD)
return {};
QString ConfigureStepFactory::displayNameForId(Core::Id id) const
{
if (id == CONFIGURE_STEP_ID)
return tr("Configure", "Display name for AutotoolsProjectManager::ConfigureStep id.");
return QString();
}
bool ConfigureStepFactory::canCreate(BuildStepList *parent, Core::Id id) const
{
return canHandle(parent) && id == CONFIGURE_STEP_ID;
QString display = tr("Configure", "Display name for AutotoolsProjectManager::ConfigureStep id.");
return {{ CONFIGURE_STEP_ID, display }};
}
BuildStep *ConfigureStepFactory::create(BuildStepList *parent, Core::Id id)
{
if (!canCreate(parent, id))
return 0;
Q_UNUSED(id)
return new ConfigureStep(parent);
}
bool ConfigureStepFactory::canClone(BuildStepList *parent, BuildStep *source) const
{
return canCreate(parent, source->id());
}
BuildStep *ConfigureStepFactory::clone(BuildStepList *parent, BuildStep *source)
{
if (!canClone(parent, source))
return 0;
return new ConfigureStep(parent, static_cast<ConfigureStep *>(source));
}
bool ConfigureStepFactory::canRestore(BuildStepList *parent, const QVariantMap &map) const
{
return canCreate(parent, idFromMap(map));
}
BuildStep *ConfigureStepFactory::restore(BuildStepList *parent, const QVariantMap &map)
{
if (!canRestore(parent, map))
return 0;
ConfigureStep *bs = new ConfigureStep(parent);
if (bs->fromMap(map))
return bs;
delete bs;
return 0;
}
bool ConfigureStepFactory::canHandle(BuildStepList *parent) const
{
if (parent->target()->project()->id() == Constants::AUTOTOOLS_PROJECT_ID)
return parent->id() == ProjectExplorer::Constants::BUILDSTEPS_BUILD;
return false;
}
////////////////////////
// ConfigureStep class
......
......@@ -54,17 +54,11 @@ class ConfigureStepFactory : public ProjectExplorer::IBuildStepFactory
public:
ConfigureStepFactory(QObject *parent = 0);
QList<Core::Id> availableCreationIds(ProjectExplorer::BuildStepList *bc) const override;
QString displayNameForId(Core::Id id) const override;
QList<ProjectExplorer::BuildStepInfo>
availableSteps(ProjectExplorer::BuildStepList *parent) const override;
bool canCreate(ProjectExplorer::BuildStepList *parent, Core::Id id) const override;
ProjectExplorer::BuildStep *create(ProjectExplorer::BuildStepList *parent, Core::Id id) override;
bool canClone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *source) const override;
ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *source) override;
bool canRestore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) const override;
ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) override;
bool canHandle(ProjectExplorer::BuildStepList *parent) const;
};
//////////////////////////
......
......@@ -62,62 +62,25 @@ const char MAKE_STEP_ADDITIONAL_ARGUMENTS_KEY[] = "AutotoolsProjectManager.MakeS
MakeStepFactory::MakeStepFactory(QObject *parent) : IBuildStepFactory(parent)
{ setObjectName(QLatin1String("Autotools::MakeStepFactory")); }
QList<Core::Id> MakeStepFactory::availableCreationIds(BuildStepList *parent) const
QList<BuildStepInfo> MakeStepFactory::availableSteps(BuildStepList *parent) const
{
if (parent->target()->project()->id() == AUTOTOOLS_PROJECT_ID)
return QList<Core::Id>() << Core::Id(MAKE_STEP_ID);
return QList<Core::Id>();
}
QString MakeStepFactory::displayNameForId(Core::Id id) const
{
if (id == MAKE_STEP_ID)
return tr("Make", "Display name for AutotoolsProjectManager::MakeStep id.");
return QString();
}
if (parent->target()->project()->id() != AUTOTOOLS_PROJECT_ID)
return {};
bool MakeStepFactory::canCreate(BuildStepList *parent, Core::Id id) const
{
if (parent->target()->project()->id() == AUTOTOOLS_PROJECT_ID)
return id == MAKE_STEP_ID;
return false;
return {{ MAKE_STEP_ID, tr("Make", "Display name for AutotoolsProjectManager::MakeStep id.") }};
}
BuildStep *MakeStepFactory::create(BuildStepList *parent, Core::Id id)
{
if (!canCreate(parent, id))
return 0;
Q_UNUSED(id)
return new MakeStep(parent);
}
bool MakeStepFactory::canClone(BuildStepList *parent, BuildStep *source) const
{
return canCreate(parent, source->id());
}
BuildStep *MakeStepFactory::clone(BuildStepList *parent, BuildStep *source)
{
if (!canClone(parent, source))
return 0;
return new MakeStep(parent, static_cast<MakeStep *>(source));
}
bool MakeStepFactory::canRestore(BuildStepList *parent, const QVariantMap &map) const
{
return canCreate(parent, idFromMap(map));
}
BuildStep *MakeStepFactory::restore(BuildStepList *parent, const QVariantMap &map)
{
if (!canRestore(parent, map))
return 0;
MakeStep *bs = new MakeStep(parent);
if (bs->fromMap(map))
return bs;
delete bs;
return 0;
}
/////////////////////
// MakeStep class
/////////////////////
......
......@@ -55,15 +55,11 @@ class MakeStepFactory : public ProjectExplorer::IBuildStepFactory
public:
MakeStepFactory(QObject *parent = 0);
QList<Core::Id> availableCreationIds(ProjectExplorer::BuildStepList *bc) const override;
QString displayNameForId(Core::Id id) const override;
QList<ProjectExplorer::BuildStepInfo>
availableSteps(ProjectExplorer::BuildStepList *parent) const override;
bool canCreate(ProjectExplorer::BuildStepList *parent, Core::Id id) const override;
ProjectExplorer::BuildStep *create(ProjectExplorer::BuildStepList *parent, Core::Id id) override;
bool canClone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *source) const override;
ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *source) override;
bool canRestore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) const override;
ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) override;
};
/////////////////////
......
......@@ -512,65 +512,28 @@ QString CMakeBuildStepConfigWidget::summaryText() const
CMakeBuildStepFactory::CMakeBuildStepFactory(QObject *parent) : IBuildStepFactory(parent)
{ }
bool CMakeBuildStepFactory::canCreate(BuildStepList *parent, Core::Id id) const
QList<BuildStepInfo> CMakeBuildStepFactory::availableSteps(BuildStepList *parent) const
{
if (parent->target()->project()->id() == Constants::CMAKEPROJECT_ID)
return id == MS_ID;
return false;
if (parent->target()->project()->id() != Constants::CMAKEPROJECT_ID)
return {};
return {{ MS_ID, tr("Build", "Display name for CMakeProjectManager::CMakeBuildStep id.") }};
}
BuildStep *CMakeBuildStepFactory::create(BuildStepList *parent, Core::Id id)
{
if (!canCreate(parent, id))
return 0;
Q_UNUSED(id);
auto step = new CMakeBuildStep(parent);
if (parent->id() == ProjectExplorer::Constants::BUILDSTEPS_CLEAN)
step->setBuildTarget(CMakeBuildStep::cleanTarget());
return step;
}
bool CMakeBuildStepFactory::canClone(BuildStepList *parent, BuildStep *source) const
{
return canCreate(parent, source->id());
}
BuildStep *CMakeBuildStepFactory::clone(BuildStepList *parent, BuildStep *source)
{
if (!canClone(parent, source))
return 0;
return new CMakeBuildStep(parent, static_cast<CMakeBuildStep *>(source));
}
bool CMakeBuildStepFactory::canRestore(BuildStepList *parent, const QVariantMap &map) const
{
return canCreate(parent, idFromMap(map));
}
BuildStep *CMakeBuildStepFactory::restore(BuildStepList *parent, const QVariantMap &map)
{
if (!canRestore(parent, map))
return 0;
auto bs = new CMakeBuildStep(parent);
if (bs->fromMap(map))
return bs;
delete bs;
return 0;
}
QList<Core::Id> CMakeBuildStepFactory::availableCreationIds(BuildStepList *parent) const
{
if (parent->target()->project()->id() == Constants::CMAKEPROJECT_ID)
return QList<Core::Id>() << Core::Id(MS_ID);
return QList<Core::Id>();
}
QString CMakeBuildStepFactory::displayNameForId(Core::Id id) const
{
if (id == MS_ID)
return tr("Build", "Display name for CMakeProjectManager::CMakeBuildStep id.");
return QString();
}
void CMakeBuildStep::processStarted()
{
m_useNinja = false;
......
......@@ -142,15 +142,11 @@ class CMakeBuildStepFactory : public ProjectExplorer::IBuildStepFactory
public:
explicit CMakeBuildStepFactory(QObject *parent = 0);
bool canCreate(ProjectExplorer::BuildStepList *parent, Core::Id id) const override;
QList<ProjectExplorer::BuildStepInfo>
availableSteps(ProjectExplorer::BuildStepList *parent) const override;
ProjectExplorer::BuildStep *create(ProjectExplorer::BuildStepList *parent, Core::Id id) override;
bool canClone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *source) const override;
ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *source) override;
bool canRestore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) const override;
ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildStepList *parent, const QVariantMap &map) override;
QList<Core::Id> availableCreationIds(ProjectExplorer::BuildStepList *bc) const override;
QString displayNameForId(Core::Id id) const override;
};
} // namespace Internal
......
......@@ -320,17 +320,19 @@ GenericMakeStepFactory::GenericMakeStepFactory(QObject *parent) :
{
}
bool GenericMakeStepFactory::canCreate(BuildStepList *parent, const Id id) const
QList<BuildStepInfo> GenericMakeStepFactory::availableSteps(BuildStepList *parent) const
{
if (parent->target()->project()->id() == Constants::GENERICPROJECT_ID)
return id == GENERIC_MS_ID;
return false;
if (parent->target()->project()->id() != Constants::GENERICPROJECT_ID)
return {};
return {{ GENERIC_MS_ID,
QCoreApplication::translate("GenericProjectManager::Internal::GenericMakeStep",