digiKam
gpsdatacontainer.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 : 2010-04-19
7  * Description : A class to hold the GPS related data
8  *
9  * Copyright (C) 2010-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2010-2014 by Michael G. Hansen <mike at mghansen dot de>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_GPS_DATA_CONTAINER_H
26 #define DIGIKAM_GPS_DATA_CONTAINER_H
27 
28 // Local includes
29 
30 #include "geocoordinates.h"
31 
32 namespace Digikam
33 {
34 
36 {
37 public:
38 
40  {
45  HasDop = 16,
46  HasFixType = 32,
47  HasSpeed = 64
48  };
49  Q_DECLARE_FLAGS(HasFlags, HasFlagsEnum)
50 
51 public:
52 
54  : m_hasFlags (HasFlags()),
55  m_coordinates(),
56  m_nSatellites(-1),
57  m_dop (-1),
58  m_fixType (-1),
59  m_speed (0)
60  {
61  }
62 
63 private:
64 
65  HasFlags m_hasFlags;
66  GeoCoordinates m_coordinates;
67  int m_nSatellites;
68  qreal m_dop;
69  int m_fixType;
70  qreal m_speed;
71 
72 public:
73 
74  // general
75 
76  bool operator==(const GPSDataContainer& b) const
77  {
78  if (m_hasFlags != b.m_hasFlags)
79  {
80  return false;
81  }
82 
83  if (m_hasFlags.testFlag(HasCoordinates))
84  {
85  if (!(m_coordinates == b.m_coordinates))
86  {
87  return false;
88  }
89  }
90 
91  if (hasNSatellites())
92  {
93  if (m_nSatellites != b.m_nSatellites)
94  {
95  return false;
96  }
97  }
98 
99  if (hasDop())
100  {
101  if (m_dop != b.m_dop)
102  {
103  return false;
104  }
105  }
106 
107  if (hasFixType())
108  {
109  if (m_fixType != b.m_fixType)
110  {
111  return false;
112  }
113  }
114 
115  if (hasSpeed())
116  {
117  if (m_speed != b.m_speed)
118  {
119  return false;
120  }
121  }
122 
123  return true;
124  }
125 
126  inline HasFlags flags() const
127  {
128  return m_hasFlags;
129  }
130 
131  inline void clear()
132  {
133  m_hasFlags = HasFlags();
134  m_coordinates.clear();
135  }
136 
137  inline void clearNonCoordinates()
138  {
139  m_hasFlags&= ~(HasNSatellites | HasDop | HasFixType | HasSpeed);
140  }
141 
142  // coordinates
143 
145  {
146  return m_coordinates;
147  }
148 
149  inline void setCoordinates(const GeoCoordinates& coordinates)
150  {
151  m_coordinates = coordinates;
152 
153  if (coordinates.hasCoordinates())
154  {
155  m_hasFlags |= HasCoordinates;
156  }
157  else
158  {
159  m_hasFlags &= ~HasCoordinates;
160  }
161 
162  if (coordinates.hasAltitude())
163  {
164  m_hasFlags |= HasAltitude;
165  }
166  else
167  {
168  m_hasFlags &= ~HasAltitude;
169  }
170 
172  }
173 
174  inline void setAltitude(const qreal alt)
175  {
176  m_coordinates.setAlt(alt);
177  m_hasFlags |= HasAltitude;
178  }
179 
180  inline bool hasAltitude() const
181  {
182  return m_hasFlags.testFlag(HasAltitude);
183  }
184 
185  inline void setLatLon(const qreal lat, const qreal lon)
186  {
187  m_coordinates.setLatLon(lat, lon);
188  m_hasFlags |= HasCoordinates;
189 
191  }
192 
193  inline void clearAltitude()
194  {
195  m_hasFlags &= ~HasAltitude;
196  m_coordinates.clearAlt();
197  }
198 
199  inline bool hasCoordinates() const
200  {
201  return m_hasFlags.testFlag(HasCoordinates);
202  }
203 
204  // NSatellites
205 
206  inline int getNSatellites() const
207  {
208  return m_nSatellites;
209  }
210 
211  inline bool hasNSatellites() const
212  {
213  return m_hasFlags.testFlag(HasNSatellites);
214  }
215 
216  inline void clearNSatellites()
217  {
218  m_hasFlags &= ~HasNSatellites;
219  }
220 
221  inline void setNSatellites(const int nSatellites)
222  {
223  m_nSatellites = nSatellites;
224  m_hasFlags |= HasNSatellites;
225  }
226 
227  // DOP
228 
229  inline bool hasDop() const
230  {
231  return m_hasFlags.testFlag(HasDop);
232  }
233 
234  inline void clearDop()
235  {
236  m_hasFlags &= ~HasDop;
237  }
238 
239  inline void setDop(const qreal dop)
240  {
241  m_dop = dop;
242  m_hasFlags |= HasDop;
243  }
244 
245  inline qreal getDop() const
246  {
247  return m_dop;
248  }
249 
250  // fix type
251 
252  inline bool hasFixType() const
253  {
254  return m_hasFlags.testFlag(HasFixType);
255  }
256 
257  inline void setFixType(const int fixType)
258  {
259  m_fixType = fixType;
260  m_hasFlags |= HasFixType;
261  }
262 
263  inline qreal getFixType() const
264  {
265  return m_fixType;
266  }
267 
268  inline void clearFixType()
269  {
270  m_hasFlags &= ~HasFixType;
271  }
272 
273  // speed
274 
278  inline qreal getSpeed() const
279  {
280  return m_speed;
281  }
282 
283  inline bool hasSpeed() const
284  {
285  return m_hasFlags.testFlag(HasSpeed);
286  }
287 
291  inline void setSpeed(const qreal speed)
292  {
293  m_hasFlags |= HasSpeed;
294  m_speed = speed;
295  }
296 
297  inline void clearSpeed()
298  {
299  m_hasFlags &= ~HasSpeed;
300  }
301 };
302 
303 } // namespace Digikam
304 
305 Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::GPSDataContainer::HasFlags)
306 
307 #endif // DIGIKAM_GPS_DATA_CONTAINER_H
Definition: gpsdatacontainer.h:36
void setLatLon(const qreal lat, const qreal lon)
Definition: gpsdatacontainer.h:185
bool hasCoordinates() const
Definition: gpsdatacontainer.h:199
qreal getDop() const
Definition: gpsdatacontainer.h:245
void clearDop()
Definition: gpsdatacontainer.h:234
void clearSpeed()
Definition: gpsdatacontainer.h:297
void clearFixType()
Definition: gpsdatacontainer.h:268
bool hasNSatellites() const
Definition: gpsdatacontainer.h:211
bool hasDop() const
Definition: gpsdatacontainer.h:229
bool operator==(const GPSDataContainer &b) const
Definition: gpsdatacontainer.h:76
HasFlags flags() const
Definition: gpsdatacontainer.h:126
GeoCoordinates getCoordinates() const
Definition: gpsdatacontainer.h:144
qreal getSpeed() const
Return the speed in m/s.
Definition: gpsdatacontainer.h:278
bool hasSpeed() const
Definition: gpsdatacontainer.h:283
void clear()
Definition: gpsdatacontainer.h:131
bool hasFixType() const
Definition: gpsdatacontainer.h:252
void setFixType(const int fixType)
Definition: gpsdatacontainer.h:257
void setNSatellites(const int nSatellites)
Definition: gpsdatacontainer.h:221
HasFlagsEnum
Definition: gpsdatacontainer.h:40
@ HasSpeed
Definition: gpsdatacontainer.h:47
@ HasFixType
Definition: gpsdatacontainer.h:46
@ HasDop
Definition: gpsdatacontainer.h:45
@ HasAltitude
Definition: gpsdatacontainer.h:42
@ HasNSatellites
Definition: gpsdatacontainer.h:44
@ HasCoordinates
Definition: gpsdatacontainer.h:41
@ HasIsInterpolated
Definition: gpsdatacontainer.h:43
void setAltitude(const qreal alt)
Definition: gpsdatacontainer.h:174
void clearNSatellites()
Definition: gpsdatacontainer.h:216
bool hasAltitude() const
Definition: gpsdatacontainer.h:180
void clearAltitude()
Definition: gpsdatacontainer.h:193
void setDop(const qreal dop)
Definition: gpsdatacontainer.h:239
void setCoordinates(const GeoCoordinates &coordinates)
Definition: gpsdatacontainer.h:149
void clearNonCoordinates()
Definition: gpsdatacontainer.h:137
GPSDataContainer()
Definition: gpsdatacontainer.h:53
void setSpeed(const qreal speed)
Set the speed in m/s.
Definition: gpsdatacontainer.h:291
int getNSatellites() const
Definition: gpsdatacontainer.h:206
qreal getFixType() const
Definition: gpsdatacontainer.h:263
Definition: geocoordinates.h:49
void clear()
Definition: geocoordinates.cpp:137
bool hasAltitude() const
Definition: geocoordinates.cpp:116
void setAlt(const double inAlt)
Definition: geocoordinates.cpp:126
void setLatLon(const double inLat, const double inLon)
Definition: geocoordinates.cpp:107
void clearAlt()
Definition: geocoordinates.cpp:132
bool hasCoordinates() const
Definition: geocoordinates.cpp:92
Definition: datefolderview.cpp:43