1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtPositioning module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39#include "qgeosatelliteinfo.h"
40#include "qgeosatelliteinfo_p.h"
41
42#include <QHash>
43#include <QDebug>
44#include <QDataStream>
45
46QT_BEGIN_NAMESPACE
47
48/*!
49 \class QGeoSatelliteInfo
50 \inmodule QtPositioning
51 \ingroup QtPositioning-positioning
52 \since 5.2
53
54 \brief The QGeoSatelliteInfo class contains basic information about a satellite.
55
56 \sa QGeoSatelliteInfoSource
57*/
58
59/*!
60 \enum QGeoSatelliteInfo::Attribute
61 Defines the attributes for the satellite information.
62 \value Elevation The elevation of the satellite, in degrees.
63 \value Azimuth The azimuth to true north, in degrees.
64*/
65
66/*!
67 \enum QGeoSatelliteInfo::SatelliteSystem
68 Defines the GNSS system of the satellite.
69 \value Undefined Not defined.
70 \value GPS Global Positioning System (USA).
71 \value GLONASS Global Positioning System (Russia).
72
73*/
74
75
76/*!
77 Creates a satellite information object.
78*/
79QGeoSatelliteInfo::QGeoSatelliteInfo()
80 : d(new QGeoSatelliteInfoPrivate)
81{
82 d->signal = -1;
83 d->satId = -1;
84 d->system = QGeoSatelliteInfo::Undefined;
85}
86
87/*!
88 Creates a satellite information object with the values of \a other.
89*/
90
91QGeoSatelliteInfo::QGeoSatelliteInfo(const QGeoSatelliteInfo &other)
92 : d(new QGeoSatelliteInfoPrivate)
93{
94 operator=(other);
95}
96
97QGeoSatelliteInfo::QGeoSatelliteInfo(QGeoSatelliteInfoPrivate &dd) : d(&dd)
98{
99}
100
101/*!
102 Destroys a satellite information object.
103*/
104QGeoSatelliteInfo::~QGeoSatelliteInfo()
105{
106 delete d;
107}
108
109/*!
110 Assigns the values from \a other to this object.
111*/
112QGeoSatelliteInfo &QGeoSatelliteInfo::operator=(const QGeoSatelliteInfo & other)
113{
114 if (this == &other)
115 return *this;
116
117 delete d;
118 d = other.d->clone();
119
120 return *this;
121}
122
123/*!
124 Returns true if all the information for this satellite
125 are the same as those of \a other.
126*/
127bool QGeoSatelliteInfo::operator==(const QGeoSatelliteInfo &other) const
128{
129 return *d == *other.d;
130}
131
132/*!
133 \fn bool QGeoSatelliteInfo::operator!=(const QGeoSatelliteInfo &other) const;
134
135 Returns true if any of the information for this satellite
136 are not the same as those of \a other.
137*/
138
139
140/*!
141 Sets the Satellite System (GPS, GLONASS, ...) to \a system.
142*/
143void QGeoSatelliteInfo::setSatelliteSystem(SatelliteSystem system)
144{
145 d->system = system;
146}
147
148/*!
149 Returns the Satellite System (GPS, GLONASS, ...)
150*/
151QGeoSatelliteInfo::SatelliteSystem QGeoSatelliteInfo::satelliteSystem() const
152{
153 return d->system;
154}
155
156/*!
157 Sets the satellite identifier number to \a satId.
158
159 The satellite identifier number can be used to identify a satellite inside the satellite system.
160 For satellite system GPS the satellite identifier number represents the PRN (Pseudo-random noise) number.
161 For satellite system GLONASS the satellite identifier number represents the slot number.
162*/
163void QGeoSatelliteInfo::setSatelliteIdentifier(int satId)
164{
165 d->satId = satId;
166}
167
168/*!
169 Returns the satellite identifier number.
170
171 The satellite identifier number can be used to identify a satellite inside the satellite system.
172 For satellite system GPS the satellite identifier number represents the PRN (Pseudo-random noise) number.
173 For satellite system GLONASS the satellite identifier number represents the slot number.
174*/
175int QGeoSatelliteInfo::satelliteIdentifier() const
176{
177 return d->satId;
178}
179
180/*!
181 Sets the signal strength to \a signalStrength, in decibels.
182*/
183void QGeoSatelliteInfo::setSignalStrength(int signalStrength)
184{
185 d->signal = signalStrength;
186}
187
188/*!
189 Returns the signal strength, or -1 if the value has not been set.
190*/
191int QGeoSatelliteInfo::signalStrength() const
192{
193 return d->signal;
194}
195
196/*!
197 Sets the value for \a attribute to \a value.
198*/
199void QGeoSatelliteInfo::setAttribute(Attribute attribute, qreal value)
200{
201 d->doubleAttribs[int(attribute)] = value;
202}
203
204/*!
205 Returns the value of the specified \a attribute as a qreal value.
206
207 Returns -1 if the value has not been set.
208
209 \sa hasAttribute(), setAttribute()
210*/
211qreal QGeoSatelliteInfo::attribute(Attribute attribute) const
212{
213 if (d->doubleAttribs.contains(akey: int(attribute)))
214 return d->doubleAttribs[int(attribute)];
215 return -1;
216}
217
218/*!
219 Removes the specified \a attribute and its value.
220*/
221void QGeoSatelliteInfo::removeAttribute(Attribute attribute)
222{
223 d->doubleAttribs.remove(akey: int(attribute));
224}
225
226/*!
227 Returns true if the specified \a attribute is present in this update.
228*/
229bool QGeoSatelliteInfo::hasAttribute(Attribute attribute) const
230{
231 return d->doubleAttribs.contains(akey: int(attribute));
232}
233
234#ifndef QT_NO_DEBUG_STREAM
235QDebug operator<<(QDebug dbg, const QGeoSatelliteInfo &info)
236{
237 QDebugStateSaver saver(dbg);
238 dbg.nospace() << "QGeoSatelliteInfo(system=" << info.d->system;
239 dbg << ", satId=" << info.d->satId;
240 dbg << ", signal-strength=" << info.d->signal;
241
242
243 QList<int> attribs = info.d->doubleAttribs.keys();
244 for (int i = 0; i < attribs.count(); ++i) {
245 dbg << ", ";
246 switch (attribs[i]) {
247 case QGeoSatelliteInfo::Elevation:
248 dbg << "Elevation=";
249 break;
250 case QGeoSatelliteInfo::Azimuth:
251 dbg << "Azimuth=";
252 break;
253 }
254 dbg << info.d->doubleAttribs[attribs[i]];
255 }
256 dbg << ')';
257 return dbg;
258}
259#endif
260
261#ifndef QT_NO_DATASTREAM
262/*!
263 \fn QDataStream &operator<<(QDataStream &stream, const QGeoSatelliteInfo &info)
264 \relates QGeoSatelliteInfo
265
266 Writes the given \a info to the specified \a stream.
267
268 \sa {Serializing Qt Data Types}
269
270*/
271
272QDataStream &operator<<(QDataStream &stream, const QGeoSatelliteInfo &info)
273{
274 stream << info.d->signal;
275 stream << info.d->doubleAttribs;
276 stream << info.d->satId;
277 stream << int(info.d->system);
278 return stream;
279}
280#endif
281
282#ifndef QT_NO_DATASTREAM
283/*!
284 \fn QDataStream &operator>>(QDataStream &stream, QGeoSatelliteInfo &info)
285 \relates QGeoSatelliteInfo
286
287 Reads satellite information from the specified \a stream into the given
288 \a info.
289
290 \sa {Serializing Qt Data Types}
291*/
292
293QDataStream &operator>>(QDataStream &stream, QGeoSatelliteInfo &info)
294{
295 int system;
296 stream >> info.d->signal;
297 stream >> info.d->doubleAttribs;
298 stream >> info.d->satId;
299 stream >> system;
300 info.d->system = (QGeoSatelliteInfo::SatelliteSystem)system;
301 return stream;
302}
303
304QGeoSatelliteInfoPrivate::QGeoSatelliteInfoPrivate()
305{
306
307}
308
309QGeoSatelliteInfoPrivate::QGeoSatelliteInfoPrivate(const QGeoSatelliteInfoPrivate &other)
310{
311 signal = other.signal;
312 satId = other.satId;
313 system = other.system;
314 doubleAttribs = other.doubleAttribs;
315}
316
317QGeoSatelliteInfoPrivate::~QGeoSatelliteInfoPrivate() {}
318
319QGeoSatelliteInfoPrivate *QGeoSatelliteInfoPrivate::clone() const
320{
321 return new QGeoSatelliteInfoPrivate(*this);
322}
323
324bool QGeoSatelliteInfoPrivate::operator==(const QGeoSatelliteInfoPrivate &other) const
325{
326 return signal == other.signal
327 && satId == other.satId
328 && system == other.system
329 && doubleAttribs == other.doubleAttribs;
330}
331
332QGeoSatelliteInfoPrivate *QGeoSatelliteInfoPrivate::get(const QGeoSatelliteInfo &info)
333{
334 return info.d;
335}
336
337#endif
338
339QT_END_NAMESPACE
340

source code of qtlocation/src/positioning/qgeosatelliteinfo.cpp