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 @@ ...@@ -56,6 +56,7 @@
#include <QMessageBox> #include <QMessageBox>
using namespace ProjectExplorer;
using namespace Android; using namespace Android;
using namespace Android::Internal; using namespace Android::Internal;
...@@ -73,60 +74,24 @@ AndroidDeployQtStepFactory::AndroidDeployQtStepFactory(QObject *parent) ...@@ -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) if (parent->id() != ProjectExplorer::Constants::BUILDSTEPS_DEPLOY
return QList<Core::Id>(); || !AndroidManager::supportsAndroid(parent->target())
if (!AndroidManager::supportsAndroid(parent->target())) || parent->contains(AndroidDeployQtStep::Id))
return QList<Core::Id>(); return {};
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();
}
bool AndroidDeployQtStepFactory::canCreate(ProjectExplorer::BuildStepList *parent, Core::Id id) const return {{ AndroidDeployQtStep::Id, tr("Deploy to Android device or emulator") }};
{
return availableCreationIds(parent).contains(id);
} }
ProjectExplorer::BuildStep *AndroidDeployQtStepFactory::create(ProjectExplorer::BuildStepList *parent, Core::Id id) ProjectExplorer::BuildStep *AndroidDeployQtStepFactory::create(ProjectExplorer::BuildStepList *parent, Core::Id id)
{ {
Q_ASSERT(canCreate(parent, id));
Q_UNUSED(id); Q_UNUSED(id);
return new AndroidDeployQtStep(parent); 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) ProjectExplorer::BuildStep *AndroidDeployQtStepFactory::clone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *product)
{ {
Q_ASSERT(canClone(parent, product));
return new AndroidDeployQtStep(parent, static_cast<AndroidDeployQtStep *>(product)); return new AndroidDeployQtStep(parent, static_cast<AndroidDeployQtStep *>(product));
} }
......
...@@ -47,17 +47,10 @@ class AndroidDeployQtStepFactory : public ProjectExplorer::IBuildStepFactory ...@@ -47,17 +47,10 @@ class AndroidDeployQtStepFactory : public ProjectExplorer::IBuildStepFactory
public: public:
explicit AndroidDeployQtStepFactory(QObject *parent = 0); explicit AndroidDeployQtStepFactory(QObject *parent = 0);
QList<Core::Id> availableCreationIds(ProjectExplorer::BuildStepList *parent) const override; QList<ProjectExplorer::BuildStepInfo>
QString displayNameForId(Core::Id id) const override; 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; 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 *clone(ProjectExplorer::BuildStepList *parent,
ProjectExplorer::BuildStep *product) override; ProjectExplorer::BuildStep *product) override;
}; };
......
...@@ -56,67 +56,27 @@ const char AUTOGEN_STEP_ID[] = "AutotoolsProjectManager.AutogenStep"; ...@@ -56,67 +56,27 @@ const char AUTOGEN_STEP_ID[] = "AutotoolsProjectManager.AutogenStep";
AutogenStepFactory::AutogenStepFactory(QObject *parent) : IBuildStepFactory(parent) AutogenStepFactory::AutogenStepFactory(QObject *parent) : IBuildStepFactory(parent)
{ } { }
QList<Core::Id> AutogenStepFactory::availableCreationIds(BuildStepList *parent) const QList<BuildStepInfo> AutogenStepFactory::availableSteps(BuildStepList *parent) const
{ {
if (!canHandle(parent)) if (parent->target()->project()->id() != Constants::AUTOTOOLS_PROJECT_ID
return QList<Core::Id>(); || parent->id() != ProjectExplorer::Constants::BUILDSTEPS_BUILD)
return QList<Core::Id>() << Core::Id(AUTOGEN_STEP_ID); return {};
}
QString AutogenStepFactory::displayNameForId(Core::Id id) const QString display = tr("Autogen", "Display name for AutotoolsProjectManager::AutogenStep id.");
{ return {{ AUTOGEN_STEP_ID, display }};
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;
} }
BuildStep *AutogenStepFactory::create(BuildStepList *parent, Core::Id id) BuildStep *AutogenStepFactory::create(BuildStepList *parent, Core::Id id)
{ {
if (!canCreate(parent, id)) Q_UNUSED(id)
return 0;
return new AutogenStep(parent); return new AutogenStep(parent);
} }
bool AutogenStepFactory::canClone(BuildStepList *parent, BuildStep *source) const
{
return canCreate(parent, source->id());
}
BuildStep *AutogenStepFactory::clone(BuildStepList *parent, BuildStep *source) BuildStep *AutogenStepFactory::clone(BuildStepList *parent, BuildStep *source)
{ {
if (!canClone(parent, source))
return 0;
return new AutogenStep(parent, static_cast<AutogenStep *>(source)); 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 // AutogenStep class
//////////////////////// ////////////////////////
......
...@@ -55,16 +55,11 @@ class AutogenStepFactory : public ProjectExplorer::IBuildStepFactory ...@@ -55,16 +55,11 @@ class AutogenStepFactory : public ProjectExplorer::IBuildStepFactory
public: public:
AutogenStepFactory(QObject *parent = 0); AutogenStepFactory(QObject *parent = 0);
QList<Core::Id> availableCreationIds(ProjectExplorer::BuildStepList *bc) const override; QList<ProjectExplorer::BuildStepInfo>
QString displayNameForId(Core::Id id) const override; 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; 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; 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 ...@@ -55,67 +55,27 @@ const char AUTORECONF_ADDITIONAL_ARGUMENTS_KEY[] = "AutotoolsProjectManager.Auto
AutoreconfStepFactory::AutoreconfStepFactory(QObject *parent) : IBuildStepFactory(parent) AutoreconfStepFactory::AutoreconfStepFactory(QObject *parent) : IBuildStepFactory(parent)
{ } { }
QList<Core::Id> AutoreconfStepFactory::availableCreationIds(BuildStepList *parent) const QList<BuildStepInfo> AutoreconfStepFactory::availableSteps(BuildStepList *parent) const
{ {
if (!canHandle(parent)) if (parent->target()->project()->id() != Constants::AUTOTOOLS_PROJECT_ID
return QList<Core::Id>(); || parent->id() != ProjectExplorer::Constants::BUILDSTEPS_BUILD)
return QList<Core::Id>() << Core::Id(AUTORECONF_STEP_ID); return {};
}
QString AutoreconfStepFactory::displayNameForId(Core::Id id) const QString display = tr("Autoreconf", "Display name for AutotoolsProjectManager::AutoreconfStep id.");
{ return {{ AUTORECONF_STEP_ID, display }};
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;
} }
BuildStep *AutoreconfStepFactory::create(BuildStepList *parent, Core::Id id) BuildStep *AutoreconfStepFactory::create(BuildStepList *parent, Core::Id id)
{ {
if (!canCreate(parent, id)) Q_UNUSED(id);
return 0;
return new AutoreconfStep(parent); return new AutoreconfStep(parent);
} }
bool AutoreconfStepFactory::canClone(BuildStepList *parent, BuildStep *source) const
{
return canCreate(parent, source->id());
}
BuildStep *AutoreconfStepFactory::clone(BuildStepList *parent, BuildStep *source) BuildStep *AutoreconfStepFactory::clone(BuildStepList *parent, BuildStep *source)
{ {
if (!canClone(parent, source))
return 0;
return new AutoreconfStep(parent, static_cast<AutoreconfStep *>(source)); 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 // AutoreconfStep class
///////////////////////// /////////////////////////
......
...@@ -54,17 +54,11 @@ class AutoreconfStepFactory : public ProjectExplorer::IBuildStepFactory ...@@ -54,17 +54,11 @@ class AutoreconfStepFactory : public ProjectExplorer::IBuildStepFactory
public: public:
AutoreconfStepFactory(QObject *parent = 0); AutoreconfStepFactory(QObject *parent = 0);
QList<Core::Id> availableCreationIds(ProjectExplorer::BuildStepList *bc) const override; QList<ProjectExplorer::BuildStepInfo>
QString displayNameForId(Core::Id id) const override; 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; 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; 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) { ...@@ -70,66 +70,27 @@ static QString projectDirRelativeToBuildDir(BuildConfiguration *bc) {
ConfigureStepFactory::ConfigureStepFactory(QObject *parent) : IBuildStepFactory(parent) ConfigureStepFactory::ConfigureStepFactory(QObject *parent) : IBuildStepFactory(parent)
{ } { }
QList<Core::Id> ConfigureStepFactory::availableCreationIds(BuildStepList *parent) const QList<BuildStepInfo> ConfigureStepFactory::availableSteps(BuildStepList *parent) const
{ {
if (!canHandle(parent)) if (parent->target()->project()->id() != Constants::AUTOTOOLS_PROJECT_ID
return QList<Core::Id>(); || parent->id() != ProjectExplorer::Constants::BUILDSTEPS_BUILD)
return QList<Core::Id>() << Core::Id(CONFIGURE_STEP_ID); return {};
}
QString ConfigureStepFactory::displayNameForId(Core::Id id) const QString display = tr("Configure", "Display name for AutotoolsProjectManager::ConfigureStep id.");
{ return {{ CONFIGURE_STEP_ID, display }};
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;
} }
BuildStep *ConfigureStepFactory::create(BuildStepList *parent, Core::Id id) BuildStep *ConfigureStepFactory::create(BuildStepList *parent, Core::Id id)
{ {
if (!canCreate(parent, id)) Q_UNUSED(id)
return 0;
return new ConfigureStep(parent); return new ConfigureStep(parent);
} }
bool ConfigureStepFactory::canClone(BuildStepList *parent, BuildStep *source) const
{
return canCreate(parent, source->id());
}
BuildStep *ConfigureStepFactory::clone(BuildStepList *parent, BuildStep *source) BuildStep *ConfigureStepFactory::clone(BuildStepList *parent, BuildStep *source)
{ {
if (!canClone(parent, source))
return 0;
return new ConfigureStep(parent, static_cast<ConfigureStep *>(source)); 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 // ConfigureStep class
......
...@@ -54,17 +54,11 @@ class ConfigureStepFactory : public ProjectExplorer::IBuildStepFactory ...@@ -54,17 +54,11 @@ class ConfigureStepFactory : public ProjectExplorer::IBuildStepFactory
public: public:
ConfigureStepFactory(QObject *parent = 0); ConfigureStepFactory(QObject *parent = 0);
QList<Core::Id> availableCreationIds(ProjectExplorer::BuildStepList *bc) const override; QList<ProjectExplorer::BuildStepInfo>
QString displayNameForId(Core::Id id) const override; 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; 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; 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 ...@@ -62,62 +62,25 @@ const char MAKE_STEP_ADDITIONAL_ARGUMENTS_KEY[] = "AutotoolsProjectManager.MakeS
MakeStepFactory::MakeStepFactory(QObject *parent) : IBuildStepFactory(parent) MakeStepFactory::MakeStepFactory(QObject *parent) : IBuildStepFactory(parent)
{ setObjectName(QLatin1String("Autotools::MakeStepFactory")); } { 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) if (parent->target()->project()->id() != AUTOTOOLS_PROJECT_ID)
return QList<Core::Id>() << Core::Id(MAKE_STEP_ID); return {};
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();
}
bool MakeStepFactory::canCreate(BuildStepList *parent, Core::Id id) const return {{ MAKE_STEP_ID, tr("Make", "Display name for AutotoolsProjectManager::MakeStep id.") }};
{
if (parent->target()->project()->id() == AUTOTOOLS_PROJECT_ID)
return id == MAKE_STEP_ID;
return false;
} }
BuildStep *MakeStepFactory::create(BuildStepList *parent, Core::Id id) BuildStep *MakeStepFactory::create(BuildStepList *parent, Core::Id id)
{ {
if (!canCreate(parent, id)) Q_UNUSED(id)
return 0;
return new MakeStep(parent); return new MakeStep(parent);
} }
bool MakeStepFactory::canClone(BuildStepList *parent, BuildStep *source) const
{
return canCreate(parent, source->id());
}
BuildStep *MakeStepFactory::clone(BuildStepList *parent, BuildStep *source) BuildStep *MakeStepFactory::clone(BuildStepList *parent, BuildStep *source)
{ {
if (!canClone(parent, source))
return 0;
return new MakeStep(parent, static_cast<MakeStep *>(source)); 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 // MakeStep class
///////////////////// /////////////////////
......
...@@ -55,15 +55,11 @@ class MakeStepFactory : public ProjectExplorer::IBuildStepFactory ...@@ -55,15 +55,11 @@ class MakeStepFactory : public ProjectExplorer::IBuildStepFactory
public: