From 519cc8ded616758cb85857e8845fdc5847339e3a Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 18 May 2016 12:37:29 +0200 Subject: 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 --- src/plugins/ios/iosdeploystepfactory.cpp | 49 ++++---------------------------- 1 file changed, 6 insertions(+), 43 deletions(-) (limited to 'src/plugins/ios/iosdeploystepfactory.cpp') diff --git a/src/plugins/ios/iosdeploystepfactory.cpp b/src/plugins/ios/iosdeploystepfactory.cpp index 7f61b5fecd..b2bc8b4a83 100644 --- a/src/plugins/ios/iosdeploystepfactory.cpp +++ b/src/plugins/ios/iosdeploystepfactory.cpp @@ -46,60 +46,23 @@ IosDeployStepFactory::IosDeployStepFactory(QObject *parent) { } -QList IosDeployStepFactory::availableCreationIds(BuildStepList *parent) const +QList IosDeployStepFactory::availableSteps(BuildStepList *parent) const { - if (parent->id() != ProjectExplorer::Constants::BUILDSTEPS_DEPLOY) - return QList(); - if (!IosManager::supportsIos(parent->target())) - return QList(); - if (parent->contains(IosDeployStep::Id)) - return QList(); - return QList() << IosDeployStep::Id; -} - -QString IosDeployStepFactory::displayNameForId(Core::Id id) const -{ - if (id == IosDeployStep::Id) - return tr("Deploy to iOS device or emulator"); - return QString(); -} - -bool IosDeployStepFactory::canCreate(BuildStepList *parent, Core::Id id) const -{ - return availableCreationIds(parent).contains(id); + if (parent->id() == ProjectExplorer::Constants::BUILDSTEPS_DEPLOY + && IosManager::supportsIos(parent->target()) + && !parent->contains(IosDeployStep::Id)) + return {{ IosDeployStep::Id, tr("Deploy to iOS device or emulator") }}; + return {}; } BuildStep *IosDeployStepFactory::create(BuildStepList *parent, Core::Id id) { - Q_ASSERT(canCreate(parent, id)); Q_UNUSED(id); return new IosDeployStep(parent); } -bool IosDeployStepFactory::canRestore(BuildStepList *parent, const QVariantMap &map) const -{ - return canCreate(parent, idFromMap(map)); -} - -BuildStep *IosDeployStepFactory::restore(BuildStepList *parent, const QVariantMap &map) -{ - Q_ASSERT(canRestore(parent, map)); - IosDeployStep * const step = new IosDeployStep(parent); - if (!step->fromMap(map)) { - delete step; - return 0; - } - return step; -} - -bool IosDeployStepFactory::canClone(BuildStepList *parent, BuildStep *product) const -{ - return canCreate(parent, product->id()); -} - BuildStep *IosDeployStepFactory::clone(BuildStepList *parent, BuildStep *product) { - Q_ASSERT(canClone(parent, product)); return new IosDeployStep(parent, static_cast(product)); } -- cgit v1.2.1