KPublicTransport

path.h
1 /*
2  SPDX-FileCopyrightText: 2021 Volker Krause <[email protected]>
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 
15 namespace KPublicTransport {
16 
17 class 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  */
24 class 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, floor level
33 
34  /** The length of this path section in meters. */
35  Q_PROPERTY(int distance READ distance STORED false)
36  /** The overall direction of this section in degree. */
37  Q_PROPERTY(int direction READ direction STORED false)
38 
39  /** Floor level change during this path section.
40  * Negative values indicate going down, positive values indicate going up
41  */
42  KPUBLICTRANSPORT_PROPERTY(int, floorLevelChange, setFloorLevelChange)
43 
44 public:
45  /** Maneuver associated with a path section. */
46  enum Maneuver {
47  Move, ///< Move/drive with the default mode of transport for this path
48  Stairs, ///< Walk up or down stairs
49  Elevator, ///< Take an elevator
50  Escalator, ///< Take an escalator
51  };
52  Q_ENUM(Maneuver)
53  /** Movement maneuver for this path section. */
54  KPUBLICTRANSPORT_PROPERTY(Maneuver, maneuver, setManeuver)
55 
56 public:
57  /** Length of this path section in meters. */
58  int distance() const;
59  /** The overall direction of this section in degree.
60  * @returns 0-359 for valid results, -1 for sections with no direction (e.g. points).
61  */
62  int direction() const;
63 
64  /** First point on the path of this section. */
65  QPointF startPoint() const;
66  /** Last point on the path of this section. */
67  QPointF endPoint() const;
68 
69  /** Serializes one path section section to JSON. */
70  static QJsonObject toJson(const PathSection &section);
71  /** Serializes a vector of path sections to JSON. */
72  static QJsonArray toJson(const std::vector<PathSection> &sections);
73  /** Deserialize an object from JSON. */
74  static PathSection fromJson(const QJsonObject &obj);
75  /** Deserialize a vector of path sections from JSON. */
76  static std::vector<PathSection> fromJson(const QJsonArray &array);
77 };
78 
79 class PathPrivate;
80 
81 /** A path followed by any kind of location change.
82  * This can be the way a train or bus takes, routing instructions
83  * for taking a rental vehicle, or instructions for transferring at
84  * a train station.
85  *
86  * A path consists of one or more PathSection.
87  */
88 class KPUBLICTRANSPORT_EXPORT Path
89 {
90  KPUBLICTRANSPORT_GADGET(Path)
91 
92  /** Access to path sections for QML. */
93  Q_PROPERTY(std::vector<KPublicTransport::PathSection> sections READ sections)
94  /** Number of path sections for QML. */
95  Q_PROPERTY(int sectionCount READ sectionCount STORED false)
96 
97  /** The length of this path in meters. */
98  Q_PROPERTY(int distance READ distance STORED false)
99 
100 public:
101  /** Returns @c true if this is an empty/not-set path. */
102  bool isEmpty() const;
103 
104  /** The path sections. */
105  const std::vector<PathSection>& sections() const;
106  /** Moves the path sections out of this object. */
107  std::vector<PathSection>&& takeSections();
108  /** Sets the path sections. */
109  void setSections(std::vector<PathSection> &&sections);
110 
111  /** Length of this path in meters. */
112  int distance() const;
113 
114  /** First point on this path. */
115  QPointF startPoint() const;
116  /** Last point on this path. */
117  QPointF endPoint() const;
118 
119  /** Serializes one path object to JSON. */
120  static QJsonObject toJson(const Path &path);
121  /** Deserialize an object from JSON. */
122  static Path fromJson(const QJsonObject &obj);
123 
124 private:
125  int sectionCount() const;
126 };
127 
128 }
129 
130 Q_DECLARE_METATYPE(KPublicTransport::PathSection)
131 Q_DECLARE_METATYPE(std::vector<KPublicTransport::PathSection>)
132 Q_DECLARE_METATYPE(KPublicTransport::Path)
133 
134 #endif // KPUBLICTRANSPORT_PATH_H
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
Maneuver
Maneuver associated with a path section.
Definition: path.h:46
A section of a Path.
Definition: path.h:24
Move/drive with the default mode of transport for this path.
Definition: path.h:47
Walk up or down stairs.
Definition: path.h:48
A path followed by any kind of location change.
Definition: path.h:88
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:05:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.