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
qgeoroutesegment.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 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// Qt-Security score:significant reason:default
4
7
9#include <QDateTime>
10
11QT_BEGIN_NAMESPACE
12
13QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QGeoRouteSegmentPrivate)
14
15/*!
16 \class QGeoRouteSegment
17 \inmodule QtLocation
18 \ingroup QtLocation-routing
19 \since 5.6
20
21 \brief The QGeoRouteSegment class represents a segment of a route.
22
23 A QGeoRouteSegment instance has information about the physical layout
24 of the route segment, the length of the route and estimated time required
25 to traverse the route segment and an optional QGeoManeuver associated with
26 the beginning of the route segment.
27
28 QGeoRouteSegment instances can be thought of as edges on a routing
29 graph, with QGeoManeuver instances as optional labels attached to the
30 vertices of the graph.
31*/
32
33/*!
34 \qmltype routeSegment
35 \inqmlmodule QtLocation
36 \ingroup qml-QtLocation5-routing
37 \since QtLocation 5.5
38
39 \brief The routeSegment type represents a segment of a Route.
40
41 A routeSegment instance has information about the physical layout
42 of the route segment, the length of the route and estimated time required
43 to traverse the route segment and optional \l {routeManeuver}s associated with
44 the end of the route segment.
45
46 Instances of routeSegment can be thought of as edges on a routing
47 graph, with routeManeuver instances as optional labels attached to the
48 vertices of the graph.
49
50 The primary means of acquiring Route objects is via Routes via \l RouteModel.
51
52 \section1 Example
53
54 The following QML snippet demonstrates how to print information about a
55 route segment:
56
57 \snippet declarative/routing.qml QtQuick import
58 \snippet declarative/maps.qml QtLocation import
59 \codeline
60 \snippet declarative/routing.qml routeSegment
61*/
62
63/*!
64 Constructs an invalid route segment object.
65
66 The route segment will remain invalid until one of setNextRouteSegment(),
67 setTravelTime(), setDistance(), setPath() or setManeuver() is called.
68*/
69QGeoRouteSegment::QGeoRouteSegment()
70 : d_ptr(new QGeoRouteSegmentPrivate()) {}
71
72/*!
73 Constructs a route segment object from the contents of \a other.
74*/
75QGeoRouteSegment::QGeoRouteSegment(const QGeoRouteSegment &other) noexcept = default;
76
77/*!
78 \internal
79*/
80QGeoRouteSegment::QGeoRouteSegment(QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> &&dd)
81 : d_ptr(dd) {}
82
83/*!
84 Destroys this route segment object.
85*/
86QGeoRouteSegment::~QGeoRouteSegment() = default;
87
88
89/*!
90 Assigns \a other to this route segment object and then returns a
91 reference to this route segment object.
92*/
93QGeoRouteSegment &QGeoRouteSegment::operator=(const QGeoRouteSegment & other) noexcept
94{
95 if (this == &other)
96 return *this;
97
98 d_ptr = other.d_ptr;
99 return *this;
100}
101
102/*!
103 \fn bool QGeoRouteSegment::operator==(const QGeoRouteSegment &lhs, const QGeoRouteSegment &rhs) noexcept
104 Returns whether the route segments \a lhs and \a rhs are equal.
105
106 The value of nextRouteSegment() is not considered in the comparison.
107*/
108
109/*!
110 \fn bool QGeoRouteSegment::operator!=(const QGeoRouteSegment &lhs, const QGeoRouteSegment &rhs) noexcept
111
112 Returns whether the route segments \a lhs and \a rhs are not equal.
113
114 The value of nextRouteSegment() is not considered in the comparison.
115*/
116
117bool QGeoRouteSegment::isEqual(const QGeoRouteSegment &other) const noexcept
118{
119 return ( (d_ptr.constData() == other.d_ptr.constData())
120 || (*d_ptr) == (*other.d_ptr));
121}
122
123/*!
124 Returns whether this route segment is valid or not.
125
126 If nextRouteSegment() is called on the last route segment of a route, the
127 returned value will be an invalid route segment.
128*/
129bool QGeoRouteSegment::isValid() const
130{
131 return d_ptr->valid();
132}
133
134/*!
135 Returns whether this route segment is the last segment of a route leg.
136
137 \since 5.12
138*/
139bool QGeoRouteSegment::isLegLastSegment() const
140{
141 if (!d_ptr->valid())
142 return false;
143
144 if (!d_ptr->nextRouteSegment())
145 return true;
146 return d_ptr->isLegLastSegment();
147}
148
149/*!
150 Sets the next route segment in the route to \a routeSegment.
151*/
152void QGeoRouteSegment::setNextRouteSegment(const QGeoRouteSegment &routeSegment)
153{
154 d_ptr->setValid(true);
155 d_ptr->setNextRouteSegment(routeSegment.d_ptr);
156}
157
158/*!
159 Returns the next route segment in the route.
160
161 Will return an invalid route segment if this is the last route
162 segment in the route.
163*/
164QGeoRouteSegment QGeoRouteSegment::nextRouteSegment() const
165{
166 if (d_ptr->valid() && d_ptr->nextRouteSegment())
167 return QGeoRouteSegment(d_ptr->nextRouteSegment());
168
169 return QGeoRouteSegment();
170}
171
172/*!
173 \qmlproperty int QtLocation::routeSegment::travelTime
174
175 Read-only property which holds the estimated amount of time it will take to
176 traverse this segment, in seconds.
177
178*/
179
180/*!
181 \property QGeoRouteSegment::travelTime
182 \brief the estimated amount of time, in seconds, that it will take to
183 traverse this segment.
184*/
185void QGeoRouteSegment::setTravelTime(int secs)
186{
187 d_ptr->setValid(true);
188 d_ptr->setTravelTime(secs);
189}
190
191int QGeoRouteSegment::travelTime() const
192{
193 return d_ptr->travelTime();
194}
195
196/*!
197 \qmlproperty real QtLocation::routeSegment::distance
198
199 Read-only property which holds the distance covered by this segment of
200 the route, in meters.
201*/
202
203/*!
204 \property QGeoRouteSegment::distance
205 \brief the distance covered by this segment of the route, in meters.
206*/
207void QGeoRouteSegment::setDistance(qreal distance)
208{
209 d_ptr->setValid(true);
210 d_ptr->setDistance(distance);
211}
212
213qreal QGeoRouteSegment::distance() const
214{
215 return d_ptr->distance();
216}
217
218/*!
219 \qmlproperty list<coordinate> QtLocation::routeSegment::path
220
221 Read-only property which holds the geographical coordinates of this segment.
222 Coordinates are listed in the order in which they would be traversed by someone
223 traveling along this segment of the route.
224
225 To access individual segments you can use standard list accessors: 'path.length'
226 indicates the number of objects and 'path[index starting from zero]' gives
227 the actual object.
228
229 \sa QtPositioning::coordinate
230*/
231
232/*!
233 \property QGeoRouteSegment::path
234 \brief the geometric shape of this route segment of the route.
235
236 The coordinates should be listed in the order in which they
237 would be traversed by someone traveling along this segment of the route.
238*/
239void QGeoRouteSegment::setPath(const QList<QGeoCoordinate> &path)
240{
241 d_ptr->setValid(true);
242 d_ptr->setPath(path);
243}
244
245QList<QGeoCoordinate> QGeoRouteSegment::path() const
246{
247 return d_ptr->path();
248}
249
250/*!
251 \qmlproperty RouteManeuver QtLocation::routeSegment::maneuver
252
253 Read-only property which holds the maneuver for this route segment.
254
255 Will return invalid maneuver if no information has been attached to the endpoint
256 of this route segment.
257*/
258
259/*!
260 \property QGeoRouteSegment::maneuver
261 \brief the maneuver for this route segment.
262
263 Holds an invalid QGeoManeuver if no information has been attached
264 to the starting point of this route segment.
265*/
266void QGeoRouteSegment::setManeuver(const QGeoManeuver &maneuver)
267{
268 d_ptr->setValid(true);
269 d_ptr->setManeuver(maneuver);
270}
271
272QGeoManeuver QGeoRouteSegment::maneuver() const
273{
274 return d_ptr->maneuver();
275}
276
277/*******************************************************************************
278*******************************************************************************/
279
280QGeoRouteSegmentPrivate::QGeoRouteSegmentPrivate() = default;
281
282bool operator==(const QGeoRouteSegmentPrivate &lhs, const QGeoRouteSegmentPrivate &rhs)
283{
284 return lhs.m_valid == rhs.m_valid
285 && lhs.m_travelTime == rhs.m_travelTime
286 && lhs.m_distance == rhs.m_distance
287 && lhs.m_path == rhs.m_path
288 && lhs.m_maneuver == rhs.m_maneuver;
289}
290
291bool QGeoRouteSegmentPrivate::valid() const
292{
293 return m_valid;
294}
295
296void QGeoRouteSegmentPrivate::setValid(bool valid)
297{
298 m_valid = valid;
299}
300
301bool QGeoRouteSegmentPrivate::isLegLastSegment() const
302{
303 return m_legLastSegment;
304}
305
306void QGeoRouteSegmentPrivate::setLegLastSegment(bool lastSegment)
307{
308 m_legLastSegment = lastSegment;
309}
310
311int QGeoRouteSegmentPrivate::travelTime() const
312{
313 return m_travelTime;
314}
315
316void QGeoRouteSegmentPrivate::setTravelTime(int travelTime)
317{
318 m_travelTime = travelTime;
319}
320
321qreal QGeoRouteSegmentPrivate::distance() const
322{
323 return m_distance;
324}
325
326void QGeoRouteSegmentPrivate::setDistance(qreal distance)
327{
328 m_distance = distance;
329}
330
331QList<QGeoCoordinate> QGeoRouteSegmentPrivate::path() const
332{
333 return m_path;
334}
335
336void QGeoRouteSegmentPrivate::setPath(const QList<QGeoCoordinate> &path)
337{
338 m_path = path;
339}
340
341QGeoManeuver QGeoRouteSegmentPrivate::maneuver() const
342{
343 return m_maneuver;
344}
345
346void QGeoRouteSegmentPrivate::setManeuver(const QGeoManeuver &maneuver)
347{
348 m_maneuver = maneuver;
349}
350
351QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> QGeoRouteSegmentPrivate::nextRouteSegment() const
352{
353 return m_nextSegment;
354}
355
356void QGeoRouteSegmentPrivate::setNextRouteSegment(const QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> &next)
357{
358 m_nextSegment = next;
359}
360
361QGeoRouteSegmentPrivate *QGeoRouteSegmentPrivate::get(QGeoRouteSegment &segment)
362{
363 return segment.d_ptr.data();
364}
365
366QT_END_NAMESPACE
367
368#include "moc_qgeoroutesegment.cpp"
bool operator==(const QGeoRouteSegmentPrivate &lhs, const QGeoRouteSegmentPrivate &rhs)