8#include "RoutingRunnerManager.h"
10#include "GeoDataDocument.h"
11#include "MarbleDebug.h"
13#include "MarblePlacemarkModel.h"
15#include "PluginManager.h"
16#include "RoutingRunnerPlugin.h"
17#include "RunnerTask.h"
18#include "routing/RouteRequest.h"
19#include "routing/RoutingProfilesModel.h"
29class Q_DECL_HIDDEN RoutingRunnerManager::Private
32 Private(RoutingRunnerManager *parent,
const MarbleModel *marbleModel);
39 void addRoutingResult(GeoDataDocument *route);
40 void cleanupRoutingTask(RoutingTask *task);
42 RoutingRunnerManager *
const q;
43 const MarbleModel *
const m_marbleModel;
44 const PluginManager *
const m_pluginManager;
49RoutingRunnerManager::Private::Private(RoutingRunnerManager *parent,
const MarbleModel *marbleModel)
51 , m_marbleModel(marbleModel)
52 , m_pluginManager(marbleModel->pluginManager())
54 qRegisterMetaType<GeoDataDocument *>(
"GeoDataDocument*");
57RoutingRunnerManager::Private::~Private()
66 for (T *plugin : plugins) {
67 if ((m_marbleModel && m_marbleModel->workOffline() && !plugin->canWorkOffline())) {
71 if (!plugin->canWork()) {
75 if (m_marbleModel && !plugin->supportsCelestialBody(m_marbleModel->planet()->id())) {
85void RoutingRunnerManager::Private::addRoutingResult(GeoDataDocument *route)
88 mDebug() <<
"route retrieved";
89 m_routingResult.push_back(route);
91 Q_EMIT q->routeRetrieved(route);
95void RoutingRunnerManager::Private::cleanupRoutingTask(RoutingTask *task)
98 mDebug() <<
"removing task" << m_routingTasks.size() <<
" " << (quintptr)task;
99 if (m_routingTasks.isEmpty()) {
100 if (m_routingResult.isEmpty()) {
101 Q_EMIT q->routeRetrieved(
nullptr);
104 Q_EMIT q->routingFinished();
108RoutingRunnerManager::RoutingRunnerManager(
const MarbleModel *marbleModel,
QObject *parent)
110 , d(new Private(this, marbleModel))
117RoutingRunnerManager::~RoutingRunnerManager()
122void RoutingRunnerManager::retrieveRoute(
const RouteRequest *request)
124 RoutingProfile profile = request->routingProfile();
126 d->m_routingTasks.clear();
127 d->m_routingResult.clear();
130 for (RoutingRunnerPlugin *plugin : std::as_const(plugins)) {
131 if (!profile.name().isEmpty() && !profile.pluginSettings().contains(plugin->nameId())) {
135 auto task =
new RoutingTask(plugin->newRunner(),
this, request);
136 connect(task, SIGNAL(finished(RoutingTask *)),
this, SLOT(cleanupRoutingTask(RoutingTask *)));
137 mDebug() <<
"route task" << plugin->nameId() <<
" " << (quintptr)task;
138 d->m_routingTasks <<
task;
141 for (RoutingTask *task : std::as_const(d->m_routingTasks)) {
145 if (d->m_routingTasks.isEmpty()) {
146 mDebug() <<
"No suitable routing plugins found, cannot retrieve a route";
147 d->cleanupRoutingTask(
nullptr);
159 watchdog.
start(timeout);
160 retrieveRoute(request);
161 localEventLoop.
exec();
162 return d->m_routingResult;
167#include "moc_RoutingRunnerManager.cpp"
This file contains the headers for MarbleModel.
Binds a QML item to a specific geodetic location in screen coordinates.
int exec(ProcessEventsFlags flags)
qsizetype removeAll(const AT &t)
QTaskBuilder< Task > task(Task &&task)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QThreadPool * globalInstance()
void setMaxThreadCount(int maxThreadCount)
void start(Callable &&callableToRun, int priority)
void setSingleShot(bool singleShot)