1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtLocation module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include "qdeclarativegeomaneuver_p.h"
38
39QT_BEGIN_NAMESPACE
40
41/*!
42 \qmltype RouteManeuver
43 \instantiates QDeclarativeGeoManeuver
44 \inqmlmodule QtLocation
45 \ingroup qml-QtLocation5-routing
46 \since QtLocation 5.5
47
48 \brief The RouteManeuver type represents the information relevant to the
49 point at which two RouteSegments meet.
50
51 RouteSegment instances can be thought of as edges on a routing
52 graph, with RouteManeuver instances as optional labels attached to the
53 vertices of the graph.
54
55 The most interesting information held in a RouteManeuver instance is
56 normally the textual navigation to provide and the position at which to
57 provide it, accessible by \l instructionText and \l position respectively.
58
59 \section1 Example
60
61 The following QML snippet demonstrates how to print information about a
62 route maneuver:
63
64 \snippet declarative/routing.qml QtQuick import
65 \snippet declarative/maps.qml QtLocation import
66 \codeline
67 \snippet declarative/routing.qml RouteManeuver
68*/
69
70QDeclarativeGeoManeuver::QDeclarativeGeoManeuver(QObject *parent)
71 : QObject(parent)
72{
73}
74
75QDeclarativeGeoManeuver::QDeclarativeGeoManeuver(const QGeoManeuver &maneuver, QObject *parent)
76 : QObject(parent),
77 maneuver_(maneuver)
78{
79}
80
81QDeclarativeGeoManeuver::~QDeclarativeGeoManeuver() {}
82
83/*!
84 \qmlproperty bool RouteManeuver::valid
85
86 This read-only property holds whether this maneuver is valid or not.
87
88 Invalid maneuvers are used when there is no information
89 that needs to be attached to the endpoint of a QGeoRouteSegment instance.
90*/
91
92bool QDeclarativeGeoManeuver::valid() const
93{
94 return maneuver_.isValid();
95}
96
97/*!
98 \qmlproperty coordinate RouteManeuver::position
99
100 This read-only property holds where the \l instructionText should be displayed.
101
102*/
103
104QGeoCoordinate QDeclarativeGeoManeuver::position() const
105{
106 return maneuver_.position();
107}
108
109/*!
110 \qmlproperty string RouteManeuver::instructionText
111
112 This read-only property holds textual navigation instruction.
113*/
114
115QString QDeclarativeGeoManeuver::instructionText() const
116{
117 return maneuver_.instructionText();
118}
119
120/*!
121 \qmlproperty enumeration RouteManeuver::direction
122
123 Describes the change in direction associated with the instruction text
124 that is associated with a RouteManeuver.
125
126 \list
127 \li RouteManeuver.NoDirection - There is no direction associated with the instruction text
128 \li RouteManeuver.DirectionForward - The instruction indicates that the direction of travel does not need to change
129 \li RouteManeuver.DirectionBearRight - The instruction indicates that the direction of travel should bear to the right
130 \li RouteManeuver.DirectionLightRight - The instruction indicates that a light turn to the right is required
131 \li RouteManeuver.DirectionRight - The instruction indicates that a turn to the right is required
132 \li RouteManeuver.DirectionHardRight - The instruction indicates that a hard turn to the right is required
133 \li RouteManeuver.DirectionUTurnRight - The instruction indicates that a u-turn to the right is required
134 \li RouteManeuver.DirectionUTurnLeft - The instruction indicates that a u-turn to the left is required
135 \li RouteManeuver.DirectionHardLeft - The instruction indicates that a hard turn to the left is required
136 \li RouteManeuver.DirectionLeft - The instruction indicates that a turn to the left is required
137 \li RouteManeuver.DirectionLightLeft - The instruction indicates that a light turn to the left is required
138 \li RouteManeuver.DirectionBearLeft - The instruction indicates that the direction of travel should bear to the left
139 \endlist
140*/
141
142QDeclarativeGeoManeuver::Direction QDeclarativeGeoManeuver::direction() const
143{
144 return QDeclarativeGeoManeuver::Direction(maneuver_.direction());
145}
146
147/*!
148 \qmlproperty int RouteManeuver::timeToNextInstruction
149
150 This read-only property holds the estimated time it will take to travel
151 from the point at which the associated instruction was issued and the
152 point that the next instruction should be issued, in seconds.
153*/
154
155int QDeclarativeGeoManeuver::timeToNextInstruction() const
156{
157 return maneuver_.timeToNextInstruction();
158}
159
160/*!
161 \qmlproperty real RouteManeuver::distanceToNextInstruction
162
163 This read-only property holds the distance, in meters, between the point at which
164 the associated instruction was issued and the point that the next instruction should
165 be issued.
166*/
167
168qreal QDeclarativeGeoManeuver::distanceToNextInstruction() const
169{
170 return maneuver_.distanceToNextInstruction();
171}
172
173/*!
174 \qmlproperty coordinate RouteManeuver::waypoint
175
176 This property holds the waypoint associated with this maneuver.
177 All maneuvers do not have a waypoint associated with them, this
178 can be checked with \l waypointValid.
179
180*/
181
182QGeoCoordinate QDeclarativeGeoManeuver::waypoint() const
183{
184 return maneuver_.waypoint();
185}
186
187/*!
188 \qmlproperty Object RouteManeuver::extendedAttributes
189
190 This property holds the extended attributes of the maneuver and is a map.
191 These attributes are plugin specific, and can be empty.
192
193 Consult the \l {Qt Location#Plugin References and Parameters}{plugin documentation}
194 for what attributes are supported and how they should be used.
195
196 Note, due to limitations of the QQmlPropertyMap, it is not possible
197 to declaratively specify the attributes in QML, assignment of attributes keys
198 and values can only be accomplished by JavaScript.
199
200 \since QtLocation 5.11
201*/
202QQmlPropertyMap *QDeclarativeGeoManeuver::extendedAttributes() const
203{
204 if (!m_extendedAttributes) {
205 QDeclarativeGeoManeuver *self = const_cast<QDeclarativeGeoManeuver *>(this);
206 self->m_extendedAttributes = new QQmlPropertyMap(self);
207 // Fill it
208 const QStringList keys = maneuver_.extendedAttributes().keys();
209 for (const QString &key: keys) {
210 self->m_extendedAttributes->insert(key,
211 value: maneuver_.extendedAttributes().value(akey: key));
212 }
213 }
214 return m_extendedAttributes;
215}
216
217/*!
218 \qmlproperty bool RouteManeuver::waypointValid
219
220 This read-only property holds whether this \l waypoint, associated with this
221 maneuver, is valid or not.
222*/
223
224bool QDeclarativeGeoManeuver::waypointValid() const
225{
226 return maneuver_.waypoint().isValid();
227}
228
229QT_END_NAMESPACE
230

source code of qtlocation/src/location/declarativemaps/qdeclarativegeomaneuver.cpp