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(QVariantList loadInformation READ loadInformationVariant 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
87public:
88 bool hasExpectedArrivalTime() const;
89 int arrivalDelay() const;
90 bool hasExpectedDepartureTime() const;
91 int departureDelay() const;
92 bool hasExpectedPlatform() const;
93 bool platformChanged() const;
94
95 /** Adds a note. This will check for duplicates and normalize the notes. */
96 void addNote(const QString &note);
97 void addNotes(const QStringList &notes);
98
99 /** Expected vehicle load for departing from this stopover. */
100 const std::vector<LoadInfo>& loadInformation() const;
101 /** Moves the load information out of this object for modification. */
102 std::vector<LoadInfo>&& takeLoadInformation();
103 /** Set the expected vehicle load information for departing from this stopover. */
104 void setLoadInformation(std::vector<LoadInfo>&& loadInfo);
105
106 /** Vehicle features.
107 * This is identical to departureVehicleLayout.features and provided for convenience
108 * for cases where no more detailed vehicle information are available.
109 */
110 [[nodiscard]] const std::vector<KPublicTransport::Feature>& features() const;
111 [[nodiscard]] std::vector<KPublicTransport::Feature>&& takeFeatures();
112 void setFeatures(std::vector<KPublicTransport::Feature> &&features);
113
114 /** Augment line meta data.
115 * @param download when set to @c true trigger download of missing assets.
116 */
117 void applyMetaData(bool download);
118
119 /** Checks if to instances refer to the same departure (which does not necessarily mean they are exactly equal). */
120 static bool isSame(const Stopover &lhs, const Stopover &rhs);
121
122 /** Merge two departure instances.
123 * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
124 */
125 static Stopover merge(const Stopover &lhs, const Stopover &rhs);
126
127 /** Serializes one object to JSON. */
128 static QJsonObject toJson(const Stopover &stopover);
129 /** Serializes a vector of departure objects to JSON. */
130 static QJsonArray toJson(const std::vector<Stopover> &deps);
131 /** Deserialize an object from JSON. */
132 static Stopover fromJson(const QJsonObject &obj);
133 /** Deserialize a list of departures from JSON. */
134 static std::vector<Stopover> fromJson(const QJsonArray &array);
135
136private:
137 QVariantList loadInformationVariant() const;
138};
139
140}
141
142Q_DECLARE_METATYPE(KPublicTransport::Stopover)
143
144#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
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.