ProjectExplorer: Simplify standard run control construction

A lot of the target-and-tool specific run controls nowadays
have something like a single main RunWorker. This patch
removes the need to have user-implemented RunControlFactories
in those cases and adjusts local run, remote linux,
python and nim to take advantage.

There's more potential use downstream.

Change-Id: Ie2d2f839b8be1fad2be3b79e21de3c0e475d88cf
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2017-06-19 13:27:59 +02:00
parent 1cb8e1d291
commit f047e1a2a2
19 changed files with 141 additions and 401 deletions

View File

@@ -479,6 +479,35 @@ IRunControlFactory::IRunControlFactory(QObject *parent)
{
}
using WorkerFactories = std::vector<RunControl::WorkerFactory>;
static WorkerFactories &theWorkerFactories()
{
static WorkerFactories factories;
return factories;
}
bool IRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMode) const
{
for (const RunControl::WorkerFactory &factory : theWorkerFactories()) {
if (factory.runMode == runMode && factory.constraint(runConfiguration))
return true;
};
return false;
}
RunControl *IRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id runMode, QString *)
{
for (const RunControl::WorkerFactory &factory : theWorkerFactories()) {
if (factory.runMode == runMode && factory.constraint(runConfiguration)) {
auto runControl = new RunControl(runConfiguration, runMode);
factory.producer(runControl);
return runControl;
}
};
return nullptr;
}
/*!
Returns an IRunConfigurationAspect to carry options for RunControls this
factory can create.
@@ -628,6 +657,7 @@ public:
QPointer<Project> project; // Not owned.
Utils::OutputFormatter *outputFormatter = nullptr;
std::function<bool(bool*)> promptToStop;
std::vector<RunControl::WorkerFactory> m_factories;
// A handle to the actual application process.
Utils::ProcessHandle applicationProcessHandle;
@@ -724,7 +754,7 @@ RunWorker *RunControl::createWorker(Core::Id id)
{
auto keys = theWorkerCreators().keys();
Q_UNUSED(keys);
RunWorkerCreator creator = theWorkerCreators().value(id);
Producer creator = theWorkerCreators().value(id);
if (creator)
return creator(this);
creator = device()->workerCreator(id);
@@ -733,6 +763,20 @@ RunWorker *RunControl::createWorker(Core::Id id)
return nullptr;
}
RunControl::Producer RunControl::producer(RunConfiguration *runConfiguration, Core::Id runMode)
{
for (const auto &factory : theWorkerFactories()) {
if (factory.runMode == runMode && factory.constraint(runConfiguration))
return factory.producer;
}
return {};
}
void RunControl::addWorkerFactory(const RunControl::WorkerFactory &workerFactory)
{
theWorkerFactories().push_back(workerFactory);
}
void RunControlPrivate::initiateStart()
{
checkState(RunControlState::Initialized);