digiKam
geodatacontainer.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2006-09-19
7  * Description : Geolocation data container.
8  *
9  * Copyright (C) 2006-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * ============================================================ */
22 
23 #ifndef DIGIKAM_GEO_DATA_CONTAINER_H
24 #define DIGIKAM_GEO_DATA_CONTAINER_H
25 
26 // Qt includes
27 
28 #include <QStringList>
29 #include <QMetaType>
30 
32 {
33 
35 {
36 public:
37 
39  : m_interpolated(false),
40  m_altitude (0.0),
41  m_latitude (0.0),
42  m_longitude (0.0)
43  {
44  };
45 
47  double latitude,
48  double longitude,
49  bool interpolated)
50  : m_interpolated(interpolated),
51  m_altitude (altitude),
52  m_latitude (latitude),
53  m_longitude (longitude)
54  {
55  };
56 
58  {
59  };
60 
62  {
63  m_interpolated = data.isInterpolated();
64  m_altitude = data.altitude();
65  m_latitude = data.latitude();
66  m_longitude = data.longitude();
67  };
68 
70  {
71  m_interpolated = data.isInterpolated();
72  m_altitude = data.altitude();
73  m_latitude = data.latitude();
74  m_longitude = data.longitude();
75 
76  return *this;
77  };
78 
79  // use this instead of '==', because '==' implies having the
80  // same value for m_interpolated
81 
82  bool sameCoordinatesAs(const GeoDataContainer& a) const
83  {
84  return (
85  (a.m_altitude == m_altitude) &&
86  (a.m_latitude == m_latitude) &&
87  (a.m_longitude == m_longitude)
88  );
89  }
90 
91  void setInterpolated(bool ite) { m_interpolated = ite; };
92  void setAltitude(double alt) { m_altitude = alt; };
93  void setLatitude(double lat) { m_latitude = lat; };
94  void setLongitude(double lng) { m_longitude = lng; };
95 
96  bool isInterpolated() const { return m_interpolated; };
97  double altitude() const { return m_altitude; };
98  double latitude() const { return m_latitude; };
99  double longitude() const { return m_longitude; };
100 
101  QString altitudeString() const { return QString::number(m_altitude, 'g', 12); }
102  QString latitudeString() const { return QString::number(m_latitude, 'g', 12); }
103  QString longitudeString() const { return QString::number(m_longitude, 'g', 12); }
104 
105  QString geoUrl() const
106  {
107  return QString::fromLatin1("geo:%1,%2,%3")
108  .arg(latitudeString())
109  .arg(longitudeString())
110  .arg(altitudeString());
111  }
112 
113  static GeoDataContainer fromGeoUrl(const QString& url, bool* const parsedOkay)
114  {
115  // parse geo:-uri according to (only partially implemented):
116  // https://tools.ietf.org/html/draft-ietf-geopriv-geo-uri-04
117  // TODO: verify that we follow the spec fully!
118 
119  if (!url.startsWith(QLatin1String("geo:")))
120  {
121  // TODO: error
122 
123  if (parsedOkay)
124  {
125  *parsedOkay = false;
126  }
127 
128  return GeoDataContainer();
129  }
130 
131  const QStringList parts = url.mid(4).split(QLatin1Char(','));
132 
134 
135  if ((parts.size() == 3) || (parts.size() == 2))
136  {
137  bool okay = true;
138  double ptLongitude = 0.0;
139  double ptAltitude = 0.0;
140  double ptLatitude = parts[0].toDouble(&okay);
141 
142  if (okay)
143  {
144  ptLongitude = parts[1].toDouble(&okay);
145  }
146 
147  if (okay && (parts.size() == 3))
148  {
149  ptAltitude = parts[2].toDouble(&okay);
150  }
151 
152  if (!okay)
153  {
154  *parsedOkay = false;
155 
156  return GeoDataContainer();
157  }
158 
159  position = GeoDataContainer(ptAltitude, ptLatitude, ptLongitude, false);
160  }
161  else
162  {
163  if (parsedOkay)
164  {
165  *parsedOkay = false;
166  }
167 
168  return GeoDataContainer();
169  }
170 
171  if (parsedOkay)
172  {
173  *parsedOkay = true;
174  }
175 
176  return position;
177  }
178 
179 private:
180 
181  bool m_interpolated;
182 
183  double m_altitude;
184  double m_latitude;
185  double m_longitude;
186 };
187 
188 } // namespace DigikamGenericGeolocationEditPlugin
189 
191 
192 #endif // DIGIKAM_GEO_DATA_CONTAINER_H
bool isInterpolated() const
Definition: geodatacontainer.h:96
QString geoUrl() const
Definition: geodatacontainer.h:105
GeoDataContainer & operator=(const GeoDataContainer &data)
Definition: geodatacontainer.h:69
static GeoDataContainer fromGeoUrl(const QString &url, bool *const parsedOkay)
Definition: geodatacontainer.h:113
void setInterpolated(bool ite)
Definition: geodatacontainer.h:91
GeoDataContainer(double altitude, double latitude, double longitude, bool interpolated)
Definition: geodatacontainer.h:46
~GeoDataContainer()
Definition: geodatacontainer.h:57
QString longitudeString() const
Definition: geodatacontainer.h:103
double longitude() const
Definition: geodatacontainer.h:99
double latitude() const
Definition: geodatacontainer.h:98
double altitude() const
Definition: geodatacontainer.h:97
void setLatitude(double lat)
Definition: geodatacontainer.h:93
QString latitudeString() const
Definition: geodatacontainer.h:102
GeoDataContainer(const GeoDataContainer &data)
Definition: geodatacontainer.h:61
void setLongitude(double lng)
Definition: geodatacontainer.h:94
QString altitudeString() const
Definition: geodatacontainer.h:101
void setAltitude(double alt)
Definition: geodatacontainer.h:92
bool sameCoordinatesAs(const GeoDataContainer &a) const
Definition: geodatacontainer.h:82
GeoDataContainer()
Definition: geodatacontainer.h:38
Definition: geolocationedit.cpp:97
Definition: scan.h:26