File indexing completed on 2024-05-12 04:42:45

0001 /*
0002     SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KPUBLICTRANSPORT_PLATFORM_H
0008 #define KPUBLICTRANSPORT_PLATFORM_H
0009 
0010 #include "kpublictransport_export.h"
0011 
0012 #include "datatypes.h"
0013 
0014 namespace KPublicTransport {
0015 
0016 class PlatformSectionPrivate;
0017 
0018 /** Information about a part of a platform. */
0019 class KPUBLICTRANSPORT_EXPORT PlatformSection
0020 {
0021     KPUBLICTRANSPORT_GADGET(PlatformSection)
0022 
0023     /** Human readable identifier of this platform section. */
0024     KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
0025 
0026     /*+ Begin of this section in relative platform coordinates. */
0027     KPUBLICTRANSPORT_PROPERTY(float, begin, setBegin)
0028     /** End of this section in relative platform coordinates. */
0029     KPUBLICTRANSPORT_PROPERTY(float, end, setEnd)
0030 
0031     /** Serializes one platform section to JSON. */
0032     static QJsonObject toJson(const PlatformSection &section);
0033     /** Serializes a vector of vehicle sections to JSON. */
0034     static QJsonArray toJson(const std::vector<PlatformSection> &sections);
0035     /** Deserialize an object from JSON. */
0036     static PlatformSection fromJson(const QJsonObject &obj);
0037     /** Deserialize a vector of platform sections from JSON. */
0038     static std::vector<PlatformSection> fromJson(const QJsonArray &array);
0039 };
0040 
0041 class PlatformPrivate;
0042 
0043 /** Information about the layout of a station platform. */
0044 class KPUBLICTRANSPORT_EXPORT Platform
0045 {
0046     KPUBLICTRANSPORT_GADGET(Platform)
0047 
0048     // TODO how does this work with the Czech way of identifying tracks/platforms?
0049     /** Human readable identifier of this platform.
0050      *  Typically a number.
0051      */
0052     KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
0053 
0054     /** Length of the platform, in meter.
0055      *  Value is negative if the information is not available.
0056      *  Useful for display scaling from relative platform coordinates.
0057      *  @see hasAbsoluteLength
0058      */
0059     KPUBLICTRANSPORT_PROPERTY(int, length, setLength)
0060 
0061     /** Platform sections for consumption by QML. */
0062     Q_PROPERTY(QVariantList sections READ sectionsVariant)
0063 
0064     /** @c true if the absolute length of the platform in meter is known.
0065      *  A platform can have a positive length if proportional section sizes are
0066      *  known, but the absolute length is unknown.
0067      */
0068     Q_PROPERTY(bool hasAbsoluteLength READ hasAbsoluteLength STORED false)
0069 
0070 public:
0071     /** Returns @c true if this object contains no information beyond default values. */
0072     bool isEmpty() const;
0073 
0074     /** The platform sections. */
0075     const std::vector<PlatformSection>& sections() const;
0076     /** Moves the platform sections out of this object. */
0077     std::vector<PlatformSection>&& takeSections();
0078     /** Sets the platform sections. */
0079     void setSections(std::vector<PlatformSection> &&sections);
0080 
0081     bool hasAbsoluteLength() const;
0082 
0083     /** Merge two platform instances. */
0084     static Platform merge(const Platform &lhs, const Platform &rhs);
0085 
0086     /** Serializes one platform object to JSON. */
0087     static QJsonObject toJson(const Platform &platform);
0088     /** Serializes a vector of platform objects to JSON. */
0089     static QJsonArray toJson(const std::vector<Platform> &platforms);
0090     /** Deserialize an object from JSON. */
0091     static Platform fromJson(const QJsonObject &obj);
0092     /** Deserialize an array from JSON. */
0093     static std::vector<Platform> fromJson(const QJsonArray &array);
0094 
0095 private:
0096     QVariantList sectionsVariant() const;
0097 };
0098 
0099 }
0100 
0101 Q_DECLARE_METATYPE(KPublicTransport::Platform)
0102 
0103 #endif // KPUBLICTRANSPORT_PLATFORM_H