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

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_RENTALVEHICLE_H
0008 #define KPUBLICTRANSPORT_RENTALVEHICLE_H
0009 
0010 #include "datatypes.h"
0011 
0012 namespace KPublicTransport {
0013 
0014 class RentalVehicleNetwork;
0015 class RentalVehiclePrivate;
0016 
0017 /** An individual rental vehicle used on a JourneySection, ie. a vehicle you don't own yourself but have to drive yourself.
0018  *  This can be:
0019  *  - free floating or dock-based rental bikes, with or without electric assistance
0020  *  - car sharing (but not ride sharing)
0021  *  - electric (kick) scooters
0022  *  - electric motorcycles (scooters)
0023  *
0024  *  @see GBFS: https://github.com/NABSA/gbfs/blob/v2.1-RC/gbfs.md#vehicle_typesjson-added-in-v21-rc
0025  *  @see MDS: https://github.com/openmobilityfoundation/mobility-data-specification/blob/master/provider/README.md#vehicle-types
0026  */
0027 class KPUBLICTRANSPORT_EXPORT RentalVehicle
0028 {
0029     KPUBLICTRANSPORT_GADGET(RentalVehicle)
0030 public:
0031     /** Type of vehicle. */
0032     enum VehicleType {
0033         Unknown = 0,
0034         Bicycle = 1, ///< human-powered bicylce
0035         Pedelec = 2, ///< bicycle with electric assistance
0036         ElectricKickScooter = 4, ///< "e scooter", electrically assisted kick scooters, not to be confused with motorcycle-like scooters
0037         ElectricMoped = 8, ///< motorcycle-like electric scooters
0038         Car = 16, ///< electrical- or combustion-powered car
0039     };
0040     Q_ENUM(VehicleType)
0041     Q_DECLARE_FLAGS(VehicleTypes, VehicleType)
0042     Q_FLAG(VehicleTypes)
0043 
0044     /** Vehicle type. */
0045     KPUBLICTRANSPORT_PROPERTY(VehicleType, type, setType)
0046 
0047     /** Sharing network operator. */
0048     KPUBLICTRANSPORT_PROPERTY(KPublicTransport::RentalVehicleNetwork, network, setNetwork)
0049 
0050     /** Remaining range of the vehicle in meters.
0051      *  Negative if unknown.
0052      */
0053     KPUBLICTRANSPORT_PROPERTY(int, remainingRange, setRemainingRange)
0054 
0055 public:
0056     /** Serializes one object to JSON. */
0057     static QJsonObject toJson(const RentalVehicle &vehicle);
0058     /** Deserialize an object from JSON. */
0059     static RentalVehicle fromJson(const QJsonObject &obj);
0060 };
0061 
0062 Q_DECLARE_OPERATORS_FOR_FLAGS(RentalVehicle::VehicleTypes)
0063 
0064 class RentalVehicleStationPrivate;
0065 
0066 /** Additional information for a vehicle renting station, attached to Location objects.
0067  *  This is typically needed for dock-based bike sharing systems.
0068  *
0069  *  @see https://github.com/NABSA/gbfs/blob/master/gbfs.md#station_informationjson
0070  *  @see https://github.com/NABSA/gbfs/blob/master/gbfs.md#station_statusjson
0071  */
0072 class KPUBLICTRANSPORT_EXPORT RentalVehicleStation
0073 {
0074     KPUBLICTRANSPORT_GADGET(RentalVehicleStation)
0075     /** Number of available (rentable) vehicles at this station. */
0076     KPUBLICTRANSPORT_PROPERTY(int, availableVehicles, setAvailableVehicles)
0077     /** Number of dock positions at this station.
0078      *  If capacity == availableVehicles no vehicles can be returned at this station.
0079      */
0080     KPUBLICTRANSPORT_PROPERTY(int, capacity, setCapacity)
0081 
0082     /** Sharing network operator. */
0083     KPUBLICTRANSPORT_PROPERTY(KPublicTransport::RentalVehicleNetwork, network, setNetwork)
0084 
0085     /** Not an empty/default constructed object. */
0086     Q_PROPERTY(bool isValid READ isValid STORED false)
0087 
0088     /** Supported vehicle types at this station. */
0089     Q_PROPERTY(KPublicTransport::RentalVehicle::VehicleTypes supportedVehicleTypes READ supportedVehicleTypes STORED false)
0090     /** Available vehicle types at this station. */
0091     Q_PROPERTY(KPublicTransport::RentalVehicle::VehicleTypes availableVehicleTypes READ availableVehicleTypes STORED false)
0092 
0093 public:
0094     bool isValid() const;
0095     RentalVehicle::VehicleTypes supportedVehicleTypes() const;
0096     RentalVehicle::VehicleTypes availableVehicleTypes() const;
0097 
0098     /** Capacity for a given vehicle type. */
0099     Q_INVOKABLE int capacity(KPublicTransport::RentalVehicle::VehicleType type) const;
0100     /** Set the capacity for a specific vehicle type. */
0101     void setCapacity(RentalVehicle::VehicleType type, int capacity);
0102 
0103     /** Available vehicles for a given vehicle type. */
0104     Q_INVOKABLE int availableVehicles(KPublicTransport::RentalVehicle::VehicleType type) const;
0105     /** Sets the number of available vehicles for a given vehicle type. */
0106     void setAvailableVehicles(RentalVehicle::VehicleType type, int count);
0107 
0108     /** Checks if two instances refer to the same station. */
0109     static bool isSame(const RentalVehicleStation &lhs, const RentalVehicleStation &rhs);
0110 
0111     /** Serializes one object to JSON. */
0112     static QJsonObject toJson(const RentalVehicleStation &station);
0113     /** Deserialize an object from JSON. */
0114     static RentalVehicleStation fromJson(const QJsonObject &obj);
0115 };
0116 
0117 class RentalVehicleNetworkPrivate;
0118 
0119 /** A vehicle sharing system/network.
0120  *  Typically one operator/area, needing an account/app for that operator to rent vehicles.
0121  *
0122  *  @see https://github.com/NABSA/gbfs/blob/master/gbfs.md#system_informationjson
0123  */
0124 class KPUBLICTRANSPORT_EXPORT RentalVehicleNetwork
0125 {
0126     KPUBLICTRANSPORT_GADGET(RentalVehicleNetwork)
0127     /** Human-visible name of this network. */
0128     KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
0129     /** Supported vehicle types by this network. */
0130     KPUBLICTRANSPORT_PROPERTY(KPublicTransport::RentalVehicle::VehicleTypes, vehicleTypes, setVehicleTypes)
0131 
0132     /** Not an empty/default constructed object. */
0133     Q_PROPERTY(bool isValid READ isValid STORED false)
0134 
0135 public:
0136     bool isValid() const;
0137 
0138     /** Checks if two instances refer to the same network. */
0139     static bool isSame(const RentalVehicleNetwork &lhs, const RentalVehicleNetwork &rhs);
0140 
0141     /** Serializes one object to JSON. */
0142     static QJsonObject toJson(const RentalVehicleNetwork &network);
0143     /** Deserialize an object from JSON. */
0144     static RentalVehicleNetwork fromJson(const QJsonObject &obj);
0145 };
0146 }
0147 
0148 Q_DECLARE_METATYPE(KPublicTransport::RentalVehicleNetwork)
0149 Q_DECLARE_METATYPE(KPublicTransport::RentalVehicleStation)
0150 Q_DECLARE_METATYPE(KPublicTransport::RentalVehicle)
0151 
0152 #endif // KPUBLICTRANSPORT_RENTALVEHICLE_H