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
qgeosatelliteinfosource.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
3// Qt-Security score:significant reason:default
4#include <qgeosatelliteinfosource.h>
5#include <qgeosatelliteinfosource_p.h>
8#include <QPluginLoader>
9#include <QStringList>
10#include <QCryptographicHash>
11#include <QtCore/private/qfactoryloader_p.h>
12#include <QFile>
13
15
16/*!
17 \class QGeoSatelliteInfoSource
18 \inmodule QtPositioning
19 \ingroup QtPositioning-positioning
20 \since 5.2
21
22 \brief The QGeoSatelliteInfoSource class is an abstract base class for the distribution of satellite information updates.
23
24 The static function QGeoSatelliteInfoSource::createDefaultSource() creates a default
25 satellite data source that is appropriate for the platform, if one is
26 available. Otherwise, available QGeoPositionInfoSourceFactory plugins will
27 be checked for one that has a satellite data source available.
28
29 Call startUpdates() and stopUpdates() to start and stop regular updates,
30 or requestUpdate() to request a single update.
31 When an update is available, satellitesInViewUpdated() and/or
32 satellitesInUseUpdated() will be emitted.
33
34 If regular satellite updates are required, setUpdateInterval() can be used
35 to specify how often these updates should be emitted. If no interval is
36 specified, updates are simply provided whenever they are available.
37 For example:
38
39 \code
40 // Emit updates every 10 seconds if available
41 QGeoSatelliteInfoSource *source = QGeoSatelliteInfoSource::createDefaultSource(0);
42 if (source)
43 source->setUpdateInterval(10000);
44 \endcode
45
46 To remove an update interval that was previously set, call
47 setUpdateInterval() with a value of 0.
48
49 \note The satellite source may have a minimum value requirement for
50 update intervals, as returned by minimumUpdateInterval().
51
52 \note To use this class from Android service, see
53 \l {Qt Positioning on Android}.
54*/
55
56QGeoSatelliteInfoSourcePrivate::~QGeoSatelliteInfoSourcePrivate()
57{
58
59}
60
61/*!
62 Creates a satellite source with the specified \a parent.
63*/
64QGeoSatelliteInfoSource::QGeoSatelliteInfoSource(QObject *parent)
65 : QObject(*new QGeoSatelliteInfoSourcePrivate, parent)
66{
67}
68
69QGeoSatelliteInfoSource::QGeoSatelliteInfoSource(QGeoSatelliteInfoSourcePrivate &dd, QObject *parent)
70 : QObject(dd, parent)
71{
72
73}
74
75/*!
76 Destroys the satellite source.
77*/
78QGeoSatelliteInfoSource::~QGeoSatelliteInfoSource()
79{
80}
81
82/*!
83 Returns the unique name of the satellite source implementation in use.
84
85 This is the same name that can be passed to createSource() in order to
86 create a new instance of a particular satellite source implementation.
87*/
88QString QGeoSatelliteInfoSource::sourceName() const
89{
90 Q_D(const QGeoSatelliteInfoSource);
91 return d->providerName;
92}
93
94
95/*!
96 \property QGeoSatelliteInfoSource::updateInterval
97 \brief This property holds the requested interval in milliseconds between each update.
98
99 If the update interval is not set (or is set to 0) the
100 source will provide updates as often as necessary.
101
102 If the update interval is set, the source will provide updates at an
103 interval as close to the requested interval as possible. If the requested
104 interval is less than the minimumUpdateInterval(),
105 the minimum interval is used instead.
106
107 Changes to the update interval will happen as soon as is practical, however the
108 time the change takes may vary between implementations. Whether or not the elapsed
109 time from the previous interval is counted as part of the new interval is also
110 implementation dependent.
111
112 The default value for this property is 0.
113
114 \note Subclass implementations must call the base implementation of
115 setUpdateInterval() so that updateInterval() returns the correct value.
116*/
117void QGeoSatelliteInfoSource::setUpdateInterval(int msec)
118{
119 Q_D(QGeoSatelliteInfoSource);
120 d->interval = msec;
121}
122
123int QGeoSatelliteInfoSource::updateInterval() const
124{
125 Q_D(const QGeoSatelliteInfoSource);
126 return d->interval.value();
127}
128
129QBindable<int> QGeoSatelliteInfoSource::bindableUpdateInterval()
130{
131 Q_D(QGeoSatelliteInfoSource);
132 return QBindable<int>(&d->interval);
133}
134
135/*!
136 \since 6.2
137 Sets the backend-specific property named \a name to \a value.
138 Returns \c true on success, \c false otherwise.
139 Backend-specific properties can be used to configure the satellite info
140 subsystem behavior at runtime.
141
142 \sa backendProperty
143*/
144bool QGeoSatelliteInfoSource::setBackendProperty(const QString &name, const QVariant &value)
145{
146 Q_UNUSED(name)
147 Q_UNUSED(value)
148 return false;
149}
150
151/*!
152 \since 6.2
153 Returns the value of the backend-specific property named \a name,
154 if present. Otherwise the returned value will be invalid.
155
156 \sa setBackendProperty
157*/
158QVariant QGeoSatelliteInfoSource::backendProperty(const QString &name) const
159{
160 Q_UNUSED(name)
161 return QVariant();
162}
163
164QGeoSatelliteInfoSource *QGeoSatelliteInfoSourcePrivate::createSourceReal(const QCborMap &meta, const QVariantMap &parameters, QObject *parent)
165{
166 QGeoSatelliteInfoSource *s = nullptr;
167 auto factory = QGeoPositionInfoSourcePrivate::loadFactory(meta);
168 if (factory)
169 s = factory->satelliteInfoSource(parent, parameters);
170 if (s)
171 s->d_func()->providerName = meta.value(QStringLiteral("Provider")).toString();
172
173 return s;
174}
175
176/*!
177 Creates and returns a source with the specified \a parent that reads
178 from the system's default source of satellite update information, or the
179 highest priority available plugin.
180
181 Returns \c nullptr if the system has no default satellite source, no valid
182 plugins could be found or the user does not have the permission to access
183 the satellite data.
184*/
185QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createDefaultSource(QObject *parent)
186{
187 return createDefaultSource(QVariantMap(), parent);
188}
189
190/*!
191 Creates and returns a source with the given \a parent,
192 by loading the plugin named \a sourceName.
193
194 Returns \c nullptr if the plugin cannot be found.
195*/
196QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createSource(const QString &sourceName, QObject *parent)
197{
198 return createSource(sourceName, QVariantMap(), parent);
199}
200
201/*!
202 Creates and returns a satellite source with the given \a parent that
203 reads from the system's default sources of satellite data, or the plugin
204 with the highest available priority.
205
206 Returns \c nullptr if the system has no default satellite source, no valid
207 plugins could be found or the user does not have the permission to access
208 the satellite information.
209
210 This method passes \a parameters to the factory to configure the source.
211
212 \since Qt 5.14
213*/
214QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createDefaultSource(const QVariantMap &parameters, QObject *parent)
215{
216 const QList<QCborMap> plugins = QGeoPositionInfoSourcePrivate::pluginsSorted();
217 for (const QCborMap &obj : plugins) {
218 if (obj.value(QStringLiteral("Satellite")).isBool()
219 && obj.value(QStringLiteral("Satellite")).toBool())
220 {
221 const QString testableKey = QStringLiteral("Testable");
222 if (obj.contains(testableKey) && !obj.value(testableKey).toBool()) {
223 static bool inTest = qEnvironmentVariableIsSet("QT_QTESTLIB_RUNNING");
224 if (inTest)
225 continue;
226 }
227 if (QGeoSatelliteInfoSource *source =
228 QGeoSatelliteInfoSourcePrivate::createSourceReal(obj, parameters, parent)) {
229 return source;
230 }
231 }
232 }
233
234 return nullptr;
235}
236
237/*!
238 Creates and returns a satellite source with the given \a parent,
239 by loading the plugin named \a sourceName.
240
241 Returns \c nullptr if the plugin cannot be found.
242
243 This method passes \a parameters to the factory to configure the source.
244
245 \since Qt 5.14
246*/
247QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createSource(const QString &sourceName, const QVariantMap &parameters, QObject *parent)
248{
249 const QList<QCborMap> candidates = QGeoPositionInfoSourcePrivate::plugins().values(sourceName);
250 for (const QCborMap &obj : candidates) {
251 if (QGeoSatelliteInfoSource *source =
252 QGeoSatelliteInfoSourcePrivate::createSourceReal(obj, parameters, parent)) {
253 return source;
254 }
255 }
256 return nullptr;
257}
258
259/*!
260 Returns a list of available source plugins, including the default system
261 backend if one is available.
262*/
263QStringList QGeoSatelliteInfoSource::availableSources()
264{
265 QStringList plugins;
266 const auto meta = QGeoPositionInfoSourcePrivate::plugins();
267 for (auto it = meta.cbegin(), end = meta.cend(); it != end; ++it) {
268 if (it.value().value(QStringLiteral("Satellite")).isBool()
269 && it.value().value(QStringLiteral("Satellite")).toBool()) {
270 plugins << it.key();
271 }
272 }
273
274 return plugins;
275}
276
277/*!
278 \fn void QGeoSatelliteInfoSource::satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &satellites);
279
280 If startUpdates() or requestUpdate() is called, this signal is emitted
281 when an update is available on the satellites that are
282 currently in view.
283
284 The \a satellites parameter holds the satellites currently in view.
285*/
286
287/*!
288 \fn void QGeoSatelliteInfoSource::satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &satellites);
289
290 If startUpdates() or requestUpdate() is called, this signal is emitted
291 when an update is available on the number of satellites that are
292 currently in use.
293
294 These are the satellites that are used to get a "fix" - that
295 is, those used to determine the current position.
296
297 The \a satellites parameter holds the satellites currently in use.
298*/
299
300/*!
301 \property QGeoSatelliteInfoSource::minimumUpdateInterval
302 \brief This property holds the minimum time (in milliseconds) required to retrieve a satellite update.
303
304 This is the minimum value accepted by setUpdateInterval() and
305 requestUpdate().
306*/
307
308
309/*!
310 \fn virtual void QGeoSatelliteInfoSource::startUpdates() = 0;
311
312 Starts emitting updates at regular intervals. The updates will be
313 provided whenever new satellite information becomes available.
314
315 If satellite information cannot be retrieved or some other
316 form of timeout has occurred the satellitesInViewUpdated()
317 and satellitesInUseUpdated() signals may be emitted with
318 empty parameter lists.
319
320 \note Since Qt6 this method always resets the last error to
321 \l {QGeoSatelliteInfoSource::}{NoError} before starting
322 the updates.
323
324 \note To understand how to use this method from an Android service, see
325 \l {Qt Positioning on Android}.
326
327 \sa satellitesInViewUpdated(), satellitesInUseUpdated()
328*/
329
330/*!
331 \fn virtual void QGeoSatelliteInfoSource::stopUpdates() = 0;
332
333 Stops emitting updates at regular intervals.
334*/
335
336/*!
337 \fn virtual void QGeoSatelliteInfoSource::requestUpdate(int timeout = 0);
338
339 Attempts to get the current satellite information and emit
340 satellitesInViewUpdated() and satellitesInUseUpdated() with this
341 information. If the current satellite information cannot be found
342 within the given \a timeout (in milliseconds) or if \a timeout is less than
343 the value returned by minimumUpdateInterval(), an errorOccurred() signal
344 with \l {QGeoSatelliteInfoSource::UpdateTimeoutError}
345 {UpdateTimeoutError} is emitted.
346
347 If the timeout is zero, the timeout defaults to a reasonable timeout
348 period as appropriate for the source.
349
350 This does nothing if another update request is in progress. However
351 it can be called even if startUpdates() has already been called and
352 regular updates are in progress.
353
354 \note Since Qt6 this method always resets the last error to
355 \l {QGeoSatelliteInfoSource::}{NoError} before requesting
356 the satellite information.
357
358 \note To understand how to use this method from an Android service, see
359 \l {Qt Positioning on Android}.
360*/
361
362/*!
363 \fn QGeoSatelliteInfoSource::Error QGeoSatelliteInfoSource::error() const = 0
364
365 Returns the last error that occurred.
366
367 \note Since Qt6 the last error is always reset when calling startUpdates()
368 or requestUpdate().
369*/
370
371/*!
372 \fn void QGeoSatelliteInfoSource::errorOccurred(QGeoSatelliteInfoSource::Error satelliteError)
373
374 This signal is emitted after an error occurred. The \a satelliteError
375 parameter describes the type of error that occurred.
376*/
377
378/*!
379 \enum QGeoSatelliteInfoSource::Error
380
381 The Error enumeration represents the errors which can occur.
382
383 \value AccessError The connection setup to the satellite backend failed because the
384 application lacked the required privileges.
385 \value ClosedError The satellite backend closed the connection, which happens for example in case
386 the user is switching location services to off. This object becomes invalid and should be deleted.
387 A new satellite source can be created by calling createDefaultSource() later on.
388 \value NoError No error has occurred.
389 \value UnknownSourceError An unidentified error occurred.
390 \value UpdateTimeoutError The current satellite information could not be
391 retrieved within the specified timeout.
392 */
393
394
395QT_END_NAMESPACE
396
397#include "moc_qgeosatelliteinfosource.cpp"
Combined button and popup list for selecting options.