diff options
author | hjk <hjk@qt.io> | 2017-06-19 13:27:59 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2017-06-20 08:04:33 +0000 |
commit | f047e1a2a2ac6667d7d19c95e3f6bb96e17f2a5a (patch) | |
tree | 3e5d2c507350212821242829784adacd39244168 /src/plugins/projectexplorer/runconfiguration.cpp | |
parent | 1cb8e1d291fdaf46b5d0435249edb72198271ded (diff) | |
download | qt-creator-f047e1a2a2ac6667d7d19c95e3f6bb96e17f2a5a.tar.gz |
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>
Diffstat (limited to 'src/plugins/projectexplorer/runconfiguration.cpp')
-rw-r--r-- | src/plugins/projectexplorer/runconfiguration.cpp | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp index 25cea48b0f..d496f35b53 100644 --- a/src/plugins/projectexplorer/runconfiguration.cpp +++ b/src/plugins/projectexplorer/runconfiguration.cpp @@ -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); |