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#include <qgeosatelliteinfosource.h>
4#include <qgeosatelliteinfosource_p.h>
7#include <QPluginLoader>
8#include <QStringList>
9#include <QCryptographicHash>
10#include <QtCore/private/qfactoryloader_p.h>
11#include <QFile>
12
14
15/*!
16 \class QGeoSatelliteInfoSource
17 \inmodule QtPositioning
18 \ingroup QtPositioning-positioning
19 \since 5.2
20
21 \brief The QGeoSatelliteInfoSource class is an abstract base class for the distribution of satellite information updates.
22
23 The static function QGeoSatelliteInfoSource::createDefaultSource() creates a default
24 satellite data source that is appropriate for the platform, if one is
25 available. Otherwise, available QGeoPositionInfoSourceFactory plugins will
26 be checked for one that has a satellite data source available.
27
28 Call startUpdates() and stopUpdates() to start and stop regular updates,
29 or requestUpdate() to request a single update.
30 When an update is available, satellitesInViewUpdated() and/or
31 satellitesInUseUpdated() will be emitted.
32
33 If regular satellite updates are required, setUpdateInterval() can be used
34 to specify how often these updates should be emitted. If no interval is
35 specified, updates are simply provided whenever they are available.
36 For example:
37
38 \code
39 // Emit updates every 10 seconds if available
40 QGeoSatelliteInfoSource *source = QGeoSatelliteInfoSource::createDefaultSource(0);
41 if (source)
42 source->setUpdateInterval(10000);
43 \endcode
44
45 To remove an update interval that was previously set, call
46 setUpdateInterval() with a value of 0.
47
48 \note The satellite source may have a minimum value requirement for
49 update intervals, as returned by minimumUpdateInterval().
50
51 \note To use this class from Android service, see
52 \l {Qt Positioning on Android}.
53*/
54
55/*!
56 Creates a satellite source with the specified \a parent.
57*/
58
59QGeoSatelliteInfoSourcePrivate::~QGeoSatelliteInfoSourcePrivate()
60{
61
62}
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 return QGeoSatelliteInfoSourcePrivate::createSourceReal(obj, parameters, parent);
228 }
229 }
230
231 return nullptr;
232}
233
234/*!
235 Creates and returns a satellite source with the given \a parent,
236 by loading the plugin named \a sourceName.
237
238 Returns \c nullptr if the plugin cannot be found.
239
240 This method passes \a parameters to the factory to configure the source.
241
242 \since Qt 5.14
243*/
244QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createSource(const QString &sourceName, const QVariantMap &parameters, QObject *parent)
245{
246 auto plugins = QGeoPositionInfoSourcePrivate::plugins();
247 if (plugins.contains(sourceName))
248 return QGeoSatelliteInfoSourcePrivate::createSourceReal(plugins.value(sourceName), parameters, parent);
249 return nullptr;
250}
251
252/*!
253 Returns a list of available source plugins, including the default system
254 backend if one is available.
255*/
256QStringList QGeoSatelliteInfoSource::availableSources()
257{
258 QStringList plugins;
259 const auto meta = QGeoPositionInfoSourcePrivate::plugins();
260 for (auto it = meta.cbegin(), end = meta.cend(); it != end; ++it) {
261 if (it.value().value(QStringLiteral("Satellite")).isBool()
262 && it.value().value(QStringLiteral("Satellite")).toBool()) {
263 plugins << it.key();
264 }
265 }
266
267 return plugins;
268}
269
270/*!
271 \fn void QGeoSatelliteInfoSource::satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &satellites);
272
273 If startUpdates() or requestUpdate() is called, this signal is emitted
274 when an update is available on the satellites that are
275 currently in view.
276
277 The \a satellites parameter holds the satellites currently in view.
278*/
279
280/*!
281 \fn void QGeoSatelliteInfoSource::satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &satellites);
282
283 If startUpdates() or requestUpdate() is called, this signal is emitted
284 when an update is available on the number of satellites that are
285 currently in use.
286
287 These are the satellites that are used to get a "fix" - that
288 is, those used to determine the current position.
289
290 The \a satellites parameter holds the satellites currently in use.
291*/
292
293/*!
294 \property QGeoSatelliteInfoSource::minimumUpdateInterval
295 \brief This property holds the minimum time (in milliseconds) required to retrieve a satellite update.
296
297 This is the minimum value accepted by setUpdateInterval() and
298 requestUpdate().
299*/
300
301
302/*!
303 \fn virtual void QGeoSatelliteInfoSource::startUpdates() = 0;
304
305 Starts emitting updates at regular intervals. The updates will be
306 provided whenever new satellite information becomes available.
307
308 If satellite information cannot be retrieved or some other
309 form of timeout has occurred the satellitesInViewUpdated()
310 and satellitesInUseUpdated() signals may be emitted with
311 empty parameter lists.
312
313 \note Since Qt6 this method always resets the last error to
314 \l {QGeoSatelliteInfoSource::}{NoError} before starting
315 the updates.
316
317 \note To understand how to use this method from an Android service, see
318 \l {Qt Positioning on Android}.
319
320 \sa satellitesInViewUpdated(), satellitesInUseUpdated()
321*/
322
323/*!
324 \fn virtual void QGeoSatelliteInfoSource::stopUpdates() = 0;
325
326 Stops emitting updates at regular intervals.
327*/
328
329/*!
330 \fn virtual void QGeoSatelliteInfoSource::requestUpdate(int timeout = 0);
331
332 Attempts to get the current satellite information and emit
333 satellitesInViewUpdated() and satellitesInUseUpdated() with this
334 information. If the current satellite information cannot be found
335 within the given \a timeout (in milliseconds) or if \a timeout is less than
336 the value returned by minimumUpdateInterval(), an errorOccurred() signal
337 with \l {QGeoSatelliteInfoSource::UpdateTimeoutError}
338 {UpdateTimeoutError} is emitted.
339
340 If the timeout is zero, the timeout defaults to a reasonable timeout
341 period as appropriate for the source.
342
343 This does nothing if another update request is in progress. However
344 it can be called even if startUpdates() has already been called and
345 regular updates are in progress.
346
347 \note Since Qt6 this method always resets the last error to
348 \l {QGeoSatelliteInfoSource::}{NoError} before requesting
349 the satellite information.
350
351 \note To understand how to use this method from an Android service, see
352 \l {Qt Positioning on Android}.
353*/
354
355/*!
356 \fn QGeoSatelliteInfoSource::Error QGeoSatelliteInfoSource::error() const = 0
357
358 Returns the last error that occurred.
359
360 \note Since Qt6 the last error is always reset when calling startUpdates()
361 or requestUpdate().
362*/
363
364/*!
365 \fn void QGeoSatelliteInfoSource::errorOccurred(QGeoSatelliteInfoSource::Error satelliteError)
366
367 This signal is emitted after an error occurred. The \a satelliteError
368 parameter describes the type of error that occurred.
369*/
370
371/*!
372 \enum QGeoSatelliteInfoSource::Error
373
374 The Error enumeration represents the errors which can occur.
375
376 \value AccessError The connection setup to the satellite backend failed because the
377 application lacked the required privileges.
378 \value ClosedError The satellite backend closed the connection, which happens for example in case
379 the user is switching location services to off. This object becomes invalid and should be deleted.
380 A new satellite source can be created by calling createDefaultSource() later on.
381 \value NoError No error has occurred.
382 \value UnknownSourceError An unidentified error occurred.
383 \value UpdateTimeoutError The current satellite information could not be
384 retrieved within the specified timeout.
385 */
386
387
388QT_END_NAMESPACE
389
390#include "moc_qgeosatelliteinfosource.cpp"
Combined button and popup list for selecting options.