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