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 Coach,
33 Ferry,
34 Funicular,
35 LocalTrain,
36 LongDistanceTrain,
37 Metro,
38 RailShuttle, ///< rail shuttle service within a complex, as e.g. found at or around airports
39 RapidTransit,
40 Shuttle, ///< shuttle bus/coach services, e.g. to/from an airport
41 Taxi,
42 Train,
43 Tramway,
44 RideShare, ///< peer-to-peer ride sharing/car pooling
45 AerialLift, ///< aerial cable cars, gondolas, etc
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
90 /** Generic icon for the line mode.
91 * @see modeIconName(Line::Mode)
92 */
93 Q_PROPERTY(QString modeIconName READ modeIconName STORED false)
94
95 /** The best available icon for this line.
96 * Either the line logo, mode logo or generic mode icon.
97 * Can be a file: or qrc: URI or a XDG icon name.
98 *
99 * @note Line and product logos are full-color, the generic ones
100 * are monochrome colorable Breeze SVG icons.
101 */
102 Q_PROPERTY(QString iconName READ iconName STORED false)
103public:
104 [[nodiscard]] bool hasColor() const;
105 [[nodiscard]] bool hasTextColor() const;
106 [[nodiscard]] QString logo() const;
107 [[nodiscard]] bool hasLogo() const;
108 [[nodiscard]] QString modeLogo() const;
109 [[nodiscard]] bool hasModeLogo() const;
110 [[nodiscard]] QString modeIconName() const;
111 [[nodiscard]] QString iconName() const;
112
113 /** Name of an icon to represent @p mode.
114 * Can be an qrc: URL or a icon name compatbile with QIcon::fromTheme.
115 */
116 Q_INVOKABLE [[nodiscard]] static QString modeIconName(KPublicTransport::Line::Mode mode);
117
118 /** @c true if @p mode is bounds to rail tracks. */
119 [[nodiscard]] static bool modeIsRailBound(KPublicTransport::Line::Mode mode);
120
121 /** Look up line meta data and apply what is found.
122 * @param location A location on or close to the line.
123 * @param download When set to @c true, not yet locally present logo URLs are retrieved.
124 */
125 void applyMetaData(const Location &location, bool download);
126
127 /** Checks if to instances refer to the same line (which does not necessarily mean they are exactly equal). */
128 [[nodiscard]] static bool isSame(const Line &lhs, const Line &rhs);
129
130 /** Merge two Line instances.
131 * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
132 */
133 [[nodiscard]] static Line merge(const Line &lhs, const Line &rhs);
134
135 /** Serializes one object to JSON. */
136 [[nodiscard]] static QJsonObject toJson(const Line &l);
137 /** Deserialize an object from JSON.
138 * @note Line meta data isn't serialized, so you might need to call applyLineMetaData() again
139 * after loading a line.
140 */
141 [[nodiscard]] static Line fromJson(const QJsonObject &obj);
142};
143
144class RoutePrivate;
145
146/** A route of a public transport line. */
147class KPUBLICTRANSPORT_EXPORT Route
148{
149 KPUBLICTRANSPORT_GADGET(Route)
150 /** Line this route belongs to. */
151 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Line, line, setLine)
152 /** Direction of the route.
153 * The direction of the the route is what is displayed on front of a train for example.
154 * For directional lines it matches the destination. For circular lines there is no destination
155 * however, the direction is then clockwise" for example.
156 */
157 KPUBLICTRANSPORT_PROPERTY(QString, direction, setDirection)
158 /** Destination of the route.
159 * If this is set it should match the direction of the line. Circular lines for example do
160 * not have a destination location though.
161 */
162 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Location, destination, setDestination)
163
164 /** Name of the route.
165 * This is not to be confused with the name of the line, which is the much more commonly used
166 * value. Use this only if both are in use and you know which one is which, otherwise default
167 * to the line name.
168 * @see Line::name.
169 */
170 KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
171
172public:
173 /** Checks if to instances refer to the same route (which does not necessarily mean they are exactly equal). */
174 [[nodiscard]] static bool isSame(const Route &lhs, const Route &rhs);
175
176 /** Merge two Route instances.
177 * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
178 */
179 [[nodiscard]] static Route merge(const Route &lhs, const Route &rhs);
180
181 /** Serializes one object to JSON. */
182 [[nodiscard]] static QJsonObject toJson(const Route &r);
183 /** Deserialize an object from JSON. */
184 [[nodiscard]] static Route fromJson(const QJsonObject &obj);
185};
186
187}
188
189Q_DECLARE_METATYPE(KPublicTransport::Line)
190Q_DECLARE_METATYPE(KPublicTransport::Route)
191
192#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:44
@ RailShuttle
rail shuttle service within a complex, as e.g. found at or around airports
Definition line.h:38
@ Shuttle
shuttle bus/coach services, e.g. to/from an airport
Definition line.h:40
@ AerialLift
aerial cable cars, gondolas, etc
Definition line.h:45
A route of a public transport line.
Definition line.h:148
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 Fri Nov 29 2024 11:57:19 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.