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