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:
@@ -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
|
||||
/////////////////////
|
||||
|
||||
Reference in New Issue
Block a user