KPublicTransport

path.h
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KPUBLICTRANSPORT_PATH_H
8#define KPUBLICTRANSPORT_PATH_H
9
10#include "kpublictransport_export.h"
11#include "datatypes.h"
12
13#include <QPolygonF>
14
15namespace KPublicTransport {
16
17class PathSectionPrivate;
18
19/** A section of a Path.
20 * A path section consists of a poly-line of geo-coordinates to follow,
21 * an initial maneuver instructions as well as additional properties for
22 * this part of the path, such as the floor level.
23 */
24class KPUBLICTRANSPORT_EXPORT PathSection
25{
26 KPUBLICTRANSPORT_GADGET(PathSection)
27 /** The geo coordinate poly-line followed by this path section. */
28 KPUBLICTRANSPORT_PROPERTY(QPolygonF, path, setPath)
29 /** Human-readable description of this path segment. */
30 KPUBLICTRANSPORT_PROPERTY(QString, description, setDescription)
31
32 // TODO add more properties: maneuver instructions
33
34 /** First point on the path of this section. */
35 Q_PROPERTY(QPointF startPoint READ startPoint STORED false)
36 /** Last point on the path of this section. */
37 Q_PROPERTY(QPointF endPoint READ endPoint STORED false)
38
39 /** The length of this path section in meters. */
40 Q_PROPERTY(int distance READ distance STORED false)
41 /** The overall direction of this section in degree. */
42 Q_PROPERTY(int direction READ direction STORED false)
43
44 /** Absolute floor level at the beginning of this path, if known. */
45 KPUBLICTRANSPORT_PROPERTY(int, startFloorLevel, setStartFloorLevel)
46 /** Indicates an absolute start floor level is known. */
47 Q_PROPERTY(bool hasStartFloorLevel READ hasStartFloorLevel STORED false)
48
49 /** Floor level change during this path section.
50 * Negative values indicate going down, positive values indicate going up
51 */
52 KPUBLICTRANSPORT_PROPERTY(int, floorLevelChange, setFloorLevelChange)
53
54public:
55 /** Maneuver associated with a path section. */
56 enum Maneuver {
57 Move, ///< Move/drive with the default mode of transport for this path
58 Stairs, ///< Walk up or down stairs
59 Elevator, ///< Take an elevator
60 Escalator, ///< Take an escalator
61 };
62 Q_ENUM(Maneuver)
63 /** Movement maneuver for this path section. */
64 KPUBLICTRANSPORT_PROPERTY(Maneuver, maneuver, setManeuver)
65
66 /** An icon representing the maneuver.
67 * Can be a qrc: URL or XDG icon name.
68 */
69 Q_PROPERTY(QString iconName READ iconName STORED false)
70
71public:
72 /** Length of this path section in meters. */
73 [[nodiscard]] int distance() const;
74 /** The overall direction of this section in degree.
75 * @returns 0-359 for valid results, -1 for sections with no direction (e.g. points).
76 */
77 [[nodiscard]] int direction() const;
78
79 [[nodiscard]] bool hasStartFloorLevel() const;
80
81 /** First point on the path of this section. */
82 [[nodiscard]] QPointF startPoint() const;
83 /** Last point on the path of this section. */
84 [[nodiscard]] QPointF endPoint() const;
85
86 [[nodiscard]] QString iconName() const;
87
88 /** An icon representing @p maneuver.
89 * Can be a qrc: URL or XDG icon name.
90 */
91 Q_INVOKABLE [[nodiscard]] static QString maneuverIconName(KPublicTransport::PathSection::Maneuver maneuver);
92
93 /** Serializes one path section section to JSON. */
94 [[nodiscard]] static QJsonObject toJson(const PathSection &section);
95 /** Serializes a vector of path sections to JSON. */
96 [[nodiscard]] static QJsonArray toJson(const std::vector<PathSection> &sections);
97 /** Deserialize an object from JSON. */
98 [[nodiscard]] static PathSection fromJson(const QJsonObject &obj);
99 /** Deserialize a vector of path sections from JSON. */
100 [[nodiscard]] static std::vector<PathSection> fromJson(const QJsonArray &array);
101};
102
103class PathPrivate;
104
105/** A path followed by any kind of location change.
106 * This can be the way a train or bus takes, routing instructions
107 * for taking a rental vehicle, or instructions for transferring at
108 * a train station.
109 *
110 * A path consists of one or more PathSection.
111 */
112class KPUBLICTRANSPORT_EXPORT Path
113{
114 KPUBLICTRANSPORT_GADGET(Path)
115
116 /** Access to path sections for QML. */
117 Q_PROPERTY(std::vector<KPublicTransport::PathSection> sections READ sections)
118 /** Number of path sections for QML. */
119 Q_PROPERTY(int sectionCount READ sectionCount STORED false)
120
121 /** The length of this path in meters. */
122 Q_PROPERTY(int distance READ distance STORED false)
123
124 /** First point on this path. */
125 Q_PROPERTY(QPointF startPoint READ startPoint STORED false)
126 /** Last point on this path. */
127 Q_PROPERTY(QPointF endPoint READ endPoint STORED false)
128
129public:
130 /** Returns @c true if this is an empty/not-set path. */
131 [[nodiscard]] bool isEmpty() const;
132
133 /** The path sections. */
134 [[nodiscard]] const std::vector<PathSection>& sections() const;
135 /** Moves the path sections out of this object. */
136 [[nodiscard]] std::vector<PathSection>&& takeSections();
137 /** Sets the path sections. */
138 void setSections(std::vector<PathSection> &&sections);
139
140 /** Length of this path in meters. */
141 [[nodiscard]] int distance() const;
142
143 /** First point on this path. */
144 [[nodiscard]] QPointF startPoint() const;
145 /** Last point on this path. */
146 [[nodiscard]] QPointF endPoint() const;
147
148 /** Serializes one path object to JSON. */
149 [[nodiscard]] static QJsonObject toJson(const Path &path);
150 /** Deserialize an object from JSON. */
151 [[nodiscard]] static Path fromJson(const QJsonObject &obj);
152
153private:
154 [[nodiscard]] int sectionCount() const;
155};
156
157}
158
159Q_DECLARE_METATYPE(KPublicTransport::PathSection)
160Q_DECLARE_METATYPE(std::vector<KPublicTransport::PathSection>)
161Q_DECLARE_METATYPE(KPublicTransport::Path)
162
163#endif // KPUBLICTRANSPORT_PATH_H
A section of a Path.
Definition path.h:25
Maneuver
Maneuver associated with a path section.
Definition path.h:56
@ Elevator
Take an elevator.
Definition path.h:59
@ Escalator
Take an escalator.
Definition path.h:60
@ Move
Move/drive with the default mode of transport for this path.
Definition path.h:57
@ Stairs
Walk up or down stairs.
Definition path.h:58
A path followed by any kind of location change.
Definition path.h:113
Query operations and data types for accessing realtime public transport information from online servi...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.