File indexing completed on 2024-05-12 04:42:45
0001 /* 0002 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KPUBLICTRANSPORT_PATH_H 0008 #define KPUBLICTRANSPORT_PATH_H 0009 0010 #include "kpublictransport_export.h" 0011 #include "datatypes.h" 0012 0013 #include <QPolygonF> 0014 0015 namespace KPublicTransport { 0016 0017 class PathSectionPrivate; 0018 0019 /** A section of a Path. 0020 * A path section consists of a poly-line of geo-coordinates to follow, 0021 * an initial maneuver instructions as well as additional properties for 0022 * this part of the path, such as the floor level. 0023 */ 0024 class KPUBLICTRANSPORT_EXPORT PathSection 0025 { 0026 KPUBLICTRANSPORT_GADGET(PathSection) 0027 /** The geo coordinate poly-line followed by this path section. */ 0028 KPUBLICTRANSPORT_PROPERTY(QPolygonF, path, setPath) 0029 /** Human-readable description of this path segment. */ 0030 KPUBLICTRANSPORT_PROPERTY(QString, description, setDescription) 0031 0032 // TODO add more properties: maneuver instructions, floor level 0033 0034 /** The length of this path section in meters. */ 0035 Q_PROPERTY(int distance READ distance STORED false) 0036 /** The overall direction of this section in degree. */ 0037 Q_PROPERTY(int direction READ direction STORED false) 0038 0039 /** Floor level change during this path section. 0040 * Negative values indicate going down, positive values indicate going up 0041 */ 0042 KPUBLICTRANSPORT_PROPERTY(int, floorLevelChange, setFloorLevelChange) 0043 0044 public: 0045 /** Maneuver associated with a path section. */ 0046 enum Maneuver { 0047 Move, ///< Move/drive with the default mode of transport for this path 0048 Stairs, ///< Walk up or down stairs 0049 Elevator, ///< Take an elevator 0050 Escalator, ///< Take an escalator 0051 }; 0052 Q_ENUM(Maneuver) 0053 /** Movement maneuver for this path section. */ 0054 KPUBLICTRANSPORT_PROPERTY(Maneuver, maneuver, setManeuver) 0055 0056 public: 0057 /** Length of this path section in meters. */ 0058 int distance() const; 0059 /** The overall direction of this section in degree. 0060 * @returns 0-359 for valid results, -1 for sections with no direction (e.g. points). 0061 */ 0062 int direction() const; 0063 0064 /** First point on the path of this section. */ 0065 QPointF startPoint() const; 0066 /** Last point on the path of this section. */ 0067 QPointF endPoint() const; 0068 0069 /** Serializes one path section section to JSON. */ 0070 static QJsonObject toJson(const PathSection §ion); 0071 /** Serializes a vector of path sections to JSON. */ 0072 static QJsonArray toJson(const std::vector<PathSection> §ions); 0073 /** Deserialize an object from JSON. */ 0074 static PathSection fromJson(const QJsonObject &obj); 0075 /** Deserialize a vector of path sections from JSON. */ 0076 static std::vector<PathSection> fromJson(const QJsonArray &array); 0077 }; 0078 0079 class PathPrivate; 0080 0081 /** A path followed by any kind of location change. 0082 * This can be the way a train or bus takes, routing instructions 0083 * for taking a rental vehicle, or instructions for transferring at 0084 * a train station. 0085 * 0086 * A path consists of one or more PathSection. 0087 */ 0088 class KPUBLICTRANSPORT_EXPORT Path 0089 { 0090 KPUBLICTRANSPORT_GADGET(Path) 0091 0092 /** Access to path sections for QML. */ 0093 Q_PROPERTY(std::vector<KPublicTransport::PathSection> sections READ sections) 0094 /** Number of path sections for QML. */ 0095 Q_PROPERTY(int sectionCount READ sectionCount STORED false) 0096 0097 /** The length of this path in meters. */ 0098 Q_PROPERTY(int distance READ distance STORED false) 0099 0100 public: 0101 /** Returns @c true if this is an empty/not-set path. */ 0102 bool isEmpty() const; 0103 0104 /** The path sections. */ 0105 const std::vector<PathSection>& sections() const; 0106 /** Moves the path sections out of this object. */ 0107 std::vector<PathSection>&& takeSections(); 0108 /** Sets the path sections. */ 0109 void setSections(std::vector<PathSection> &§ions); 0110 0111 /** Length of this path in meters. */ 0112 int distance() const; 0113 0114 /** First point on this path. */ 0115 QPointF startPoint() const; 0116 /** Last point on this path. */ 0117 QPointF endPoint() const; 0118 0119 /** Serializes one path object to JSON. */ 0120 static QJsonObject toJson(const Path &path); 0121 /** Deserialize an object from JSON. */ 0122 static Path fromJson(const QJsonObject &obj); 0123 0124 private: 0125 int sectionCount() const; 0126 }; 0127 0128 } 0129 0130 Q_DECLARE_METATYPE(KPublicTransport::PathSection) 0131 Q_DECLARE_METATYPE(std::vector<KPublicTransport::PathSection>) 0132 Q_DECLARE_METATYPE(KPublicTransport::Path) 0133 0134 #endif // KPUBLICTRANSPORT_PATH_H