KPublicTransport

vehicle.h
1/*
2 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KPUBLICTRANSPORT_VEHICLE_H
8#define KPUBLICTRANSPORT_VEHICLE_H
9
10#include "kpublictransport_export.h"
11
12#include "datatypes.h"
13#include "feature.h"
14#include "load.h"
15
16namespace KPublicTransport {
17
18class VehicleSectionPrivate;
19
20/** Information about a part of a vehicle.
21 * This typically describes a coach of a train.
22 * @see Vehicle
23 */
24class KPUBLICTRANSPORT_EXPORT VehicleSection
25{
26 KPUBLICTRANSPORT_GADGET(VehicleSection)
27
28 /** Human readable identifier of this section, typically the coach number.
29 * Can be empty for sections closed to passengers, such as train engines.
30 */
31 KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
32
33 /** Relative position [0-1] of the begin of this vehicle section on the platform.
34 * 0 representing the begin of the platform in platform coordinate (@see Platform), 1 being the opposite end.
35 */
36 KPUBLICTRANSPORT_PROPERTY(float, platformPositionBegin, setPlatformPositionBegin)
37 /** Relative position [0-1] of the end of this vehicle section on the platform.
38 * 0 representing the begin of the platform in platform coordinate (@see Platform), 1 being the opposite end.
39 */
40 KPUBLICTRANSPORT_PROPERTY(float, platformPositionEnd, setPlatformPositionEnd)
41
42 /** Vehicle section type. */
43 enum Type {
44 UnknownType, ///< no information about the vehicle section type available
45 Engine, ///< train engine, not accessible by passengers, only shown for orientation
46 PowerCar, ///< power car of a train, similar to Engine, distinction exists just for better visualization
47 ControlCar, ///< usually at the head of the train, but accessible for passengers and the same way as a PassengerCar
48 PassengerCar, ///< passenger car of a train
49 RestaurantCar, ///< full-car restaurant
50 SleepingCar, ///< sleeping passenger car of an overnight train
51 CouchetteCar, ///< couchette passenger car of an overnight train
52 CarTransportCar, ///< car for transporting cars
53 };
54 Q_ENUM(Type)
55 /** Type of this vehicle section. */
56 KPUBLICTRANSPORT_PROPERTY(Type, type, setType)
57
58 /** Classes available in a vehicle section. */
59 enum Class {
60 UnknownClass = 0,
61 FirstClass = 1, ///< 1st class
62 SecondClass = 2, ///< 2nd class
63 ThirdClass = 4 ///< 3rd class
64 };
65 Q_DECLARE_FLAGS(Classes, Class)
66 Q_FLAG(Classes)
67 /** Classes available in this vehicle section.
68 * Can be more than one.
69 */
70 KPUBLICTRANSPORT_PROPERTY(Classes, classes, setClasses)
71
72 /** Features of this section, for consumption by QML. */
73 Q_PROPERTY(std::vector<KPublicTransport::Feature> sectionFeatures READ sectionFeatures STORED false)
74
75 [[nodiscard]] const std::vector<KPublicTransport::Feature>& sectionFeatures() const;
76 [[nodiscard]] std::vector<KPublicTransport::Feature>&& takeSectionFeatures();
77 void setSectionFeatures(std::vector<KPublicTransport::Feature> &&features);
78
79 /** Returns the first feature of type @p type.
80 * Returns an invalid feature of no feature of that type exists.
81 */
82 Q_INVOKABLE [[nodiscard]] KPublicTransport::Feature feature(KPublicTransport::Feature::Type type) const;
83
84 /** Number of decks in this vehicle section. */
85 KPUBLICTRANSPORT_PROPERTY(int, deckCount, setDeckCount)
86
87 /** Vehicle section side.
88 * Front is towards the smaller platform coordinate, Back is the opposite direction.
89 */
90 enum Side {
91 NoSide = 0,
92 Front = 1,
93 Back = 2
94 };
95 Q_DECLARE_FLAGS(Sides, Side)
96 Q_FLAG(Sides)
97 /** Sides on which this vehicle section is connected to neighboring sections
98 * in a way that passengers can move between those sections.
99 * This matters for example for a double segment train with to control cars
100 * in the middle of its full layout.
101 */
102 KPUBLICTRANSPORT_PROPERTY(Sides, connectedSides, setConnectedSides)
103
104 /** Distruption affecting this coach.
105 * Disruption::NoService here means the coach is closed.
106 */
107 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Disruption::Effect, disruptionEffect, setDisruptionEffect)
108
109 /** Occupancy level for this coach. */
110 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Load::Category, load, setLoad)
111
112 /** Name of the platform section(s) this coach is position in.
113 * This is primarily meant as a fallback when exact platform positions aren't available.
114 */
115 KPUBLICTRANSPORT_PROPERTY(QString, platformSectionName, setPlatformSectionName)
116
117 /** Returns @c true if this vehicle section has a valid platform position set. */
118 [[nodiscard]] bool hasPlatformPosition() const;
119
120 /** Returns a suitable icon to represent the coach type.
121 * Can be a qrc: URL, an XDG icon name or empty.
122 * @since 24.08
123 */
124 Q_INVOKABLE [[nodiscard]] static QString vehicleTypeIconName(KPublicTransport::VehicleSection::Type type);
125
126 /** A suitable icon representing the coach.
127 * Can be a qrc: URL, an XDG icon name or empty.
128 * @since 24.08
129 */
130 Q_PROPERTY(QString iconName READ iconName STORED false)
131 [[nodiscard]] QString iconName() const;
132
133 /** Merge two VehicleSection instances. */
134 [[nodiscard]] static VehicleSection merge(const VehicleSection &lhs, const VehicleSection &rhs);
135
136 /** Serializes one vehicle section to JSON. */
137 [[nodiscard]] static QJsonObject toJson(const VehicleSection &section);
138 /** Serializes a vector of vehicle sections to JSON. */
139 [[nodiscard]] static QJsonArray toJson(const std::vector<VehicleSection> &sections);
140 /** Deserialize an object from JSON. */
141 [[nodiscard]] static VehicleSection fromJson(const QJsonObject &obj);
142 /** Deserialize a vector of vehicle sections from JSON. */
143 [[nodiscard]] static std::vector<VehicleSection> fromJson(const QJsonArray &array);
144
145private:
146 [[nodiscard]] QVariantList featureList() const;
147};
148
149class VehiclePrivate;
150
151/** Information about the vehicle used on a journey.
152 * This is typically only available for trains, and describes their coach layout.
153 *
154 * A vehicle object always is tied to a specific Platform object, to which all positions
155 * refer to.
156 * @see Platform
157 */
158class KPUBLICTRANSPORT_EXPORT Vehicle
159{
160 KPUBLICTRANSPORT_GADGET(Vehicle)
161 /** Human readable identifier of this vehicle, typically a train number. */
162 KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
163
164 /** Direction of travel. */
165 enum Direction {
166 UnknownDirection,
167 Forward, ///< vehicle departs toward the 0 platform coordinate
168 Backward ///< vehicle departs toward the 1 platforma coordinate
169 };
170 Q_ENUM(Direction)
171 /** Direction of travel of this vehicle. */
172 KPUBLICTRANSPORT_PROPERTY(Direction, direction, setDirection)
173
174 /** Journey sections for consumption by QML. */
175 Q_PROPERTY(QVariantList sections READ sectionsVariant)
176
177 /** Relative position [0-1] of the begin of this vehicle on the platform.
178 * 0 representing the begin of the platform in platform coordinate (@see Platform), 1 being the opposite end.
179 */
180 Q_PROPERTY(float platformPositionBegin READ platformPositionBegin STORED false)
181 /** Relative position [0-1] of the end of this vehicle on the platform.
182 * 0 representing the begin of the platform in platform coordinate (@see Platform), 1 being the opposite end.
183 */
184 Q_PROPERTY(float platformPositionEnd READ platformPositionEnd STORED false)
185
186 /** Features of this vehicle as a whole, not including the features of individual sections. */
187 Q_PROPERTY(std::vector<KPublicTransport::Feature> features READ features)
188
189 /** Features of the entire vehicle including a union of all features of the individual sections. */
190 Q_PROPERTY(std::vector<KPublicTransport::Feature> combinedFeatures READ combinedFeatures)
191
192public:
193 /** Returns @c true if this object contains no information beyond the default values. */
194 [[nodiscard]] bool isEmpty() const;
195
196 /** The vehicle sections. */
197 [[nodiscard]] const std::vector<VehicleSection>& sections() const;
198 /** Moves the vehicle sections out of this object. */
199 [[nodiscard]] std::vector<VehicleSection>&& takeSections();
200 /** Sets the vehicle sections. */
201 void setSections(std::vector<VehicleSection> &&sections);
202 void setSections(const std::vector<VehicleSection> &sections);
203
204 [[nodiscard]] float platformPositionBegin() const;
205 [[nodiscard]] float platformPositionEnd() const;
206
207 /** Returns the center position of the vehicle section named @p sectionName
208 * in relative platform coordinates.
209 * Useful for centering a view on a selected section for example.
210 */
211 Q_INVOKABLE [[nodiscard]] float platformPositionForSection(const QString &sectionName) const;
212
213 /** Checks whether all vehicle sections have platform positions set. */
214 [[nodiscard]] bool hasPlatformPositions() const;
215 /** Check whether all vehicle sections have platform section names set. */
216 [[nodiscard]] bool hasPlatformSectionNames() const;
217
218 /** Vehicle features. */
219 [[nodiscard]] const std::vector<KPublicTransport::Feature>& features() const;
220 [[nodiscard]] std::vector<KPublicTransport::Feature>&& takeFeatures();
221 void setFeatures(std::vector<KPublicTransport::Feature> &&features);
222
223 /** Combined vehicle features. */
224 [[nodiscard]] std::vector<KPublicTransport::Feature> combinedFeatures() const;
225
226 /** Merge two Vehicle instances. */
227 [[nodiscard]] static Vehicle merge(const Vehicle &lhs, const Vehicle &rhs);
228
229 /** Serializes one vehicle object to JSON. */
230 [[nodiscard]] static QJsonObject toJson(const Vehicle &vehicle);
231 /** Serializes multiple vehicle objects to JSON. */
232 [[nodiscard]] static QJsonArray toJson(const std::vector<Vehicle> &vehicles);
233 /** Deserialize an object from JSON. */
234 [[nodiscard]] static Vehicle fromJson(const QJsonObject &obj);
235 /** Deserialize multiple objects from JSON. */
236 [[nodiscard]] static std::vector<Vehicle> fromJson(const QJsonArray &array);
237
238private:
239 [[nodiscard]] QVariantList sectionsVariant() const;
240};
241
242Q_DECLARE_OPERATORS_FOR_FLAGS(VehicleSection::Classes)
243Q_DECLARE_OPERATORS_FOR_FLAGS(VehicleSection::Sides)
244
245}
246
247Q_DECLARE_METATYPE(KPublicTransport::VehicleSection)
248Q_DECLARE_METATYPE(KPublicTransport::Vehicle)
249
250#endif // KPUBLICTRANSPORT_VEHICLE_H
An amenity, facility or other relevant property of a vehicle (train, bus, etc), vehicle part (e....
Definition feature.h:20
Information about a part of a vehicle.
Definition vehicle.h:25
Information about the vehicle used on a journey.
Definition vehicle.h:159
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 Mon Nov 18 2024 12:07:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.