File indexing completed on 2025-01-05 03:58:30
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-04-19 0007 * Description : A class to hold the GPS related data 0008 * 0009 * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2010-2014 by Michael G. Hansen <mike at mghansen dot de> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #ifndef DIGIKAM_GPS_DATA_CONTAINER_H 0017 #define DIGIKAM_GPS_DATA_CONTAINER_H 0018 0019 // Local includes 0020 0021 #include "geocoordinates.h" 0022 0023 namespace Digikam 0024 { 0025 0026 class GPSDataContainer 0027 { 0028 public: 0029 0030 enum HasFlagsEnum 0031 { 0032 HasCoordinates = 1, 0033 HasAltitude = 2, 0034 HasIsInterpolated = 4, 0035 HasNSatellites = 8, 0036 HasDop = 16, 0037 HasFixType = 32, 0038 HasSpeed = 64 0039 }; 0040 Q_DECLARE_FLAGS(HasFlags, HasFlagsEnum) 0041 0042 public: 0043 0044 GPSDataContainer() 0045 : m_hasFlags (HasFlags()), 0046 m_coordinates(), 0047 m_nSatellites(-1), 0048 m_dop (-1), 0049 m_fixType (-1), 0050 m_speed (0) 0051 { 0052 } 0053 0054 private: 0055 0056 HasFlags m_hasFlags; 0057 GeoCoordinates m_coordinates; 0058 int m_nSatellites; 0059 qreal m_dop; 0060 int m_fixType; 0061 qreal m_speed; 0062 0063 public: 0064 0065 // general 0066 0067 bool operator==(const GPSDataContainer& b) const 0068 { 0069 if (m_hasFlags != b.m_hasFlags) 0070 { 0071 return false; 0072 } 0073 0074 if (m_hasFlags.testFlag(HasCoordinates)) 0075 { 0076 if (!(m_coordinates == b.m_coordinates)) 0077 { 0078 return false; 0079 } 0080 } 0081 0082 if (hasNSatellites()) 0083 { 0084 if (m_nSatellites != b.m_nSatellites) 0085 { 0086 return false; 0087 } 0088 } 0089 0090 if (hasDop()) 0091 { 0092 if (m_dop != b.m_dop) 0093 { 0094 return false; 0095 } 0096 } 0097 0098 if (hasFixType()) 0099 { 0100 if (m_fixType != b.m_fixType) 0101 { 0102 return false; 0103 } 0104 } 0105 0106 if (hasSpeed()) 0107 { 0108 if (m_speed != b.m_speed) 0109 { 0110 return false; 0111 } 0112 } 0113 0114 return true; 0115 } 0116 0117 inline HasFlags flags() const 0118 { 0119 return m_hasFlags; 0120 } 0121 0122 inline void clear() 0123 { 0124 m_hasFlags = HasFlags(); 0125 m_coordinates.clear(); 0126 } 0127 0128 inline void clearNonCoordinates() 0129 { 0130 m_hasFlags&= ~(HasNSatellites | HasDop | HasFixType | HasSpeed); 0131 } 0132 0133 // coordinates 0134 0135 inline GeoCoordinates getCoordinates() const 0136 { 0137 return m_coordinates; 0138 } 0139 0140 inline void setCoordinates(const GeoCoordinates& coordinates) 0141 { 0142 m_coordinates = coordinates; 0143 0144 if (coordinates.hasCoordinates()) 0145 { 0146 m_hasFlags |= HasCoordinates; 0147 } 0148 else 0149 { 0150 m_hasFlags &= ~HasCoordinates; 0151 } 0152 0153 if (coordinates.hasAltitude()) 0154 { 0155 m_hasFlags |= HasAltitude; 0156 } 0157 else 0158 { 0159 m_hasFlags &= ~HasAltitude; 0160 } 0161 0162 clearNonCoordinates(); 0163 } 0164 0165 inline void setAltitude(const qreal alt) 0166 { 0167 m_coordinates.setAlt(alt); 0168 m_hasFlags |= HasAltitude; 0169 } 0170 0171 inline bool hasAltitude() const 0172 { 0173 return m_hasFlags.testFlag(HasAltitude); 0174 } 0175 0176 inline void setLatLon(const qreal lat, const qreal lon) 0177 { 0178 m_coordinates.setLatLon(lat, lon); 0179 m_hasFlags |= HasCoordinates; 0180 0181 clearNonCoordinates(); 0182 } 0183 0184 inline void clearAltitude() 0185 { 0186 m_hasFlags &= ~HasAltitude; 0187 m_coordinates.clearAlt(); 0188 } 0189 0190 inline bool hasCoordinates() const 0191 { 0192 return m_hasFlags.testFlag(HasCoordinates); 0193 } 0194 0195 // NSatellites 0196 0197 inline int getNSatellites() const 0198 { 0199 return m_nSatellites; 0200 } 0201 0202 inline bool hasNSatellites() const 0203 { 0204 return m_hasFlags.testFlag(HasNSatellites); 0205 } 0206 0207 inline void clearNSatellites() 0208 { 0209 m_hasFlags &= ~HasNSatellites; 0210 } 0211 0212 inline void setNSatellites(const int nSatellites) 0213 { 0214 m_nSatellites = nSatellites; 0215 m_hasFlags |= HasNSatellites; 0216 } 0217 0218 // DOP 0219 0220 inline bool hasDop() const 0221 { 0222 return m_hasFlags.testFlag(HasDop); 0223 } 0224 0225 inline void clearDop() 0226 { 0227 m_hasFlags &= ~HasDop; 0228 } 0229 0230 inline void setDop(const qreal dop) 0231 { 0232 m_dop = dop; 0233 m_hasFlags |= HasDop; 0234 } 0235 0236 inline qreal getDop() const 0237 { 0238 return m_dop; 0239 } 0240 0241 // fix type 0242 0243 inline bool hasFixType() const 0244 { 0245 return m_hasFlags.testFlag(HasFixType); 0246 } 0247 0248 inline void setFixType(const int fixType) 0249 { 0250 m_fixType = fixType; 0251 m_hasFlags |= HasFixType; 0252 } 0253 0254 inline qreal getFixType() const 0255 { 0256 return m_fixType; 0257 } 0258 0259 inline void clearFixType() 0260 { 0261 m_hasFlags &= ~HasFixType; 0262 } 0263 0264 // speed 0265 0266 /** 0267 * @brief Return the speed in m/s 0268 */ 0269 inline qreal getSpeed() const 0270 { 0271 return m_speed; 0272 } 0273 0274 inline bool hasSpeed() const 0275 { 0276 return m_hasFlags.testFlag(HasSpeed); 0277 } 0278 0279 /** 0280 * @brief Set the speed in m/s 0281 */ 0282 inline void setSpeed(const qreal speed) 0283 { 0284 m_hasFlags |= HasSpeed; 0285 m_speed = speed; 0286 } 0287 0288 inline void clearSpeed() 0289 { 0290 m_hasFlags &= ~HasSpeed; 0291 } 0292 }; 0293 0294 } // namespace Digikam 0295 0296 Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::GPSDataContainer::HasFlags) 0297 0298 #endif // DIGIKAM_GPS_DATA_CONTAINER_H