summaryrefslogtreecommitdiff
path: root/src/plugins/projectexplorer/runconfiguration.cpp
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2017-06-19 13:27:59 +0200
committerhjk <hjk@qt.io>2017-06-20 08:04:33 +0000
commitf047e1a2a2ac6667d7d19c95e3f6bb96e17f2a5a (patch)
tree3e5d2c507350212821242829784adacd39244168 /src/plugins/projectexplorer/runconfiguration.cpp
parent1cb8e1d291fdaf46b5d0435249edb72198271ded (diff)
downloadqt-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.cpp46
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);