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
qgeorouterequest.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
6
7#include <QtPositioning/QGeoCoordinate>
8#include <QtPositioning/QGeoRectangle>
9
11
12QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QGeoRouteRequestPrivate)
13
14/*!
15 \class QGeoRouteRequest
16 \inmodule QtLocation
17 \ingroup QtLocation-routing
18 \since 5.6
19
20 \brief The QGeoRouteRequest class represents the parameters and restrictions
21 which define a request for routing information.
22
23 The default state of a QGeoRouteRequest instance will result in a request
24 for basic route segment and navigation maneuvers describing the fastest
25 route by car which covers the given waypoints.
26
27 There may be significant variation in the features supported by different
28 providers of routing information, or even in the features supported by
29 the same provider if different levels of authorization are used.
30
31 There are several functions in QGeoRoutingManager which can be used to
32 check which features are supported with the current provider and
33 authorization level.
34 \sa QGeoRoutingManager
35*/
36
37/*
38 DESIGN NOTE
39
40 There are plans to make this extensible by allowing the user to set a
41 list of QGeoTransportOptions (or QGeoTransitOptions). We don't have any
42 subclasses for that just yet, otherwise they'd be present.
43
44 A QGeoPublicTransportOption subclass would allow users to specify things
45 like cost limits, the maximum number of changes of vehicle, the maximum
46 walking time / distance between changes of vehicle.
47
48 There's Nokia / Navteq support for specifying things like Truck attributes
49 so you can route around various road restrictions and conditions which
50 effect trucks.
51
52 A QGeoTrafficAwareTransportOption is probably also a good place to put the
53 inputs for the various traffic / time aware bits of information. A
54 departure / arrrival time could be set, and the presence of this transport
55 options subclass (and the fact that user auth said that the user had
56 support) would mean we could provide better values for the estimated
57 travel times and so on.
58
59 This all relies on at least one service making this data available to us,
60 which would probably be tied to token based authorization. It could be
61 some time before this becomes available.
62*/
63
64/*!
65 \enum QGeoRouteRequest::TravelMode
66
67 Defines modes of travel to be used for a route.
68
69 \value CarTravel
70 The route will be optimized for someone who is driving a car.
71 \value PedestrianTravel
72 The route will be optimized for someone who is walking.
73 \value BicycleTravel
74 The route will be optimized for someone who is riding a bicycle.
75 \value PublicTransitTravel
76 The route will be optimized for someone who is making use of public transit.
77 \value TruckTravel
78 The route will be optimized for someone who is driving a truck.
79*/
80
81/*!
82 \enum QGeoRouteRequest::FeatureType
83
84 Defines a feature which is important to the planning of a route.
85
86 These values will be used in combination with
87 QGeoRouteRequest::FeatureWeight to determine if they should or should
88 not be part of the route.
89
90 \value NoFeature
91 Used by QGeoRoutingManager::supportedFeatureTypes() to indicate that
92 no features will be taken into account when planning the route.
93 \value TollFeature
94 Consdier tollways when planning the route.
95 \value HighwayFeature
96 Consider highways when planning the route.
97 \value PublicTransitFeature
98 Consider public transit when planning the route.
99 \value FerryFeature
100 Consider ferries when planning the route.
101 \value TunnelFeature
102 Consider tunnels when planning the route.
103 \value DirtRoadFeature
104 Consider dirt roads when planning the route.
105 \value ParksFeature
106 Consider parks when planning the route.
107 \value MotorPoolLaneFeature
108 Consider motor pool lanes when planning the route.
109 \value TrafficFeature
110 Consider the current traffic situation when planning the route. Since QtLocation 5.10
111*/
112
113/*!
114 \enum QGeoRouteRequest::FeatureWeight
115
116 Defines the weight to associate with a feature during the
117 planning of a route.
118
119 These values will be used in combination with
120 QGeoRouteRequest::Feature to determine if they should or should
121 not be part of the route.
122
123 \value NeutralFeatureWeight
124 The presence or absence of the feature will not affect the
125 planning of the route.
126 \value PreferFeatureWeight
127 Routes which contain the feature will be preferred over those that do
128 not.
129 \value RequireFeatureWeight
130 Only routes which contain the feature will be considered, otherwise
131 no route will be returned.
132 \value AvoidFeatureWeight
133 Routes which do not contain the feature will be preferred over those
134 that do.
135 \value DisallowFeatureWeight
136 Only routes which do not contain the feature will be considered,
137 otherwise no route will be returned.
138*/
139
140// TODO improve description of MostScenicRoute
141/*!
142 \enum QGeoRouteRequest::RouteOptimization
143
144 Defines the type of optimization which is applied to the planning of the route.
145
146 \value ShortestRoute
147 Minimize the length of the journey.
148 \value FastestRoute
149 Minimize the traveling time for the journey.
150 \value MostEconomicRoute
151 Minimize the cost of the journey.
152 \value MostScenicRoute
153 Maximize the scenic potential of the journey.
154*/
155
156/*!
157 \enum QGeoRouteRequest::SegmentDetail
158
159 Defines the amount of route segment information that should be included
160 with the route.
161
162 \value NoSegmentData
163 No segment data should be included with the route. A route requested
164 with this level of segment detail will initialize
165 QGeoRouteSegment::path() as a straight line between the positions of
166 the previous and next QGeoManeuver instances.
167
168 \value BasicSegmentData
169 Basic segment data will be included with the route. This will include
170 QGeoRouteSegment::path().
171*/
172
173/*!
174 \enum QGeoRouteRequest::ManeuverDetail
175
176 Defines the amount of maneuver information that should be included with
177 the route.
178
179 \value NoManeuvers
180 No maneuvers should be included with the route.
181
182 \value BasicManeuvers
183 Basic manevuers will be included with the route. This will
184 include QGeoManeuver::instructionText().
185*/
186
187/*!
188 Constructs a request to calculate a route through the coordinates \a waypoints.
189
190 The route will traverse the objects of \a waypoints in order.
191*/
192QGeoRouteRequest::QGeoRouteRequest(const QList<QGeoCoordinate> &waypoints)
193 : d_ptr(new QGeoRouteRequestPrivate())
194{
195 d_ptr->waypoints = waypoints;
196}
197
198/*!
199 Constructs a request to calculate a route between \a origin and
200 \a destination.
201*/
202QGeoRouteRequest::QGeoRouteRequest(const QGeoCoordinate &origin, const QGeoCoordinate &destination)
203 : d_ptr(new QGeoRouteRequestPrivate())
204{
205 d_ptr->waypoints.append(origin);
206 d_ptr->waypoints.append(destination);
207}
208
209/*!
210 Constructs a route request object from the contents of \a other.
211*/
212QGeoRouteRequest::QGeoRouteRequest(const QGeoRouteRequest &other) noexcept = default;
213
214/*!
215 Destroys the request.
216*/
217QGeoRouteRequest::~QGeoRouteRequest() = default;
218
219/*!
220 Assigns \a other to this route request object and then returns a reference
221 to this route request object.
222*/
223QGeoRouteRequest &QGeoRouteRequest::operator=(const QGeoRouteRequest & other) noexcept
224{
225 if (this == &other)
226 return *this;
227
228 d_ptr = other.d_ptr;
229 return *this;
230}
231
232/*!
233 \fn bool QGeoRouteRequest::operator==(const QGeoRouteRequest &lhs, const QGeoRouteRequest &rhs) noexcept
234
235 Returns whether the route requests \a lhs and \a rhs are equal.
236*/
237
238/*!
239 \fn bool QGeoRouteRequest::operator!=(const QGeoRouteRequest &lhs, const QGeoRouteRequest &rhs) noexcept
240
241 Returns whether the route requests \a lhs and \a rhs are not equal.
242*/
243
244bool QGeoRouteRequest::isEqual(const QGeoRouteRequest &other) const noexcept
245{
246 return ((d_ptr.constData() == other.d_ptr.constData())
247 || (*d_ptr) == (*other.d_ptr));
248}
249
250/*!
251 Sets \a waypoints as the waypoints that the route should pass through.
252
253 The waypoints should be given in order from origin to destination.
254
255 This request will be invalid until the waypoints have been set to a
256 list containing two or more coordinates.
257*/
258void QGeoRouteRequest::setWaypoints(const QList<QGeoCoordinate> &waypoints)
259{
260 d_ptr->waypoints = waypoints;
261}
262
263/*!
264 Returns the waypoints that the route will pass through.
265*/
266QList<QGeoCoordinate> QGeoRouteRequest::waypoints() const
267{
268 return d_ptr->waypoints;
269}
270
271/*!
272 Sets \a areas as excluded areas that the route must not cross.
273*/
274void QGeoRouteRequest::setExcludeAreas(const QList<QGeoRectangle> &areas)
275{
276 d_ptr->excludeAreas = areas;
277}
278
279/*!
280 Returns areas the route must not cross.
281*/
282QList<QGeoRectangle> QGeoRouteRequest::excludeAreas() const
283{
284 return d_ptr->excludeAreas;
285}
286
287/*!
288 Sets the number of alternative routes to request to \a alternatives. If \a alternatives is
289 negative the number of alternative routes is set to 0.
290
291 The default value is 0.
292*/
293void QGeoRouteRequest::setNumberAlternativeRoutes(int alternatives)
294{
295 d_ptr->numberAlternativeRoutes = qMax(0, alternatives);
296}
297
298/*!
299 Returns the number of alternative routes which will be requested.
300*/
301int QGeoRouteRequest::numberAlternativeRoutes() const
302{
303 return d_ptr->numberAlternativeRoutes;
304}
305
306/*!
307 Sets the travel modes which should be considered during the planning of the
308 route to \a travelModes.
309
310 The default value is QGeoRouteRequest::CarTravel.
311*/
312void QGeoRouteRequest::setTravelModes(QGeoRouteRequest::TravelModes travelModes)
313{
314 d_ptr->travelModes = travelModes;
315}
316
317/*!
318 Returns the travel modes which this request specifies should be considered
319 during the planning of the route.
320*/
321QGeoRouteRequest::TravelModes QGeoRouteRequest::travelModes() const
322{
323 return d_ptr->travelModes;
324}
325
326/*!
327 Assigns the weight \a featureWeight to the feature \a featureType during
328 the planning of the route.
329
330 By default all features are assigned a weight of NeutralFeatureWeight.
331
332 It is impossible to assign a weight to QGeoRouteRequest::NoFeature.
333*/
334void QGeoRouteRequest::setFeatureWeight(QGeoRouteRequest::FeatureType featureType, QGeoRouteRequest::FeatureWeight featureWeight)
335{
336 if (featureWeight != QGeoRouteRequest::NeutralFeatureWeight) {
337 if (featureType != QGeoRouteRequest::NoFeature)
338 d_ptr->featureWeights[featureType] = featureWeight;
339 } else {
340 d_ptr->featureWeights.remove(featureType);
341 }
342}
343
344/*!
345 Returns the weight assigned to \a featureType in the planning of the route.
346
347 If no feature weight has been specified for \a featureType then
348 NeutralFeatureWeight will be returned.
349*/
350QGeoRouteRequest::FeatureWeight QGeoRouteRequest::featureWeight(QGeoRouteRequest::FeatureType featureType) const
351{
352 return d_ptr->featureWeights.value(featureType, QGeoRouteRequest::NeutralFeatureWeight);
353}
354
355/*!
356 Returns the list of features that will be considered when planning the
357 route. Features with a weight of NeutralFeatureWeight will not be returned.
358*/
359QList<QGeoRouteRequest::FeatureType> QGeoRouteRequest::featureTypes() const
360{
361 return d_ptr->featureWeights.keys();
362}
363
364/*!
365 Sets the optimization criteria to use while planning the route to
366 \a optimization.
367
368 The default value is QGeoRouteRequest::FastestRoute.
369*/
370void QGeoRouteRequest::setRouteOptimization(QGeoRouteRequest::RouteOptimizations optimization)
371{
372 d_ptr->routeOptimization = optimization;
373}
374
375/*!
376 Returns the optimization criteria which this request specifies should be
377 used while planning the route.
378*/
379QGeoRouteRequest::RouteOptimizations QGeoRouteRequest::routeOptimization() const
380{
381 return d_ptr->routeOptimization;
382}
383
384/*!
385 Sets the level of detail to use when representing routing segments to
386 \a segmentDetail.
387*/
388void QGeoRouteRequest::setSegmentDetail(QGeoRouteRequest::SegmentDetail segmentDetail)
389{
390 d_ptr->segmentDetail = segmentDetail;
391}
392
393/*!
394 Returns the level of detail which will be used in the representation of
395 routing segments.
396*/
397QGeoRouteRequest::SegmentDetail QGeoRouteRequest::segmentDetail() const
398{
399 return d_ptr->segmentDetail;
400}
401
402/*!
403 Sets the level of detail to use when representing routing maneuvers to
404 \a maneuverDetail.
405
406 The default value is QGeoRouteRequest::BasicManeuvers.
407*/
408void QGeoRouteRequest::setManeuverDetail(QGeoRouteRequest::ManeuverDetail maneuverDetail)
409{
410 d_ptr->maneuverDetail = maneuverDetail;
411}
412
413/*!
414 Returns the level of detail which will be used in the representation of
415 routing maneuvers.
416*/
417QGeoRouteRequest::ManeuverDetail QGeoRouteRequest::maneuverDetail() const
418{
419 return d_ptr->maneuverDetail;
420}
421
422/*!
423 Sets the departure time \a departureTime for the route calculation. This
424 information can be used by the backend to calculate a faster route, for
425 example, by avoiding traffic congestion during rush hour.
426
427 The default value is an invalid QDateTime.
428
429 \since 5.13
430*/
431void QGeoRouteRequest::setDepartureTime(const QDateTime &departureTime)
432{
433 d_ptr->departureTime = departureTime;
434}
435
436/*!
437 Returns the departure time in the request.
438
439 \since 5.13
440*/
441QDateTime QGeoRouteRequest::departureTime() const
442{
443 return d_ptr->departureTime;
444}
445
446/*******************************************************************************
447*******************************************************************************/
448
449bool QGeoRouteRequestPrivate::operator==(const QGeoRouteRequestPrivate &other) const
450{
451 return ((waypoints == other.waypoints)
452 && (excludeAreas == other.excludeAreas)
453 && (numberAlternativeRoutes == other.numberAlternativeRoutes)
454 && (travelModes == other.travelModes)
455 && (featureWeights == other.featureWeights)
456 && (routeOptimization == other.routeOptimization)
457 && (segmentDetail == other.segmentDetail)
458 && (maneuverDetail == other.maneuverDetail));
459}
460
461QT_END_NAMESPACE
Combined button and popup list for selecting options.