File indexing completed on 2024-05-12 04:42:45
0001 /* 0002 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KPUBLICTRANSPORT_STOPOVER_H 0008 #define KPUBLICTRANSPORT_STOPOVER_H 0009 0010 #include "datatypes.h" 0011 #include "disruption.h" 0012 #include "line.h" 0013 #include "load.h" 0014 #include "location.h" 0015 #include "platform.h" 0016 #include "vehicle.h" 0017 0018 class QDateTime; 0019 0020 namespace KPublicTransport { 0021 0022 class StopoverPrivate; 0023 0024 /** Information about an arrival and/or departure of a vehicle at a stop area. */ 0025 class KPUBLICTRANSPORT_EXPORT Stopover 0026 { 0027 KPUBLICTRANSPORT_GADGET(Stopover) 0028 0029 /** Planned arrival time. */ 0030 KPUBLICTRANSPORT_PROPERTY(QDateTime, scheduledArrivalTime, setScheduledArrivalTime) 0031 /** Actual arrival time, if available. 0032 * Set to invalid to indicate real-time data is not available. 0033 */ 0034 KPUBLICTRANSPORT_PROPERTY(QDateTime, expectedArrivalTime, setExpectedArrivalTime) 0035 /** @c true if this has real-time data. */ 0036 Q_PROPERTY(bool hasExpectedArrivalTime READ hasExpectedArrivalTime STORED false) 0037 /** Difference to schedule in minutes. */ 0038 Q_PROPERTY(int arrivalDelay READ arrivalDelay STORED false) 0039 0040 /** Planned departure time. */ 0041 KPUBLICTRANSPORT_PROPERTY(QDateTime, scheduledDepartureTime, setScheduledDepartureTime) 0042 /** Actual departure time, if available. 0043 * Set to invalid to indicate real-time data is not available. 0044 */ 0045 KPUBLICTRANSPORT_PROPERTY(QDateTime, expectedDepartureTime, setExpectedDepartureTime) 0046 /** @c true if this has real-time data. */ 0047 Q_PROPERTY(bool hasExpectedDepartureTime READ hasExpectedDepartureTime STORED false) 0048 /** Difference to schedule in minutes. */ 0049 Q_PROPERTY(int departureDelay READ departureDelay STORED false) 0050 0051 /** Planned departure platform. */ 0052 KPUBLICTRANSPORT_PROPERTY(QString, scheduledPlatform, setScheduledPlatform) 0053 /** Actual departure platform, in case real-time information are available. */ 0054 KPUBLICTRANSPORT_PROPERTY(QString, expectedPlatform, setExpectedPlatform) 0055 /** @c true if real-time platform information are available. */ 0056 Q_PROPERTY(bool hasExpectedPlatform READ hasExpectedPlatform STORED false) 0057 /** @c true if we have real-time platform information and the platform changed. */ 0058 Q_PROPERTY(bool platformChanged READ platformChanged STORED false) 0059 0060 /** The departing route. */ 0061 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Route, route, setRoute) 0062 0063 /** The stop point of this departure. */ 0064 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Location, stopPoint, setStopPoint) 0065 0066 /** Disruption effect on this arrival or departure, if any. */ 0067 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Disruption::Effect, disruptionEffect, setDisruptionEffect) 0068 /** General human-readable notes on this service, e.g. details about a disruption. */ 0069 KPUBLICTRANSPORT_PROPERTY(QStringList, notes, setNotes) 0070 0071 /** Vehicle load information for departure from this stopover 0072 * Contains LoadInfo objects for consumption by QML. 0073 */ 0074 Q_PROPERTY(QVariantList loadInformation READ loadInformationVariant STORED false) 0075 0076 /** Vehicle coach layout information at this stopover. */ 0077 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Vehicle, vehicleLayout, setVehicleLayout) 0078 /** Platform layout information. */ 0079 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Platform, platformLayout, setPlatformLayout) 0080 0081 public: 0082 bool hasExpectedArrivalTime() const; 0083 int arrivalDelay() const; 0084 bool hasExpectedDepartureTime() const; 0085 int departureDelay() const; 0086 bool hasExpectedPlatform() const; 0087 bool platformChanged() const; 0088 0089 /** Adds a note. This will check for duplicates and normalize the notes. */ 0090 void addNote(const QString ¬e); 0091 void addNotes(const QStringList ¬es); 0092 0093 /** Expected vehicle load for departing from this stopover. */ 0094 const std::vector<LoadInfo>& loadInformation() const; 0095 /** Moves the load information out of this object for modification. */ 0096 std::vector<LoadInfo>&& takeLoadInformation(); 0097 /** Set the expected vehicle load information for departing from this stopover. */ 0098 void setLoadInformation(std::vector<LoadInfo>&& loadInfo); 0099 0100 /** Augment line meta data. 0101 * @param download when set to @c true trigger download of missing assets. 0102 */ 0103 void applyMetaData(bool download); 0104 0105 /** Checks if to instances refer to the same departure (which does not necessarily mean they are exactly equal). */ 0106 static bool isSame(const Stopover &lhs, const Stopover &rhs); 0107 0108 /** Merge two departure instances. 0109 * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information. 0110 */ 0111 static Stopover merge(const Stopover &lhs, const Stopover &rhs); 0112 0113 /** Serializes one object to JSON. */ 0114 static QJsonObject toJson(const Stopover &stopover); 0115 /** Serializes a vector of departure objects to JSON. */ 0116 static QJsonArray toJson(const std::vector<Stopover> &deps); 0117 /** Deserialize an object from JSON. */ 0118 static Stopover fromJson(const QJsonObject &obj); 0119 /** Deserialize a list of departures from JSON. */ 0120 static std::vector<Stopover> fromJson(const QJsonArray &array); 0121 0122 private: 0123 QVariantList loadInformationVariant() const; 0124 }; 0125 0126 } 0127 0128 Q_DECLARE_METATYPE(KPublicTransport::Stopover) 0129 0130 #endif // KPUBLICTRANSPORT_STOPOVER_H