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;
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)
32
33public:
34 /** Type of location. */
35 enum Type {
36 Place = 0, ///< a location that isn't of any specific type
37 Stop = 1, ///< a public transport stop (train station, bus stop, etc)
38 RentedVehicleStation = 2, ///< a pick-up/drop-off point for dock-based rental bike/scooter systems
39 RentedVehicle = 4, ///< a free-floating rental bike/scooter
40 Equipment = 8, ///< elevator/escalator
41 CarpoolPickupDropoff = 16, ///< a pickup or dropoff location for a carpool trip
42 Address = 32 ///< postal addresses
43 };
44 Q_ENUM(Type)
45 Q_DECLARE_FLAGS(Types, Type)
46 Q_FLAG(Types)
47
48 /** Location type. */
49 KPUBLICTRANSPORT_PROPERTY(Type, type, setType)
50
51 /** Human-readable name of the location. */
52 KPUBLICTRANSPORT_PROPERTY(QString, name, setName)
53 /** Latitude of the location, in degree, NaN if unknown. */
54 KPUBLICTRANSPORT_PROPERTY(double, latitude, setLatitude)
55 /** Longitude of the location, in degree, NaN if unknown. */
56 KPUBLICTRANSPORT_PROPERTY(double, longitude, setLongitude)
57
58 /** Street address of the location, if known. */
59 KPUBLICTRANSPORT_PROPERTY(QString, streetAddress, setStreetAddress)
60 /** Postal code of the location, if known. */
61 KPUBLICTRANSPORT_PROPERTY(QString, postalCode, setPostalCode)
62 /** Locality/city of the location, if known. */
63 KPUBLICTRANSPORT_PROPERTY(QString, locality, setLocality)
64 /** Region (as in ISO 3166-2) of the location, if known. */
65 KPUBLICTRANSPORT_PROPERTY(QString, region, setRegion)
66 /** Country of the location as ISO 3166-1 alpha 2 code, if known. */
67 KPUBLICTRANSPORT_PROPERTY(QString, country, setCountry)
68
69 Q_PROPERTY(bool hasCoordinate READ hasCoordinate STORED false)
70
71 /** OSM floor level of this location.
72 * Not set by default.
73 */
74 KPUBLICTRANSPORT_PROPERTY(int, floorLevel, setFloorLevel)
75 /** Indicates whether the floor level is set. */
76 Q_PROPERTY(bool hasFloorLevel READ hasFloorLevel STORED false)
77
78 /** Location type specific data.
79 * Depending on the location type this can be e.g. a RentalVehicleStation or an Equipment instance.
80 */
81 KPUBLICTRANSPORT_PROPERTY(QVariant, data, setData)
82
83 /** Rental vehicle dock information, if applicable for this location. */
85 /** Rental vehicle information, if applicable for this location. */
87 /** Equipment information, if applicable for this location. */
88 Q_PROPERTY(KPublicTransport::Equipment equipment READ equipment STORED false)
89
90 /** Icon representing the location type.
91 * Can be a qrc: URL or an XDG icon name.
92 */
93 Q_PROPERTY(QString iconName READ iconName STORED false)
94
95 /** Identifier types set on this location. */
96 Q_PROPERTY(QStringList identifierTypes READ identifierTypes STORED false)
97
98public:
99 void setCoordinate(double latitude, double longitude);
100 [[nodiscard]] bool hasCoordinate() const;
101 [[nodiscard]] bool hasFloorLevel() const;
102
103 /** Returns @c true if this is an default-constructed location object not specifying any location. */
104 [[nodiscard]] bool isEmpty() const;
105
106 /** The timezone this location is in, if known. */
107 [[nodiscard]] QTimeZone timeZone() const;
108 void setTimeZone(const QTimeZone &tz);
109
110 /** Location identifiers. */
111 [[nodiscard]] QString identifier(QAnyStringView identifierType) const;
112 Q_INVOKABLE [[nodiscard]] inline QString identifier(const QString &identifierType) const { return identifier(QAnyStringView(identifierType)); }
113 [[nodiscard]] inline QString identifier(QLatin1StringView identifierType) const { return identifier(QAnyStringView(identifierType)); }
114 void setIdentifier(const QString &identifierType, const QString &id);
115 [[nodiscard]] bool hasIdentifier(QAnyStringView identifierType) const;
116 [[nodiscard]] QStringList identifierTypes() const;
117
118 /** Checks if to instances refer to the same location (which does not necessarily mean they are exactly equal). */
119 [[nodiscard]] static bool isSame(const Location &lhs, const Location &rhs);
120 /** Checks if two location names refer to the same location. */
121 [[nodiscard]] static bool isSameName(const QString &lhs, const QString &rhs);
122
123 /** Merge two departure instances.
124 * This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
125 */
126 [[nodiscard]] static Location merge(const Location &lhs, const Location &rhs);
127
128 /** Compute the distance between two geo coordinates, in meters. */
129 [[nodiscard]] static double distance(double lat1, double lon1, double lat2, double lon2);
130 /** Computes the distance in meters between two locations.
131 * Returns NAN if one of the arguments has no coordinates set.
132 */
133 [[nodiscard]] static double distance(const Location &lhs, const Location &rhs);
134
135 [[nodiscard]] RentalVehicleStation rentalVehicleStation() const;
136 [[nodiscard]] RentalVehicle rentalVehicle() const;
137 [[nodiscard]] KPublicTransport::Equipment equipment() const;
138
139 [[nodiscard]] QString iconName() const;
140
141 /** Serializes one Location object to JSON. */
142 [[nodiscard]] static QJsonObject toJson(const Location &loc);
143 /** Serializes an array of Location objects to JSON. */
144 [[nodiscard]] static QJsonArray toJson(const std::vector<Location> &locs);
145 /** Deserialize a Location object from JSON. */
146 [[nodiscard]] static Location fromJson(const QJsonObject &obj);
147 /** Dezerializes an array Location objects from JSON. */
148 [[nodiscard]] static std::vector<Location> fromJson(const QJsonArray &a);
149
150};
151
152Q_DECLARE_OPERATORS_FOR_FLAGS(Location::Types)
153
154}
155
156Q_DECLARE_METATYPE(KPublicTransport::Location)
157
158#endif // KPUBLICTRANSPORT_LOCATION_H
Status information about equipment such as elevators or escalators.
Definition equipment.h:25
bool hasFloorLevel
Indicates whether the floor level is set.
Definition location.h:76
QStringList identifierTypes
Identifier types set on this location.
Definition location.h:96
KPublicTransport::Equipment equipment
Equipment information, if applicable for this location.
Definition location.h:88
KPublicTransport::RentalVehicle rentalVehicle
Rental vehicle information, if applicable for this location.
Definition location.h:86
double longitude
Longitude of the location, in degree, NaN if unknown.
Definition location.h:56
QTimeZone timeZone() const
The timezone this location is in, if known.
Definition location.cpp:126
KPublicTransport::RentalVehicleStation rentalVehicleStation
Rental vehicle dock information, if applicable for this location.
Definition location.h:84
QString region
Region (as in ISO 3166-2) of the location, if known.
Definition location.h:65
Type
Type of location.
Definition location.h:35
@ RentedVehicleStation
a pick-up/drop-off point for dock-based rental bike/scooter systems
Definition location.h:38
@ Place
a location that isn't of any specific type
Definition location.h:36
@ RentedVehicle
a free-floating rental bike/scooter
Definition location.h:39
@ Equipment
elevator/escalator
Definition location.h:40
@ Address
postal addresses
Definition location.h:42
@ Stop
a public transport stop (train station, bus stop, etc)
Definition location.h:37
@ CarpoolPickupDropoff
a pickup or dropoff location for a carpool trip
Definition location.h:41
QVariant data
Location type specific data.
Definition location.h:81
QString iconName
Icon representing the location type.
Definition location.h:93
int floorLevel
OSM floor level of this location.
Definition location.h:74
QString identifier(QAnyStringView identifierType) const
Location identifiers.
Definition location.cpp:145
double latitude
Latitude of the location, in degree, NaN if unknown.
Definition location.h:54
QString streetAddress
Street address of the location, if known.
Definition location.h:59
QString country
Country of the location as ISO 3166-1 alpha 2 code, if known.
Definition location.h:67
QString locality
Locality/city of the location, if known.
Definition location.h:63
QString name
Human-readable name of the location.
Definition location.h:52
QString postalCode
Postal code of the location, if known.
Definition location.h:61
bool isEmpty() const
Returns true if this is an default-constructed location object not specifying any location.
Definition location.cpp:121
Type type
Location type.
Definition location.h:49
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-2025 The KDE developers.
Generated on Fri Feb 14 2025 12:02:12 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.