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
qgeomaneuver.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 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
4#include "qgeomaneuver.h"
6
7#include <QtCore/QVariant>
9
10QT_BEGIN_NAMESPACE
11
12QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QGeoManeuverPrivate)
13
14/*!
15 \class QGeoManeuver
16 \inmodule QtLocation
17 \ingroup QtLocation-routing
18 \since 5.6
19
20 \brief The QGeoManeuver class represents the information relevant to the
21 point at which two QGeoRouteSegments meet.
22
23 QGeoRouteSegment instances can be thought of as edges on a routing
24 graph, with QGeoManeuver instances as optional labels attached to the
25 vertices of the graph.
26
27 The most interesting information help in a QGeoManeuver instance is
28 normally the textual navigation to provide and the position at which to
29 provide it, accessible by instructionText() and position() respectively.
30
31 It is also possible to determine if a routing waypoint has been passed by
32 checking if waypoint() returns a valid QGeoCoordinate.
33*/
34
35/*!
36 \qmltype routeManeuver
37 \inqmlmodule QtLocation
38 \ingroup qml-QtLocation5-routing
39 \since QtLocation 5.5
40
41 \brief The routeManeuver type represents the information relevant to the
42 point at which two routeSegments meet.
43
44 Instances of routeSegment can be thought of as edges on a routing
45 graph, with routeManeuver instances as optional labels attached to the
46 vertices of the graph.
47
48 The most interesting information held in a routeManeuver instance is
49 normally the textual navigation to provide and the position at which to
50 provide it, accessible by \l instructionText and \l position respectively.
51
52 \section1 Example
53
54 The following QML snippet demonstrates how to print information about a
55 route maneuver:
56
57 \snippet declarative/routing.qml QtQuick import
58 \snippet declarative/maps.qml QtLocation import
59 \codeline
60 \snippet declarative/routing.qml routeManeuver
61*/
62
63/*!
64\enum QGeoManeuver::InstructionDirection
65
66Describes the change in direction associated with the instruction text
67that is associated with a QGeoManaeuver.
68
69\value NoDirection
70There is no direction associated with the instruction text.
71
72\value DirectionForward
73The instruction indicates that the direction of travel does not need to change.
74
75\value DirectionBearRight
76The instruction indicates that the direction of travel should bear to the right.
77
78\value DirectionLightRight
79The instruction indicates that a light turn to the right is required.
80
81\value DirectionRight
82The instruction indicates that a turn to the right is required.
83
84\value DirectionHardRight
85The instruction indicates that a hard turn to the right is required.
86
87\value DirectionUTurnRight
88The instruction indicates that a u-turn to the right is required.
89
90\value DirectionUTurnLeft
91The instruction indicates that a u-turn to the left is required.
92
93\value DirectionHardLeft
94The instruction indicates that a hard turn to the left is required.
95
96\value DirectionLeft
97The instruction indicates that a turn to the left is required.
98
99\value DirectionLightLeft
100The instruction indicates that a light turn to the left is required.
101
102\value DirectionBearLeft
103The instruction indicates that the direction of travel should bear to the left.
104
105*/
106
107/*!
108 Constructs a invalid maneuver object.
109
110 The maneuver will remain invalid until one of
111 setPosition(), setInstructionText(), setDirection(),
112 setTimeToNextInstruction(), setDistanceToNextInstruction() or
113 setWaypoint() is called.
114*/
115QGeoManeuver::QGeoManeuver()
116 : d_ptr(new QGeoManeuverPrivate()) {}
117
118/*!
119 Constructs a maneuver object from the contents of \a other.
120*/
121QGeoManeuver::QGeoManeuver(const QGeoManeuver &other) noexcept = default;
122
123/*!
124 Destroys this maneuver object.
125*/
126QGeoManeuver::~QGeoManeuver() = default;
127
128/*!
129 Assigns \a other to this maneuver object and then returns
130 a reference to this maneuver object.
131*/
132QGeoManeuver &QGeoManeuver::operator= (const QGeoManeuver & other)
133{
134 if (this == &other)
135 return *this;
136
137 d_ptr = other.d_ptr;
138 return *this;
139}
140
141/*!
142 \fn bool QGeoManeuver::operator==(const QGeoManeuver &lhs, const QGeoManeuver &rhs) noexcept
143
144 Returns whether the \a lhs maneuver is equal to \a rhs.
145*/
146
147/*!
148 \fn bool QGeoManeuver::operator!= (const QGeoManeuver &lhs, const QGeoManeuver &rhs) noexcept
149
150 Returns whether the \a lhs maneuver is not equal to \a rhs.
151*/
152
153bool QGeoManeuver::isEqual(const QGeoManeuver &other) const
154{
155 return ( (d_ptr.constData() == other.d_ptr.constData())
156 || (d_ptr->equals(*other.d_ptr)) );
157}
158
159/*!
160 \qmlproperty bool routeManeuver::valid
161
162 This read-only property holds whether this maneuver is valid or not.
163
164 Invalid maneuvers are used when there is no information
165 that needs to be attached to the endpoint of a QGeoRouteSegment instance.
166*/
167
168/*!
169 \property QGeoManeuver::valid
170 \brief whether this maneuver is valid or not.
171
172 Invalid maneuvers are used when there is no information
173 that needs to be attached to the endpoint of a QGeoRouteSegment instance.
174*/
175bool QGeoManeuver::isValid() const
176{
177 return d_ptr->valid();
178}
179
180/*!
181 \qmlproperty coordinate routeManeuver::position
182
183 This read-only property holds where the \l instructionText should be displayed.
184
185*/
186
187/*!
188 \property QGeoManeuver::position
189 \brief the position where \l instructionText should be displayed.
190*/
191void QGeoManeuver::setPosition(const QGeoCoordinate &position)
192{
193 d_ptr->setValid(true);
194 d_ptr->setPosition(position);
195}
196
197QGeoCoordinate QGeoManeuver::position() const
198{
199 return d_ptr->position();
200}
201
202/*!
203 \qmlproperty string routeManeuver::instructionText
204
205 This read-only property holds textual navigation instruction.
206*/
207
208/*!
209 \property QGeoManeuver::instructionText
210 \brief the textual navigation instructions.
211*/
212void QGeoManeuver::setInstructionText(const QString &instructionText)
213{
214 d_ptr->setValid(true);
215 d_ptr->setText(instructionText);
216}
217
218QString QGeoManeuver::instructionText() const
219{
220 return d_ptr->text();
221}
222
223/*!
224 \qmlproperty enumeration routeManeuver::direction
225
226 Describes the change in direction associated with the instruction text
227 that is associated with a routeManeuver.
228
229 \list
230 \li RouteManeuver.NoDirection - There is no direction associated with the instruction text
231 \li RouteManeuver.DirectionForward - The instruction indicates that the direction of travel does not need to change
232 \li RouteManeuver.DirectionBearRight - The instruction indicates that the direction of travel should bear to the right
233 \li RouteManeuver.DirectionLightRight - The instruction indicates that a light turn to the right is required
234 \li RouteManeuver.DirectionRight - The instruction indicates that a turn to the right is required
235 \li RouteManeuver.DirectionHardRight - The instruction indicates that a hard turn to the right is required
236 \li RouteManeuver.DirectionUTurnRight - The instruction indicates that a u-turn to the right is required
237 \li RouteManeuver.DirectionUTurnLeft - The instruction indicates that a u-turn to the left is required
238 \li RouteManeuver.DirectionHardLeft - The instruction indicates that a hard turn to the left is required
239 \li RouteManeuver.DirectionLeft - The instruction indicates that a turn to the left is required
240 \li RouteManeuver.DirectionLightLeft - The instruction indicates that a light turn to the left is required
241 \li RouteManeuver.DirectionBearLeft - The instruction indicates that the direction of travel should bear to the left
242 \endlist
243*/
244
245/*!
246 \property QGeoManeuver::direction
247 \brief the direction associated with the associated instruction.
248*/
249void QGeoManeuver::setDirection(QGeoManeuver::InstructionDirection direction)
250{
251 d_ptr->setValid(true);
252 d_ptr->setDirection(direction);
253}
254
255QGeoManeuver::InstructionDirection QGeoManeuver::direction() const
256{
257 return d_ptr->direction();
258}
259
260/*!
261 \qmlproperty int routeManeuver::timeToNextInstruction
262
263 This read-only property holds the estimated time, in seconds, that it will take
264 to travel from the point at which the associated instruction was issued
265 to the point at which the next instruction should be issued, in seconds.
266*/
267
268/*!
269 \property QGeoManeuver::timeToNextInstruction
270 \brief the estimated time, in seconds, that it will take to travel from the
271 point at which the associated instruction was issued to the point at which the
272 next instruction should be issued.
273*/
274void QGeoManeuver::setTimeToNextInstruction(int secs)
275{
276 d_ptr->setValid(true);
277 d_ptr->setTimeToNextInstruction(secs);
278}
279
280int QGeoManeuver::timeToNextInstruction() const
281{
282 return d_ptr->timeToNextInstruction();
283}
284
285/*!
286 \qmlproperty real routeManeuver::distanceToNextInstruction
287
288 This read-only property holds the distance, in meters, between the point at which
289 the associated instruction was issued and the point that the next instruction should
290 be issued.
291*/
292
293/*!
294 \property QGeoManeuver::distanceToNextInstruction
295 \brief the distance, in meters, between the point at which this instruction was
296 issued, and the point at which the next instruction should be issued.
297*/
298void QGeoManeuver::setDistanceToNextInstruction(qreal distance)
299{
300 d_ptr->setValid(true);
301 d_ptr->setDistanceToNextInstruction(distance);
302}
303
304qreal QGeoManeuver::distanceToNextInstruction() const
305{
306 return d_ptr->distanceToNextInstruction();
307}
308
309/*!
310 \qmlproperty coordinate routeManeuver::waypoint
311
312 This property holds the waypoint associated with this maneuver.
313 Not all maneuvers have a waypoint associated with them.
314*/
315
316/*!
317 \property QGeoManeuver::waypoint
318 \brief the waypoint associated with this maneuver.
319
320 If there is not waypoint associated with this maneuver, then this
321 property holds an invalid QGeoCoordinate.
322*/
323void QGeoManeuver::setWaypoint(const QGeoCoordinate &coordinate)
324{
325 d_ptr->setValid(true);
326 d_ptr->setWaypoint(coordinate);
327}
328
329QGeoCoordinate QGeoManeuver::waypoint() const
330{
331 return d_ptr->waypoint();
332}
333
334/*!
335 \qmlproperty Object routeManeuver::extendedAttributes
336
337 This property holds the extended attributes of the maneuver and is a map.
338 These attributes are plugin specific, and can be empty.
339
340 Consult the \l {Qt Location#Plugin References and Parameters}{plugin documentation}
341 for what attributes are supported and how they should be used.
342
343 Note, due to limitations of the QQmlPropertyMap, it is not possible
344 to declaratively specify the attributes in QML, assignment of attributes keys
345 and values can only be accomplished by JavaScript.
346
347 \since QtLocation 5.11
348*/
349
350/*!
351 \property QGeoManeuver::extendedAttributes
352 \brief the extended attributes associated with this maneuver.
353 \since QtLocation 5.11
354*/
355void QGeoManeuver::setExtendedAttributes(const QVariantMap &extendedAttributes)
356{
357 d_ptr->setValid(true);
358 d_ptr->setExtendedAttributes(extendedAttributes);
359}
360
361QVariantMap QGeoManeuver::extendedAttributes() const
362{
363 return d_ptr->extendedAttributes();
364}
365
366/*******************************************************************************
367*******************************************************************************/
368
369bool QGeoManeuverPrivate::equals(const QGeoManeuverPrivate &other) const
370{
371 return ((valid() == other.valid())
372 && (position() == other.position())
373 && (text() == other.text())
374 && (direction() == other.direction())
375 && (timeToNextInstruction() == other.timeToNextInstruction())
376 && (distanceToNextInstruction() == other.distanceToNextInstruction())
377 && (waypoint() == other.waypoint()));
378}
379
380/*******************************************************************************
381*******************************************************************************/
382
383bool QGeoManeuverPrivate::valid() const
384{
385 return m_valid;
386}
387
388void QGeoManeuverPrivate::setValid(bool valid)
389{
390 m_valid = valid;
391}
392
393QString QGeoManeuverPrivate::id() const
394{
395 return m_id;
396}
397
398void QGeoManeuverPrivate::setId(const QString &id)
399{
400 m_id = id;
401}
402
403QGeoCoordinate QGeoManeuverPrivate::position() const
404{
405 return m_position;
406}
407
408void QGeoManeuverPrivate::setPosition(const QGeoCoordinate &position)
409{
410 m_position = position;
411}
412
413QString QGeoManeuverPrivate::text() const
414{
415 return m_text;
416}
417
418void QGeoManeuverPrivate::setText(const QString &text)
419{
420 m_text = text;
421}
422
423QGeoManeuver::InstructionDirection QGeoManeuverPrivate::direction() const
424{
425 return m_direction;
426}
427
428void QGeoManeuverPrivate::setDirection(QGeoManeuver::InstructionDirection direction)
429{
430 m_direction = direction;
431}
432
433int QGeoManeuverPrivate::timeToNextInstruction() const
434{
435 return m_timeToNextInstruction;
436}
437
438void QGeoManeuverPrivate::setTimeToNextInstruction(int timeToNextInstruction)
439{
440 m_timeToNextInstruction = timeToNextInstruction;
441}
442
443qreal QGeoManeuverPrivate::distanceToNextInstruction() const
444{
445 return m_distanceToNextInstruction;
446}
447
448void QGeoManeuverPrivate::setDistanceToNextInstruction(qreal distanceToNextInstruction)
449{
450 m_distanceToNextInstruction = distanceToNextInstruction;
451}
452
453QGeoCoordinate QGeoManeuverPrivate::waypoint() const
454{
455 return m_waypoint;
456}
457
458void QGeoManeuverPrivate::setWaypoint(const QGeoCoordinate &waypoint)
459{
460 m_waypoint = waypoint;
461}
462
463QVariantMap QGeoManeuverPrivate::extendedAttributes() const
464{
465 return m_extendedAttributes;
466}
467
468void QGeoManeuverPrivate::setExtendedAttributes(const QVariantMap &extendedAttributes)
469{
470 m_extendedAttributes = extendedAttributes;
471}
472
473QT_END_NAMESPACE
474
475#include "moc_qgeomaneuver.cpp"