KPublicTransport

line.h
1 /*
2  SPDX-FileCopyrightText: 2018 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef KPUBLICTRANSPORT_LINE_H
8 #define KPUBLICTRANSPORT_LINE_H
9 
10 #include "datatypes.h"
11 #include "location.h"
12 
13 namespace KPublicTransport {
14 
15 class Line;
16 class LinePrivate;
17 class LineMetaData;
18 namespace LineUtil{
19 KPUBLICTRANSPORT_EXPORT void setMetaData(Line&, const LineMetaData&);
20 }
21 
22 /** A public transport line. */
23 class KPUBLICTRANSPORT_EXPORT Line
24 {
25  KPUBLICTRANSPORT_GADGET(Line)
26 
27 public:
28  /** Mode of transportation.
29  * @toto direct copy from Navitia, we maybe can reduce that a bit
30  */
31  enum Mode {
32  Unknown,
33  Air,
34  Boat,
35  Bus,
36  BusRapidTransit,
37  Coach,
38  Ferry,
39  Funicular,
40  LocalTrain,
41  LongDistanceTrain,
42  Metro,
43  RailShuttle,
44  RapidTransit,
45  Shuttle,
46  Taxi,
47  Train,
48  Tramway,
49  RideShare, ///< peer-to-peer ride sharing/car pooling
50  };
51  Q_ENUM(Mode)
52 
53  /** Name of the line. */
54  KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
55  /** Color of the line. */
56  KPUBLICTRANSPORT_PROPERTY(QColor, color, setColor)
57  /** @c true if a line color is set. */
58  Q_PROPERTY(bool hasColor READ hasColor STORED false)
59  /** Text color to use on top of the line color. */
60  KPUBLICTRANSPORT_PROPERTY(QColor, textColor, setTextColor)
61  /** @c true if a text color is set. */
62  Q_PROPERTY(bool hasTextColor READ hasTextColor STORED false)
63  /** Type of transport. */
64  KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Line::Mode, mode, setMode)
65  /** Human readable representation of the type of transport.
66  * This is not necessarily a simple 1:1 mapping from mode, but can contain
67  * e.g. a product name.
68  */
69  KPUBLICTRANSPORT_PROPERTY(QString, modeString, setModeString)
70  /** Path of a local file containing the line logo.
71  * A line logo is typically a simple icon containing the short line name
72  * and color.
73  * This is downloaded on demand, and therefore might not be available
74  * immediately.
75  */
76  Q_PROPERTY(QString logo READ logo STORED false)
77  /** @c true if the line has a logo. */
78  Q_PROPERTY(bool hasLogo READ hasLogo STORED false)
79 
80  /** Path of a local file containing the line mode logo.
81  * A mode logo is the logo of the mode of transportation, or "product"
82  * this line belongs to, such as the general logo for a subway or metro
83  * service of this operator or in this city.
84  * This is downloaded on demand, and therefore might not be available
85  * immediately.
86  */
87  Q_PROPERTY(QString modeLogo READ modeLogo STORED false)
88  /** @c true if the line has a mode logo. */
89  Q_PROPERTY(bool hasModeLogo READ hasModeLogo STORED false)
90 
91 public:
92  bool hasColor() const;
93  bool hasTextColor() const;
94  QString logo() const;
95  bool hasLogo() const;
96  QString modeLogo() const;
97  bool hasModeLogo() const;
98 
99  /** Checks if to instances refer to the same line (which does not necessarily mean they are exactly equal). */
100  static bool isSame(const Line &lhs, const Line &rhs);
101 
102  /** Merge two Line instances.
103  * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
104  */
105  static Line merge(const Line &lhs, const Line &rhs);
106 
107  /** Serializes one object to JSON. */
108  static QJsonObject toJson(const Line &l);
109  /** Deserialize an object from JSON. */
110  static Line fromJson(const QJsonObject &obj);
111 
112 private:
113  friend void LineUtil::setMetaData(Line&, const LineMetaData&);
114  void setMetaData(const LineMetaData &metaData);
115 };
116 
117 class RoutePrivate;
118 
119 /** A route of a public transport line. */
120 class KPUBLICTRANSPORT_EXPORT Route
121 {
122  KPUBLICTRANSPORT_GADGET(Route)
123  /** Line this route belongs to. */
124  KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Line, line, setLine)
125  /** Direction of the route.
126  * The direction of the the route is what is displayed on front of a train for example.
127  * For directional lines it matches the destination. For circular lines there is no destination
128  * however, the direction is then clockwise" for example.
129  */
130  KPUBLICTRANSPORT_PROPERTY(QString, direction, setDirection)
131  /** Destination of the route.
132  * If this is set it should match the direction of the line. Circular lines for example do
133  * not have a destination location though.
134  */
135  KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Location, destination, setDestination)
136 
137 public:
138  /** Checks if to instances refer to the same route (which does not necessarily mean they are exactly equal). */
139  static bool isSame(const Route &lhs, const Route &rhs);
140 
141  /** Merge two Route instances.
142  * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
143  */
144  static Route merge(const Route &lhs, const Route &rhs);
145 
146  /** Serializes one object to JSON. */
147  static QJsonObject toJson(const Route &r);
148  /** Deserialize an object from JSON. */
149  static Route fromJson(const QJsonObject &obj);
150 };
151 
152 }
153 
154 Q_DECLARE_METATYPE(KPublicTransport::Line)
155 Q_DECLARE_METATYPE(KPublicTransport::Route)
156 
157 #endif // KPUBLICTRANSPORT_LINE_H
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
A route of a public transport line.
Definition: line.h:120
peer-to-peer ride sharing/car pooling
Definition: line.h:49
Mode
Mode of transportation.
Definition: line.h:31
KCOREADDONS_EXPORT void setMetaData(const MetaDataMap &metaData, QMimeData *mimeData)
Static information about a public transport line.
Definition: linemetadata.h:25
A public transport line.
Definition: line.h:23
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.