forked from qt-creator/qt-creator
ProjectExplorer: Consolidate RunConfig creation codepaths
Move some code around to make interfaces slimmer. Also no need to check canHandle() twice per creation. Change-Id: I7c86e2dc78ebd53a0f8e9609e9fa135aaf31e7b7 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -404,12 +404,7 @@ bool Project::copySteps(Target *sourceTarget, Target *newTarget)
|
||||
}
|
||||
|
||||
foreach (RunConfiguration *sourceRc, sourceTarget->runConfigurations()) {
|
||||
IRunConfigurationFactory *factory = IRunConfigurationFactory::find(newTarget, sourceRc);
|
||||
if (!factory) {
|
||||
runconfigurationError << sourceRc->displayName();
|
||||
continue;
|
||||
}
|
||||
RunConfiguration *newRc = factory->clone(newTarget, sourceRc);
|
||||
RunConfiguration *newRc = IRunConfigurationFactory::clone(newTarget, sourceRc);
|
||||
if (!newRc) {
|
||||
runconfigurationError << sourceRc->displayName();
|
||||
continue;
|
||||
|
||||
@@ -561,63 +561,27 @@ RunConfiguration *IRunConfigurationFactory::create(Target *parent, Core::Id id,
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool IRunConfigurationFactory::canClone(Target *parent, RunConfiguration *product) const
|
||||
RunConfiguration *IRunConfigurationFactory::restore(Target *parent, const QVariantMap &map)
|
||||
{
|
||||
if (!canHandle(parent))
|
||||
return false;
|
||||
const Core::Id id = product->id();
|
||||
return id.name().startsWith(m_runConfigBaseId.name());
|
||||
}
|
||||
|
||||
RunConfiguration *IRunConfigurationFactory::restore(Target *parent, const QVariantMap &map) const
|
||||
{
|
||||
if (!canRestore(parent, map))
|
||||
return nullptr;
|
||||
QTC_ASSERT(m_creator, return nullptr);
|
||||
RunConfiguration *rc = m_creator(parent);
|
||||
QTC_ASSERT(rc, return nullptr);
|
||||
if (!rc->fromMap(map)) {
|
||||
delete rc;
|
||||
rc = nullptr;
|
||||
for (IRunConfigurationFactory *factory : g_runConfigurationFactories) {
|
||||
if (factory->canHandle(parent)) {
|
||||
const Core::Id id = idFromMap(map);
|
||||
if (id.name().startsWith(factory->m_runConfigBaseId.name())) {
|
||||
QTC_ASSERT(factory->m_creator, continue);
|
||||
RunConfiguration *rc = factory->m_creator(parent);
|
||||
if (rc->fromMap(map))
|
||||
return rc;
|
||||
delete rc;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool IRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
|
||||
RunConfiguration *IRunConfigurationFactory::clone(Target *parent, RunConfiguration *source)
|
||||
{
|
||||
if (!canHandle(parent))
|
||||
return false;
|
||||
const Core::Id id = idFromMap(map);
|
||||
return id.name().startsWith(m_runConfigBaseId.name());
|
||||
}
|
||||
|
||||
RunConfiguration *IRunConfigurationFactory::clone(Target *parent, RunConfiguration *product) const
|
||||
{
|
||||
QTC_ASSERT(m_creator, return nullptr);
|
||||
if (!canClone(parent, product))
|
||||
return nullptr;
|
||||
RunConfiguration *runConfig = m_creator(parent);
|
||||
|
||||
QVariantMap data = product->toMap();
|
||||
runConfig->fromMap(data);
|
||||
|
||||
return runConfig;
|
||||
}
|
||||
|
||||
IRunConfigurationFactory *IRunConfigurationFactory::find(Target *parent, const QVariantMap &map)
|
||||
{
|
||||
return Utils::findOrDefault(g_runConfigurationFactories,
|
||||
[&parent, &map](IRunConfigurationFactory *factory) {
|
||||
return factory->canRestore(parent, map);
|
||||
});
|
||||
}
|
||||
|
||||
IRunConfigurationFactory *IRunConfigurationFactory::find(Target *parent, RunConfiguration *rc)
|
||||
{
|
||||
return Utils::findOrDefault(g_runConfigurationFactories,
|
||||
[&parent, rc](IRunConfigurationFactory *factory) {
|
||||
return factory->canClone(parent, rc);
|
||||
});
|
||||
return restore(parent, source->toMap());
|
||||
}
|
||||
|
||||
const QList<IRunConfigurationFactory *> IRunConfigurationFactory::allFactories()
|
||||
|
||||
@@ -313,13 +313,9 @@ public:
|
||||
virtual bool canHandle(Target *target) const;
|
||||
|
||||
RunConfiguration *create(Target *parent, Core::Id id, const QString &extra) const;
|
||||
bool canRestore(Target *parent, const QVariantMap &map) const;
|
||||
RunConfiguration *restore(Target *parent, const QVariantMap &map) const;
|
||||
bool canClone(Target *parent, RunConfiguration *product) const;
|
||||
RunConfiguration *clone(Target *parent, RunConfiguration *product) const;
|
||||
|
||||
static IRunConfigurationFactory *find(Target *parent, const QVariantMap &map);
|
||||
static IRunConfigurationFactory *find(Target *parent, RunConfiguration *rc);
|
||||
static RunConfiguration *restore(Target *parent, const QVariantMap &map);
|
||||
static RunConfiguration *clone(Target *parent, RunConfiguration *source);
|
||||
static const QList<IRunConfigurationFactory *> allFactories();
|
||||
|
||||
Core::Id runConfigurationBaseId() const { return m_runConfigBaseId; }
|
||||
|
||||
@@ -265,10 +265,6 @@ void RunSettingsWidget::aboutToShowAddMenu()
|
||||
void RunSettingsWidget::cloneRunConfiguration()
|
||||
{
|
||||
RunConfiguration* activeRunConfiguration = m_target->activeRunConfiguration();
|
||||
IRunConfigurationFactory *factory = IRunConfigurationFactory::find(m_target,
|
||||
activeRunConfiguration);
|
||||
if (!factory)
|
||||
return;
|
||||
|
||||
//: Title of a the cloned RunConfiguration window, text of the window
|
||||
QString name = uniqueRCName(
|
||||
@@ -276,11 +272,11 @@ void RunSettingsWidget::cloneRunConfiguration()
|
||||
tr("Clone Configuration"),
|
||||
tr("New configuration name:"),
|
||||
QLineEdit::Normal,
|
||||
m_target->activeRunConfiguration()->displayName()));
|
||||
activeRunConfiguration->displayName()));
|
||||
if (name.isEmpty())
|
||||
return;
|
||||
|
||||
RunConfiguration *newRc = factory->clone(m_target, activeRunConfiguration);
|
||||
RunConfiguration *newRc = IRunConfigurationFactory::clone(m_target, activeRunConfiguration);
|
||||
if (!newRc)
|
||||
return;
|
||||
|
||||
|
||||
@@ -815,10 +815,7 @@ bool Target::fromMap(const QVariantMap &map)
|
||||
|
||||
// Ignore missing RCs: We will just populate them using the default ones.
|
||||
QVariantMap valueMap = map.value(key).toMap();
|
||||
IRunConfigurationFactory *factory = IRunConfigurationFactory::find(this, valueMap);
|
||||
if (!factory)
|
||||
continue;
|
||||
RunConfiguration *rc = factory->restore(this, valueMap);
|
||||
RunConfiguration *rc = IRunConfigurationFactory::restore(this, valueMap);
|
||||
if (!rc)
|
||||
continue;
|
||||
QTC_CHECK(rc->id().withSuffix(rc->extraId()) == ProjectExplorer::idFromMap(valueMap));
|
||||
|
||||
Reference in New Issue
Block a user