KPublicTransport

stopover.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_STOPOVER_H
8#define KPUBLICTRANSPORT_STOPOVER_H
9
10#include "datatypes.h"
11#include "disruption.h"
12#include "line.h"
13#include "load.h"
14#include "location.h"
15#include "platform.h"
16#include "vehicle.h"
17
18class QDateTime;
19
20namespace KPublicTransport {
21
22class StopoverPrivate;
23
24/** Information about an arrival and/or departure of a vehicle at a stop area. */
25class KPUBLICTRANSPORT_EXPORT Stopover
26{
27 KPUBLICTRANSPORT_GADGET(Stopover)
28
29 /** Planned arrival time. */
30 KPUBLICTRANSPORT_PROPERTY(QDateTime, scheduledArrivalTime, setScheduledArrivalTime)
31 /** Actual arrival time, if available.
32 * Set to invalid to indicate real-time data is not available.
33 */
34 KPUBLICTRANSPORT_PROPERTY(QDateTime, expectedArrivalTime, setExpectedArrivalTime)
35 /** @c true if this has real-time data. */
36 Q_PROPERTY(bool hasExpectedArrivalTime READ hasExpectedArrivalTime STORED false)
37 /** Difference to schedule in minutes. */
38 Q_PROPERTY(int arrivalDelay READ arrivalDelay STORED false)
39
40 /** Planned departure time. */
41 KPUBLICTRANSPORT_PROPERTY(QDateTime, scheduledDepartureTime, setScheduledDepartureTime)
42 /** Actual departure time, if available.
43 * Set to invalid to indicate real-time data is not available.
44 */
45 KPUBLICTRANSPORT_PROPERTY(QDateTime, expectedDepartureTime, setExpectedDepartureTime)
46 /** @c true if this has real-time data. */
47 Q_PROPERTY(bool hasExpectedDepartureTime READ hasExpectedDepartureTime STORED false)
48 /** Difference to schedule in minutes. */
49 Q_PROPERTY(int departureDelay READ departureDelay STORED false)
50
51 /** Planned departure platform. */
52 KPUBLICTRANSPORT_PROPERTY(QString, scheduledPlatform, setScheduledPlatform)
53 /** Actual departure platform, in case real-time information are available. */
54 KPUBLICTRANSPORT_PROPERTY(QString, expectedPlatform, setExpectedPlatform)
55 /** @c true if real-time platform information are available. */
56 Q_PROPERTY(bool hasExpectedPlatform READ hasExpectedPlatform STORED false)
57 /** @c true if we have real-time platform information and the platform changed. */
58 Q_PROPERTY(bool platformChanged READ platformChanged STORED false)
59
60 /** The departing route. */
61 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Route, route, setRoute)
62
63 /** The stop point of this departure. */
64 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Location, stopPoint, setStopPoint)
65
66 /** Disruption effect on this arrival or departure, if any. */
67 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Disruption::Effect, disruptionEffect, setDisruptionEffect)
68 /** General human-readable notes on this service, e.g. details about a disruption. */
69 KPUBLICTRANSPORT_PROPERTY(QStringList, notes, setNotes)
70
71 /** Vehicle load information for departure from this stopover
72 * Contains LoadInfo objects for consumption by QML.
73 */
74 Q_PROPERTY(QList<KPublicTransport::LoadInfo> loadInformation READ loadInformationList STORED false)
75
76 /** Vehicle coach layout information at this stopover. */
77 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Vehicle, vehicleLayout, setVehicleLayout)
78 /** Platform layout information. */
79 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Platform, platformLayout, setPlatformLayout)
80
81 /** Features of the vehicle used on this section.
82 * This is identical to departureVehicleLayout.features and provided for convenience
83 * for cases where no more detailed vehicle information are available.
84 */
85 Q_PROPERTY(std::vector<KPublicTransport::Feature> features READ features)
86
87 /** Maximum occpancy leaving this stop, over all classes. */
88 Q_PROPERTY(KPublicTransport::Load::Category maximumOccupancy READ maximumOccupancy STORED false)
89
90public:
91 [[nodiscard]] bool hasExpectedArrivalTime() const;
92 [[nodiscard]] int arrivalDelay() const;
93 [[nodiscard]] bool hasExpectedDepartureTime() const;
94 [[nodiscard]] int departureDelay() const;
95 [[nodiscard]] bool hasExpectedPlatform() const;
96 [[nodiscard]] bool platformChanged() const;
97
98 /** Adds a note. This will check for duplicates and normalize the notes. */
99 void addNote(const QString &note);
100 void addNotes(const QStringList &notes);
101
102 /** Expected vehicle load for departing from this stopover. */
103 [[nodiscard]] const std::vector<LoadInfo>& loadInformation() const;
104 /** Moves the load information out of this object for modification. */
105 std::vector<LoadInfo>&& takeLoadInformation();
106 /** Set the expected vehicle load information for departing from this stopover. */
107 void setLoadInformation(std::vector<LoadInfo>&& loadInfo);
108
109 /** Vehicle features.
110 * This is identical to departureVehicleLayout.features and provided for convenience
111 * for cases where no more detailed vehicle information are available.
112 */
113 [[nodiscard]] const std::vector<KPublicTransport::Feature>& features() const;
114 [[nodiscard]] std::vector<KPublicTransport::Feature>&& takeFeatures();
115 void setFeatures(std::vector<KPublicTransport::Feature> &&features);
116
117 [[nodiscard]] Load::Category maximumOccupancy() const;
118
119 /** Augment line meta data.
120 * @param download when set to @c true trigger download of missing assets.
121 */
122 void applyMetaData(bool download);
123
124 /** Checks if to instances refer to the same departure (which does not necessarily mean they are exactly equal). */
125 static bool isSame(const Stopover &lhs, const Stopover &rhs);
126
127 /** Merge two departure instances.
128 * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
129 */
130 static Stopover merge(const Stopover &lhs, const Stopover &rhs);
131
132 /** Serializes one object to JSON. */
133 static QJsonObject toJson(const Stopover &stopover);
134 /** Serializes a vector of departure objects to JSON. */
135 static QJsonArray toJson(const std::vector<Stopover> &deps);
136 /** Deserialize an object from JSON. */
137 static Stopover fromJson(const QJsonObject &obj);
138 /** Deserialize a list of departures from JSON. */
139 static std::vector<Stopover> fromJson(const QJsonArray &array);
140
141private:
142 [[nodiscard]] Q_DECL_HIDDEN QList<LoadInfo> loadInformationList() const;
143};
144
145}
146
147Q_DECLARE_METATYPE(KPublicTransport::Stopover)
148
149#endif // KPUBLICTRANSPORT_STOPOVER_H
An amenity, facility or other relevant property of a vehicle (train, bus, etc), vehicle part (e....
Definition feature.h:20
Vehicle load information.
Definition load.h:38
Information about the layout of a station platform.
Definition platform.h:45
A route of a public transport line.
Definition line.h:148
Information about an arrival and/or departure of a vehicle at a stop area.
Definition stopover.h:26
static Stopover merge(const Stopover &lhs, const Stopover &rhs)
Merge two departure instances.
Definition stopover.cpp:212
KPublicTransport::Route route
The departing route.
Definition stopover.h:61
bool platformChanged
true if we have real-time platform information and the platform changed.
Definition stopover.h:58
void applyMetaData(bool download)
Augment line meta data.
Definition stopover.cpp:175
bool hasExpectedDepartureTime
true if this has real-time data.
Definition stopover.h:47
KPublicTransport::Load::Category maximumOccupancy
Maximum occpancy leaving this stop, over all classes.
Definition stopover.h:88
int arrivalDelay
Difference to schedule in minutes.
Definition stopover.h:38
QDateTime expectedDepartureTime
Actual departure time, if available.
Definition stopover.h:45
QStringList notes
General human-readable notes on this service, e.g.
Definition stopover.h:69
QString expectedPlatform
Actual departure platform, in case real-time information are available.
Definition stopover.h:54
static QJsonObject toJson(const Stopover &stopover)
Serializes one object to JSON.
Definition stopover.cpp:239
static bool isSame(const Stopover &lhs, const Stopover &rhs)
Checks if to instances refer to the same departure (which does not necessarily mean they are exactly ...
Definition stopover.cpp:182
KPublicTransport::Location stopPoint
The stop point of this departure.
Definition stopover.h:64
void setLoadInformation(std::vector< LoadInfo > &&loadInfo)
Set the expected vehicle load information for departing from this stopover.
Definition stopover.cpp:138
QDateTime expectedArrivalTime
Actual arrival time, if available.
Definition stopover.h:34
std::vector< LoadInfo > && takeLoadInformation()
Moves the load information out of this object for modification.
Definition stopover.cpp:132
QDateTime scheduledArrivalTime
Planned arrival time.
Definition stopover.h:30
QList< KPublicTransport::LoadInfo > loadInformation
Vehicle load information for departure from this stopover Contains LoadInfo objects for consumption b...
Definition stopover.h:74
bool hasExpectedArrivalTime
true if this has real-time data.
Definition stopover.h:36
bool hasExpectedPlatform
true if real-time platform information are available.
Definition stopover.h:56
static Stopover fromJson(const QJsonObject &obj)
Deserialize an object from JSON.
Definition stopover.cpp:271
KPublicTransport::Disruption::Effect disruptionEffect
Disruption effect on this arrival or departure, if any.
Definition stopover.h:67
void addNote(const QString &note)
Adds a note.
Definition stopover.cpp:110
std::vector< KPublicTransport::Feature > features
Features of the vehicle used on this section.
Definition stopover.h:85
int departureDelay
Difference to schedule in minutes.
Definition stopover.h:49
KPublicTransport::Vehicle vehicleLayout
Vehicle coach layout information at this stopover.
Definition stopover.h:77
QDateTime scheduledDepartureTime
Planned departure time.
Definition stopover.h:41
KPublicTransport::Platform platformLayout
Platform layout information.
Definition stopover.h:79
QString scheduledPlatform
Planned departure platform.
Definition stopover.h:52
Information about the vehicle used on a journey.
Definition vehicle.h:159
Disruption information for a Departure or a JourneySection.
Definition disruption.h:21
Vehicle load categories.
Definition load.h:16
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-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:50:52 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.