ProjectExplorer: Re-organize RunConfiguration constructors

The idea is to massage the setup in a way to make implementation
of new configurations less error prone by identifying recurring patterns
and sharing repetitive code that tends to be forgotten (see Android cloning).

The former two lines of constructors (owner-and-id, owner-and-source)
are split into a simple, shared, constructor and new setId() and
copyFrom() functions.

The change is mostly mechanical, some multiple calls to fromMap
have been removed, though, some consts added.

Otherwise, to keep the patch small it temporarily introduces two
helper templates in IRunConfigurationFactory. Also, setId() signatures
have not been unified yet. These won't be needed in the final setup.

Change-Id: I8c0734496caae744a9883fe6d92c1d8f8e0234ea
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
hjk
2017-09-01 13:23:02 +02:00
parent 4710e6b4b2
commit 890c1906e6
52 changed files with 510 additions and 506 deletions

View File

@@ -60,35 +60,36 @@ const char CMAKE_RC_PREFIX[] = "CMakeProjectManager.CMakeRunConfiguration.";
const char TITLE_KEY[] = "CMakeProjectManager.CMakeRunConfiguation.Title";
} // namespace
CMakeRunConfiguration::CMakeRunConfiguration(Target *parent, Core::Id id, const QString &target,
const Utils::FileName &workingDirectory, const QString &title) :
RunConfiguration(parent, id),
m_buildSystemTarget(target),
m_executable(target),
m_title(title)
CMakeRunConfiguration::CMakeRunConfiguration(Target *target)
: RunConfiguration(target)
{
addExtraAspect(new LocalEnvironmentAspect(this, LocalEnvironmentAspect::BaseEnvironmentModifier()));
addExtraAspect(new ArgumentsAspect(this, QStringLiteral("CMakeProjectManager.CMakeRunConfiguration.Arguments")));
addExtraAspect(new TerminalAspect(this, QStringLiteral("CMakeProjectManager.CMakeRunConfiguration.UseTerminal")));
auto wd = new WorkingDirectoryAspect(this, QStringLiteral("CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory"));
wd->setDefaultWorkingDirectory(workingDirectory);
addExtraAspect(wd);
ctor();
addExtraAspect(new ArgumentsAspect(this, "CMakeProjectManager.CMakeRunConfiguration.Arguments"));
addExtraAspect(new TerminalAspect(this, "CMakeProjectManager.CMakeRunConfiguration.UseTerminal"));
addExtraAspect(new WorkingDirectoryAspect(this, "CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory"));
}
CMakeRunConfiguration::CMakeRunConfiguration(Target *parent, CMakeRunConfiguration *source) :
RunConfiguration(parent, source),
m_buildSystemTarget(source->m_buildSystemTarget),
m_executable(source->m_executable),
m_title(source->m_title)
void CMakeRunConfiguration::initialize(Core::Id id, const QString &target,
const Utils::FileName &workingDirectory, const QString &title)
{
ctor();
RunConfiguration::initialize(id);
m_buildSystemTarget = target;
m_executable = target;
m_title = title;
extraAspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(workingDirectory);
setDefaultDisplayName(defaultDisplayName());
}
void CMakeRunConfiguration::ctor()
void CMakeRunConfiguration::copyFrom(const CMakeRunConfiguration *source)
{
RunConfiguration::copyFrom(source);
m_buildSystemTarget = source->m_buildSystemTarget;
m_executable = source->m_executable;
m_title = source->m_title;
setDefaultDisplayName(defaultDisplayName());
}
@@ -256,7 +257,7 @@ RunConfiguration *CMakeRunConfigurationFactory::doCreate(Target *parent, Core::I
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
const QString title(buildTargetFromId(id));
const CMakeBuildTarget &ct = project->buildTargetForTitle(title);
return new CMakeRunConfiguration(parent, id, title, ct.workingDirectory, ct.title);
return createHelper<CMakeRunConfiguration>(parent, id, title, ct.workingDirectory, ct.title);
}
bool CMakeRunConfigurationFactory::canClone(Target *parent, RunConfiguration *source) const
@@ -270,8 +271,7 @@ RunConfiguration *CMakeRunConfigurationFactory::clone(Target *parent, RunConfigu
{
if (!canClone(parent, source))
return 0;
CMakeRunConfiguration *crc(static_cast<CMakeRunConfiguration *>(source));
return new CMakeRunConfiguration(parent, crc);
return cloneHelper<CMakeRunConfiguration>(parent, source);
}
bool CMakeRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
@@ -284,7 +284,7 @@ bool CMakeRunConfigurationFactory::canRestore(Target *parent, const QVariantMap
RunConfiguration *CMakeRunConfigurationFactory::doRestore(Target *parent, const QVariantMap &map)
{
const Core::Id id = idFromMap(map);
return new CMakeRunConfiguration(parent, id, buildTargetFromId(id), Utils::FileName(), QString());
return createHelper<CMakeRunConfiguration>(parent, id, buildTargetFromId(id), Utils::FileName(), QString());
}
QString CMakeRunConfigurationFactory::buildTargetFromId(Core::Id id)