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()) {
|
foreach (RunConfiguration *sourceRc, sourceTarget->runConfigurations()) {
|
||||||
IRunConfigurationFactory *factory = IRunConfigurationFactory::find(newTarget, sourceRc);
|
RunConfiguration *newRc = IRunConfigurationFactory::clone(newTarget, sourceRc);
|
||||||
if (!factory) {
|
|
||||||
runconfigurationError << sourceRc->displayName();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
RunConfiguration *newRc = factory->clone(newTarget, sourceRc);
|
|
||||||
if (!newRc) {
|
if (!newRc) {
|
||||||
runconfigurationError << sourceRc->displayName();
|
runconfigurationError << sourceRc->displayName();
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -561,63 +561,27 @@ RunConfiguration *IRunConfigurationFactory::create(Target *parent, Core::Id id,
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRunConfigurationFactory::canClone(Target *parent, RunConfiguration *product) const
|
RunConfiguration *IRunConfigurationFactory::restore(Target *parent, const QVariantMap &map)
|
||||||
{
|
{
|
||||||
if (!canHandle(parent))
|
for (IRunConfigurationFactory *factory : g_runConfigurationFactories) {
|
||||||
return false;
|
if (factory->canHandle(parent)) {
|
||||||
const Core::Id id = product->id();
|
const Core::Id id = idFromMap(map);
|
||||||
return id.name().startsWith(m_runConfigBaseId.name());
|
if (id.name().startsWith(factory->m_runConfigBaseId.name())) {
|
||||||
}
|
QTC_ASSERT(factory->m_creator, continue);
|
||||||
|
RunConfiguration *rc = factory->m_creator(parent);
|
||||||
RunConfiguration *IRunConfigurationFactory::restore(Target *parent, const QVariantMap &map) const
|
if (rc->fromMap(map))
|
||||||
{
|
return rc;
|
||||||
if (!canRestore(parent, map))
|
delete rc;
|
||||||
return nullptr;
|
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;
|
|
||||||
}
|
}
|
||||||
return rc;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
|
RunConfiguration *IRunConfigurationFactory::clone(Target *parent, RunConfiguration *source)
|
||||||
{
|
{
|
||||||
if (!canHandle(parent))
|
return restore(parent, source->toMap());
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QList<IRunConfigurationFactory *> IRunConfigurationFactory::allFactories()
|
const QList<IRunConfigurationFactory *> IRunConfigurationFactory::allFactories()
|
||||||
|
|||||||
@@ -313,13 +313,9 @@ public:
|
|||||||
virtual bool canHandle(Target *target) const;
|
virtual bool canHandle(Target *target) const;
|
||||||
|
|
||||||
RunConfiguration *create(Target *parent, Core::Id id, const QString &extra) 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 RunConfiguration *restore(Target *parent, const QVariantMap &map);
|
||||||
static IRunConfigurationFactory *find(Target *parent, RunConfiguration *rc);
|
static RunConfiguration *clone(Target *parent, RunConfiguration *source);
|
||||||
static const QList<IRunConfigurationFactory *> allFactories();
|
static const QList<IRunConfigurationFactory *> allFactories();
|
||||||
|
|
||||||
Core::Id runConfigurationBaseId() const { return m_runConfigBaseId; }
|
Core::Id runConfigurationBaseId() const { return m_runConfigBaseId; }
|
||||||
|
|||||||
@@ -265,10 +265,6 @@ void RunSettingsWidget::aboutToShowAddMenu()
|
|||||||
void RunSettingsWidget::cloneRunConfiguration()
|
void RunSettingsWidget::cloneRunConfiguration()
|
||||||
{
|
{
|
||||||
RunConfiguration* activeRunConfiguration = m_target->activeRunConfiguration();
|
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
|
//: Title of a the cloned RunConfiguration window, text of the window
|
||||||
QString name = uniqueRCName(
|
QString name = uniqueRCName(
|
||||||
@@ -276,11 +272,11 @@ void RunSettingsWidget::cloneRunConfiguration()
|
|||||||
tr("Clone Configuration"),
|
tr("Clone Configuration"),
|
||||||
tr("New configuration name:"),
|
tr("New configuration name:"),
|
||||||
QLineEdit::Normal,
|
QLineEdit::Normal,
|
||||||
m_target->activeRunConfiguration()->displayName()));
|
activeRunConfiguration->displayName()));
|
||||||
if (name.isEmpty())
|
if (name.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RunConfiguration *newRc = factory->clone(m_target, activeRunConfiguration);
|
RunConfiguration *newRc = IRunConfigurationFactory::clone(m_target, activeRunConfiguration);
|
||||||
if (!newRc)
|
if (!newRc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -815,10 +815,7 @@ bool Target::fromMap(const QVariantMap &map)
|
|||||||
|
|
||||||
// Ignore missing RCs: We will just populate them using the default ones.
|
// Ignore missing RCs: We will just populate them using the default ones.
|
||||||
QVariantMap valueMap = map.value(key).toMap();
|
QVariantMap valueMap = map.value(key).toMap();
|
||||||
IRunConfigurationFactory *factory = IRunConfigurationFactory::find(this, valueMap);
|
RunConfiguration *rc = IRunConfigurationFactory::restore(this, valueMap);
|
||||||
if (!factory)
|
|
||||||
continue;
|
|
||||||
RunConfiguration *rc = factory->restore(this, valueMap);
|
|
||||||
if (!rc)
|
if (!rc)
|
||||||
continue;
|
continue;
|
||||||
QTC_CHECK(rc->id().withSuffix(rc->extraId()) == ProjectExplorer::idFromMap(valueMap));
|
QTC_CHECK(rc->id().withSuffix(rc->extraId()) == ProjectExplorer::idFromMap(valueMap));
|
||||||
|
|||||||
Reference in New Issue
Block a user