forked from qt-creator/qt-creator
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 <tobias.hunger@qt.io>
This commit is contained in:
@@ -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;
|
||||
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<ProjectExplorer::BuildStepInfo>
|
||||
availableSteps(ProjectExplorer::BuildStepList *parent) const override;
|
||||
|
||||
bool canHandle(ProjectExplorer::BuildStepList *parent) const;
|
||||
ProjectExplorer::BuildStep *create(ProjectExplorer::BuildStepList *parent, Core::Id id) override;
|
||||
ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStepList *parent, ProjectExplorer::BuildStep *source) override;
|
||||
};
|
||||
|
||||
///////////////////////
|
||||
|
||||
@@ -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>();
|
||||
}
|
||||
if (parent->target()->project()->id() != AUTOTOOLS_PROJECT_ID)
|
||||
return {};
|
||||
|
||||
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
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
/////////////////////
|
||||
|
||||
Reference in New Issue
Block a user