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
42 QT_BEGIN_NAMESPACE
43
44 template<>
clone()45 QGeoManeuverPrivate *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
74 Describes the change in direction associated with the instruction text
75 that is associated with a QGeoManaeuver.
76
77 \value NoDirection
78 There is no direction associated with the instruction text.
79
80 \value DirectionForward
81 The instruction indicates that the direction of travel does not need to change.
82
83 \value DirectionBearRight
84 The instruction indicates that the direction of travel should bear to the right.
85
86 \value DirectionLightRight
87 The instruction indicates that a light turn to the right is required.
88
89 \value DirectionRight
90 The instruction indicates that a turn to the right is required.
91
92 \value DirectionHardRight
93 The instruction indicates that a hard turn to the right is required.
94
95 \value DirectionUTurnRight
96 The instruction indicates that a u-turn to the right is required.
97
98 \value DirectionUTurnLeft
99 The instruction indicates that a u-turn to the left is required.
100
101 \value DirectionHardLeft
102 The instruction indicates that a hard turn to the left is required.
103
104 \value DirectionLeft
105 The instruction indicates that a turn to the left is required.
106
107 \value DirectionLightLeft
108 The instruction indicates that a light turn to the left is required.
109
110 \value DirectionBearLeft
111 The 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 */
QGeoManeuver()123 QGeoManeuver::QGeoManeuver()
124 : d_ptr(new QGeoManeuverPrivateDefault()) {}
125
126 /*!
127 Constructs a maneuver object from the contents of \a other.
128 */
QGeoManeuver(const QGeoManeuver & other)129 QGeoManeuver::QGeoManeuver(const QGeoManeuver &other)
130 : d_ptr(other.d_ptr) {}
131
132 /*!
133 Destroys this maneuver object.
134 */
~QGeoManeuver()135 QGeoManeuver::~QGeoManeuver() {}
136
137 /*!
138 Assigns \a other to this maneuver object and then returns
139 a reference to this maneuver object.
140 */
operator =(const QGeoManeuver & other)141 QGeoManeuver &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 */
operator ==(const QGeoManeuver & other) const153 bool 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 */
operator !=(const QGeoManeuver & other) const162 bool 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 */
isValid() const173 bool 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 */
setPosition(const QGeoCoordinate & position)182 void 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 */
position() const191 QGeoCoordinate QGeoManeuver::position() const
192 {
193 return d_ptr->position();
194 }
195
196 /*!
197 Sets the textual navigation instructions to \a instructionText.
198 */
setInstructionText(const QString & instructionText)199 void 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 */
instructionText() const208 QString 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 */
setDirection(QGeoManeuver::InstructionDirection direction)217 void 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 */
direction() const226 QGeoManeuver::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 */
setTimeToNextInstruction(int secs)236 void 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 */
timeToNextInstruction() const247 int 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 */
setDistanceToNextInstruction(qreal distance)257 void 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 */
distanceToNextInstruction() const268 qreal QGeoManeuver::distanceToNextInstruction() const
269 {
270 return d_ptr->distanceToNextInstruction();
271 }
272
273 /*!
274 Sets the waypoint associated with this maneuver to \a coordinate.
275 */
setWaypoint(const QGeoCoordinate & coordinate)276 void 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 */
waypoint() const288 QGeoCoordinate QGeoManeuver::waypoint() const
289 {
290 return d_ptr->waypoint();
291 }
292
QGeoManeuver(const QSharedDataPointer<QGeoManeuverPrivate> & dd)293 QGeoManeuver::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 */
setExtendedAttributes(const QVariantMap & extendedAttributes)301 void 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 */
extendedAttributes() const312 QVariantMap QGeoManeuver::extendedAttributes() const
313 {
314 return d_ptr->extendedAttributes();
315 }
316
317 /*******************************************************************************
318 *******************************************************************************/
319
QGeoManeuverPrivate()320 QGeoManeuverPrivate::QGeoManeuverPrivate()
321 {
322
323 }
324
QGeoManeuverPrivate(const QGeoManeuverPrivate & other)325 QGeoManeuverPrivate::QGeoManeuverPrivate(const QGeoManeuverPrivate &other)
326 : QSharedData(other)
327 {
328
329 }
330
~QGeoManeuverPrivate()331 QGeoManeuverPrivate::~QGeoManeuverPrivate()
332 {
333
334 }
335
operator ==(const QGeoManeuverPrivate & other) const336 bool QGeoManeuverPrivate::operator==(const QGeoManeuverPrivate &other) const
337 {
338 return equals(other);
339 }
340
equals(const QGeoManeuverPrivate & other) const341 bool 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
valid() const352 bool QGeoManeuverPrivate::valid() const
353 {
354 return false;
355 }
356
setValid(bool valid)357 void QGeoManeuverPrivate::setValid(bool valid)
358 {
359 Q_UNUSED(valid);
360 }
361
id() const362 QString QGeoManeuverPrivate::id() const
363 {
364 return QString();
365 }
366
setId(const QString id)367 void QGeoManeuverPrivate::setId(const QString id)
368 {
369 Q_UNUSED(id);
370 }
371
position() const372 QGeoCoordinate QGeoManeuverPrivate::position() const
373 {
374 return QGeoCoordinate();
375 }
376
setPosition(const QGeoCoordinate & position)377 void QGeoManeuverPrivate::setPosition(const QGeoCoordinate &position)
378 {
379 Q_UNUSED(position);
380 }
381
text() const382 QString QGeoManeuverPrivate::text() const
383 {
384 return QString();
385 }
386
setText(const QString & text)387 void QGeoManeuverPrivate::setText(const QString &text)
388 {
389 Q_UNUSED(text);
390 }
391
direction() const392 QGeoManeuver::InstructionDirection QGeoManeuverPrivate::direction() const
393 {
394 return QGeoManeuver::NoDirection;
395 }
396
setDirection(QGeoManeuver::InstructionDirection direction)397 void QGeoManeuverPrivate::setDirection(QGeoManeuver::InstructionDirection direction)
398 {
399 Q_UNUSED(direction);
400 }
401
timeToNextInstruction() const402 int QGeoManeuverPrivate::timeToNextInstruction() const
403 {
404 return 0;
405 }
406
setTimeToNextInstruction(int timeToNextInstruction)407 void QGeoManeuverPrivate::setTimeToNextInstruction(int timeToNextInstruction)
408 {
409 Q_UNUSED(timeToNextInstruction);
410 }
411
distanceToNextInstruction() const412 qreal QGeoManeuverPrivate::distanceToNextInstruction() const
413 {
414 return 0;
415 }
416
setDistanceToNextInstruction(qreal distanceToNextInstruction)417 void QGeoManeuverPrivate::setDistanceToNextInstruction(qreal distanceToNextInstruction)
418 {
419 Q_UNUSED(distanceToNextInstruction);
420 }
421
waypoint() const422 QGeoCoordinate QGeoManeuverPrivate::waypoint() const
423 {
424 return QGeoCoordinate();
425 }
426
setWaypoint(const QGeoCoordinate & waypoint)427 void QGeoManeuverPrivate::setWaypoint(const QGeoCoordinate &waypoint)
428 {
429 Q_UNUSED(waypoint);
430 }
431
extendedAttributes() const432 QVariantMap QGeoManeuverPrivate::extendedAttributes() const
433 {
434 return QVariantMap();
435 }
436
setExtendedAttributes(const QVariantMap & extendedAttributes)437 void QGeoManeuverPrivate::setExtendedAttributes(const QVariantMap &extendedAttributes)
438 {
439 Q_UNUSED(extendedAttributes);
440 }
441
442
443
444 /*******************************************************************************
445 *******************************************************************************/
446
QGeoManeuverPrivateDefault()447 QGeoManeuverPrivateDefault::QGeoManeuverPrivateDefault()
448 : m_valid(false),
449 m_direction(QGeoManeuver::NoDirection),
450 m_timeToNextInstruction(0),
451 m_distanceToNextInstruction(0.0) {}
452
QGeoManeuverPrivateDefault(const QGeoManeuverPrivateDefault & other)453 QGeoManeuverPrivateDefault::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
~QGeoManeuverPrivateDefault()463 QGeoManeuverPrivateDefault::~QGeoManeuverPrivateDefault() {}
464
clone()465 QGeoManeuverPrivate *QGeoManeuverPrivateDefault::clone()
466 {
467 return new QGeoManeuverPrivateDefault(*this);
468 }
469
valid() const470 bool QGeoManeuverPrivateDefault::valid() const
471 {
472 return m_valid;
473 }
474
setValid(bool valid)475 void QGeoManeuverPrivateDefault::setValid(bool valid)
476 {
477 m_valid = valid;
478 }
479
id() const480 QString QGeoManeuverPrivateDefault::id() const
481 {
482 return m_id;
483 }
484
setId(const QString id)485 void QGeoManeuverPrivateDefault::setId(const QString id)
486 {
487 m_id = id;
488 }
489
position() const490 QGeoCoordinate QGeoManeuverPrivateDefault::position() const
491 {
492 return m_position;
493 }
494
setPosition(const QGeoCoordinate & position)495 void QGeoManeuverPrivateDefault::setPosition(const QGeoCoordinate &position)
496 {
497 m_position = position;
498 }
499
text() const500 QString QGeoManeuverPrivateDefault::text() const
501 {
502 return m_text;
503 }
504
setText(const QString & text)505 void QGeoManeuverPrivateDefault::setText(const QString &text)
506 {
507 m_text = text;
508 }
509
direction() const510 QGeoManeuver::InstructionDirection QGeoManeuverPrivateDefault::direction() const
511 {
512 return m_direction;
513 }
514
setDirection(QGeoManeuver::InstructionDirection direction)515 void QGeoManeuverPrivateDefault::setDirection(QGeoManeuver::InstructionDirection direction)
516 {
517 m_direction = direction;
518 }
519
timeToNextInstruction() const520 int QGeoManeuverPrivateDefault::timeToNextInstruction() const
521 {
522 return m_timeToNextInstruction;
523 }
524
setTimeToNextInstruction(int timeToNextInstruction)525 void QGeoManeuverPrivateDefault::setTimeToNextInstruction(int timeToNextInstruction)
526 {
527 m_timeToNextInstruction = timeToNextInstruction;
528 }
529
distanceToNextInstruction() const530 qreal QGeoManeuverPrivateDefault::distanceToNextInstruction() const
531 {
532 return m_distanceToNextInstruction;
533 }
534
setDistanceToNextInstruction(qreal distanceToNextInstruction)535 void QGeoManeuverPrivateDefault::setDistanceToNextInstruction(qreal distanceToNextInstruction)
536 {
537 m_distanceToNextInstruction = distanceToNextInstruction;
538 }
539
waypoint() const540 QGeoCoordinate QGeoManeuverPrivateDefault::waypoint() const
541 {
542 return m_waypoint;
543 }
544
setWaypoint(const QGeoCoordinate & waypoint)545 void QGeoManeuverPrivateDefault::setWaypoint(const QGeoCoordinate &waypoint)
546 {
547 m_waypoint = waypoint;
548 }
549
extendedAttributes() const550 QVariantMap QGeoManeuverPrivateDefault::extendedAttributes() const
551 {
552 return m_extendedAttributes;
553 }
554
setExtendedAttributes(const QVariantMap & extendedAttributes)555 void QGeoManeuverPrivateDefault::setExtendedAttributes(const QVariantMap &extendedAttributes)
556 {
557 m_extendedAttributes = extendedAttributes;
558 }
559
560 QT_END_NAMESPACE
561