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