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

@@ -151,7 +151,7 @@ class PythonRunConfiguration : public RunConfiguration
Q_PROPERTY(QString arguments READ arguments)
public:
PythonRunConfiguration(Target *parent, Core::Id id);
explicit PythonRunConfiguration(Target *target);
QWidget *createConfigurationWidget() override;
QVariantMap toMap() const override;
@@ -165,8 +165,10 @@ public:
void setInterpreter(const QString &interpreter) { m_interpreter = interpreter; }
private:
friend class PythonRunConfigurationFactory;
PythonRunConfiguration(Target *parent, PythonRunConfiguration *source);
friend class ProjectExplorer::IRunConfigurationFactory;
void initialize(Core::Id id);
void copyFrom(const PythonRunConfiguration *source);
QString defaultDisplayName() const;
QString m_interpreter;
@@ -175,26 +177,31 @@ private:
////////////////////////////////////////////////////////////////
PythonRunConfiguration::PythonRunConfiguration(Target *parent, Core::Id id) :
RunConfiguration(parent, id),
m_mainScript(scriptFromId(id))
PythonRunConfiguration::PythonRunConfiguration(Target *target)
: RunConfiguration(target)
{
Environment sysEnv = Environment::systemEnvironment();
const QString exec = sysEnv.searchInPath("python").toString();
m_interpreter = exec.isEmpty() ? "python" : exec;
addExtraAspect(new LocalEnvironmentAspect(this, LocalEnvironmentAspect::BaseEnvironmentModifier()));
addExtraAspect(new ArgumentsAspect(this, "PythonEditor.RunConfiguration.Arguments"));
addExtraAspect(new TerminalAspect(this, "PythonEditor.RunConfiguration.UseTerminal"));
setDefaultDisplayName(defaultDisplayName());
}
PythonRunConfiguration::PythonRunConfiguration(Target *parent, PythonRunConfiguration *source) :
RunConfiguration(parent, source),
m_interpreter(source->interpreter()),
m_mainScript(source->m_mainScript)
void PythonRunConfiguration::initialize(Core::Id id)
{
setDefaultDisplayName(defaultDisplayName());
RunConfiguration::initialize(id);
m_mainScript = scriptFromId(id);
Environment sysEnv = Environment::systemEnvironment();
const QString exec = sysEnv.searchInPath("python").toString();
m_interpreter = exec.isEmpty() ? "python" : exec;
}
void PythonRunConfiguration::copyFrom(const PythonRunConfiguration *source)
{
RunConfiguration::copyFrom(source);
m_interpreter = source->interpreter();
m_mainScript = source->m_mainScript;
}
QVariantMap PythonRunConfiguration::toMap() const
@@ -324,7 +331,7 @@ public:
{
if (!canClone(parent, source))
return 0;
return new PythonRunConfiguration(parent, static_cast<PythonRunConfiguration*>(source));
return cloneHelper<PythonRunConfiguration>(parent, source);
}
private:
@@ -332,13 +339,12 @@ private:
RunConfiguration *doCreate(Target *parent, Core::Id id) override
{
return new PythonRunConfiguration(parent, id);
return createHelper<PythonRunConfiguration>(parent, id);
}
RunConfiguration *doRestore(Target *parent, const QVariantMap &map) override
{
Core::Id id(idFromMap(map));
return new PythonRunConfiguration(parent, id);
return createHelper<PythonRunConfiguration>(parent, idFromMap(map));
}
};
@@ -575,7 +581,7 @@ Project::RestoreResult PythonProject::fromMap(const QVariantMap &map, QString *e
}
}
if (!alreadyPresent)
t->addRunConfiguration(new PythonRunConfiguration(t, id));
t->addRunConfiguration(IRunConfigurationFactory::createHelper<PythonRunConfiguration>(t, id));
}
}
}