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 "qgeomaneuver.h"
38#include "qgeomaneuver_p.h"
39
40#include "qgeocoordinate.h"
41
42QT_BEGIN_NAMESPACE
43
44template<>
45QGeoManeuverPrivate *QSharedDataPointer<QGeoManeuverPrivate>::clone()
46{
47 return d->clone();
48}
49
50/*!
51 \class QGeoManeuver
52 \inmodule QtLocation
53 \ingroup QtLocation-routing
54 \since 5.6
55
56 \brief The QGeoManeuver class represents the information relevant to the
57 point at which two QGeoRouteSegments meet.
58
59 QGeoRouteSegment instances can be thought of as edges on a routing
60 graph, with QGeoManeuver instances as optional labels attached to the
61 vertices of the graph.
62
63 The most interesting information help in a QGeoManeuver instance is
64 normally the textual navigation to provide and the position at which to
65 provide it, accessible by instructionText() and position() respectively.
66
67 It is also possible to determine if a routing waypoint has been passed by
68 checking if waypoint() returns a valid QGeoCoordinate.
69*/
70
71/*!
72\enum QGeoManeuver::InstructionDirection
73
74Describes the change in direction associated with the instruction text
75that is associated with a QGeoManaeuver.
76
77\value NoDirection
78There is no direction associated with the instruction text.
79
80\value DirectionForward
81The instruction indicates that the direction of travel does not need to change.
82
83\value DirectionBearRight
84The instruction indicates that the direction of travel should bear to the right.
85
86\value DirectionLightRight
87The instruction indicates that a light turn to the right is required.
88
89\value DirectionRight
90The instruction indicates that a turn to the right is required.
91
92\value DirectionHardRight
93The instruction indicates that a hard turn to the right is required.
94
95\value DirectionUTurnRight
96The instruction indicates that a u-turn to the right is required.
97
98\value DirectionUTurnLeft
99The instruction indicates that a u-turn to the left is required.
100
101\value DirectionHardLeft
102The instruction indicates that a hard turn to the left is required.
103
104\value DirectionLeft
105The instruction indicates that a turn to the left is required.
106
107\value DirectionLightLeft
108The instruction indicates that a light turn to the left is required.
109
110\value DirectionBearLeft
111The instruction indicates that the direction of travel should bear to the left.
112
113*/
114
115/*!
116 Constructs a invalid maneuver object.
117
118 The maneuver will remain invalid until one of
119 setPosition(), setInstructionText(), setDirection(),
120 setTimeToNextInstruction(), setDistanceToNextInstruction() or
121 setWaypoint() is called.
122*/
123QGeoManeuver::QGeoManeuver()
124 : d_ptr(new QGeoManeuverPrivateDefault()) {}
125
126/*!
127 Constructs a maneuver object from the contents of \a other.
128*/
129QGeoManeuver::QGeoManeuver(const QGeoManeuver &other)
130 : d_ptr(other.d_ptr) {}
131
132/*!
133 Destroys this maneuver object.
134*/
135QGeoManeuver::~QGeoManeuver() {}
136
137/*!
138 Assigns \a other to this maneuver object and then returns
139 a reference to this maneuver object.
140*/
141QGeoManeuver &QGeoManeuver::operator= (const QGeoManeuver & other)
142{
143 if (this == &other)
144 return *this;
145
146 d_ptr = other.d_ptr;
147 return *this;
148}
149
150/*!
151 Returns whether this maneuver is equal to \a other.
152*/
153bool QGeoManeuver::operator== (const QGeoManeuver &other) const
154{
155 return ( (d_ptr.constData() == other.d_ptr.constData())
156 || (*(d_ptr.constData()) == *(other.d_ptr.constData())) );
157}
158
159/*!
160 Returns whether this maneuver is not equal to \a other.
161*/
162bool QGeoManeuver::operator!= (const QGeoManeuver &other) const
163{
164 return !(operator==(other));
165}
166
167/*!
168 Returns whether this maneuver is valid or not.
169
170 Invalid maneuvers are used when there is no information
171 that needs to be attached to the endpoint of a QGeoRouteSegment instance.
172*/
173bool QGeoManeuver::isValid() const
174{
175 return d_ptr->valid();
176}
177
178/*!
179 Sets the position where instructionText() should be displayed to \a
180 position.
181*/
182void QGeoManeuver::setPosition(const QGeoCoordinate &position)
183{
184 d_ptr->setValid(true);
185 d_ptr->setPosition(position);
186}
187
188/*!
189 Returns the position where instructionText() should be displayed.
190*/
191QGeoCoordinate QGeoManeuver::position() const
192{
193 return d_ptr->position();
194}
195
196/*!
197 Sets the textual navigation instructions to \a instructionText.
198*/
199void QGeoManeuver::setInstructionText(const QString &instructionText)
200{
201 d_ptr->setValid(true);
202 d_ptr->setText(instructionText);
203}
204
205/*!
206 Returns the textual navigation instructions.
207*/
208QString QGeoManeuver::instructionText() const
209{
210 return d_ptr->text();
211}
212
213/*!
214 Sets the direction associated with the associated instruction to \a
215 direction.
216*/
217void QGeoManeuver::setDirection(QGeoManeuver::InstructionDirection direction)
218{
219 d_ptr->setValid(true);
220 d_ptr->setDirection(direction);
221}
222
223/*!
224 Returns the direction associated with the associated instruction.
225*/
226QGeoManeuver::InstructionDirection QGeoManeuver::direction() const
227{
228 return d_ptr->direction();
229}
230
231/*!
232 Sets the estimated time it will take to travel from the point at which the
233 associated instruction was issued and the point that the next instruction
234 should be issued, in seconds, to \a secs.
235*/
236void QGeoManeuver::setTimeToNextInstruction(int secs)
237{
238 d_ptr->setValid(true);
239 d_ptr->setTimeToNextInstruction(secs);
240}
241
242/*!
243 Returns the estimated time it will take to travel from the point at which
244 the associated instruction was issued and the point that the next
245 instruction should be issued, in seconds.
246*/
247int QGeoManeuver::timeToNextInstruction() const
248{
249 return d_ptr->timeToNextInstruction();
250}
251
252/*!
253 Sets the distance, in meters, between the point at which the associated
254 instruction was issued and the point that the next instruction should be
255 issued to \a distance.
256*/
257void QGeoManeuver::setDistanceToNextInstruction(qreal distance)
258{
259 d_ptr->setValid(true);
260 d_ptr->setDistanceToNextInstruction(distance);
261}
262
263/*!
264 Returns the distance, in meters, between the point at which the associated
265 instruction was issued and the point that the next instruction should be
266 issued.
267*/
268qreal QGeoManeuver::distanceToNextInstruction() const
269{
270 return d_ptr->distanceToNextInstruction();
271}
272
273/*!
274 Sets the waypoint associated with this maneuver to \a coordinate.
275*/
276void QGeoManeuver::setWaypoint(const QGeoCoordinate &coordinate)
277{
278 d_ptr->setValid(true);
279 d_ptr->setWaypoint(coordinate);
280}
281
282/*!
283 Returns the waypoint associated with this maneuver.
284
285 If there is not waypoint associated with this maneuver an invalid
286 QGeoCoordinate will be returned.
287*/
288QGeoCoordinate QGeoManeuver::waypoint() const
289{
290 return d_ptr->waypoint();
291}
292
293QGeoManeuver::QGeoManeuver(const QSharedDataPointer<QGeoManeuverPrivate> &dd)
294 : d_ptr(dd) {}
295
296/*!
297 Sets the extended attributes \a extendedAttributes associated with this maneuver.
298
299 \since QtLocation 5.11
300*/
301void QGeoManeuver::setExtendedAttributes(const QVariantMap &extendedAttributes)
302{
303 d_ptr->setValid(true);
304 d_ptr->setExtendedAttributes(extendedAttributes);
305}
306
307/*!
308 Returns the extended attributes associated with this maneuver.
309
310 \since QtLocation 5.11
311*/
312QVariantMap QGeoManeuver::extendedAttributes() const
313{
314 return d_ptr->extendedAttributes();
315}
316
317/*******************************************************************************
318*******************************************************************************/
319
320QGeoManeuverPrivate::QGeoManeuverPrivate()
321{
322
323}
324
325QGeoManeuverPrivate::QGeoManeuverPrivate(const QGeoManeuverPrivate &other)
326 : QSharedData(other)
327{
328
329}
330
331QGeoManeuverPrivate::~QGeoManeuverPrivate()
332{
333
334}
335
336bool QGeoManeuverPrivate::operator==(const QGeoManeuverPrivate &other) const
337{
338 return equals(other);
339}
340
341bool QGeoManeuverPrivate::equals(const QGeoManeuverPrivate &other) const
342{
343 return ((valid() == other.valid())
344 && (position() == other.position())
345 && (text() == other.text())
346 && (direction() == other.direction())
347 && (timeToNextInstruction() == other.timeToNextInstruction())
348 && (distanceToNextInstruction() == other.distanceToNextInstruction())
349 && (waypoint() == other.waypoint()));
350}
351
352bool QGeoManeuverPrivate::valid() const
353{
354 return false;
355}
356
357void QGeoManeuverPrivate::setValid(bool valid)
358{
359 Q_UNUSED(valid);
360}
361
362QString QGeoManeuverPrivate::id() const
363{
364 return QString();
365}
366
367void QGeoManeuverPrivate::setId(const QString id)
368{
369 Q_UNUSED(id);
370}
371
372QGeoCoordinate QGeoManeuverPrivate::position() const
373{
374 return QGeoCoordinate();
375}
376
377void QGeoManeuverPrivate::setPosition(const QGeoCoordinate &position)
378{
379 Q_UNUSED(position);
380}
381
382QString QGeoManeuverPrivate::text() const
383{
384 return QString();
385}
386
387void QGeoManeuverPrivate::setText(const QString &text)
388{
389 Q_UNUSED(text);
390}
391
392QGeoManeuver::InstructionDirection QGeoManeuverPrivate::direction() const
393{
394 return QGeoManeuver::NoDirection;
395}
396
397void QGeoManeuverPrivate::setDirection(QGeoManeuver::InstructionDirection direction)
398{
399 Q_UNUSED(direction);
400}
401
402int QGeoManeuverPrivate::timeToNextInstruction() const
403{
404 return 0;
405}
406
407void QGeoManeuverPrivate::setTimeToNextInstruction(int timeToNextInstruction)
408{
409 Q_UNUSED(timeToNextInstruction);
410}
411
412qreal QGeoManeuverPrivate::distanceToNextInstruction() const
413{
414 return 0;
415}
416
417void QGeoManeuverPrivate::setDistanceToNextInstruction(qreal distanceToNextInstruction)
418{
419 Q_UNUSED(distanceToNextInstruction);
420}
421
422QGeoCoordinate QGeoManeuverPrivate::waypoint() const
423{
424 return QGeoCoordinate();
425}
426
427void QGeoManeuverPrivate::setWaypoint(const QGeoCoordinate &waypoint)
428{
429 Q_UNUSED(waypoint);
430}
431
432QVariantMap QGeoManeuverPrivate::extendedAttributes() const
433{
434 return QVariantMap();
435}
436
437void QGeoManeuverPrivate::setExtendedAttributes(const QVariantMap &extendedAttributes)
438{
439 Q_UNUSED(extendedAttributes);
440}
441
442
443
444/*******************************************************************************
445*******************************************************************************/
446
447QGeoManeuverPrivateDefault::QGeoManeuverPrivateDefault()
448 : m_valid(false),
449 m_direction(QGeoManeuver::NoDirection),
450 m_timeToNextInstruction(0),
451 m_distanceToNextInstruction(0.0) {}
452
453QGeoManeuverPrivateDefault::QGeoManeuverPrivateDefault(const QGeoManeuverPrivateDefault &other)
454 : QGeoManeuverPrivate(other),
455 m_valid(other.m_valid),
456 m_position(other.m_position),
457 m_text(other.m_text),
458 m_direction(other.m_direction),
459 m_timeToNextInstruction(other.m_timeToNextInstruction),
460 m_distanceToNextInstruction(other.m_distanceToNextInstruction),
461 m_waypoint(other.m_waypoint) {}
462
463QGeoManeuverPrivateDefault::~QGeoManeuverPrivateDefault() {}
464
465QGeoManeuverPrivate *QGeoManeuverPrivateDefault::clone()
466{
467 return new QGeoManeuverPrivateDefault(*this);
468}
469
470bool QGeoManeuverPrivateDefault::valid() const
471{
472 return m_valid;
473}
474
475void QGeoManeuverPrivateDefault::setValid(bool valid)
476{
477 m_valid = valid;
478}
479
480QString QGeoManeuverPrivateDefault::id() const
481{
482 return m_id;
483}
484
485void QGeoManeuverPrivateDefault::setId(const QString id)
486{
487 m_id = id;
488}
489
490QGeoCoordinate QGeoManeuverPrivateDefault::position() const
491{
492 return m_position;
493}
494
495void QGeoManeuverPrivateDefault::setPosition(const QGeoCoordinate &position)
496{
497 m_position = position;
498}
499
500QString QGeoManeuverPrivateDefault::text() const
501{
502 return m_text;
503}
504
505void QGeoManeuverPrivateDefault::setText(const QString &text)
506{
507 m_text = text;
508}
509
510QGeoManeuver::InstructionDirection QGeoManeuverPrivateDefault::direction() const
511{
512 return m_direction;
513}
514
515void QGeoManeuverPrivateDefault::setDirection(QGeoManeuver::InstructionDirection direction)
516{
517 m_direction = direction;
518}
519
520int QGeoManeuverPrivateDefault::timeToNextInstruction() const
521{
522 return m_timeToNextInstruction;
523}
524
525void QGeoManeuverPrivateDefault::setTimeToNextInstruction(int timeToNextInstruction)
526{
527 m_timeToNextInstruction = timeToNextInstruction;
528}
529
530qreal QGeoManeuverPrivateDefault::distanceToNextInstruction() const
531{
532 return m_distanceToNextInstruction;
533}
534
535void QGeoManeuverPrivateDefault::setDistanceToNextInstruction(qreal distanceToNextInstruction)
536{
537 m_distanceToNextInstruction = distanceToNextInstruction;
538}
539
540QGeoCoordinate QGeoManeuverPrivateDefault::waypoint() const
541{
542 return m_waypoint;
543}
544
545void QGeoManeuverPrivateDefault::setWaypoint(const QGeoCoordinate &waypoint)
546{
547 m_waypoint = waypoint;
548}
549
550QVariantMap QGeoManeuverPrivateDefault::extendedAttributes() const
551{
552 return m_extendedAttributes;
553}
554
555void QGeoManeuverPrivateDefault::setExtendedAttributes(const QVariantMap &extendedAttributes)
556{
557 m_extendedAttributes = extendedAttributes;
558}
559
560QT_END_NAMESPACE
561

source code of qtlocation/src/location/maps/qgeomaneuver.cpp