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