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