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
14namespace KPublicTransport {
15
16class VehicleSectionPrivate;
17
18/** Information about a part of a vehicle.
19 * This typically describes a coach of a train.
20 * @see Vehicle
21 */
22class KPUBLICTRANSPORT_EXPORT VehicleSection
23{
24 KPUBLICTRANSPORT_GADGET(VehicleSection)
25
26 /** Human readable identifier of this section, typically the coach number.
27 * Can be empty for sections closed to passengers, such as train engines.
28 */
29 KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
30
31 /** Relative position [0-1] of the begin of this vehicle section on the platform.
32 * 0 representing the begin of the platform in platform coordinate (@see Platform), 1 being the opposite end.
33 */
34 KPUBLICTRANSPORT_PROPERTY(float, platformPositionBegin, setPlatformPositionBegin)
35 /** Relative position [0-1] of the end of this vehicle section on the platform.
36 * 0 representing the begin of the platform in platform coordinate (@see Platform), 1 being the opposite end.
37 */
38 KPUBLICTRANSPORT_PROPERTY(float, platformPositionEnd, setPlatformPositionEnd)
39
40 /** Vehicle section type. */
41 enum Type {
42 UnknownType, ///< no information about the vehicle section type available
43 Engine, ///< train engine, not accessible by passengers, only shown for orientation
44 PowerCar, ///< power car of a train, similar to Engine, distinction exists just for better visualization
45 ControlCar, ///< usually at the head of the train, but accessible for passengers and the same way as a PassengerCar
46 PassengerCar, ///< passenger car of a train
47 RestaurantCar, ///< full-car restaurant
48 SleepingCar, ///< sleeping passenger car of an overnight train
49 CouchetteCar, ///< couchette passenger car of an overnight train
50 CarTransportCar, ///< car for transporting cars
51 };
52 Q_ENUM(Type)
53 /** Type of this vehicle section. */
54 KPUBLICTRANSPORT_PROPERTY(Type, type, setType)
55
56 /** Classes available in a vehicle section. */
57 enum Class {
58 UnknownClass = 0,
59 FirstClass = 1, ///< 1st class
60 SecondClass = 2, ///< 2nd class
61 ThirdClass = 4 ///< 3rd class
62 };
63 Q_DECLARE_FLAGS(Classes, Class)
64 Q_FLAG(Classes)
65 /** Classes available in this vehicle section.
66 * Can be more than one.
67 */
68 KPUBLICTRANSPORT_PROPERTY(Classes, classes, setClasses)
69
70 /** Amenities or other features available in a vehicle section. */
71 enum Feature {
72 NoFeatures = 0,
73 AirConditioning = 1, ///< vehicle section is air conditioned
74 Restaurant = 2, ///< vehicle has a place to obtain food/drinks (but not necessarily a full-scale RestaurantCar)
75 ToddlerArea = 4, ///< vehicle section contains infrastructure for toddler maintenance
76 WheelchairAccessible = 8, ///< wheelchair access supported
77 SilentArea = 16, ///< wishful thinking usually
78 BikeStorage = 32, ///< vehicle section contains space for bikes
79 // TODO there's a few more we get from DB
80 };
81 Q_DECLARE_FLAGS(Features, Feature)
82 Q_FLAG(Features)
83 /** Features available in this vehicle section.
84 * Can be more than one.
85 */
86 KPUBLICTRANSPORT_PROPERTY(Features, features, setFeatures)
87 /** Feature flag as a variant list, for consumption in QML. */
88 Q_PROPERTY(QVariantList featureList READ featureList STORED false)
89
90 /** Number of decks in this vehicle section. */
91 KPUBLICTRANSPORT_PROPERTY(int, deckCount, setDeckCount)
92
93 /** Vehicle section side.
94 * Front is towards the smaller platform coordinate, Back is the opposite direction.
95 */
96 enum Side {
97 NoSide = 0,
98 Front = 1,
99 Back = 2
100 };
101 Q_DECLARE_FLAGS(Sides, Side)
102 Q_FLAG(Sides)
103 /** Sides on which this vehicle section is connected to neighboring sections
104 * in a way that passengers can move between those sections.
105 * This matters for example for a double segment train with to control cars
106 * in the middle of its full layout.
107 */
108 KPUBLICTRANSPORT_PROPERTY(Sides, connectedSides, setConnectedSides)
109
110 /** Name of the platform section(s) this coach is position in.
111 * This is primarily meant as a fallback when exact platform positions aren't available.
112 */
113 KPUBLICTRANSPORT_PROPERTY(QString, platformSectionName, setPlatformSectionName)
114
115 /** Returns @c true if this vehicle section has a valid platform position set. */
116 [[nodiscard]] bool hasPlatformPosition() const;
117
118 /** Merge two VehicleSection instances. */
119 [[nodiscard]] static VehicleSection merge(const VehicleSection &lhs, const VehicleSection &rhs);
120
121 /** Serializes one vehicle section to JSON. */
122 [[nodiscard]] static QJsonObject toJson(const VehicleSection &section);
123 /** Serializes a vector of vehicle sections to JSON. */
124 [[nodiscard]] static QJsonArray toJson(const std::vector<VehicleSection> &sections);
125 /** Deserialize an object from JSON. */
126 [[nodiscard]] static VehicleSection fromJson(const QJsonObject &obj);
127 /** Deserialize a vector of vehicle sections from JSON. */
128 [[nodiscard]] static std::vector<VehicleSection> fromJson(const QJsonArray &array);
129
130private:
131 [[nodiscard]] QVariantList featureList() const;
132};
133
134class VehiclePrivate;
135
136/** Information about the vehicle used on a journey.
137 * This is typically only available for trains, and describes their coach layout.
138 *
139 * A vehicle object always is tied to a specific Platform object, to which all positions
140 * refer to.
141 * @see Platform
142 */
143class KPUBLICTRANSPORT_EXPORT Vehicle
144{
145 KPUBLICTRANSPORT_GADGET(Vehicle)
146 /** Human readable identifier of this vehicle, typically a train number. */
147 KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
148
149 /** Direction of travel. */
150 enum Direction {
151 UnknownDirection,
152 Forward, ///< vehicle departs toward the 0 platform coordinate
153 Backward ///< vehicle departs toward the 1 platforma coordinate
154 };
155 Q_ENUM(Direction)
156 /** Direction of travel of this vehicle. */
157 KPUBLICTRANSPORT_PROPERTY(Direction, direction, setDirection)
158
159 /** Journey sections for consumption by QML. */
160 Q_PROPERTY(QVariantList sections READ sectionsVariant)
161
162 /** Relative position [0-1] of the begin of this vehicle on the platform.
163 * 0 representing the begin of the platform in platform coordinate (@see Platform), 1 being the opposite end.
164 */
165 Q_PROPERTY(float platformPositionBegin READ platformPositionBegin STORED false)
166 /** Relative position [0-1] of the end of this vehicle on the platform.
167 * 0 representing the begin of the platform in platform coordinate (@see Platform), 1 being the opposite end.
168 */
169 Q_PROPERTY(float platformPositionEnd READ platformPositionEnd STORED false)
170
171public:
172 /** Returns @c true if this object contains no information beyond the default values. */
173 [[nodiscard]] bool isEmpty() const;
174
175 /** The vehicle sections. */
176 [[nodiscard]] const std::vector<VehicleSection>& sections() const;
177 /** Moves the vehicle sections out of this object. */
178 [[nodiscard]] std::vector<VehicleSection>&& takeSections();
179 /** Sets the vehicle sections. */
180 void setSections(std::vector<VehicleSection> &&sections);
181 void setSections(const std::vector<VehicleSection> &sections);
182
183 [[nodiscard]] float platformPositionBegin() const;
184 [[nodiscard]] float platformPositionEnd() const;
185
186 /** Returns the center position of the vehicle section named @p sectionName
187 * in relative platform coordinates.
188 * Useful for centering a view on a selected section for example.
189 */
190 Q_INVOKABLE [[nodiscard]] float platformPositionForSection(const QString &sectionName) const;
191
192 /** Checks whether all vehicle sections have platform positions set. */
193 [[nodiscard]] bool hasPlatformPositions() const;
194 /** Check whether all vehicle sections have platform section names set. */
195 [[nodiscard]] bool hasPlatformSectionNames() const;
196
197 /** Merge two Vehicle instances. */
198 [[nodiscard]] static Vehicle merge(const Vehicle &lhs, const Vehicle &rhs);
199
200 /** Serializes one vehicle object to JSON. */
201 [[nodiscard]] static QJsonObject toJson(const Vehicle &vehicle);
202 /** Serializes multiple vehicle objects to JSON. */
203 [[nodiscard]] static QJsonArray toJson(const std::vector<Vehicle> &vehicles);
204 /** Deserialize an object from JSON. */
205 [[nodiscard]] static Vehicle fromJson(const QJsonObject &obj);
206 /** Deserialize multiple objects from JSON. */
207 [[nodiscard]] static std::vector<Vehicle> fromJson(const QJsonArray &array);
208
209private:
210 [[nodiscard]] QVariantList sectionsVariant() const;
211};
212
213Q_DECLARE_OPERATORS_FOR_FLAGS(VehicleSection::Classes)
214Q_DECLARE_OPERATORS_FOR_FLAGS(VehicleSection::Features)
215Q_DECLARE_OPERATORS_FOR_FLAGS(VehicleSection::Sides)
216
217}
218
219Q_DECLARE_METATYPE(KPublicTransport::VehicleSection)
220Q_DECLARE_METATYPE(KPublicTransport::Vehicle)
221
222#endif // KPUBLICTRANSPORT_VEHICLE_H
Information about a part of a vehicle.
Definition vehicle.h:23
Information about the vehicle used on a journey.
Definition vehicle.h:144
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.