KItinerary

place.cpp
1/*
2 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "place.h"
8#include "datatypes_impl.h"
9#include "datatypes_p.h"
10#include "locationutil.h"
11
12#include <cmath>
13
14using namespace KItinerary;
15
16namespace KItinerary {
17
18class GeoCoordinatesPrivate : public QSharedData
19{
20public:
21 float latitude = NAN;
22 float longitude = NAN;
23};
24
25KITINERARY_MAKE_CLASS(GeoCoordinates)
26KITINERARY_MAKE_PROPERTY(GeoCoordinates, float, latitude, setLatitude)
27KITINERARY_MAKE_PROPERTY(GeoCoordinates, float, longitude, setLongitude)
28KITINERARY_MAKE_OPERATOR(GeoCoordinates)
29
30GeoCoordinates::GeoCoordinates(float latitude, float longitude) :
31 d(*s_GeoCoordinates_shared_null())
32{
33 d.detach();
34 d->latitude = latitude;
35 d->longitude = longitude;
36}
37
38bool GeoCoordinates::isValid() const
39{
40 return !std::isnan(d->latitude) && !std::isnan(d->longitude);
41}
42
43class PostalAddressPrivate : public QSharedData
44{
45public:
46 QString streetAddress;
47 QString addressLocality;
48 QString postalCode;
49 QString addressRegion;
50 QString addressCountry;
51};
52
53KITINERARY_MAKE_CLASS(PostalAddress)
54KITINERARY_MAKE_PROPERTY(PostalAddress, QString, streetAddress, setStreetAddress)
55KITINERARY_MAKE_PROPERTY(PostalAddress, QString, addressLocality, setAddressLocality)
56KITINERARY_MAKE_PROPERTY(PostalAddress, QString, postalCode, setPostalCode)
57KITINERARY_MAKE_PROPERTY(PostalAddress, QString, addressRegion, setAddressRegion)
58KITINERARY_MAKE_PROPERTY(PostalAddress, QString, addressCountry, setAddressCountry)
59KITINERARY_MAKE_OPERATOR(PostalAddress)
60
61bool PostalAddress::isEmpty() const
62{
63 return d->streetAddress.isEmpty() && d->addressLocality.isEmpty()
64 && d->postalCode.isEmpty() && d->addressRegion.isEmpty()
65 && d->addressCountry.isEmpty();
66}
67
68
69class PlacePrivate : public QSharedData
70{
71 KITINERARY_PRIVATE_BASE_GADGET(Place)
72public:
73 QString name;
74 PostalAddress address;
76 QString telephone;
77 QString identifier;
78};
79
80KITINERARY_MAKE_CLASS(Place)
81KITINERARY_MAKE_PROPERTY(Place, QString, name, setName)
82KITINERARY_MAKE_PROPERTY(Place, PostalAddress, address, setAddress)
83KITINERARY_MAKE_PROPERTY(Place, GeoCoordinates, geo, setGeo)
84KITINERARY_MAKE_PROPERTY(Place, QString, telephone, setTelephone)
85KITINERARY_MAKE_PROPERTY(Place, QString, identifier, setIdentifier)
86KITINERARY_MAKE_OPERATOR(Place)
87
88QUrl Place::geoUri() const
89{
90 return LocationUtil::geoUri(*this);
91}
92
93
94class AirportPrivate : public PlacePrivate
95{
96 KITINERARY_PRIVATE_GADGET(Airport)
97public:
98 QString iataCode;
99};
100
101KITINERARY_MAKE_DERIVED_CLASS(Airport, Place)
102KITINERARY_MAKE_PROPERTY(Airport, QString, iataCode, setIataCode)
103KITINERARY_MAKE_OPERATOR(Airport)
104
105class BoatTerminalPrivate : public PlacePrivate
106{
107 KITINERARY_PRIVATE_GADGET(BoatTerminal)
108};
109KITINERARY_MAKE_DERIVED_CLASS(BoatTerminal, Place)
110KITINERARY_MAKE_OPERATOR(BoatTerminal)
111
112class TrainStationPrivate : public PlacePrivate
113{
114 KITINERARY_PRIVATE_GADGET(TrainStation)
115};
116KITINERARY_MAKE_DERIVED_CLASS(TrainStation, Place)
117KITINERARY_MAKE_OPERATOR(TrainStation)
118
119class BusStationPrivate : public PlacePrivate
120{
121 KITINERARY_PRIVATE_GADGET(BusStation)
122};
123KITINERARY_MAKE_DERIVED_CLASS(BusStation, Place)
124KITINERARY_MAKE_OPERATOR(BusStation)
125
126class TouristAttractionPrivate: public PlacePrivate
127{
128 KITINERARY_PRIVATE_GADGET(TouristAttraction)
129};
130KITINERARY_MAKE_DERIVED_CLASS(TouristAttraction, Place)
131KITINERARY_MAKE_OPERATOR(TouristAttraction)
132
133}
134
135template <>
137{
138 return d->clone();
139}
140
141#include "moc_place.cpp"
Boat or ferry terminal.
Definition place.h:116
Bus station.
Definition place.h:136
Geographic coordinates.
Definition place.h:23
Base class for places.
Definition place.h:69
Postal address.
Definition place.h:46
Tourist attraction (e.g.
Definition place.h:146
Train station.
Definition place.h:126
QUrl geoUri(const QVariant &location)
Returns a geo: URI for the given location.
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 4 2024 12:00:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.