KPublicTransport

stopover.h
1 /*
2  SPDX-FileCopyrightText: 2018 Volker Krause <[email protected]>
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 
18 class QDateTime;
19 
20 namespace KPublicTransport {
21 
22 class StopoverPrivate;
23 
24 /** Information about an arrival and/or departure of a vehicle at a stop area. */
25 class 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 public:
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  /** Checks if to instances refer to the same departure (which does not necessarily mean they are exactly equal). */
101  static bool isSame(const Stopover &lhs, const Stopover &rhs);
102 
103  /** Merge two departure instances.
104  * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
105  */
106  static Stopover merge(const Stopover &lhs, const Stopover &rhs);
107 
108  /** Serializes one object to JSON. */
109  static QJsonObject toJson(const Stopover &stopover);
110  /** Serializes a vector of departure objects to JSON. */
111  static QJsonArray toJson(const std::vector<Stopover> &deps);
112  /** Deserialize an object from JSON. */
113  static Stopover fromJson(const QJsonObject &obj);
114  /** Deserialize a list of departures from JSON. */
115  static std::vector<Stopover> fromJson(const QJsonArray &array);
116 
117 private:
118  QVariantList loadInformationVariant() const;
119 };
120 
121 }
122 
123 Q_DECLARE_METATYPE(KPublicTransport::Stopover)
124 
125 #endif // KPUBLICTRANSPORT_STOPOVER_H
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
Vehicle load information.
Definition: load.h:37
A route of a public transport line.
Definition: line.h:120
Information about the vehicle used on a journey.
Definition: vehicle.h:140
Information about an arrival and/or departure of a vehicle at a stop area.
Definition: stopover.h:25
Information about the layout of a station platform.
Definition: platform.h:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Oct 24 2021 23:05:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.