Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qgeosatelliteinfo.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4#include "private/qgeosatelliteinfo_p.h"
5
6#include <QHash>
7#include <QDebug>
8#include <QDataStream>
9
10QT_BEGIN_NAMESPACE
11
12QT_IMPL_METATYPE_EXTERN(QGeoSatelliteInfo)
13
14/*!
15 \class QGeoSatelliteInfo
16 \inmodule QtPositioning
17 \ingroup QtPositioning-positioning
18 \ingroup shared
19 \since 5.2
20
21 \brief The QGeoSatelliteInfo class contains basic information about a satellite.
22
23 \sa QGeoSatelliteInfoSource
24*/
25
26/*!
27 \enum QGeoSatelliteInfo::Attribute
28 Defines the attributes for the satellite information.
29 \value Elevation The elevation of the satellite, in degrees.
30 \value Azimuth The azimuth to true north, in degrees.
31*/
32
33/*!
34 \enum QGeoSatelliteInfo::SatelliteSystem
35 Defines the GNSS system of the satellite.
36 \value Undefined Not defined.
37 \value GPS Global Positioning System (USA).
38 \value GLONASS Global Positioning System (Russia).
39 \value GALILEO Global navigation satellite system (EU).
40 \value BEIDOU BeiDou navigation satellite system (China).
41 \value QZSS Quasi-Zenith Satellite System (Japan).
42 \value Multiple This type normally indicates that the information is
43 received from a device that supports multiple satellite systems, and
44 the satellite system is not explicitly specified. Depending on the
45 data source, you might use other information to determine the actual
46 system type. One example of the usage of this type is an NMEA $GNGSA
47 message, which contains the IDs of the satellites being used, but
48 does not explicitly mention their system types.
49 \value CustomType The first type that can be used for user purposes. For
50 example when reimplementing NMEA data parsing in
51 \l QNmeaSatelliteInfoSource. User can add more types using
52 \c {CustomType + 1}, \c {CustomType + 2} and so on.
53*/
54
55/*!
56 Creates a satellite information object.
57*/
58QGeoSatelliteInfo::QGeoSatelliteInfo()
59 : d(new QGeoSatelliteInfoPrivate)
60{
61 d->signal = -1;
62 d->satId = -1;
63 d->system = QGeoSatelliteInfo::Undefined;
64}
65
66/*!
67 Creates a satellite information object with the values of \a other.
68*/
69
70QGeoSatelliteInfo::QGeoSatelliteInfo(const QGeoSatelliteInfo &other)
71 : d(other.d)
72{
73}
74
75QGeoSatelliteInfo::QGeoSatelliteInfo(QGeoSatelliteInfoPrivate &dd) : d(&dd)
76{
77}
78
79/*!
80 \fn QGeoSatelliteInfo::QGeoSatelliteInfo(QGeoSatelliteInfo &&other) noexcept
81 \since 6.2
82
83 Creates a satellite information object by moving from \a other.
84
85 Note that a moved-from QGeoSatelliteInfo can only be destroyed or
86 assigned to. The effect of calling other functions than the destructor
87 or one of the assignment operators is undefined.
88*/
89
90/*!
91 Destroys a satellite information object.
92*/
93QGeoSatelliteInfo::~QGeoSatelliteInfo()
94{
95}
96
97QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QGeoSatelliteInfoPrivate)
98
99/*!
100 Assigns the values from \a other to this object.
101*/
102QGeoSatelliteInfo &QGeoSatelliteInfo::operator=(const QGeoSatelliteInfo & other)
103{
104 if (this == &other)
105 return *this;
106
107 d = other.d;
108 return *this;
109}
110
111/*!
112 \fn QGeoSatelliteInfo &QGeoSatelliteInfo::operator=(QGeoSatelliteInfo &&other) noexcept
113 \since 6.2
114
115 Move-assigns the value from \a other to this object
116
117 Note that a moved-from QGeoSatelliteInfo can only be destroyed or
118 assigned to. The effect of calling other functions than the destructor
119 or one of the assignment operators is undefined.
120*/
121
122/*!
123 \fn bool QGeoSatelliteInfo::operator==(const QGeoSatelliteInfo &lhs, const QGeoSatelliteInfo &rhs)
124
125 Returns \c true if all the parameters of the \a lhs satellite are the same
126 as those of \a rhs. Otherwise returns \c false.
127*/
128
129/*!
130 \fn bool QGeoSatelliteInfo::operator!=(const QGeoSatelliteInfo &lhs, const QGeoSatelliteInfo &rhs)
131
132 Returns \c true if any of the parameters of the \a lhs satellite are not
133 the same as those of \a rhs. Otherwise returns \c false.
134*/
135
136/*!
137 \fn void QGeoSatelliteInfo::swap(QGeoSatelliteInfo &other)
138 \since 6.2
139 \memberswap{satellite information}
140*/
141
142/*!
143 Sets the Satellite System (GPS, GLONASS, ...) to \a system.
144*/
145void QGeoSatelliteInfo::setSatelliteSystem(SatelliteSystem system)
146{
147 d.detach();
148 d->system = system;
149}
150
151/*!
152 Returns the Satellite System (GPS, GLONASS, ...)
153
154 \note This value can be used together with \l satelliteIdentifier()
155 to uniquely identify a satellite.
156
157 \sa satelliteIdentifier()
158*/
159QGeoSatelliteInfo::SatelliteSystem QGeoSatelliteInfo::satelliteSystem() const
160{
161 return d->system;
162}
163
164/*!
165 Sets the satellite identifier number to \a satId.
166
167 The satellite identifier number can be used to identify a satellite within
168 the satellite system.
169
170 The actual value may vary, depending on the platform and the selected
171 backend.
172
173 For example, if \e nmea plugin is used, the satellite identifier for GPS
174 satellite system represents the PRN (Pseudo-random noise) number, and the
175 satellite identifier for GLONASS satellite system represents the slot
176 number.
177*/
178void QGeoSatelliteInfo::setSatelliteIdentifier(int satId)
179{
180 d.detach();
181 d->satId = satId;
182}
183
184/*!
185 Returns the satellite identifier number.
186
187 The satellite identifier number can be used to identify a satellite within
188 the satellite system.
189
190 The actual value may vary, depending on the platform and the selected
191 backend.
192
193 For example, if \e nmea plugin is used, the satellite identifier for GPS
194 satellite system represents the PRN (Pseudo-random noise) number, and the
195 satellite identifier for GLONASS satellite system represents the slot
196 number.
197
198 For NMEA-based backends the satellite identifier can be used to determine
199 the satellite system type if it is not available from other sources.
200 You can refer to \l {https://gpsd.gitlab.io/gpsd/NMEA.html#_satellite_ids}
201 {satellite IDs list} to check the ID ranges for different satellite systems.
202
203 \note Depending on the platform and the selected backend, the satellite
204 identifier ranges for different satellite systems may intersect. To uniquely
205 identify a satellite, a combination of satelliteIndetifier() and
206 \l satelliteSystem() must be used.
207
208 \sa satelliteSystem()
209*/
210int QGeoSatelliteInfo::satelliteIdentifier() const
211{
212 return d->satId;
213}
214
215/*!
216 Sets the signal strength to \a signalStrength, in decibels.
217*/
218void QGeoSatelliteInfo::setSignalStrength(int signalStrength)
219{
220 d.detach();
221 d->signal = signalStrength;
222}
223
224/*!
225 Returns the signal strength, or -1 if the value has not been set.
226*/
227int QGeoSatelliteInfo::signalStrength() const
228{
229 return d->signal;
230}
231
232/*!
233 Sets the value for \a attribute to \a value.
234*/
235void QGeoSatelliteInfo::setAttribute(Attribute attribute, qreal value)
236{
237 d.detach();
238 d->doubleAttribs[int(attribute)] = value;
239}
240
241/*!
242 Returns the value of the specified \a attribute as a qreal value.
243
244 Returns -1 if the value has not been set.
245
246 \sa hasAttribute(), setAttribute()
247*/
248qreal QGeoSatelliteInfo::attribute(Attribute attribute) const
249{
250 if (d->doubleAttribs.contains(int(attribute)))
251 return d->doubleAttribs[int(attribute)];
252 return -1;
253}
254
255/*!
256 Removes the specified \a attribute and its value.
257*/
258void QGeoSatelliteInfo::removeAttribute(Attribute attribute)
259{
260 d.detach();
261 d->doubleAttribs.remove(int(attribute));
262}
263
264/*!
265 Returns true if the specified \a attribute is present in this update.
266*/
267bool QGeoSatelliteInfo::hasAttribute(Attribute attribute) const
268{
269 return d->doubleAttribs.contains(int(attribute));
270}
271
272/*!
273 \internal
274*/
275void QGeoSatelliteInfo::detach()
276{
277 if (d)
278 d.detach();
279 else
280 d = new QGeoSatelliteInfoPrivate;
281}
282
283bool QGeoSatelliteInfo::equals(const QGeoSatelliteInfo &lhs, const QGeoSatelliteInfo &rhs)
284{
285 return *lhs.d == *rhs.d;
286}
287
288#ifndef QT_NO_DEBUG_STREAM
289QDebug QGeoSatelliteInfo::debugStreaming(QDebug dbg, const QGeoSatelliteInfo &info)
290{
291 QDebugStateSaver saver(dbg);
292 dbg.nospace() << "QGeoSatelliteInfo(system=" << info.d->system;
293 dbg << ", satId=" << info.d->satId;
294 dbg << ", signal-strength=" << info.d->signal;
295
296
297 QList<int> attribs = info.d->doubleAttribs.keys();
298 for (int i = 0; i < attribs.size(); ++i) {
299 dbg << ", ";
300 switch (attribs[i]) {
301 case QGeoSatelliteInfo::Elevation:
302 dbg << "Elevation=";
303 break;
304 case QGeoSatelliteInfo::Azimuth:
305 dbg << "Azimuth=";
306 break;
307 }
308 dbg << info.d->doubleAttribs[attribs[i]];
309 }
310 dbg << ')';
311 return dbg;
312}
313#endif // QT_NO_DEBUG_STREAM
314
315#ifndef QT_NO_DATASTREAM
316/*!
317 \fn QDataStream &QGeoSatelliteInfo::operator<<(QDataStream &stream, const QGeoSatelliteInfo &info)
318
319 Writes the given \a info to the specified \a stream.
320
321 \sa {Serializing Qt Data Types}
322
323*/
324
325QDataStream &QGeoSatelliteInfo::dataStreamOut(QDataStream &stream, const QGeoSatelliteInfo &info)
326{
327 stream << info.d->signal;
328 stream << info.d->doubleAttribs;
329 stream << info.d->satId;
330 stream << int(info.d->system);
331 return stream;
332}
333#endif // QT_NO_DATASTREAM
334
335#ifndef QT_NO_DATASTREAM
336/*!
337 \fn QDataStream &QGeoSatelliteInfo::operator>>(QDataStream &stream, QGeoSatelliteInfo &info)
338
339 Reads satellite information from the specified \a stream into the given
340 \a info.
341
342 \sa {Serializing Qt Data Types}
343*/
344
345QDataStream &QGeoSatelliteInfo::dataStreamIn(QDataStream &stream, QGeoSatelliteInfo &info)
346{
347 int system;
348 stream >> info.d->signal;
349 stream >> info.d->doubleAttribs;
350 stream >> info.d->satId;
351 stream >> system;
352 info.d->system = (QGeoSatelliteInfo::SatelliteSystem)system;
353 return stream;
354}
355#endif // QT_NO_DATASTREAM
356
357QGeoSatelliteInfoPrivate::QGeoSatelliteInfoPrivate() : QSharedData()
358{
359
360}
361
362QGeoSatelliteInfoPrivate::QGeoSatelliteInfoPrivate(const QGeoSatelliteInfoPrivate &other)
363 : QSharedData(other)
364{
365 signal = other.signal;
366 satId = other.satId;
367 system = other.system;
368 doubleAttribs = other.doubleAttribs;
369}
370
371QGeoSatelliteInfoPrivate::~QGeoSatelliteInfoPrivate() {}
372
373bool QGeoSatelliteInfoPrivate::operator==(const QGeoSatelliteInfoPrivate &other) const
374{
375 return signal == other.signal
376 && satId == other.satId
377 && system == other.system
378 && doubleAttribs == other.doubleAttribs;
379}
380
381QGeoSatelliteInfoPrivate *QGeoSatelliteInfoPrivate::get(const QGeoSatelliteInfo &info)
382{
383 return info.d.data();
384}
385
386size_t qHash(const QGeoSatelliteInfo &key, size_t seed) noexcept
387{
388 // Other properties and attributes might change
389 return qHashMulti(seed, key.d->satId, key.d->system);
390}
391
392namespace QTest
393{
394
395char *toString(const QGeoSatelliteInfo &info)
396{
397 QString result;
398 QDebug dbg(&result);
399 dbg << info;
400
401 return qstrdup(qPrintable(result));
402}
403
404}
405
406
407QT_END_NAMESPACE
char * toString(const QGeoSatelliteInfo &info)
size_t qHash(const QGeoSatelliteInfo &key, size_t seed) noexcept