Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
>
6
#
include
"qgeopositioninfosourcefactory.h"
7
#
include
"qgeopositioninfosource_p.h"
8
#
include
<
QPluginLoader
>
9
#
include
<
QStringList
>
10
#
include
<
QCryptographicHash
>
11
#
include
<
QtCore
/
private
/
qfactoryloader_p
.
h
>
12
#
include
<
QFile
>
13
14
QT_BEGIN_NAMESPACE
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
56
QGeoSatelliteInfoSourcePrivate::~QGeoSatelliteInfoSourcePrivate()
57
{
58
59
}
60
61
/*!
62
Creates a satellite source with the specified \a parent.
63
*/
64
QGeoSatelliteInfoSource::QGeoSatelliteInfoSource(QObject *parent)
65
: QObject(*
new
QGeoSatelliteInfoSourcePrivate, parent)
66
{
67
}
68
69
QGeoSatelliteInfoSource::QGeoSatelliteInfoSource(QGeoSatelliteInfoSourcePrivate &dd, QObject *parent)
70
: QObject(dd, parent)
71
{
72
73
}
74
75
/*!
76
Destroys the satellite source.
77
*/
78
QGeoSatelliteInfoSource::~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
*/
88
QString 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
*/
117
void
QGeoSatelliteInfoSource::setUpdateInterval(
int
msec)
118
{
119
Q_D(QGeoSatelliteInfoSource);
120
d->interval = msec;
121
}
122
123
int
QGeoSatelliteInfoSource::updateInterval()
const
124
{
125
Q_D(
const
QGeoSatelliteInfoSource);
126
return
d->interval.value();
127
}
128
129
QBindable<
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
*/
144
bool
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
*/
158
QVariant QGeoSatelliteInfoSource::backendProperty(
const
QString &name)
const
159
{
160
Q_UNUSED(name)
161
return
QVariant();
162
}
163
164
QGeoSatelliteInfoSource *
QGeoSatelliteInfoSourcePrivate
::createSourceReal(
const
QCborMap &meta,
const
QVariantMap ¶meters, 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
*/
185
QGeoSatelliteInfoSource *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
*/
196
QGeoSatelliteInfoSource *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
*/
214
QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createDefaultSource(
const
QVariantMap ¶meters, 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
*/
244
QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createSource(
const
QString &sourceName,
const
QVariantMap ¶meters, 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
*/
256
QStringList 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
388
QT_END_NAMESPACE
389
390
#
include
"moc_qgeosatelliteinfosource.cpp"
QGeoSatelliteInfoSourcePrivate
Definition
qgeosatelliteinfosource_p.h:26
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtpositioning
src
positioning
qgeosatelliteinfosource.cpp
Generated on
for Qt by
1.18.0