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