File indexing completed on 2024-12-29 04:49:57

0001 /*
0002     SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "place.h"
0008 #include "datatypes_impl.h"
0009 #include "datatypes_p.h"
0010 #include "locationutil.h"
0011 
0012 #include <cmath>
0013 
0014 using namespace KItinerary;
0015 
0016 namespace KItinerary {
0017 
0018 class GeoCoordinatesPrivate : public QSharedData
0019 {
0020 public:
0021     float latitude = NAN;
0022     float longitude = NAN;
0023 };
0024 
0025 KITINERARY_MAKE_CLASS(GeoCoordinates)
0026 KITINERARY_MAKE_PROPERTY(GeoCoordinates, float, latitude, setLatitude)
0027 KITINERARY_MAKE_PROPERTY(GeoCoordinates, float, longitude, setLongitude)
0028 KITINERARY_MAKE_OPERATOR(GeoCoordinates)
0029 
0030 GeoCoordinates::GeoCoordinates(float latitude, float longitude) :
0031     d(*s_GeoCoordinates_shared_null())
0032 {
0033     d.detach();
0034     d->latitude = latitude;
0035     d->longitude = longitude;
0036 }
0037 
0038 bool GeoCoordinates::isValid() const
0039 {
0040     return !std::isnan(d->latitude) && !std::isnan(d->longitude);
0041 }
0042 
0043 class PostalAddressPrivate : public QSharedData
0044 {
0045 public:
0046     QString streetAddress;
0047     QString addressLocality;
0048     QString postalCode;
0049     QString addressRegion;
0050     QString addressCountry;
0051 };
0052 
0053 KITINERARY_MAKE_CLASS(PostalAddress)
0054 KITINERARY_MAKE_PROPERTY(PostalAddress, QString, streetAddress, setStreetAddress)
0055 KITINERARY_MAKE_PROPERTY(PostalAddress, QString, addressLocality, setAddressLocality)
0056 KITINERARY_MAKE_PROPERTY(PostalAddress, QString, postalCode, setPostalCode)
0057 KITINERARY_MAKE_PROPERTY(PostalAddress, QString, addressRegion, setAddressRegion)
0058 KITINERARY_MAKE_PROPERTY(PostalAddress, QString, addressCountry, setAddressCountry)
0059 KITINERARY_MAKE_OPERATOR(PostalAddress)
0060 
0061 bool PostalAddress::isEmpty() const
0062 {
0063     return d->streetAddress.isEmpty() && d->addressLocality.isEmpty()
0064         && d->postalCode.isEmpty() && d->addressRegion.isEmpty()
0065         && d->addressCountry.isEmpty();
0066 }
0067 
0068 
0069 class PlacePrivate : public QSharedData
0070 {
0071     KITINERARY_PRIVATE_BASE_GADGET(Place)
0072 public:
0073     QString name;
0074     PostalAddress address;
0075     GeoCoordinates geo;
0076     QString telephone;
0077     QString identifier;
0078 };
0079 
0080 KITINERARY_MAKE_CLASS(Place)
0081 KITINERARY_MAKE_PROPERTY(Place, QString, name, setName)
0082 KITINERARY_MAKE_PROPERTY(Place, PostalAddress, address, setAddress)
0083 KITINERARY_MAKE_PROPERTY(Place, GeoCoordinates, geo, setGeo)
0084 KITINERARY_MAKE_PROPERTY(Place, QString, telephone, setTelephone)
0085 KITINERARY_MAKE_PROPERTY(Place, QString, identifier, setIdentifier)
0086 KITINERARY_MAKE_OPERATOR(Place)
0087 
0088 QUrl Place::geoUri() const
0089 {
0090     return LocationUtil::geoUri(*this);
0091 }
0092 
0093 
0094 class AirportPrivate : public PlacePrivate
0095 {
0096     KITINERARY_PRIVATE_GADGET(Airport)
0097 public:
0098     QString iataCode;
0099 };
0100 
0101 KITINERARY_MAKE_DERIVED_CLASS(Airport, Place)
0102 KITINERARY_MAKE_PROPERTY(Airport, QString, iataCode, setIataCode)
0103 KITINERARY_MAKE_OPERATOR(Airport)
0104 
0105 class BoatTerminalPrivate : public PlacePrivate
0106 {
0107     KITINERARY_PRIVATE_GADGET(BoatTerminal)
0108 };
0109 KITINERARY_MAKE_DERIVED_CLASS(BoatTerminal, Place)
0110 KITINERARY_MAKE_OPERATOR(BoatTerminal)
0111 
0112 class TrainStationPrivate : public PlacePrivate
0113 {
0114     KITINERARY_PRIVATE_GADGET(TrainStation)
0115 };
0116 KITINERARY_MAKE_DERIVED_CLASS(TrainStation, Place)
0117 KITINERARY_MAKE_OPERATOR(TrainStation)
0118 
0119 class BusStationPrivate : public PlacePrivate
0120 {
0121     KITINERARY_PRIVATE_GADGET(BusStation)
0122 };
0123 KITINERARY_MAKE_DERIVED_CLASS(BusStation, Place)
0124 KITINERARY_MAKE_OPERATOR(BusStation)
0125 
0126 class TouristAttractionPrivate: public PlacePrivate
0127 {
0128     KITINERARY_PRIVATE_GADGET(TouristAttraction)
0129 };
0130 KITINERARY_MAKE_DERIVED_CLASS(TouristAttraction, Place)
0131 KITINERARY_MAKE_OPERATOR(TouristAttraction)
0132 
0133 }
0134 
0135 template <>
0136 KItinerary::PlacePrivate *QExplicitlySharedDataPointer<KItinerary::PlacePrivate>::clone()
0137 {
0138     return d->clone();
0139 }
0140 
0141 #include "moc_place.cpp"