KPublicTransport

location.h
1 /*
2  SPDX-FileCopyrightText: 2018 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef KPUBLICTRANSPORT_LOCATION_H
8 #define KPUBLICTRANSPORT_LOCATION_H
9 
10 #include "datatypes.h"
11 
12 class QJsonArray;
13 class QJsonObject;
14 class QJsonValue;
15 class QTimeZone;
16 template <typename K, typename T> class QHash;
17 
18 namespace KPublicTransport {
19 
20 class LocationPrivate;
21 class Equipment;
22 class RentalVehicle;
23 class RentalVehicleStation;
24 
25 /** A location.
26  * This can be a train station, a bus stop, a rental vehicle dock, a free-floating vehicle position,
27  * an elevator or escalator, etc.
28  */
29 class KPUBLICTRANSPORT_EXPORT Location
30 {
31  KPUBLICTRANSPORT_GADGET(Location)
32 public:
33  /** Type of location. */
34  enum Type {
35  Place = 0, ///< a location that isn't of any specific type
36  Stop = 1, ///< a public transport stop (train station, bus stop, etc)
37  RentedVehicleStation = 2, ///< a pick-up/drop-off point for dock-based rental bike/scooter systems
38  RentedVehicle = 4, ///< a free-floating rental bike/scooter
39  Equipment = 8, ///< elevator/escalator
40  CarpoolPickupDropoff = 16, ///< a pickup or dropoff location for a carpool trip
41  };
42  Q_ENUM(Type)
43  Q_DECLARE_FLAGS(Types, Type)
44  Q_FLAG(Types)
45 
46  /** Location type. */
47  KPUBLICTRANSPORT_PROPERTY(Type, type, setType)
48 
49  /** Human-readable name of the location. */
50  KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
51  /** Latitude of the location, in degree, NaN if unknown. */
52  KPUBLICTRANSPORT_PROPERTY(float, latitude, setLatitude)
53  /** Longitude of the location, in degree, NaN if unknown. */
54  KPUBLICTRANSPORT_PROPERTY(float, longitude, setLongitude)
55 
56  /** Street address of the location, if known. */
57  KPUBLICTRANSPORT_PROPERTY(QString, streetAddress, setStreetAddress)
58  /** Postal code of the location, if known. */
59  KPUBLICTRANSPORT_PROPERTY(QString, postalCode, setPostalCode)
60  /** Locality/city of the location, if known. */
61  KPUBLICTRANSPORT_PROPERTY(QString, locality, setLocality)
62  /** Region (as in ISO 3166-2) of the location, if known. */
63  KPUBLICTRANSPORT_PROPERTY(QString, region, setRegion)
64  /** Country of the location as ISO 3166-1 alpha 2 code, if known. */
65  KPUBLICTRANSPORT_PROPERTY(QString, country, setCountry)
66 
67  Q_PROPERTY(bool hasCoordinate READ hasCoordinate STORED false)
68 
69  /** Location type specific data.
70  * Depending on the location type this can be e.g. a RentalVehicleStation or an Equipment instance.
71  */
72  KPUBLICTRANSPORT_PROPERTY(QVariant, data, setData)
73 
74  /** Rental vehicle dock information, if applicable for this location. */
75  Q_PROPERTY(KPublicTransport::RentalVehicleStation rentalVehicleStation READ rentalVehicleStation STORED false)
76  /** Rental vehicle information, if applicable for this location. */
77  Q_PROPERTY(KPublicTransport::RentalVehicle rentalVehicle READ rentalVehicle STORED false)
78  /** Equipment information, if applicable for this location. */
79  Q_PROPERTY(KPublicTransport::Equipment equipment READ equipment STORED false)
80 
81 public:
82  void setCoordinate(float latitude, float longitude);
83  bool hasCoordinate() const;
84 
85  /** Returns @c true if this is an default-constructed location object not specifying any location. */
86  bool isEmpty() const;
87 
88  /** The timezone this location is in, if known. */
89  QTimeZone timeZone() const;
90  void setTimeZone(const QTimeZone &tz);
91 
92  /** Location identifiers. */
93  QString identifier(const QString &identifierType) const;
94  void setIdentifier(const QString &identifierType, const QString &id);
95  QHash<QString, QString> identifiers() const;
96 
97  /** Checks if to instances refer to the same location (which does not necessarily mean they are exactly equal). */
98  static bool isSame(const Location &lhs, const Location &rhs);
99  /** Checks if two location names refer to the same location. */
100  static bool isSameName(const QString &lhs, const QString &rhs);
101 
102  /** Merge two departure instances.
103  * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
104  */
105  static Location merge(const Location &lhs, const Location &rhs);
106 
107  /** Compute the distance between two geo coordinates, in meters. */
108  static float distance(float lat1, float lon1, float lat2, float lon2);
109  /** Computes the distance in meters between two locations.
110  * Returns MAX_INT if one of the arguments has no coordinates set.
111  */
112  static float distance(const Location &lhs, const Location &rhs);
113 
114  RentalVehicleStation rentalVehicleStation() const;
115  [[deprecated("use setData instead")]] void setRentalVehicleStation(const RentalVehicleStation &dock);
116  RentalVehicle rentalVehicle() const;
117  KPublicTransport::Equipment equipment() const;
118 
119  /** Serializes one Location object to JSON. */
120  static QJsonObject toJson(const Location &loc);
121  /** Serializes an array of Location objects to JSON. */
122  static QJsonArray toJson(const std::vector<Location> &locs);
123  /** Deserialize a Location object from JSON. */
124  static Location fromJson(const QJsonObject &obj);
125  /** Dezerializes an array Location objects from JSON. */
126  static std::vector<Location> fromJson(const QJsonArray &a);
127 
128 };
129 
130 Q_DECLARE_OPERATORS_FOR_FLAGS(Location::Types)
131 
132 }
133 
134 Q_DECLARE_METATYPE(KPublicTransport::Location)
135 
136 #endif // KPUBLICTRANSPORT_LOCATION_H
Status information about equipment such as elevators or escalators.
Definition: equipment.h:24
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
Additional information for a vehicle renting station, attached to Location objects.
Definition: rentalvehicle.h:72
Definition: location.h:16
An individual rental vehicle used on a JourneySection, ie.
Definition: rentalvehicle.h:27
Type
Type of location.
Definition: location.h:34
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Oct 24 2021 23:05:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.