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
routehandler.h
Go to the documentation of this file.
1
// Copyright (C) 2021 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4
//! [RouteHandler]
5
class
RouteHandler
:
public
QObject
6
{
7
Q_OBJECT
8
public
:
9
RouteHandler
(
QGeoRoutingManager
*
routingManager
,
10
const
QGeoCoordinate
&
origin
,
11
const
QGeoCoordinate
&
destination
) {
12
13
QGeoRouteRequest
request
(
origin
,
destination
);
14
15
// The request defaults to the fastest route by car, which is
16
// equivalent to:
17
// request.setTravelMode(QGeoRouteRequest::CarTravel);
18
// request.setRouteOptimization(QGeoRouteRequest::FastestRoute);
19
20
request
.
setAvoidFeatureTypes
(
QGeoRouteRequest
::
AvoidTolls
);
21
request
.
setAvoidFeatureTypes
(
QGeoRouteRequest
::
AvoidMotorPoolLanes
);
22
23
QGeoRouteRequest
::
AvoidFeaturesTypes
avoidableFeatures
=
routingManager
->
supportedAvoidFeatureTypes
();
24
25
if
(!(
avoidableFeatures
&
request
.
avoidFeatureTypes
())) {
26
// ... inform the user that the routing manager does not
27
// provide support for avoiding tolls and/or motor pool lanes ...
28
return
;
29
}
30
31
QGeoRouteReply
*
reply
=
routingManager
->
calculateRoute
(
request
);
32
33
if
(
reply
->
isFinished
()) {
34
if
(
reply
->
error
() ==
QGeoRouteReply
::
NoError
) {
35
routeCalculated
(
reply
);
36
}
else
{
37
routeError
(
reply
,
reply
->
error
(),
reply
->
errorString
());
38
}
39
return
;
40
}
41
42
connect
(
routingManager
, &
QGeoRoutingManager
::
finished
,
43
this
, &
RouteHandler
::
routeCalculated
);
44
45
connect
(
routingManager
, &
QGeoRoutingManager
::
errorOccurred
,
46
this
, &
RouteHandler
::
routeError
);
47
}
48
49
private
slots
:
50
void
routeCalculated
(
QGeoRouteReply
*
reply
)
51
{
52
// A route request can ask for several alternative routes ...
53
if
(
reply
->
routes
().
size
() != 0) {
54
55
// ... but by default it will only get a single route
56
QGeoRoute
route
=
reply
->
routes
().
at
(0);
57
58
//... now we have to make use of the route ...
59
}
60
61
reply
->
deleteLater
();
62
}
63
64
void
routeError
(
QGeoRouteReply
*
reply
,
QGeoRouteReply
:
Error
error
,
const
QString
&
errorString
)
65
{
66
// ... inform the user that an error has occurred ...
67
reply
->
deleteLater
();
68
}
69
};
70
//! [RouteHandler]
RouteHandler
[RouteHandler]
Definition
routehandler.h:6
qtlocation
src
location
doc
snippets
maps
routehandler.h
Generated on
for Qt by
1.14.0