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

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KPUBLICTRANSPORT_LOAD_H
0008 #define KPUBLICTRANSPORT_LOAD_H
0009 
0010 #include "datatypes.h"
0011 
0012 namespace KPublicTransport {
0013 
0014 /** Vehicle load categories. */
0015 namespace Load
0016 {
0017     KPUBLICTRANSPORT_EXPORT Q_NAMESPACE
0018 
0019     /** Vehicle load categories. */
0020     enum Category {
0021         Unknown, ///< no load information are available
0022         Low,
0023         Medium,
0024         High,
0025         Full, ///< no remaining seats
0026     };
0027     Q_ENUM_NS(Category)
0028 }
0029 
0030 class LoadInfoPrivate;
0031 
0032 /** Vehicle load information.
0033  *  This consists of a load category and additional
0034  *  specifiers for which part of the vehicle this applies to,
0035  *  such as the class or vehicle section.
0036  */
0037 class KPUBLICTRANSPORT_EXPORT LoadInfo
0038 {
0039     KPUBLICTRANSPORT_GADGET(LoadInfo)
0040     /** Load category. */
0041     KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Load::Category, load, setLoad)
0042     /** Seating class, empty if not applicable.
0043      *  TODO should this be the same enum as in VehicleSection?
0044      */
0045     KPUBLICTRANSPORT_PROPERTY(QString, seatingClass, setSeatingClass)
0046     // TODO vehicle section, once we have a backend reporting this (SBB has that in theory I think)
0047 public:
0048     /** Serializes one load information object to JSON. */
0049     static QJsonObject toJson(const LoadInfo &info);
0050     /** Serializes a vector of load information objects to JSON. */
0051     static QJsonArray toJson(const std::vector<LoadInfo> &loadInfos);
0052     /** Deserialize an object from JSON. */
0053     static LoadInfo fromJson(const QJsonObject &obj);
0054     /** Deserialize a list of load information from JSON. */
0055     static std::vector<LoadInfo> fromJson(const QJsonArray &array);
0056 };
0057 
0058 }
0059 
0060 Q_DECLARE_METATYPE(KPublicTransport::LoadInfo)
0061 
0062 #endif // KPUBLICTRANSPORT_LOAD_H