|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include "qgeosatelliteinfo.h" |
|
42 |
|
43 #include <QHash> |
|
44 #include <QDebug> |
|
45 #include <QDataStream> |
|
46 |
|
47 QTM_BEGIN_NAMESPACE |
|
48 |
|
49 class QGeoSatelliteInfoPrivate |
|
50 { |
|
51 public: |
|
52 int prn; |
|
53 int signal; |
|
54 QHash<int, qreal> doubleAttribs; |
|
55 }; |
|
56 |
|
57 |
|
58 /*! |
|
59 \class QGeoSatelliteInfo |
|
60 \brief The QGeoSatelliteInfo class contains basic information about a satellite. |
|
61 \ingroup location |
|
62 |
|
63 \sa QGeoSatelliteInfoSource |
|
64 */ |
|
65 |
|
66 /*! |
|
67 \enum QGeoSatelliteInfo::Attribute |
|
68 Defines the attributes for the satellite information. |
|
69 |
|
70 \value Elevation The elevation of the satellite, in degrees. |
|
71 \value Azimuth The azimuth to true north, in degrees. |
|
72 */ |
|
73 |
|
74 |
|
75 /*! |
|
76 Creates a satellite information object. |
|
77 */ |
|
78 QGeoSatelliteInfo::QGeoSatelliteInfo() |
|
79 : d(new QGeoSatelliteInfoPrivate) |
|
80 { |
|
81 d->prn = -1; |
|
82 d->signal = -1; |
|
83 } |
|
84 |
|
85 /*! |
|
86 Creates a satellite information object with the values of \a other. |
|
87 */ |
|
88 |
|
89 QGeoSatelliteInfo::QGeoSatelliteInfo(const QGeoSatelliteInfo &other) |
|
90 : d(new QGeoSatelliteInfoPrivate) |
|
91 { |
|
92 operator=(other); |
|
93 } |
|
94 |
|
95 /*! |
|
96 Destroys a satellite information object. |
|
97 */ |
|
98 QGeoSatelliteInfo::~QGeoSatelliteInfo() |
|
99 { |
|
100 delete d; |
|
101 } |
|
102 |
|
103 /*! |
|
104 Assigns the values from \a other to this object. |
|
105 */ |
|
106 QGeoSatelliteInfo &QGeoSatelliteInfo::operator=(const QGeoSatelliteInfo & other) |
|
107 { |
|
108 if (this == &other) |
|
109 return *this; |
|
110 |
|
111 d->prn = other.d->prn; |
|
112 d->signal = other.d->signal; |
|
113 d->doubleAttribs = other.d->doubleAttribs; |
|
114 return *this; |
|
115 } |
|
116 |
|
117 /*! |
|
118 Returns true if all the information for this satellite |
|
119 are the same as those of \a other. |
|
120 */ |
|
121 bool QGeoSatelliteInfo::operator==(const QGeoSatelliteInfo &other) const |
|
122 { |
|
123 return d->prn == other.d->prn |
|
124 && d->signal == other.d->signal |
|
125 && d->doubleAttribs == other.d->doubleAttribs; |
|
126 } |
|
127 |
|
128 /*! |
|
129 \fn bool QGeoSatelliteInfo::operator!=(const QGeoSatelliteInfo &other) const; |
|
130 |
|
131 Returns true if any of the information for this satellite |
|
132 are not the same as those of \a other. |
|
133 */ |
|
134 |
|
135 /*! |
|
136 Sets the PRN (Pseudo-random noise) number to \a prn. |
|
137 |
|
138 The PRN number can be used to identify a satellite. |
|
139 */ |
|
140 void QGeoSatelliteInfo::setPrnNumber(int prn) |
|
141 { |
|
142 d->prn = prn; |
|
143 } |
|
144 |
|
145 /*! |
|
146 Returns the PRN (Pseudo-random noise) number, or -1 if the value has not been set. |
|
147 */ |
|
148 |
|
149 int QGeoSatelliteInfo::prnNumber() const |
|
150 { |
|
151 return d->prn; |
|
152 } |
|
153 |
|
154 /*! |
|
155 Sets the signal strength to \a signalStrength, in decibels. |
|
156 */ |
|
157 void QGeoSatelliteInfo::setSignalStrength(int signalStrength) |
|
158 { |
|
159 d->signal = signalStrength; |
|
160 } |
|
161 |
|
162 /*! |
|
163 Returns the signal strength, or -1 if the value has not been set. |
|
164 */ |
|
165 int QGeoSatelliteInfo::signalStrength() const |
|
166 { |
|
167 return d->signal; |
|
168 } |
|
169 |
|
170 /*! |
|
171 Sets the value for \a attribute to \a value. |
|
172 */ |
|
173 void QGeoSatelliteInfo::setAttribute(Attribute attribute, qreal value) |
|
174 { |
|
175 d->doubleAttribs[int(attribute)] = value; |
|
176 } |
|
177 |
|
178 /*! |
|
179 Returns the value of the specified \a attribute as a qreal value. |
|
180 |
|
181 Returns -1 if the value has not been set. |
|
182 |
|
183 \sa hasAttribute(), setAttribute() |
|
184 */ |
|
185 qreal QGeoSatelliteInfo::attribute(Attribute attribute) const |
|
186 { |
|
187 if (d->doubleAttribs.contains(int(attribute))) |
|
188 return d->doubleAttribs[int(attribute)]; |
|
189 return -1; |
|
190 } |
|
191 |
|
192 /*! |
|
193 Removes the specified \a attribute and its value. |
|
194 */ |
|
195 void QGeoSatelliteInfo::removeAttribute(Attribute attribute) |
|
196 { |
|
197 d->doubleAttribs.remove(int(attribute)); |
|
198 } |
|
199 |
|
200 /*! |
|
201 Returns true if the specified \a attribute is present in this update. |
|
202 */ |
|
203 bool QGeoSatelliteInfo::hasAttribute(Attribute attribute) const |
|
204 { |
|
205 return d->doubleAttribs.contains(int(attribute)); |
|
206 } |
|
207 |
|
208 #ifndef QT_NO_DEBUG_STREAM |
|
209 QDebug operator<<(QDebug dbg, const QGeoSatelliteInfo &info) |
|
210 { |
|
211 dbg.nospace() << "QGeoSatelliteInfo(PRN=" << info.d->prn; |
|
212 dbg.nospace() << ", signal-strength="; |
|
213 dbg.nospace() << info.d->signal; |
|
214 |
|
215 QList<int> attribs = info.d->doubleAttribs.keys(); |
|
216 for (int i = 0; i < attribs.count(); i++) { |
|
217 dbg.nospace() << ", "; |
|
218 switch (attribs[i]) { |
|
219 case QGeoSatelliteInfo::Elevation: |
|
220 dbg.nospace() << "Elevation="; |
|
221 break; |
|
222 case QGeoSatelliteInfo::Azimuth: |
|
223 dbg.nospace() << "Azimuth="; |
|
224 break; |
|
225 } |
|
226 dbg.nospace() << info.d->doubleAttribs[attribs[i]]; |
|
227 } |
|
228 dbg.nospace() << ')'; |
|
229 return dbg; |
|
230 } |
|
231 #endif |
|
232 |
|
233 #ifndef QT_NO_DATASTREAM |
|
234 /*! |
|
235 \fn QDataStream &operator<<(QDataStream &stream, const QGeoSatelliteInfo &info) |
|
236 \relates QGeoSatelliteInfo |
|
237 |
|
238 Writes the given \a info to the specified \a stream. |
|
239 |
|
240 \sa {Format of the QDataStream Operators} |
|
241 */ |
|
242 |
|
243 QDataStream &operator<<(QDataStream &stream, const QGeoSatelliteInfo &info) |
|
244 { |
|
245 stream << info.d->prn; |
|
246 stream << info.d->signal; |
|
247 stream << info.d->doubleAttribs; |
|
248 return stream; |
|
249 } |
|
250 #endif |
|
251 |
|
252 #ifndef QT_NO_DATASTREAM |
|
253 /*! |
|
254 \fn QDataStream &operator>>(QDataStream &stream, QGeoSatelliteInfo &info) |
|
255 \relates QGeoSatelliteInfo |
|
256 |
|
257 Reads satellite information from the specified \a stream into the given |
|
258 \a info. |
|
259 |
|
260 \sa {Format of the QDataStream Operators} |
|
261 */ |
|
262 |
|
263 QDataStream &operator>>(QDataStream &stream, QGeoSatelliteInfo &info) |
|
264 { |
|
265 stream >> info.d->prn; |
|
266 stream >> info.d->signal; |
|
267 stream >> info.d->doubleAttribs; |
|
268 return stream; |
|
269 } |
|
270 #endif |
|
271 |
|
272 QTM_END_NAMESPACE |