aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2019-03-13 15:34:44 +0100
committerhjk <hjk@qt.io>2019-03-20 09:16:08 +0000
commit68a10d71e75b9184eb731afb5000fa01809bab37 (patch)
tree03817136fcfdf8ed07a9815a69efb4a0ab73b0ae /src/plugins
parent358bb49f62052693bad159a1864755cd7947d30a (diff)
ProjectExplorer: Replace RunControl::producer
... by two more specialized canRun() / createMainWorker() functions resulting in somewhat leaner code on the user side and paving the way for introducing a RunWorkerFactory class intended to follow the now-canonical way of having factories as members in the plugin pimpl. Change-Id: Id6fc2043a340203f14ab0b896a8dfa1e298f58a6 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/projectexplorer/projectexplorer.cpp7
-rw-r--r--src/plugins/projectexplorer/runcontrol.cpp20
-rw-r--r--src/plugins/projectexplorer/runcontrol.h3
-rw-r--r--src/plugins/valgrind/callgrindtool.cpp3
-rw-r--r--src/plugins/valgrind/memchecktool.cpp3
5 files changed, 19 insertions, 17 deletions
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index 29366c60c6a..36e336d8320 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -2196,15 +2196,13 @@ void ProjectExplorerPluginPrivate::executeRunConfiguration(RunConfiguration *run
}
}
- RunControl::WorkerCreator producer = RunControl::producer(runConfiguration, runMode);
- QTC_ASSERT(producer, return);
auto runControl = new RunControl(runMode);
runControl->setRunConfiguration(runConfiguration);
// A user needed interaction may have cancelled the run
// (by example asking for a process pid or server url).
- if (!producer(runControl)) {
+ if (!runControl->createMainWorker()) {
delete runControl;
return;
}
@@ -2996,8 +2994,7 @@ bool ProjectExplorerPlugin::canRunStartupProject(Core::Id runMode, QString *whyN
}
// shouldn't actually be shown to the user...
- RunControl::WorkerCreator producer = RunControl::producer(activeRC, runMode);
- if (!producer) {
+ if (!RunControl::canRun(activeRC, runMode)) {
if (whyNot)
*whyNot = tr("Cannot run \"%1\".").arg(activeRC->displayName());
return false;
diff --git a/src/plugins/projectexplorer/runcontrol.cpp b/src/plugins/projectexplorer/runcontrol.cpp
index cf1350d0840..1774586feeb 100644
--- a/src/plugins/projectexplorer/runcontrol.cpp
+++ b/src/plugins/projectexplorer/runcontrol.cpp
@@ -443,19 +443,25 @@ RunWorker *RunControl::createWorker(Core::Id id)
return nullptr;
}
-RunWorkerFactory::WorkerCreator RunControl::producer(RunConfiguration *runConfig, Core::Id runMode)
+bool RunControl::createMainWorker()
{
- const auto canRun = std::bind(&RunWorkerFactory::canRun, std::placeholders::_1, runConfig, runMode);
+ const auto canRun = std::bind(&RunWorkerFactory::canRun, std::placeholders::_1,
+ d->runConfiguration, d->runMode);
const QList<RunWorkerFactory *> candidates = Utils::filtered(g_runWorkerFactories, canRun);
-
- // This is legit, there might be combinations that cannot run.
- if (candidates.empty())
- return {};
+ // There might be combinations that cannot run. But that should have been checked
+ // with canRun below.
+ QTC_ASSERT(!candidates.empty(), return false);
// There should be at most one top-level producer feeling responsible per combination.
// Breaking a tie should be done by tightening the restrictions on one of them.
QTC_CHECK(candidates.size() == 1);
- return candidates.front()->producer();
+ return candidates.front()->producer()(this) != nullptr;
+}
+
+bool RunControl::canRun(RunConfiguration *runConfig, Core::Id runMode)
+{
+ const auto check = std::bind(&RunWorkerFactory::canRun, std::placeholders::_1, runConfig, runMode);
+ return Utils::contains(g_runWorkerFactories, check);
}
void RunControlPrivate::initiateStart()
diff --git a/src/plugins/projectexplorer/runcontrol.h b/src/plugins/projectexplorer/runcontrol.h
index 657c7acd75f..f4b5ae5c823 100644
--- a/src/plugins/projectexplorer/runcontrol.h
+++ b/src/plugins/projectexplorer/runcontrol.h
@@ -274,7 +274,8 @@ public:
factory->addConstraint(constraint);
}
- static WorkerCreator producer(RunConfiguration *runConfiguration, Core::Id runMode);
+ bool createMainWorker();
+ static bool canRun(RunConfiguration *runConfig, Core::Id runMode);
signals:
void appendMessage(const QString &msg, Utils::OutputFormat format);
diff --git a/src/plugins/valgrind/callgrindtool.cpp b/src/plugins/valgrind/callgrindtool.cpp
index 92c664eaa31..decc9897815 100644
--- a/src/plugins/valgrind/callgrindtool.cpp
+++ b/src/plugins/valgrind/callgrindtool.cpp
@@ -282,8 +282,7 @@ CallgrindTool::CallgrindTool()
m_perspective.select();
auto runControl = new RunControl(CALLGRIND_RUN_MODE);
runControl->setRunConfiguration(runConfig);
- if (auto creator = RunControl::producer(runConfig, CALLGRIND_RUN_MODE))
- creator(runControl);
+ runControl->createMainWorker();
const auto runnable = dlg.runnable();
runControl->setRunnable(runnable);
runControl->setDisplayName(runnable.executable);
diff --git a/src/plugins/valgrind/memchecktool.cpp b/src/plugins/valgrind/memchecktool.cpp
index ac500217d44..221d2972779 100644
--- a/src/plugins/valgrind/memchecktool.cpp
+++ b/src/plugins/valgrind/memchecktool.cpp
@@ -673,8 +673,7 @@ MemcheckTool::MemcheckTool()
m_perspective.select();
RunControl *rc = new RunControl(MEMCHECK_RUN_MODE);
rc->setRunConfiguration(runConfig);
- if (auto creator = RunControl::producer(runConfig, MEMCHECK_RUN_MODE))
- creator(rc);
+ rc->createMainWorker();
const auto runnable = dlg.runnable();
rc->setRunnable(runnable);
rc->setDisplayName(runnable.executable);