KPublicTransport

line.h
1/*
2 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
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
13namespace KPublicTransport {
14
15class Line;
16class LinePrivate;
17
18/** A public transport line. */
19class KPUBLICTRANSPORT_EXPORT Line
20{
21 KPUBLICTRANSPORT_GADGET(Line)
22
23public:
24 /** Mode of transportation.
25 * @toto direct copy from Navitia, we maybe can reduce that a bit
26 */
27 enum Mode {
28 Unknown,
29 Air,
30 Boat,
31 Bus,
32 BusRapidTransit,
33 Coach,
34 Ferry,
35 Funicular,
36 LocalTrain,
37 LongDistanceTrain,
38 Metro,
39 RailShuttle,
40 RapidTransit,
41 Shuttle,
42 Taxi,
43 Train,
44 Tramway,
45 RideShare, ///< peer-to-peer ride sharing/car pooling
46 };
47 Q_ENUM(Mode)
48
49 /** Name of the line. */
50 KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
51 /** Color of the line. */
52 KPUBLICTRANSPORT_PROPERTY(QColor, color, setColor)
53 /** @c true if a line color is set. */
54 Q_PROPERTY(bool hasColor READ hasColor STORED false)
55 /** Text color to use on top of the line color. */
56 KPUBLICTRANSPORT_PROPERTY(QColor, textColor, setTextColor)
57 /** @c true if a text color is set. */
58 Q_PROPERTY(bool hasTextColor READ hasTextColor STORED false)
59 /** Type of transport. */
60 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Line::Mode, mode, setMode)
61 /** Human readable representation of the type of transport.
62 * This is not necessarily a simple 1:1 mapping from mode, but can contain
63 * e.g. a product name.
64 */
65 KPUBLICTRANSPORT_PROPERTY(QString, modeString, setModeString)
66 /** Path of a local file containing the line logo.
67 * A line logo is typically a simple icon containing the short line name
68 * and color.
69 * This is downloaded on demand, and therefore might not be available
70 * immediately.
71 */
72 Q_PROPERTY(QString logo READ logo STORED false)
73 /** @c true if the line has a logo. */
74 Q_PROPERTY(bool hasLogo READ hasLogo STORED false)
75
76 /** Path of a local file containing the line mode logo.
77 * A mode logo is the logo of the mode of transportation, or "product"
78 * this line belongs to, such as the general logo for a subway or metro
79 * service of this operator or in this city.
80 * This is downloaded on demand, and therefore might not be available
81 * immediately.
82 */
83 Q_PROPERTY(QString modeLogo READ modeLogo STORED false)
84 /** @c true if the line has a mode logo. */
85 Q_PROPERTY(bool hasModeLogo READ hasModeLogo STORED false)
86
87 /** Name of the operator running this line. */
88 KPUBLICTRANSPORT_PROPERTY(QString, operatorName, setOperatorName)
89
90public:
91 bool hasColor() const;
92 bool hasTextColor() const;
93 QString logo() const;
94 bool hasLogo() const;
95 QString modeLogo() const;
96 bool hasModeLogo() const;
97
98 /** Look up line meta data and apply what is found.
99 * @param location A location on or close to the line.
100 * @param download When set to @c true, not yet locally present logo URLs are retrieved.
101 */
102 void applyMetaData(const Location &location, bool download);
103
104 /** Checks if to instances refer to the same line (which does not necessarily mean they are exactly equal). */
105 static bool isSame(const Line &lhs, const Line &rhs);
106
107 /** Merge two Line instances.
108 * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
109 */
110 static Line merge(const Line &lhs, const Line &rhs);
111
112 /** Serializes one object to JSON. */
113 static QJsonObject toJson(const Line &l);
114 /** Deserialize an object from JSON.
115 * @note Line meta data isn't serialized, so you might need to call applyLineMetaData() again
116 * after loading a line.
117 */
118 static Line fromJson(const QJsonObject &obj);
119};
120
121class RoutePrivate;
122
123/** A route of a public transport line. */
124class KPUBLICTRANSPORT_EXPORT Route
125{
126 KPUBLICTRANSPORT_GADGET(Route)
127 /** Line this route belongs to. */
128 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Line, line, setLine)
129 /** Direction of the route.
130 * The direction of the the route is what is displayed on front of a train for example.
131 * For directional lines it matches the destination. For circular lines there is no destination
132 * however, the direction is then clockwise" for example.
133 */
134 KPUBLICTRANSPORT_PROPERTY(QString, direction, setDirection)
135 /** Destination of the route.
136 * If this is set it should match the direction of the line. Circular lines for example do
137 * not have a destination location though.
138 */
139 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Location, destination, setDestination)
140
141 /** Name of the route.
142 * This is not to be confused with the name of the line, which is the much more commonly used
143 * value. Use this only if both are in use and you know which one is which, otherwise default
144 * to the line name.
145 * @see Line::name.
146 */
147 KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
148
149public:
150 /** Checks if to instances refer to the same route (which does not necessarily mean they are exactly equal). */
151 static bool isSame(const Route &lhs, const Route &rhs);
152
153 /** Merge two Route instances.
154 * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
155 */
156 static Route merge(const Route &lhs, const Route &rhs);
157
158 /** Serializes one object to JSON. */
159 static QJsonObject toJson(const Route &r);
160 /** Deserialize an object from JSON. */
161 static Route fromJson(const QJsonObject &obj);
162};
163
164}
165
166Q_DECLARE_METATYPE(KPublicTransport::Line)
167Q_DECLARE_METATYPE(KPublicTransport::Route)
168
169#endif // KPUBLICTRANSPORT_LINE_H
A public transport line.
Definition line.h:20
Mode
Mode of transportation.
Definition line.h:27
@ RideShare
peer-to-peer ride sharing/car pooling
Definition line.h:45
A route of a public transport line.
Definition line.h:125
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 Tue Mar 26 2024 11:13:06 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.