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 \property QGeoSatelliteInfo::satelliteSystem
153 \brief the satellite system in use, such as GPS or GLONASS.
154*/
155
156/*!
157 Returns the Satellite System (GPS, GLONASS, ...)
158
159 \note This value can be used together with \l satelliteIdentifier()
160 to uniquely identify a satellite.
161
162 \sa satelliteIdentifier()
163*/
164QGeoSatelliteInfo::SatelliteSystem QGeoSatelliteInfo::satelliteSystem() const
165{
166 return d->system;
167}
168
169/*!
170 Sets the satellite identifier number to \a satId.
171
172 The satellite identifier number can be used to identify a satellite within
173 the satellite system.
174
175 The actual value may vary, depending on the platform and the selected
176 backend.
177
178 For example, if \e nmea plugin is used, the satellite identifier for GPS
179 satellite system represents the PRN (Pseudo-random noise) number, and the
180 satellite identifier for GLONASS satellite system represents the slot
181 number.
182*/
183void QGeoSatelliteInfo::setSatelliteIdentifier(int satId)
184{
185 d.detach();
186 d->satId = satId;
187}
188
189/*!
190 \property QGeoSatelliteInfo::satelliteIdentifier
191 \brief the satellite identifier number.
192
193 The satellite identifier number can be used to identify a satellite within
194 the satellite system.
195
196 The actual value may vary, depending on the platform and the selected
197 backend.
198
199 For example, if \e nmea plugin is used, the satellite identifier for GPS
200 satellite system represents the PRN (Pseudo-random noise) number, and the
201 satellite identifier for GLONASS satellite system represents the slot
202 number.
203
204 For NMEA-based backends the satellite identifier can be used to determine
205 the satellite system type if it is not available from other sources.
206 You can refer to \l {https://gpsd.gitlab.io/gpsd/NMEA.html#_satellite_ids}
207 {satellite IDs list} to check the ID ranges for different satellite systems.
208
209 \note Depending on the platform and the selected backend, the satellite
210 identifier ranges for different satellite systems may intersect. To uniquely
211 identify a satellite, a combination of satelliteIndetifier() and
212 \l satelliteSystem() must be used.
213*/
214
215/*!
216 Returns the satellite identifier number.
217
218 \sa satelliteSystem()
219*/
220int QGeoSatelliteInfo::satelliteIdentifier() const
221{
222 return d->satId;
223}
224
225/*!
226 Sets the signal strength to \a signalStrength, in decibels.
227*/
228void QGeoSatelliteInfo::setSignalStrength(int signalStrength)
229{
230 d.detach();
231 d->signal = signalStrength;
232}
233
234/*!
235 \property QGeoSatelliteInfo::signalStrength
236 \brief the signal strength.
237*/
238
239/*!
240 Returns the signal strength, or -1 if the value has not been set.
241*/
242int QGeoSatelliteInfo::signalStrength() const
243{
244 return d->signal;
245}
246
247/*!
248 Sets the value for \a attribute to \a value.
249*/
250void QGeoSatelliteInfo::setAttribute(Attribute attribute, qreal value)
251{
252 d.detach();
253 d->doubleAttribs[attribute] = value;
254}
255
256/*!
257 Returns the value of the specified \a attribute as a qreal value.
258
259 Returns -1 if the value has not been set.
260
261 \sa hasAttribute(), setAttribute()
262*/
263qreal QGeoSatelliteInfo::attribute(Attribute attribute) const
264{
265 return d->doubleAttribs.value(attribute, -1);
266}
267
268/*!
269 Removes the specified \a attribute and its value.
270*/
271void QGeoSatelliteInfo::removeAttribute(Attribute attribute)
272{
273 const auto it = d->doubleAttribs.constFind(attribute);
274 if (it != d->doubleAttribs.cend()) {
275 d.detach();
276 d->doubleAttribs.erase(it);
277 }
278}
279
280/*!
281 Returns true if the specified \a attribute is present in this update.
282*/
283bool QGeoSatelliteInfo::hasAttribute(Attribute attribute) const
284{
285 return d->doubleAttribs.contains(attribute);
286}
287
288/*!
289 \internal
290*/
291void QGeoSatelliteInfo::detach()
292{
293 if (d)
294 d.detach();
295 else
296 d = new QGeoSatelliteInfoPrivate;
297}
298
299bool QGeoSatelliteInfo::equals(const QGeoSatelliteInfo &lhs, const QGeoSatelliteInfo &rhs)
300{
301 return *lhs.d == *rhs.d;
302}
303
304#ifndef QT_NO_DEBUG_STREAM
305QDebug QGeoSatelliteInfo::debugStreaming(QDebug dbg, const QGeoSatelliteInfo &info)
306{
307 QDebugStateSaver saver(dbg);
308 dbg.nospace() << "QGeoSatelliteInfo(system=" << info.d->system;
309 dbg << ", satId=" << info.d->satId;
310 dbg << ", signal-strength=" << info.d->signal;
311
312
313 const QList<QGeoSatelliteInfo::Attribute> attribs = info.d->doubleAttribs.keys();
314 for (qsizetype i = 0; i < attribs.size(); ++i) {
315 dbg << ", ";
316 switch (attribs[i]) {
317 case QGeoSatelliteInfo::Elevation:
318 dbg << "Elevation=";
319 break;
320 case QGeoSatelliteInfo::Azimuth:
321 dbg << "Azimuth=";
322 break;
323 }
324 dbg << info.d->doubleAttribs[attribs[i]];
325 }
326 dbg << ')';
327 return dbg;
328}
329#endif // QT_NO_DEBUG_STREAM
330
331#ifndef QT_NO_DATASTREAM
332/*!
333 \fn QDataStream &QGeoSatelliteInfo::operator<<(QDataStream &stream, const QGeoSatelliteInfo &info)
334
335 Writes the given \a info to the specified \a stream.
336
337 \sa {Serializing Qt Data Types}
338
339*/
340
341QDataStream &QGeoSatelliteInfo::dataStreamOut(QDataStream &stream, const QGeoSatelliteInfo &info)
342{
343 stream << info.d->signal;
344 stream << info.d->doubleAttribs;
345 stream << info.d->satId;
346 stream << int(info.d->system);
347 return stream;
348}
349#endif // QT_NO_DATASTREAM
350
351#ifndef QT_NO_DATASTREAM
352/*!
353 \fn QDataStream &QGeoSatelliteInfo::operator>>(QDataStream &stream, QGeoSatelliteInfo &info)
354
355 Reads satellite information from the specified \a stream into the given
356 \a info.
357
358 \sa {Serializing Qt Data Types}
359*/
360
361QDataStream &QGeoSatelliteInfo::dataStreamIn(QDataStream &stream, QGeoSatelliteInfo &info)
362{
363 int system;
364 stream >> info.d->signal;
365 stream >> info.d->doubleAttribs;
366 stream >> info.d->satId;
367 stream >> system;
368 info.d->system = (QGeoSatelliteInfo::SatelliteSystem)system;
369 return stream;
370}
371#endif // QT_NO_DATASTREAM
372
373QGeoSatelliteInfoPrivate::QGeoSatelliteInfoPrivate() : QSharedData()
374{
375
376}
377
378QGeoSatelliteInfoPrivate::QGeoSatelliteInfoPrivate(const QGeoSatelliteInfoPrivate &other)
379 : QSharedData(other)
380{
381 signal = other.signal;
382 satId = other.satId;
383 system = other.system;
384 doubleAttribs = other.doubleAttribs;
385}
386
387QGeoSatelliteInfoPrivate::~QGeoSatelliteInfoPrivate() {}
388
389bool QGeoSatelliteInfoPrivate::operator==(const QGeoSatelliteInfoPrivate &other) const
390{
391 return signal == other.signal
392 && satId == other.satId
393 && system == other.system
394 && doubleAttribs == other.doubleAttribs;
395}
396
397QGeoSatelliteInfoPrivate *QGeoSatelliteInfoPrivate::get(const QGeoSatelliteInfo &info)
398{
399 return info.d.data();
400}
401
402size_t qHash(const QGeoSatelliteInfo &key, size_t seed) noexcept
403{
404 // Other properties and attributes might change
405 return qHashMulti(seed, key.d->satId, key.d->system);
406}
407
408namespace QTest
409{
410
411char *toString(const QGeoSatelliteInfo &info)
412{
413 QString result;
414 QDebug dbg(&result);
415 dbg << info;
416
417 return qstrdup(qPrintable(result));
418}
419
420}
421
422
423QT_END_NAMESPACE
char * toString(const QGeoSatelliteInfo &info)
size_t qHash(const QGeoSatelliteInfo &key, size_t seed) noexcept