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

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_LINE_H
0008 #define KPUBLICTRANSPORT_LINE_H
0009 
0010 #include "datatypes.h"
0011 #include "location.h"
0012 
0013 namespace KPublicTransport {
0014 
0015 class Line;
0016 class LinePrivate;
0017 
0018 /** A public transport line. */
0019 class KPUBLICTRANSPORT_EXPORT Line
0020 {
0021     KPUBLICTRANSPORT_GADGET(Line)
0022 
0023 public:
0024     /** Mode of transportation.
0025      *  @toto direct copy from Navitia, we maybe can reduce that a bit
0026      */
0027     enum Mode {
0028         Unknown,
0029         Air,
0030         Boat,
0031         Bus,
0032         BusRapidTransit,
0033         Coach,
0034         Ferry,
0035         Funicular,
0036         LocalTrain,
0037         LongDistanceTrain,
0038         Metro,
0039         RailShuttle,
0040         RapidTransit,
0041         Shuttle,
0042         Taxi,
0043         Train,
0044         Tramway,
0045         RideShare, ///< peer-to-peer ride sharing/car pooling
0046     };
0047     Q_ENUM(Mode)
0048 
0049     /** Name of the line. */
0050     KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
0051     /** Color of the line. */
0052     KPUBLICTRANSPORT_PROPERTY(QColor, color, setColor)
0053     /** @c true if a line color is set. */
0054     Q_PROPERTY(bool hasColor READ hasColor STORED false)
0055     /** Text color to use on top of the line color. */
0056     KPUBLICTRANSPORT_PROPERTY(QColor, textColor, setTextColor)
0057     /** @c true if a text color is set. */
0058     Q_PROPERTY(bool hasTextColor READ hasTextColor STORED false)
0059     /** Type of transport. */
0060     KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Line::Mode, mode, setMode)
0061     /** Human readable representation of the type of transport.
0062      *  This is not necessarily a simple 1:1 mapping from mode, but can contain
0063      *  e.g. a product name.
0064      */
0065     KPUBLICTRANSPORT_PROPERTY(QString, modeString, setModeString)
0066     /** Path of a local file containing the line logo.
0067      *  A line logo is typically a simple icon containing the short line name
0068      *  and color.
0069      *  This is downloaded on demand, and therefore might not be available
0070      *  immediately.
0071      */
0072     Q_PROPERTY(QString logo READ logo STORED false)
0073     /** @c true if the line has a logo. */
0074     Q_PROPERTY(bool hasLogo READ hasLogo STORED false)
0075 
0076     /** Path of a local file containing the line mode logo.
0077      *  A mode logo is the logo of the mode of transportation, or "product"
0078      *  this line belongs to, such as the general logo for a subway or metro
0079      *  service of this operator or in this city.
0080      *  This is downloaded on demand, and therefore might not be available
0081      *  immediately.
0082      */
0083     Q_PROPERTY(QString modeLogo READ modeLogo STORED false)
0084     /** @c true if the line has a mode logo. */
0085     Q_PROPERTY(bool hasModeLogo READ hasModeLogo STORED false)
0086 
0087 public:
0088     bool hasColor() const;
0089     bool hasTextColor() const;
0090     QString logo() const;
0091     bool hasLogo() const;
0092     QString modeLogo() const;
0093     bool hasModeLogo() const;
0094 
0095     /** Look up line meta data and apply what is found.
0096      *  @param location A location on or close to the line.
0097      *  @param download When set to @c true, not yet locally present logo URLs are retrieved.
0098      */
0099     void applyMetaData(const Location &location, bool download);
0100 
0101     /** Checks if to instances refer to the same line (which does not necessarily mean they are exactly equal). */
0102     static bool isSame(const Line &lhs, const Line &rhs);
0103 
0104     /** Merge two Line instances.
0105      *  This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
0106      */
0107     static Line merge(const Line &lhs, const Line &rhs);
0108 
0109     /** Serializes one object to JSON. */
0110     static QJsonObject toJson(const Line &l);
0111     /** Deserialize an object from JSON.
0112      *  @note Line meta data isn't serialized, so you might need to call applyLineMetaData() again
0113      *  after loading a line.
0114      */
0115     static Line fromJson(const QJsonObject &obj);
0116 };
0117 
0118 class RoutePrivate;
0119 
0120 /** A route of a public transport line. */
0121 class KPUBLICTRANSPORT_EXPORT Route
0122 {
0123     KPUBLICTRANSPORT_GADGET(Route)
0124     /** Line this route belongs to. */
0125     KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Line, line, setLine)
0126     /** Direction of the route.
0127      *  The direction of the the route is what is displayed on front of a train for example.
0128      *  For directional lines it matches the destination. For circular lines there is no destination
0129      *  however, the direction is then clockwise" for example.
0130      */
0131     KPUBLICTRANSPORT_PROPERTY(QString, direction, setDirection)
0132     /** Destination of the route.
0133      *  If this is set it should match the direction of the line. Circular lines for example do
0134      *  not have a destination location though.
0135      */
0136     KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Location, destination, setDestination)
0137 
0138     /** Name of the route.
0139      *  This is not to be confused with the name of the line, which is the much more commonly used
0140      *  value. Use this only if both are in use and you know which one is which, otherwise default
0141      *  to the line name.
0142      *  @see Line::name.
0143      */
0144     KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
0145 
0146 public:
0147     /** Checks if to instances refer to the same route (which does not necessarily mean they are exactly equal). */
0148     static bool isSame(const Route &lhs, const Route &rhs);
0149 
0150     /** Merge two Route instances.
0151      *  This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
0152      */
0153     static Route merge(const Route &lhs, const Route &rhs);
0154 
0155     /** Serializes one object to JSON. */
0156     static QJsonObject toJson(const Route &r);
0157     /** Deserialize an object from JSON. */
0158     static Route fromJson(const QJsonObject &obj);
0159 };
0160 
0161 }
0162 
0163 Q_DECLARE_METATYPE(KPublicTransport::Line)
0164 Q_DECLARE_METATYPE(KPublicTransport::Route)
0165 
0166 #endif // KPUBLICTRANSPORT_LINE_H