|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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 |
|
46 QTM_BEGIN_NAMESPACE |
|
47 |
|
48 class QGeoSatelliteInfoPrivate |
|
49 { |
|
50 public: |
|
51 int prn; |
|
52 int signal; |
|
53 QHash<int, qreal> doubleAttribs; |
|
54 }; |
|
55 |
|
56 |
|
57 /*! |
|
58 \class QGeoSatelliteInfo |
|
59 \brief The QGeoSatelliteInfo class contains basic information about a satellite. |
|
60 \ingroup location |
|
61 |
|
62 \sa QGeoSatelliteInfoSource |
|
63 */ |
|
64 |
|
65 /*! |
|
66 \enum QGeoSatelliteInfo::Attribute |
|
67 Defines the attributes for the satellite information. |
|
68 |
|
69 \value Elevation The elevation of the satellite, in degrees. |
|
70 \value Azimuth The azimuth to true north, in degrees. |
|
71 */ |
|
72 |
|
73 |
|
74 /*! |
|
75 Creates a satellite information object. |
|
76 */ |
|
77 QGeoSatelliteInfo::QGeoSatelliteInfo() |
|
78 : d(new QGeoSatelliteInfoPrivate) |
|
79 { |
|
80 d->prn = -1; |
|
81 d->signal = -1; |
|
82 } |
|
83 |
|
84 /*! |
|
85 Creates a satellite information object with the values of \a other. |
|
86 */ |
|
87 |
|
88 QGeoSatelliteInfo::QGeoSatelliteInfo(const QGeoSatelliteInfo &other) |
|
89 : d(new QGeoSatelliteInfoPrivate) |
|
90 { |
|
91 operator=(other); |
|
92 } |
|
93 |
|
94 /*! |
|
95 Destroys a satellite information object. |
|
96 */ |
|
97 QGeoSatelliteInfo::~QGeoSatelliteInfo() |
|
98 { |
|
99 delete d; |
|
100 } |
|
101 |
|
102 /*! |
|
103 Assigns the values from \a other to this object. |
|
104 */ |
|
105 QGeoSatelliteInfo &QGeoSatelliteInfo::operator=(const QGeoSatelliteInfo & other) |
|
106 { |
|
107 if (this == &other) |
|
108 return *this; |
|
109 |
|
110 d->prn = other.d->prn; |
|
111 d->signal = other.d->signal; |
|
112 d->doubleAttribs = other.d->doubleAttribs; |
|
113 return *this; |
|
114 } |
|
115 |
|
116 /*! |
|
117 Returns true if all the information for this satellite |
|
118 are the same as those of \a other. |
|
119 */ |
|
120 bool QGeoSatelliteInfo::operator==(const QGeoSatelliteInfo &other) const |
|
121 { |
|
122 return d->prn == other.d->prn |
|
123 && d->signal == other.d->signal |
|
124 && d->doubleAttribs == other.d->doubleAttribs; |
|
125 } |
|
126 |
|
127 /*! |
|
128 \fn bool QGeoSatelliteInfo::operator!=(const QGeoSatelliteInfo &other) const; |
|
129 |
|
130 Returns true if any of the information for this satellite |
|
131 are not the same as those of \a other. |
|
132 */ |
|
133 |
|
134 /*! |
|
135 Sets the PRN (Pseudo-random noise) number to \a prn. |
|
136 |
|
137 The PRN number can be used to identify a satellite. |
|
138 */ |
|
139 void QGeoSatelliteInfo::setPrnNumber(int prn) |
|
140 { |
|
141 d->prn = prn; |
|
142 } |
|
143 |
|
144 /*! |
|
145 Returns the PRN (Pseudo-random noise) number, or -1 if the value has not been set. |
|
146 */ |
|
147 |
|
148 int QGeoSatelliteInfo::prnNumber() const |
|
149 { |
|
150 return d->prn; |
|
151 } |
|
152 |
|
153 /*! |
|
154 Sets the signal strength to \a signalStrength, in decibels. |
|
155 */ |
|
156 void QGeoSatelliteInfo::setSignalStrength(int signalStrength) |
|
157 { |
|
158 d->signal = signalStrength; |
|
159 } |
|
160 |
|
161 /*! |
|
162 Returns the signal strength, or -1 if the value has not been set. |
|
163 */ |
|
164 int QGeoSatelliteInfo::signalStrength() const |
|
165 { |
|
166 return d->signal; |
|
167 } |
|
168 |
|
169 /*! |
|
170 Sets the value for \a attribute to \a value. |
|
171 */ |
|
172 void QGeoSatelliteInfo::setAttribute(Attribute attribute, qreal value) |
|
173 { |
|
174 d->doubleAttribs[int(attribute)] = value; |
|
175 } |
|
176 |
|
177 /*! |
|
178 Returns the value of the specified \a attribute as a qreal value. |
|
179 |
|
180 Returns -1 if the value has not been set. |
|
181 |
|
182 \sa hasAttribute(), setAttribute() |
|
183 */ |
|
184 qreal QGeoSatelliteInfo::attribute(Attribute attribute) const |
|
185 { |
|
186 if (d->doubleAttribs.contains(int(attribute))) |
|
187 return d->doubleAttribs[int(attribute)]; |
|
188 return -1; |
|
189 } |
|
190 |
|
191 /*! |
|
192 Removes the specified \a attribute and its value. |
|
193 */ |
|
194 void QGeoSatelliteInfo::removeAttribute(Attribute attribute) |
|
195 { |
|
196 d->doubleAttribs.remove(int(attribute)); |
|
197 } |
|
198 |
|
199 /*! |
|
200 Returns true if the specified \a attribute is present in this update. |
|
201 */ |
|
202 bool QGeoSatelliteInfo::hasAttribute(Attribute attribute) const |
|
203 { |
|
204 return d->doubleAttribs.contains(int(attribute)); |
|
205 } |
|
206 |
|
207 #ifndef QT_NO_DEBUG_STREAM |
|
208 QDebug operator<<(QDebug dbg, const QGeoSatelliteInfo &info) |
|
209 { |
|
210 dbg.nospace() << "QGeoSatelliteInfo(PRN=" << info.d->prn; |
|
211 dbg.nospace() << ", signal-strength="; |
|
212 dbg.nospace() << info.d->signal; |
|
213 |
|
214 QList<int> attribs = info.d->doubleAttribs.keys(); |
|
215 for (int i = 0; i < attribs.count(); i++) { |
|
216 dbg.nospace() << ", "; |
|
217 switch (attribs[i]) { |
|
218 case QGeoSatelliteInfo::Elevation: |
|
219 dbg.nospace() << "Elevation="; |
|
220 break; |
|
221 case QGeoSatelliteInfo::Azimuth: |
|
222 dbg.nospace() << "Azimuth="; |
|
223 break; |
|
224 } |
|
225 dbg.nospace() << info.d->doubleAttribs[attribs[i]]; |
|
226 } |
|
227 dbg.nospace() << ')'; |
|
228 return dbg; |
|
229 } |
|
230 #endif |
|
231 |
|
232 QTM_END_NAMESPACE |