forked from qt-creator/qt-creator
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:
@@ -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);
|
auto runControl = new RunControl(runMode);
|
||||||
runControl->setRunConfiguration(runConfiguration);
|
runControl->setRunConfiguration(runConfiguration);
|
||||||
|
|
||||||
// A user needed interaction may have cancelled the run
|
// A user needed interaction may have cancelled the run
|
||||||
// (by example asking for a process pid or server url).
|
// (by example asking for a process pid or server url).
|
||||||
if (!producer(runControl)) {
|
if (!runControl->createMainWorker()) {
|
||||||
delete runControl;
|
delete runControl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2996,8 +2994,7 @@ bool ProjectExplorerPlugin::canRunStartupProject(Core::Id runMode, QString *whyN
|
|||||||
}
|
}
|
||||||
|
|
||||||
// shouldn't actually be shown to the user...
|
// shouldn't actually be shown to the user...
|
||||||
RunControl::WorkerCreator producer = RunControl::producer(activeRC, runMode);
|
if (!RunControl::canRun(activeRC, runMode)) {
|
||||||
if (!producer) {
|
|
||||||
if (whyNot)
|
if (whyNot)
|
||||||
*whyNot = tr("Cannot run \"%1\".").arg(activeRC->displayName());
|
*whyNot = tr("Cannot run \"%1\".").arg(activeRC->displayName());
|
||||||
return false;
|
return false;
|
||||||
|
@@ -443,19 +443,25 @@ RunWorker *RunControl::createWorker(Core::Id id)
|
|||||||
return nullptr;
|
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);
|
const QList<RunWorkerFactory *> candidates = Utils::filtered(g_runWorkerFactories, canRun);
|
||||||
|
// There might be combinations that cannot run. But that should have been checked
|
||||||
// This is legit, there might be combinations that cannot run.
|
// with canRun below.
|
||||||
if (candidates.empty())
|
QTC_ASSERT(!candidates.empty(), return false);
|
||||||
return {};
|
|
||||||
|
|
||||||
// There should be at most one top-level producer feeling responsible per combination.
|
// 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.
|
// Breaking a tie should be done by tightening the restrictions on one of them.
|
||||||
QTC_CHECK(candidates.size() == 1);
|
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()
|
void RunControlPrivate::initiateStart()
|
||||||
|
@@ -274,7 +274,8 @@ public:
|
|||||||
factory->addConstraint(constraint);
|
factory->addConstraint(constraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
static WorkerCreator producer(RunConfiguration *runConfiguration, Core::Id runMode);
|
bool createMainWorker();
|
||||||
|
static bool canRun(RunConfiguration *runConfig, Core::Id runMode);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void appendMessage(const QString &msg, Utils::OutputFormat format);
|
void appendMessage(const QString &msg, Utils::OutputFormat format);
|
||||||
|
@@ -282,8 +282,7 @@ CallgrindTool::CallgrindTool()
|
|||||||
m_perspective.select();
|
m_perspective.select();
|
||||||
auto runControl = new RunControl(CALLGRIND_RUN_MODE);
|
auto runControl = new RunControl(CALLGRIND_RUN_MODE);
|
||||||
runControl->setRunConfiguration(runConfig);
|
runControl->setRunConfiguration(runConfig);
|
||||||
if (auto creator = RunControl::producer(runConfig, CALLGRIND_RUN_MODE))
|
runControl->createMainWorker();
|
||||||
creator(runControl);
|
|
||||||
const auto runnable = dlg.runnable();
|
const auto runnable = dlg.runnable();
|
||||||
runControl->setRunnable(runnable);
|
runControl->setRunnable(runnable);
|
||||||
runControl->setDisplayName(runnable.executable);
|
runControl->setDisplayName(runnable.executable);
|
||||||
|
@@ -673,8 +673,7 @@ MemcheckTool::MemcheckTool()
|
|||||||
m_perspective.select();
|
m_perspective.select();
|
||||||
RunControl *rc = new RunControl(MEMCHECK_RUN_MODE);
|
RunControl *rc = new RunControl(MEMCHECK_RUN_MODE);
|
||||||
rc->setRunConfiguration(runConfig);
|
rc->setRunConfiguration(runConfig);
|
||||||
if (auto creator = RunControl::producer(runConfig, MEMCHECK_RUN_MODE))
|
rc->createMainWorker();
|
||||||
creator(rc);
|
|
||||||
const auto runnable = dlg.runnable();
|
const auto runnable = dlg.runnable();
|
||||||
rc->setRunnable(runnable);
|
rc->setRunnable(runnable);
|
||||||
rc->setDisplayName(runnable.executable);
|
rc->setDisplayName(runnable.executable);
|
||||||
|
Reference in New Issue
Block a user