Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qgeoroutingmanager.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
7
8#include <QLocale>
9
11
12/*!
13 \class QGeoRoutingManager
14 \inmodule QtLocation
15 \ingroup QtLocation-routing
16 \since 5.6
17
18 \brief The QGeoRoutingManager class provides support for geographic routing
19 operations.
20
21 The calculateRoute() and updateRoute() methods function QGeoRouteReply
22 objects, which manage these operations and report on the result of the
23 operations and any errors which may have occurred.
24
25 The calculateRoute() function is used to find a route (or routes) that
26 follows a set of waypoints and matches various other criteria. The
27 QGeoRouteRequest class is used to specify this information.
28
29 If supportsRouteUpdates() returns true then the QGeoRoutingManager
30 supports updating route information based on position updates. This
31 will cause the travel time and distance estimates to be updated, and
32 any QGeoRouteSegments already traversed to be removed from the route.
33
34 The updates can be triggered with the updateRoute() function, which makes
35 use of the QGeoPositionInfo instances emitted as position updates by
36 QGeoPositionInfoSource.
37
38 Instances of QGeoRoutingManager can be accessed with
39 QGeoServiceProvider::routingManager().
40
41 A small example of the usage of QGeoRoutingManager and QGeoRouteRequests
42 follows:
43 \snippet maps/routehandler.h RouteHandler
44*/
45
46/*!
47 Constructs a new manager with the specified \a parent and with the
48 implementation provided by \a engine.
49
50 This constructor is used internally by QGeoServiceProviderFactory. Regular
51 users should acquire instances of QGeoRoutingManager with
52 QGeoServiceProvider::routingManager();
53*/
54QGeoRoutingManager::QGeoRoutingManager(QGeoRoutingManagerEngine *engine, QObject *parent)
55 : QObject(parent),
56 d_ptr(new QGeoRoutingManagerPrivate())
57{
58 d_ptr->engine.reset(engine);
59 if (d_ptr->engine) {
60 d_ptr->engine->setParent(this);
61
62 connect(d_ptr->engine.get(), &QGeoRoutingManagerEngine::finished,
63 this, &QGeoRoutingManager::finished);
64
65 connect(d_ptr->engine.get(), &QGeoRoutingManagerEngine::errorOccurred,
66 this, &QGeoRoutingManager::errorOccurred);
67 } else {
68 qFatal("The routing manager engine that was set for this routing manager was NULL.");
69 }
70}
71
72/*!
73 Destroys this manager.
74*/
75QGeoRoutingManager::~QGeoRoutingManager()
76{
77 delete d_ptr;
78}
79
80/*!
81 Returns the name of the engine which implements the behaviour of this
82 routing manager.
83
84 The combination of managerName() and managerVersion() should be unique
85 amongst the plugin implementations.
86*/
87QString QGeoRoutingManager::managerName() const
88{
89 return d_ptr->engine->managerName();
90}
91
92/*!
93 Returns the version of the engine which implements the behaviour of this
94 routin manager.
95
96 The combination of managerName() and managerVersion() should be unique
97 amongst the plugin implementations.
98*/
99int QGeoRoutingManager::managerVersion() const
100{
101 return d_ptr->engine->managerVersion();
102}
103
104/*!
105 Begins the calculation of the route specified by \a request.
106
107 A QGeoRouteReply object will be returned, which can be used to manage the
108 routing operation and to return the results of the operation.
109
110 This manager and the returned QGeoRouteReply object will emit signals
111 indicating if the operation completes or if errors occur.
112
113 Once the operation has completed, QGeoRouteReply::routes can be used to
114 retrieve the calculated route or routes.
115
116 If \a request includes features which are not supported by this manager, as
117 reported by the methods in this manager, then a
118 QGeoRouteReply::UnsupportedOptionError will occur.
119
120 The user is responsible for deleting the returned reply object, although
121 this can be done in the slot connected to QGeoRoutingManager::finished(),
122 QGeoRoutingManager::errorOccurred(), QGeoRouteReply::finished() or
123 QGeoRouteReply::errorOccurred() with deleteLater().
124*/
125QGeoRouteReply *QGeoRoutingManager::calculateRoute(const QGeoRouteRequest &request)
126{
127 return d_ptr->engine->calculateRoute(request);
128}
129
130/*!
131 Begins the process of updating \a route based on the current position \a
132 position.
133
134 A QGeoRouteReply object will be returned, which can be used to manage the
135 routing operation and to return the results of the operation.
136
137 This manager and the returned QGeoRouteReply object will emit signals
138 indicating if the operation completes or if errors occur.
139
140 If supportsRouteUpdates() returns false an
141 QGeoRouteReply::UnsupportedOptionError will occur.
142
143 Once the operation has completed, QGeoRouteReply::routes can be used to
144 retrieve the updated route.
145
146 The returned route could be entirely different to the original route,
147 especially if \a position is far away from the initial route.
148 Otherwise the route will be similar, although the remaining time and
149 distance will be updated and any segments of the original route which
150 have been traversed will be removed.
151
152 The user is responsible for deleting the returned reply object, although
153 this can be done in the slot connected to QGeoRoutingManager::finished(),
154 QGeoRoutingManager::errorOccurred(), QGeoRouteReply::finished() or
155 QGeoRouteReply::errorOccurred() with deleteLater().
156*/
157QGeoRouteReply *QGeoRoutingManager::updateRoute(const QGeoRoute &route, const QGeoCoordinate &position)
158{
159 return d_ptr->engine->updateRoute(route, position);
160}
161
162/*!
163 Returns the travel modes supported by this manager.
164*/
165QGeoRouteRequest::TravelModes QGeoRoutingManager::supportedTravelModes() const
166{
167 return d_ptr->engine->supportedTravelModes();
168}
169
170/*!
171 Returns the types of features that this manager can take into account
172 during route planning.
173*/
174QGeoRouteRequest::FeatureTypes QGeoRoutingManager::supportedFeatureTypes() const
175{
176 return d_ptr->engine->supportedFeatureTypes();
177}
178
179/*!
180 Returns the weightings which this manager can apply to different features
181 during route planning.
182*/
183QGeoRouteRequest::FeatureWeights QGeoRoutingManager::supportedFeatureWeights() const
184{
185 return d_ptr->engine->supportedFeatureWeights();
186}
187
188/*!
189 Returns the route optimizations supported by this manager.
190*/
191QGeoRouteRequest::RouteOptimizations QGeoRoutingManager::supportedRouteOptimizations() const
192{
193 return d_ptr->engine->supportedRouteOptimizations();
194}
195
196/*!
197 Returns the levels of detail for routing segments which can be requested
198 with this manager.
199*/
200QGeoRouteRequest::SegmentDetails QGeoRoutingManager::supportedSegmentDetails() const
201{
202 return d_ptr->engine->supportedSegmentDetails();
203}
204
205/*!
206 Returns the levels of detail for navigation maneuvers which can be
207 requested by this manager.
208*/
209QGeoRouteRequest::ManeuverDetails QGeoRoutingManager::supportedManeuverDetails() const
210{
211 return d_ptr->engine->supportedManeuverDetails();
212}
213
214/*!
215 Sets the locale to be used by this manager to \a locale.
216
217 If this routing manager supports returning addresses and instructions
218 in different languages, they will be returned in the language of \a locale.
219
220 The locale used defaults to the system locale if this is not set.
221*/
222void QGeoRoutingManager::setLocale(const QLocale &locale)
223{
224 d_ptr->engine->setLocale(locale);
225}
226
227/*!
228 Returns the locale used to hint to this routing manager about what
229 language to use for addresses and instructions.
230*/
231QLocale QGeoRoutingManager::locale() const
232{
233 return d_ptr->engine->locale();
234}
235
236/*!
237 Sets the measurement system used by this manager to \a system.
238
239 The measurement system can be set independently of the locale. Both setLocale() and this
240 function set the measurement system. The value set by the last function called will be used.
241
242 \sa measurementSystem(), locale(), setLocale()
243*/
244void QGeoRoutingManager::setMeasurementSystem(QLocale::MeasurementSystem system)
245{
246 d_ptr->engine->setMeasurementSystem(system);
247}
248
249/*!
250 Returns the measurement system used by this manager.
251
252 If setMeasurementSystem() has been called then the value returned by this function may be
253 different to that returned by locale().\l {QLocale::measurementSystem()}{measurementSystem()}.
254 In which case the value returned by this function is what will be used by the manager.
255
256 \sa setMeasurementSystem(), setLocale()
257*/
258QLocale::MeasurementSystem QGeoRoutingManager::measurementSystem() const
259{
260 return d_ptr->engine->measurementSystem();
261}
262
263/*!
264\fn void QGeoRoutingManager::finished(QGeoRouteReply *reply)
265
266This signal is emitted when \a reply has finished processing.
267
268If reply::error() equals QGeoRouteReply::NoError then the processing
269finished successfully.
270
271This signal and QGeoRouteReply::finished() will be emitted at the same time.
272
273\note Do not delete the \a reply object in the slot connected to this signal.
274Use deleteLater() instead.
275*/
276
277/*!
278\fn void QGeoRoutingManager::errorOccurred(QGeoRouteReply *reply, QGeoRouteReply::Error error, const QString &errorString)
279
280This signal is emitted when an error has been detected in the processing of
281\a reply. The QGeoRoutingManager::finished() signal will probably follow.
282
283The error will be described by the error code \a error. If \a errorString is
284not empty it will contain a textual description of the error.
285
286This signal and QGeoRouteReply::errorOccurred() will be emitted at the same time.
287
288\note Do not delete the \a reply object in the slot connected to this signal.
289Use deleteLater() instead.
290*/
291
292/*******************************************************************************
293*******************************************************************************/
294
295QT_END_NAMESPACE