KPublicTransport

location.h
1/*
2 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
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#include <QVariant>
12
13class QJsonArray;
14class QJsonObject;
15class QTimeZone;
16template <typename K, typename T> class QHash;
17
18namespace KPublicTransport {
19
20class LocationPrivate;
21class Equipment;
22class RentalVehicle;
23class 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 */
29class KPUBLICTRANSPORT_EXPORT Location
30{
31 KPUBLICTRANSPORT_GADGET(Location)
32public:
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
81public:
82 void setCoordinate(float latitude, float longitude);
83 [[nodiscard]] bool hasCoordinate() const;
84
85 /** Returns @c true if this is an default-constructed location object not specifying any location. */
86 [[nodiscard]] bool isEmpty() const;
87
88 /** The timezone this location is in, if known. */
89 [[nodiscard]] QTimeZone timeZone() const;
90 void setTimeZone(const QTimeZone &tz);
91
92 /** Location identifiers. */
93 Q_INVOKABLE [[nodiscard]] QString identifier(const QString &identifierType) const;
94 void setIdentifier(const QString &identifierType, const QString &id);
95 [[nodiscard]] bool hasIdentifier(const QString &identifierType) const;
96 [[nodiscard]] QHash<QString, QString> identifiers() const;
97
98 /** Checks if to instances refer to the same location (which does not necessarily mean they are exactly equal). */
99 [[nodiscard]] static bool isSame(const Location &lhs, const Location &rhs);
100 /** Checks if two location names refer to the same location. */
101 [[nodiscard]] static bool isSameName(const QString &lhs, const QString &rhs);
102
103 /** Merge two departure instances.
104 * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
105 */
106 [[nodiscard]] static Location merge(const Location &lhs, const Location &rhs);
107
108 /** Compute the distance between two geo coordinates, in meters. */
109 [[nodiscard]] static float distance(float lat1, float lon1, float lat2, float lon2);
110 /** Computes the distance in meters between two locations.
111 * Returns MAX_INT if one of the arguments has no coordinates set.
112 */
113 [[nodiscard]] static float distance(const Location &lhs, const Location &rhs);
114
115 [[nodiscard]] RentalVehicleStation rentalVehicleStation() const;
116 [[deprecated("use setData instead")]] void setRentalVehicleStation(const RentalVehicleStation &dock);
117 [[nodiscard]] RentalVehicle rentalVehicle() const;
118 [[nodiscard]] KPublicTransport::Equipment equipment() const;
119
120 /** Serializes one Location object to JSON. */
121 [[nodiscard]] static QJsonObject toJson(const Location &loc);
122 /** Serializes an array of Location objects to JSON. */
123 [[nodiscard]] static QJsonArray toJson(const std::vector<Location> &locs);
124 /** Deserialize a Location object from JSON. */
125 [[nodiscard]] static Location fromJson(const QJsonObject &obj);
126 /** Dezerializes an array Location objects from JSON. */
127 [[nodiscard]] static std::vector<Location> fromJson(const QJsonArray &a);
128
129};
130
131Q_DECLARE_OPERATORS_FOR_FLAGS(Location::Types)
132
133}
134
135Q_DECLARE_METATYPE(KPublicTransport::Location)
136
137#endif // KPUBLICTRANSPORT_LOCATION_H
Status information about equipment such as elevators or escalators.
Definition equipment.h:25
Type
Type of location.
Definition location.h:34
Additional information for a vehicle renting station, attached to Location objects.
An individual rental vehicle used on a JourneySection, ie.
Query operations and data types for accessing realtime public transport information from online servi...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:06 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.