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>
This commit is contained in:
hjk
2019-03-13 15:34:44 +01:00
parent 358bb49f62
commit 68a10d71e7
5 changed files with 19 additions and 17 deletions

View File

@@ -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;

View File

@@ -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()

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);