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:
hjk
2016-05-18 12:37:29 +02:00
parent 4ce0494284
commit 519cc8ded6
50 changed files with 309 additions and 1290 deletions

View File

@@ -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;
}
if (parent->id() != ProjectExplorer::Constants::BUILDSTEPS_DEPLOY
|| !AndroidManager::supportsAndroid(parent->target())
|| parent->contains(AndroidDeployQtStep::Id))
return {};
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 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));
}