KPublicTransport

platform.h
1 /*
2  SPDX-FileCopyrightText: 2019 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef KPUBLICTRANSPORT_PLATFORM_H
8 #define KPUBLICTRANSPORT_PLATFORM_H
9 
10 #include "kpublictransport_export.h"
11 
12 #include "datatypes.h"
13 
14 namespace KPublicTransport {
15 
16 class PlatformSectionPrivate;
17 
18 /** Information about a part of a platform. */
19 class KPUBLICTRANSPORT_EXPORT PlatformSection
20 {
21  KPUBLICTRANSPORT_GADGET(PlatformSection)
22 
23  /** Human readable identifier of this platform section. */
24  KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
25 
26  /*+ Begin of this section in relative platform coordinates. */
27  KPUBLICTRANSPORT_PROPERTY(float, begin, setBegin)
28  /** End of this section in relative platform coordinates. */
29  KPUBLICTRANSPORT_PROPERTY(float, end, setEnd)
30 
31  /** Serializes one platform section to JSON. */
32  static QJsonObject toJson(const PlatformSection &section);
33  /** Serializes a vector of vehicle sections to JSON. */
34  static QJsonArray toJson(const std::vector<PlatformSection> &sections);
35  /** Deserialize an object from JSON. */
36  static PlatformSection fromJson(const QJsonObject &obj);
37  /** Deserialize a vector of platform sections from JSON. */
38  static std::vector<PlatformSection> fromJson(const QJsonArray &array);
39 };
40 
41 class PlatformPrivate;
42 
43 /** Information about the layout of a station platform. */
44 class KPUBLICTRANSPORT_EXPORT Platform
45 {
46  KPUBLICTRANSPORT_GADGET(Platform)
47 
48  // TODO how does this work with the Czech way of identifying tracks/platforms?
49  /** Human readable identifier of this platform.
50  * Typically a number.
51  */
52  KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
53 
54  /** Length of the platform, in meter.
55  * Value is negative if the information is not available.
56  * Useful for display scaling from relative platform coordinates.
57  * @see hasAbsoluteLength
58  */
59  KPUBLICTRANSPORT_PROPERTY(int, length, setLength)
60 
61  /** Platform sections for consumption by QML. */
62  Q_PROPERTY(QVariantList sections READ sectionsVariant)
63 
64  /** @c true if the absolute length of the platform in meter is known.
65  * A platform can have a positive length if proportional section sizes are
66  * known, but the absolute length is unknown.
67  */
68  Q_PROPERTY(bool hasAbsoluteLength READ hasAbsoluteLength)
69 
70 public:
71  /** Returns @c true if this object contains no information beyond default values. */
72  bool isEmpty() const;
73 
74  /** The platform sections. */
75  const std::vector<PlatformSection>& sections() const;
76  /** Moves the platform sections out of this object. */
77  std::vector<PlatformSection>&& takeSections();
78  /** Sets the platform sections. */
79  void setSections(std::vector<PlatformSection> &&sections);
80 
81  bool hasAbsoluteLength() const;
82 
83  /** Merge two platform instances. */
84  static Platform merge(const Platform &lhs, const Platform &rhs);
85 
86  /** Serializes one platform object to JSON. */
87  static QJsonObject toJson(const Platform &platform);
88  /** Serializes a vector of platform objects to JSON. */
89  static QJsonArray toJson(const std::vector<Platform> &platforms);
90  /** Deserialize an object from JSON. */
91  static Platform fromJson(const QJsonObject &obj);
92  /** Deserialize an array from JSON. */
93  static std::vector<Platform> fromJson(const QJsonArray &array);
94 
95 private:
96  QVariantList sectionsVariant() const;
97 };
98 
99 }
100 
101 Q_DECLARE_METATYPE(KPublicTransport::Platform)
102 
103 #endif // KPUBLICTRANSPORT_PLATFORM_H
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
Information about a part of a platform.
Definition: platform.h:19
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 Fri Oct 15 2021 23:07:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.