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
qgeoroutingmanagerengine.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
7
9
10/*!
11 \class QGeoRoutingManagerEngine
12 \inmodule QtLocation
13 \ingroup QtLocation-impl
14 \since 5.6
15
16 \brief The QGeoRoutingManagerEngine class provides an interface and
17 convenience methods to implementers of QGeoServiceProvider plugins who want
18 to provide access to geographic routing information.
19
20 \note There are no source or binary compatibility guarantees for the
21 backend classes. The API is only guaranteed to work with the Qt version it
22 was developed against. API changes will however only be made in minor
23 releases. (6.6, 6.7, and so on.)
24
25 Subclasses of QGeoRoutingManagerEngine need to provide an implementation of
26 calculateRoute().
27
28 In the default implementation, supportsRouteUpdates() returns false and
29 updateRoute() returns a QGeoRouteReply object containing a
30 QGeoRouteReply::UnsupportedOptionError.
31
32 If the routing service supports updating routes as they are being
33 traveled, the subclass should provide an implementation of updateRoute()
34 and call setSupportsRouteUpdates(true) at some point in time before
35 updateRoute() is called.
36
37 The function setSupportsRouteUpdates() is one of several functions which
38 configure the reported capabilities of the engine. If the capabilities
39 of an engine differ from the default values these functions should be
40 used so that the reported capabilities are accurate.
41
42 It is important that this is done before calculateRoute(), updateRoute()
43 or any of the capability reporting functions are used to prevent
44 incorrect or inconsistent behavior.
45
46 A subclass of QGeoRouteManagerEngine will often make use of a subclass
47 fo QGeoRouteReply internally, in order to add any engine-specific
48 data (such as a QNetworkReply object for network-based services) to the
49 QGeoRouteReply instances used by the engine.
50
51 \sa QGeoRoutingManager
52*/
53
54/*!
55 Constructs a new engine with the specified \a parent, using \a parameters
56 to pass any implementation specific data to the engine.
57*/
58QGeoRoutingManagerEngine::QGeoRoutingManagerEngine(const QVariantMap &parameters, QObject *parent)
59 : QObject(parent),
60 d_ptr(new QGeoRoutingManagerEnginePrivate())
61{
62 Q_UNUSED(parameters);
63}
64
65/*!
66 Destroys this engine.
67*/
68QGeoRoutingManagerEngine::~QGeoRoutingManagerEngine()
69{
70 delete d_ptr;
71}
72
73/*!
74 Sets the name which this engine implementation uses to distinguish itself
75 from the implementations provided by other plugins to \a managerName.
76
77 The combination of managerName() and managerVersion() should be unique
78 amongst plugin implementations.
79*/
80void QGeoRoutingManagerEngine::setManagerName(const QString &managerName)
81{
82 d_ptr->managerName = managerName;
83}
84
85/*!
86 Returns the name which this engine implementation uses to distinguish
87 itself from the implementations provided by other plugins.
88
89 The combination of managerName() and managerVersion() should be unique
90 amongst plugin implementations.
91*/
92QString QGeoRoutingManagerEngine::managerName() const
93{
94 return d_ptr->managerName;
95}
96
97/*!
98 Sets the version of this engine implementation to \a managerVersion.
99
100 The combination of managerName() and managerVersion() should be unique
101 amongst plugin implementations.
102*/
103void QGeoRoutingManagerEngine::setManagerVersion(int managerVersion)
104{
105 d_ptr->managerVersion = managerVersion;
106}
107
108/*!
109 Returns the version of this engine implementation.
110
111 The combination of managerName() and managerVersion() should be unique
112 amongst plugin implementations.
113*/
114int QGeoRoutingManagerEngine::managerVersion() const
115{
116 return d_ptr->managerVersion;
117}
118
119/*!
120\fn QGeoRouteReply *QGeoRoutingManagerEngine::calculateRoute(const QGeoRouteRequest &request)
121
122 Begins the calculation of the route specified by \a request.
123
124 A QGeoRouteReply object will be returned, which can be used to manage the
125 routing operation and to return the results of the operation.
126
127 This engine and the returned QGeoRouteReply object will emit signals
128 indicating if the operation completes or if errors occur.
129
130 Once the operation has completed, QGeoRouteReply::routes can be used to
131 retrieve the calculated route or routes.
132
133 If \a request includes features which are not supported by this engine, as
134 reported by the methods in this engine, then a
135 QGeoRouteReply::UnsupportedOptionError will occur.
136
137 The user is responsible for deleting the returned reply object, although
138 this can be done in the slot connected to QGeoRoutingManagerEngine::finished(),
139 QGeoRoutingManagerEngine::errorOccurred(), QGeoRouteReply::finished() or
140 QGeoRouteReply::errorOccurred() with deleteLater().
141*/
142
143/*!
144 Begins the process of updating \a route based on the current position \a
145 position.
146
147 A QGeoRouteReply object will be returned, which can be used to manage the
148 routing operation and to return the results of the operation.
149
150 This engine and the returned QGeoRouteReply object will emit signals
151 indicating if the operation completes or if errors occur.
152
153 If supportsRouteUpdates() returns false an
154 QGeoRouteReply::UnsupportedOptionError will occur.
155
156 Once the operation has completed, QGeoRouteReply::routes can be used to
157 retrieve the updated route.
158
159 The returned route could be entirely different to the original route,
160 especially if \a position is far enough away from the initial route.
161 Otherwise the route will be similar, although the remaining time and
162 distance will be updated and any segments of the original route which
163 have been traversed will be removed.
164
165 The user is responsible for deleting the returned reply object, although
166 this can be done in the slot connected to QGeoRoutingManagerEngine::finished(),
167 QGeoRoutingManagerEngine::errorOccurred(), QGeoRouteReply::finished() or
168 QGeoRouteReply::errorOccurred() with deleteLater().
169*/
170QGeoRouteReply *QGeoRoutingManagerEngine::updateRoute(const QGeoRoute &route, const QGeoCoordinate &position)
171{
172 Q_UNUSED(route);
173 Q_UNUSED(position);
174 return new QGeoRouteReply(QGeoRouteReply::UnsupportedOptionError,
175 QLatin1String("The updating of routes is not supported by this service provider."), this);
176}
177
178/*!
179 Sets the travel modes supported by this engine to \a travelModes.
180
181 It is important that subclasses use this method to ensure that the engine
182 reports its capabilities correctly. If this function is not used the
183 engine will report that it supports no travel modes at all.
184*/
185void QGeoRoutingManagerEngine::setSupportedTravelModes(QGeoRouteRequest::TravelModes travelModes)
186{
187 d_ptr->supportedTravelModes = travelModes;
188}
189
190/*!
191 Returns the travel modes supported by this engine.
192*/
193QGeoRouteRequest::TravelModes QGeoRoutingManagerEngine::supportedTravelModes() const
194{
195 return d_ptr->supportedTravelModes;
196}
197
198/*!
199 Sets the types of features that this engine can take into account
200 during route planning to \a featureTypes.
201
202 It is important that subclasses use this method to ensure that the engine
203 reports its capabilities correctly. If this function is not used the
204 engine will report that it supports no feature types at all.
205*/
206void QGeoRoutingManagerEngine::setSupportedFeatureTypes(QGeoRouteRequest::FeatureTypes featureTypes)
207{
208 d_ptr->supportedFeatureTypes = featureTypes;
209}
210
211/*!
212 Returns the types of features that this engine can take into account
213 during route planning.
214*/
215QGeoRouteRequest::FeatureTypes QGeoRoutingManagerEngine::supportedFeatureTypes() const
216{
217 return d_ptr->supportedFeatureTypes;
218}
219
220/*!
221 Sets the weightings which this engine can apply to different features
222 during route planning to \a featureWeights.
223
224 It is important that subclasses use this method to ensure that the engine
225 reports its capabilities correctly. If this function is not used the
226 engine will report that it supports no feature weights at all.
227*/
228void QGeoRoutingManagerEngine::setSupportedFeatureWeights(QGeoRouteRequest::FeatureWeights featureWeights)
229{
230 d_ptr->supportedFeatureWeights = featureWeights;
231 d_ptr->supportedFeatureWeights |= QGeoRouteRequest::NeutralFeatureWeight;
232}
233
234/*!
235 Returns the weightings which this engine can apply to different features
236 during route planning.
237*/
238QGeoRouteRequest::FeatureWeights QGeoRoutingManagerEngine::supportedFeatureWeights() const
239{
240 return d_ptr->supportedFeatureWeights;
241}
242
243/*!
244 Sets the route optimizations supported by this engine to \a optimizations.
245
246 It is important that subclasses use this method to ensure that the engine
247 reports its capabilities correctly. If this function is not used the
248 engine will report that it supports no route optimizations at all.
249*/
250void QGeoRoutingManagerEngine::setSupportedRouteOptimizations(QGeoRouteRequest::RouteOptimizations optimizations)
251{
252 d_ptr->supportedRouteOptimizations = optimizations;
253}
254
255/*!
256 Returns the route optimizations supported by this engine.
257*/
258QGeoRouteRequest::RouteOptimizations QGeoRoutingManagerEngine::supportedRouteOptimizations() const
259{
260 return d_ptr->supportedRouteOptimizations;
261}
262
263/*!
264 Sets the levels of detail for routing segments which can be
265 requested by this engine to \a segmentDetails.
266
267 It is important that subclasses use this method to ensure that the engine
268 reports its capabilities correctly. If this function is not used the
269 engine will report that it supports no segment detail at all.
270*/
271void QGeoRoutingManagerEngine::setSupportedSegmentDetails(QGeoRouteRequest::SegmentDetails segmentDetails)
272{
273 d_ptr->supportedSegmentDetails = segmentDetails;
274}
275
276/*!
277 Returns the levels of detail for routing segments which can be
278 requested by this engine.
279*/
280QGeoRouteRequest::SegmentDetails QGeoRoutingManagerEngine::supportedSegmentDetails() const
281{
282 return d_ptr->supportedSegmentDetails;
283}
284
285/*!
286 Sets the levels of detail for navigation maneuvers which can be
287 requested by this engine to \a maneuverDetails.
288
289 It is important that subclasses use this method to ensure that the engine
290 reports its capabilities correctly. If this function is not used the
291 engine will report that it supports no maneuver details at all.
292*/
293void QGeoRoutingManagerEngine::setSupportedManeuverDetails(QGeoRouteRequest::ManeuverDetails maneuverDetails)
294{
295 d_ptr->supportedManeuverDetails = maneuverDetails;
296}
297
298/*!
299 Returns the levels of detail for navigation maneuvers which can be
300 requested by this engine.
301*/
302QGeoRouteRequest::ManeuverDetails QGeoRoutingManagerEngine::supportedManeuverDetails() const
303{
304 return d_ptr->supportedManeuverDetails;
305}
306
307/*!
308 Sets the locale to be used by this manager to \a locale.
309
310 If this routing manager supports returning addresses and instructions
311 in different languages, they will be returned in the language of \a locale.
312
313 The locale used defaults to the system locale if this is not set.
314*/
315void QGeoRoutingManagerEngine::setLocale(const QLocale &locale)
316{
317 d_ptr->locale = locale;
318 d_ptr->measurementSystem = locale.measurementSystem();
319}
320
321/*!
322 Returns the locale used to hint to this routing manager about what
323 language to use for addresses and instructions.
324*/
325QLocale QGeoRoutingManagerEngine::locale() const
326{
327 return d_ptr->locale;
328}
329
330/*!
331 Sets the measurement system used by this manager to \a system.
332
333 The measurement system can be set independently of the locale. Both setLocale() and this
334 function set the measurement system. The value set by the last function called will be used.
335
336 \sa measurementSystem(), locale(), setLocale()
337*/
338void QGeoRoutingManagerEngine::setMeasurementSystem(QLocale::MeasurementSystem system)
339{
340 d_ptr->measurementSystem = system;
341}
342
343/*!
344 Returns the measurement system used by this manager.
345
346 If setMeasurementSystem() has been called then the value returned by this function may be
347 different to that returned by locale().\l {QLocale::measurementSystem()}{measurementSystem()}.
348 In which case the value returned by this function is what will be used by the manager.
349
350 \sa setMeasurementSystem(), setLocale()
351*/
352QLocale::MeasurementSystem QGeoRoutingManagerEngine::measurementSystem() const
353{
354 return d_ptr->measurementSystem;
355}
356
357/*!
358\fn void QGeoRoutingManagerEngine::finished(QGeoRouteReply *reply)
359
360This signal is emitted when \a reply has finished processing.
361
362If reply::error() equals QGeoRouteReply::NoError then the processing
363finished successfully.
364
365This signal and QGeoRouteReply::finished() will be emitted at the same time.
366
367\note Do not delete the \a reply object in the slot connected to this signal.
368Use deleteLater() instead.
369*/
370
371/*!
372\fn void QGeoRoutingManagerEngine::errorOccurred(QGeoRouteReply *reply, QGeoRouteReply::Error error, const QString &errorString)
373
374This signal is emitted when an error has been detected in the processing of
375\a reply. The QGeoRoutingManagerEngine::finished() signal will probably follow.
376
377The error will be described by the error code \a error. If \a errorString is
378not empty it will contain a textual description of the error.
379
380This signal and QGeoRouteReply::errorOccurred() will be emitted at the same time.
381
382\note Do not delete the \a reply object in the slot connected to this signal.
383Use deleteLater() instead.
384*/
385
386QT_END_NAMESPACE
Combined button and popup list for selecting options.