KPublicTransport

journey.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_JOURNEY_H
8#define KPUBLICTRANSPORT_JOURNEY_H
9
10#include "datatypes.h"
11#include "disruption.h"
12#include "individualtransport.h"
13#include "line.h"
14#include "load.h"
15#include "location.h"
16#include "path.h"
17#include "platform.h"
18#include "vehicle.h"
19
20#include <QDateTime>
21
22#include <vector>
23
24namespace KPublicTransport {
25
26class JourneySectionPrivate;
27class RentalVehicle;
28class Stopover;
29
30/** A segment of a journey plan. */
31class KPUBLICTRANSPORT_EXPORT JourneySection
32{
33 KPUBLICTRANSPORT_GADGET(JourneySection)
34
35public:
36 /** Mode of transport.
37 * These categories are fairly coarse, for a more detailed break-down of PublicTransport see Line::Mode.
38 */
39 enum Mode {
40 Invalid = 0,
41 PublicTransport = 1,
42 Transfer = 2,
43 Walking = 4,
44 Waiting = 8,
45 RentedVehicle = 16, ///< free floating or dock-based rental bike service, electric scooters, car sharing services, ie. any vehicle you drive yourself but that isn't your own
46 IndividualTransport = 32, ///< using your own vehicle (bike, car, etc).
47 };
48 Q_ENUM(Mode)
49 Q_DECLARE_FLAGS(Modes, Mode)
50 Q_FLAG(Modes)
51
52 /** Mode of transport for this section. */
53 KPUBLICTRANSPORT_PROPERTY(Mode, mode, setMode)
54
55 /** Planned departure time. */
56 KPUBLICTRANSPORT_PROPERTY(QDateTime, scheduledDepartureTime, setScheduledDepartureTime)
57 /** Actual departure time, if available.
58 * Set to invalid to indicate real-time data is not available.
59 */
60 KPUBLICTRANSPORT_PROPERTY(QDateTime, expectedDepartureTime, setExpectedDepartureTime)
61 /** @c true if this has real-time data. */
62 Q_PROPERTY(bool hasExpectedDepartureTime READ hasExpectedDepartureTime STORED false)
63 /** Difference to schedule in minutes. */
64 Q_PROPERTY(int departureDelay READ departureDelay STORED false)
65
66 /** Planned arrival time. */
67 KPUBLICTRANSPORT_PROPERTY(QDateTime, scheduledArrivalTime, setScheduledArrivalTime)
68 /** Actual arrival time, if available.
69 * Set to invalid to indicate real-time data is not available.
70 */
71 KPUBLICTRANSPORT_PROPERTY(QDateTime, expectedArrivalTime, setExpectedArrivalTime)
72 /** @c true if this has real-time data. */
73 Q_PROPERTY(bool hasExpectedArrivalTime READ hasExpectedArrivalTime STORED false)
74 /** Difference to schedule in minutes. */
75 Q_PROPERTY(int arrivalDelay READ arrivalDelay STORED false)
76
77 /** Duration of the section in seconds. */
78 Q_PROPERTY(int duration READ duration STORED false)
79 /** Distance of the section in meter. */
80 KPUBLICTRANSPORT_PROPERTY(int, distance, setDistance)
81
82 /** Departure location of this segment. */
83 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Location, from, setFrom)
84 /** Arrival location of this segment. */
85 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Location, to, setTo)
86 /** Route to take on this segment. */
87 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Route, route, setRoute)
88
89 /** Planned departure platform. */
90 KPUBLICTRANSPORT_PROPERTY(QString, scheduledDeparturePlatform, setScheduledDeparturePlatform)
91 /** Actual departure platform, in case real-time information are available. */
92 KPUBLICTRANSPORT_PROPERTY(QString, expectedDeparturePlatform, setExpectedDeparturePlatform)
93 /** @c true if real-time platform information are available. */
94 Q_PROPERTY(bool hasExpectedDeparturePlatform READ hasExpectedDeparturePlatform STORED false)
95 /** @c true if we have real-time platform information and the platform changed. */
96 Q_PROPERTY(bool departurePlatformChanged READ departurePlatformChanged STORED false)
97
98 /** Planned arrival platform. */
99 KPUBLICTRANSPORT_PROPERTY(QString, scheduledArrivalPlatform, setScheduledArrivalPlatform)
100 /** Actual arrival platform, in case real-time information are available. */
101 KPUBLICTRANSPORT_PROPERTY(QString, expectedArrivalPlatform, setExpectedArrivalPlatform)
102 /** @c true if real-time platform information are available. */
103 Q_PROPERTY(bool hasExpectedArrivalPlatform READ hasExpectedArrivalPlatform STORED false)
104 /** @c true if we have real-time platform information and the platform changed. */
105 Q_PROPERTY(bool arrivalPlatformChanged READ arrivalPlatformChanged STORED false)
106
107 /** Disruption effect on this section, if any. */
108 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Disruption::Effect, disruptionEffect, setDisruptionEffect)
109 /** General human-readable notes on this service, e.g. details about a disruption. */
110 KPUBLICTRANSPORT_PROPERTY(QStringList, notes, setNotes)
111
112 /** Intermediate stops for consumption by QML. */
113 Q_PROPERTY(QVariantList intermediateStops READ intermediateStopsVariant)
114
115 /** All departure information represented as Stopover object. */
116 Q_PROPERTY(KPublicTransport::Stopover departure READ departure STORED false)
117 /** All arrival information represented as Stopover object. */
118 Q_PROPERTY(KPublicTransport::Stopover arrival READ arrival STORED false)
119
120 /** CO₂ emission during this journey section, in gram.
121 * In case the backend doesn't provide this value, it is estimated based on the
122 * distance travelled during this section and the mode of transport, based on
123 * average emission values from https://en.wikipedia.org/wiki/Environmental_impact_of_transport
124 * This value can be 0 (e.g. in case of walk or wait sections), or -1 if no
125 * information is available.
126 */
127 KPUBLICTRANSPORT_PROPERTY(int, co2Emission, setCo2Emission)
128
129 /** Vehicle load information for this journey section.
130 * Contains LoadInfo objects for consumption by QML.
131 */
132 Q_PROPERTY(QVariantList loadInformation READ loadInformationVariant STORED false)
133
134 /** Information about a rental vehicle, for sections using one. */
135 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::RentalVehicle, rentalVehicle, setRentalVehicle)
136
137 /** Movement path for this journey section.
138 * This can be navigation instructions for individual transport modes and transfers,
139 * or the path a public transport vehicle takes.
140 */
141 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Path, path, setPath)
142
143 /** Vehicle coach layout information at departure. */
144 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Vehicle, departureVehicleLayout, setDepartureVehicleLayout)
145 /** Platform layout information at departure. */
146 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Platform, departurePlatformLayout, setDeparturePlatformLayout)
147 /** Vehicle coach layout information at arrival.
148 * Note that this does not necessarily need to be the same as departureVehicleLayout, as e.g. trains
149 * can be split up or merged along the way.
150 */
151 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Vehicle, arrivalVehicleLayout, setArrivalVehicleLayout)
152 /** Platform layout information at arrival. */
153 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Platform, arrivalPlatformLayout, setArrivalPlatformLayout)
154
155 /** Individual transport details for sections using your own vehicle. */
156 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::IndividualTransport, individualTransport, setIndividualTransport)
157
158public:
159 [[nodiscard]] bool hasExpectedDepartureTime() const;
160 [[nodiscard]] int departureDelay() const;
161 [[nodiscard]] bool hasExpectedArrivalTime() const;
162 [[nodiscard]] int arrivalDelay() const;
163
164 [[nodiscard]] int duration() const;
165
166 [[nodiscard]] bool hasExpectedDeparturePlatform() const;
167 [[nodiscard]] bool departurePlatformChanged() const;
168 [[nodiscard]] bool hasExpectedArrivalPlatform() const;
169 [[nodiscard]] bool arrivalPlatformChanged() const;
170
171 /** Adds a note. This will check for duplicates and normalize the notes. */
172 void addNote(const QString &note);
173 void addNotes(const QStringList &notes);
174
175 /** Intermediate stop-overs along this journey section.
176 * This does not include the departure and arrival stops, and might be empty on backends not providing this information.
177 */
178 [[nodiscard]] const std::vector<Stopover>& intermediateStops() const;
179 /** Moves the intermediate stops out of this object. */
180 std::vector<Stopover>&& takeIntermediateStops();
181 /** Set the intermediate stops. */
182 void setIntermediateStops(std::vector<Stopover> &&stops);
183
184 /** Returns the departure stopover of this journey section.
185 * This is the same information as accessible by individual properties,
186 * so this is mainly useful if you have to interface with code expecting a Stopover object.
187 */
188 [[nodiscard]] Stopover departure() const;
189 /**
190 * Sets all departure properties from a given Stopover.
191 * This effects location and time, but doesn't modify intermediate stops or paths.
192 */
193 void setDeparture(const Stopover &departure);
194
195 /** Returns the arrival stopover of this journey section.
196 * This is the same information as accessible by individual properties,
197 * so this is mainly useful if you have to interface with code expecting a Stopover object.
198 */
199 [[nodiscard]] Stopover arrival() const;
200 /**
201 * Sets all arrival properties from a given Stopover.
202 * This effects location and time, but doesn't modify intermediate stops or paths.
203 */
204 void setArrival(const Stopover &arrival);
205
206 /** Vehicle load information for this journey section, if available. */
207 [[nodiscard]] const std::vector<LoadInfo>& loadInformation() const;
208 /** Moves the load information out of this object for modification. */
209 std::vector<LoadInfo>&& takeLoadInformation();
210 /** Set the vehicle load information for this journey section. */
211 void setLoadInformation(std::vector<LoadInfo>&& loadInfo);
212
213 /** Augment line meta data.
214 * @param download if set to @p true, trigger the download of locally missing assets.
215 */
216 void applyMetaData(bool download);
217
218 /** Checks if two instances refer to the same journey section (which does not necessarily mean they are exactly equal). */
219 [[nodiscard]] static bool isSame(const JourneySection &lhs, const JourneySection &rhs);
220
221 /** Merge two instances.
222 * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
223 */
224 [[nodiscard]] static JourneySection merge(const JourneySection &lhs, const JourneySection &rhs);
225
226 /** Serializes one journey section to JSON. */
227 [[nodiscard]] static QJsonObject toJson(const JourneySection &section);
228 /** Serializes a vector of journey sections to JSON. */
229 [[nodiscard]] static QJsonArray toJson(const std::vector<JourneySection> &sections);
230 /** Deserialize an object from JSON. */
231 [[nodiscard]] static JourneySection fromJson(const QJsonObject &obj);
232 /** Deserialize a vector of journey sections from JSON. */
233 [[nodiscard]] static std::vector<JourneySection> fromJson(const QJsonArray &array);
234
235private:
236 [[nodiscard]] QVariantList intermediateStopsVariant() const;
237 [[nodiscard]] QVariantList loadInformationVariant() const;
238};
239
240Q_DECLARE_OPERATORS_FOR_FLAGS(JourneySection::Modes)
241
242class JourneyPrivate;
243
244/** A journey plan. */
245class KPUBLICTRANSPORT_EXPORT Journey
246{
247 KPUBLICTRANSPORT_GADGET(Journey)
248 /** Journey sections for consumption by QML. */
249 Q_PROPERTY(QVariantList sections READ sectionsVariant)
250 /** Departure time of the journey, according to schedule. */
251 Q_PROPERTY(QDateTime scheduledDepartureTime READ scheduledDepartureTime STORED false)
252 /** @c true if this has real-time data. */
253 Q_PROPERTY(bool hasExpectedDepartureTime READ hasExpectedDepartureTime STORED false)
254 /** Actual departure time, if available.
255 * Set to invalid to indicate real-time data is not available.
256 */
257 Q_PROPERTY(QDateTime expectedDepartureTime READ expectedDepartureTime STORED false)
258 /** Difference to schedule in minutes. */
259 Q_PROPERTY(int departureDelay READ departureDelay STORED false)
260
261 /** Arrival time of the journey, according to schedule. */
262 Q_PROPERTY(QDateTime scheduledArrivalTime READ scheduledArrivalTime STORED false)
263 /** @c true if this has real-time data. */
264 Q_PROPERTY(bool hasExpectedArrivalTime READ hasExpectedArrivalTime STORED false)
265 /** Actual arrival time, if available.
266 * Set to invalid to indicate real-time data is not available.
267 */
268 Q_PROPERTY(QDateTime expectedArrivalTime READ expectedArrivalTime STORED false)
269 /** Difference to schedule in minutes. */
270 Q_PROPERTY(int arrivalDelay READ arrivalDelay STORED false)
271
272 /** Duration of the entire journey in seconds. */
273 Q_PROPERTY(int duration READ duration STORED false)
274 /** Number of changes on this journey. */
275 Q_PROPERTY(int numberOfChanges READ numberOfChanges STORED false)
276 /** Worst disruption effect of any of the journey sections. */
277 Q_PROPERTY(KPublicTransport::Disruption::Effect disruptionEffect READ disruptionEffect STORED false)
278
279public:
280 /** The journey sections. */
281 [[nodiscard]] const std::vector<JourneySection>& sections() const;
282 /** Moves the journey sections out of this object. */
283 [[nodiscard]] std::vector<JourneySection>&& takeSections();
284 /** Sets the journey sections. */
285 void setSections(std::vector<JourneySection> &&sections);
286
287 [[nodiscard]] QDateTime scheduledDepartureTime() const;
288 [[nodiscard]] bool hasExpectedDepartureTime() const;
289 [[nodiscard]] QDateTime expectedDepartureTime() const;
290 [[nodiscard]] int departureDelay() const;
291
292 [[nodiscard]] QDateTime scheduledArrivalTime() const;
293 [[nodiscard]] bool hasExpectedArrivalTime() const;
294 [[nodiscard]] QDateTime expectedArrivalTime() const;
295 [[nodiscard]] int arrivalDelay() const;
296
297 [[nodiscard]] int duration() const;
298 [[nodiscard]] int numberOfChanges() const;
299 [[nodiscard]] Disruption::Effect disruptionEffect() const;
300
301 /** Augment line meta data.
302 * @param download if set to @p true, trigger the download of locally missing assets.
303 */
304 void applyMetaData(bool download);
305
306 /** Checks if two instances refer to the same journey (which does not necessarily mean they are exactly equal). */
307 [[nodiscard]] static bool isSame(const Journey &lhs, const Journey &rhs);
308
309 /** Merge two instances.
310 * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
311 */
312 [[nodiscard]] static Journey merge(const Journey &lhs, const Journey &rhs);
313
314 /** Serializes one journey object to JSON. */
315 [[nodiscard]] static QJsonObject toJson(const Journey &journey);
316 /** Serializes a vector of journey objects to JSON. */
317 [[nodiscard]] static QJsonArray toJson(const std::vector<Journey> &journeys);
318 /** Deserialize an object from JSON. */
319 [[nodiscard]] static Journey fromJson(const QJsonObject &obj);
320 /** Deserialize a list of journey from JSON. */
321 [[nodiscard]] static std::vector<Journey> fromJson(const QJsonArray &array);
322
323private:
324 [[nodiscard]] QVariantList sectionsVariant() const;
325};
326
327}
328
329Q_DECLARE_METATYPE(KPublicTransport::JourneySection)
330Q_DECLARE_METATYPE(KPublicTransport::Journey)
331
332#endif // KPUBLICTRANSPORT_JOURNEY_H
Individual transport mode details for a journey section, and for specifying journey requests.
A segment of a journey plan.
Definition journey.h:32
A journey plan.
Definition journey.h:246
Vehicle load information.
Definition load.h:38
A path followed by any kind of location change.
Definition path.h:89
Information about the layout of a station platform.
Definition platform.h:45
An individual rental vehicle used on a JourneySection, ie.
A route of a public transport line.
Definition line.h:125
Information about an arrival and/or departure of a vehicle at a stop area.
Definition stopover.h:26
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.