forked from qt-creator/qt-creator
ProjectExplorer: Simplify DeployConfigurationFactory interface
Following the RunConfigurationFactory lead this replaces f = Foo::find(); f->do() by static Foo::do() stanzas. Also protect DeployConfigurationFactory::canCreate() Change-Id: I80fa491f836c3b9186f6ce6dccac4d52d4b80fc8 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -217,33 +217,25 @@ DeployConfiguration *DeployConfigurationFactory::create(Target *parent, Core::Id
|
|||||||
return dc;
|
return dc;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeployConfigurationFactory::canClone(Target *parent, DeployConfiguration *product) const
|
DeployConfiguration *DeployConfigurationFactory::clone(Target *parent,
|
||||||
|
const DeployConfiguration *source)
|
||||||
{
|
{
|
||||||
if (!canHandle(parent))
|
return restore(parent, source->toMap());
|
||||||
return false;
|
|
||||||
const Core::Id id = product->id();
|
|
||||||
if (!id.name().startsWith(m_deployConfigBaseId.name()))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeployConfiguration *DeployConfigurationFactory::clone(Target *parent, DeployConfiguration *product)
|
|
||||||
{
|
|
||||||
QTC_ASSERT(m_creator, return nullptr);
|
|
||||||
if (!canClone(parent, product))
|
|
||||||
return nullptr;
|
|
||||||
DeployConfiguration *dc = m_creator(parent);
|
|
||||||
QVariantMap data = product->toMap();
|
|
||||||
dc->fromMap(data);
|
|
||||||
return dc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeployConfiguration *DeployConfigurationFactory::restore(Target *parent, const QVariantMap &map)
|
DeployConfiguration *DeployConfigurationFactory::restore(Target *parent, const QVariantMap &map)
|
||||||
{
|
{
|
||||||
if (!canRestore(parent, map))
|
const Core::Id id = idFromMap(map);
|
||||||
|
DeployConfigurationFactory *factory = Utils::findOrDefault(g_deployConfigurationFactories,
|
||||||
|
[parent, id](DeployConfigurationFactory *f) {
|
||||||
|
if (!f->canHandle(parent))
|
||||||
|
return false;
|
||||||
|
return id.name().startsWith(f->m_deployConfigBaseId.name());
|
||||||
|
});
|
||||||
|
if (!factory)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
QTC_ASSERT(m_creator, return nullptr);
|
QTC_ASSERT(factory->m_creator, return nullptr);
|
||||||
DeployConfiguration *dc = m_creator(parent);
|
DeployConfiguration *dc = factory->m_creator(parent);
|
||||||
QTC_ASSERT(dc, return nullptr);
|
QTC_ASSERT(dc, return nullptr);
|
||||||
if (!dc->fromMap(map)) {
|
if (!dc->fromMap(map)) {
|
||||||
delete dc;
|
delete dc;
|
||||||
@@ -252,22 +244,6 @@ DeployConfiguration *DeployConfigurationFactory::restore(Target *parent, const Q
|
|||||||
return dc;
|
return dc;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeployConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
|
|
||||||
{
|
|
||||||
if (!canHandle(parent))
|
|
||||||
return false;
|
|
||||||
const Core::Id id = idFromMap(map);
|
|
||||||
return id.name().startsWith(m_deployConfigBaseId.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
DeployConfigurationFactory *DeployConfigurationFactory::find(Target *parent, const QVariantMap &map)
|
|
||||||
{
|
|
||||||
return Utils::findOrDefault(g_deployConfigurationFactories,
|
|
||||||
[&parent, &map](DeployConfigurationFactory *factory) {
|
|
||||||
return factory->canRestore(parent, map);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<DeployConfigurationFactory *> DeployConfigurationFactory::find(Target *parent)
|
QList<DeployConfigurationFactory *> DeployConfigurationFactory::find(Target *parent)
|
||||||
{
|
{
|
||||||
return Utils::filtered(g_deployConfigurationFactories,
|
return Utils::filtered(g_deployConfigurationFactories,
|
||||||
@@ -276,14 +252,6 @@ QList<DeployConfigurationFactory *> DeployConfigurationFactory::find(Target *par
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DeployConfigurationFactory *DeployConfigurationFactory::find(Target *parent, DeployConfiguration *dc)
|
|
||||||
{
|
|
||||||
return Utils::findOrDefault(g_deployConfigurationFactories,
|
|
||||||
[&parent, &dc](DeployConfigurationFactory *factory) {
|
|
||||||
return factory->canClone(parent, dc);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeployConfigurationFactory::setSupportedTargetDeviceTypes(const QList<Core::Id> &ids)
|
void DeployConfigurationFactory::setSupportedTargetDeviceTypes(const QList<Core::Id> &ids)
|
||||||
{
|
{
|
||||||
m_supportedTargetDeviceTypes = ids;
|
m_supportedTargetDeviceTypes = ids;
|
||||||
|
@@ -85,25 +85,19 @@ public:
|
|||||||
// used to translate the types to names to display to the user
|
// used to translate the types to names to display to the user
|
||||||
QString displayNameForId(Core::Id id) const;
|
QString displayNameForId(Core::Id id) const;
|
||||||
|
|
||||||
virtual bool canHandle(ProjectExplorer::Target *target) const;
|
|
||||||
|
|
||||||
bool canCreate(Target *parent, Core::Id id) const;
|
bool canCreate(Target *parent, Core::Id id) const;
|
||||||
virtual DeployConfiguration *create(Target *parent, Core::Id id);
|
virtual DeployConfiguration *create(Target *parent, Core::Id id);
|
||||||
// used to recreate the runConfigurations when restoring settings
|
|
||||||
bool canRestore(Target *parent, const QVariantMap &map) const;
|
|
||||||
DeployConfiguration *restore(Target *parent, const QVariantMap &map);
|
|
||||||
bool canClone(Target *parent, DeployConfiguration *product) const;
|
|
||||||
DeployConfiguration *clone(Target *parent, DeployConfiguration *product);
|
|
||||||
|
|
||||||
static DeployConfigurationFactory *find(Target *parent, const QVariantMap &map);
|
|
||||||
static QList<DeployConfigurationFactory *> find(Target *parent);
|
static QList<DeployConfigurationFactory *> find(Target *parent);
|
||||||
static DeployConfigurationFactory *find(Target *parent, DeployConfiguration *dc);
|
static DeployConfiguration *restore(Target *parent, const QVariantMap &map);
|
||||||
|
static DeployConfiguration *clone(Target *parent, const DeployConfiguration *dc);
|
||||||
|
|
||||||
void setSupportedTargetDeviceTypes(const QList<Core::Id> &ids);
|
void setSupportedTargetDeviceTypes(const QList<Core::Id> &ids);
|
||||||
void setDefaultDisplayName(const QString &defaultDisplayName);
|
void setDefaultDisplayName(const QString &defaultDisplayName);
|
||||||
void setSupportedProjectType(Core::Id id);
|
void setSupportedProjectType(Core::Id id);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool canHandle(ProjectExplorer::Target *target) const;
|
||||||
virtual QList<QString> availableBuildTargets(Target *parent) const;
|
virtual QList<QString> availableBuildTargets(Target *parent) const;
|
||||||
virtual QString displayNameForBuildTarget(const QString &buildTarget) const;
|
virtual QString displayNameForBuildTarget(const QString &buildTarget) const;
|
||||||
|
|
||||||
|
@@ -382,12 +382,7 @@ bool Project::copySteps(Target *sourceTarget, Target *newTarget)
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (DeployConfiguration *sourceDc, sourceTarget->deployConfigurations()) {
|
foreach (DeployConfiguration *sourceDc, sourceTarget->deployConfigurations()) {
|
||||||
DeployConfigurationFactory *factory = DeployConfigurationFactory::find(newTarget, sourceDc);
|
DeployConfiguration *newDc = DefaultDeployConfigurationFactory::clone(newTarget, sourceDc);
|
||||||
if (!factory) {
|
|
||||||
deployconfigurationError << sourceDc->displayName();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
DeployConfiguration *newDc = factory->clone(newTarget, sourceDc);
|
|
||||||
if (!newDc) {
|
if (!newDc) {
|
||||||
deployconfigurationError << sourceDc->displayName();
|
deployconfigurationError << sourceDc->displayName();
|
||||||
continue;
|
continue;
|
||||||
|
@@ -773,18 +773,13 @@ bool Target::fromMap(const QVariantMap &map)
|
|||||||
if (!map.contains(key))
|
if (!map.contains(key))
|
||||||
return false;
|
return false;
|
||||||
QVariantMap valueMap = map.value(key).toMap();
|
QVariantMap valueMap = map.value(key).toMap();
|
||||||
DeployConfigurationFactory *factory = DeployConfigurationFactory::find(this, valueMap);
|
DeployConfiguration *dc = DeployConfigurationFactory::restore(this, valueMap);
|
||||||
if (!factory) {
|
if (!dc) {
|
||||||
Core::Id id = idFromMap(valueMap);
|
Core::Id id = idFromMap(valueMap);
|
||||||
qWarning("No factory found to restore deployment configuration of id '%s'!",
|
qWarning("No factory found to restore deployment configuration of id '%s'!",
|
||||||
id.isValid() ? qPrintable(id.toString()) : "UNKNOWN");
|
id.isValid() ? qPrintable(id.toString()) : "UNKNOWN");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
DeployConfiguration *dc = factory->restore(this, valueMap);
|
|
||||||
if (!dc) {
|
|
||||||
qWarning("Factory '%s' failed to restore deployment configuration!", qPrintable(factory->objectName()));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
QTC_CHECK(dc->id().withSuffix(dc->extraId()) == ProjectExplorer::idFromMap(valueMap));
|
QTC_CHECK(dc->id().withSuffix(dc->extraId()) == ProjectExplorer::idFromMap(valueMap));
|
||||||
addDeployConfiguration(dc);
|
addDeployConfiguration(dc);
|
||||||
if (i == activeConfiguration)
|
if (i == activeConfiguration)
|
||||||
|
Reference in New Issue
Block a user