KItinerary

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

KDE's Doxygen guidelines are available online.