9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
66QDeclarativeSatelliteSource::QDeclarativeSatelliteSource()
67 : m_active(0), m_componentComplete(0), m_parametersInitialized(0),
68 m_startRequested(0), m_defaultSourceUsed(0), m_regularUpdates(0),
69 m_singleUpdate(0), m_singleUpdateRequested(0)
73QDeclarativeSatelliteSource::~QDeclarativeSatelliteSource()
76 m_source->disconnect(
this);
80
81
82
83
84
85
86
87
88bool QDeclarativeSatelliteSource::isActive()
const
94
95
96
97
98
99
100
101
102
103
104bool QDeclarativeSatelliteSource::isValid()
const
106 return m_source !=
nullptr;
110
111
112
113
114int QDeclarativeSatelliteSource::updateInterval()
const
116 return m_source ? m_source->updateInterval() : m_updateInterval;
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139QDeclarativeSatelliteSource::SourceError QDeclarativeSatelliteSource::sourceError()
const
145
146
147
148
149
150
151
152
153
154
155
156
157
158QString QDeclarativeSatelliteSource::name()
const
160 return m_source ? m_source->sourceName() : m_name;
164
165
166
167
168
169
170
171
172QQmlListProperty<QDeclarativePluginParameter> QDeclarativeSatelliteSource::parameters()
174 return QQmlListProperty<QDeclarativePluginParameter>(
this,
nullptr,
182
183
184
185
186
187
188
189QList<QGeoSatelliteInfo> QDeclarativeSatelliteSource::satellitesInUse()
const
191 return m_satellitesInUse;
195
196
197
198
199
200QList<QGeoSatelliteInfo> QDeclarativeSatelliteSource::satellitesInView()
const
202 return m_satellitesInView;
205void QDeclarativeSatelliteSource::setUpdateInterval(
int updateInterval)
207 if (m_updateInterval == updateInterval)
210 const auto oldInterval = m_updateInterval;
213 m_source->setUpdateInterval(updateInterval);
217 m_updateInterval = m_source->updateInterval();
219 m_updateInterval = updateInterval;
221 if (oldInterval != m_updateInterval)
222 emit updateIntervalChanged();
225void QDeclarativeSatelliteSource::setActive(
bool active)
227 if (active == m_active)
236void QDeclarativeSatelliteSource::setName(
const QString &name)
238 if ((m_name == name) || (name.isEmpty() && m_defaultSourceUsed))
241 if (m_componentComplete && m_parametersInitialized) {
249void QDeclarativeSatelliteSource::componentComplete()
251 m_componentComplete =
true;
252 m_parametersInitialized =
true;
253 for (QDeclarativePluginParameter *p: std::as_const(m_parameters)) {
254 if (!p->isInitialized()) {
255 m_parametersInitialized =
false;
256 connect(p, &QDeclarativePluginParameter::initialized,
257 this, &QDeclarativeSatelliteSource::onParameterInitialized,
258 Qt::SingleShotConnection);
262 if (m_parametersInitialized)
263 createSource(m_name);
267
268
269
270
271
272
273bool QDeclarativeSatelliteSource::setBackendProperty(
const QString &name,
const QVariant &value)
276 return m_source->setBackendProperty(name, value);
281
282
283
284
285
286
287QVariant QDeclarativeSatelliteSource::backendProperty(
const QString &name)
const
289 return m_source ? m_source->backendProperty(name) : QVariant{};
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308void QDeclarativeSatelliteSource::update(
int timeout)
310 if (m_componentComplete && m_parametersInitialized) {
311 executeSingleUpdate(timeout);
313 m_singleUpdateDesiredTimeout = timeout;
314 m_singleUpdateRequested =
true;
319
320
321
322
323
324
325
326
327void QDeclarativeSatelliteSource::start()
329 if (m_componentComplete && m_parametersInitialized)
332 m_startRequested =
true;
336
337
338
339
340
341
342
343void QDeclarativeSatelliteSource::stop()
346 m_source->stopUpdates();
347 m_regularUpdates =
false;
349 if (m_active && !m_singleUpdate) {
351 emit activeChanged();
354 m_startRequested =
false;
358void QDeclarativeSatelliteSource::sourceErrorReceived(
const QGeoSatelliteInfoSource::Error error)
360 const auto oldError = m_error;
361 m_error =
static_cast<SourceError>(error);
362 if (m_error != oldError)
363 emit sourceErrorChanged();
367 if (m_singleUpdate) {
368 m_singleUpdate =
false;
369 if (m_active && !m_regularUpdates) {
371 emit activeChanged();
376void QDeclarativeSatelliteSource::onParameterInitialized()
378 m_parametersInitialized =
true;
379 for (QDeclarativePluginParameter *p: std::as_const(m_parameters)) {
380 if (!p->isInitialized()) {
381 m_parametersInitialized =
false;
387 if (m_parametersInitialized)
388 createSource(m_name);
391void QDeclarativeSatelliteSource::satellitesInViewUpdateReceived(
const QList<QGeoSatelliteInfo> &satellites)
393 m_satellitesInView = satellites;
394 emit satellitesInViewChanged();
395 handleSingleUpdateReceived();
398void QDeclarativeSatelliteSource::satellitesInUseUpdateReceived(
const QList<QGeoSatelliteInfo> &satellites)
400 m_satellitesInUse = satellites;
401 emit satellitesInUseChanged();
402 handleSingleUpdateReceived();
405QVariantMap QDeclarativeSatelliteSource::parameterMap()
const
408 for (
const auto *parameter : std::as_const(m_parameters))
409 map.insert(parameter->name(), parameter->value());
413void QDeclarativeSatelliteSource::createSource(
const QString &newName)
415 if (m_source && m_source->sourceName() == newName)
418 const auto oldName = name();
419 const bool oldIsValid = isValid();
420 const bool oldActive = isActive();
421 const auto oldUpdateInterval = updateInterval();
424 m_source->disconnect(
this);
425 m_source->stopUpdates();
426 m_source.reset(
nullptr);
430 if (!newName.isEmpty()) {
431 m_source.reset(QGeoSatelliteInfoSource::createSource(newName, parameterMap(),
nullptr));
432 m_defaultSourceUsed =
false;
434 m_source.reset(QGeoSatelliteInfoSource::createDefaultSource(parameterMap(),
nullptr));
435 m_defaultSourceUsed =
true;
439 connect(m_source.get(), &QGeoSatelliteInfoSource::errorOccurred,
440 this, &QDeclarativeSatelliteSource::sourceErrorReceived);
441 connect(m_source.get(), &QGeoSatelliteInfoSource::satellitesInViewUpdated,
442 this, &QDeclarativeSatelliteSource::satellitesInViewUpdateReceived);
443 connect(m_source.get(), &QGeoSatelliteInfoSource::satellitesInUseUpdated,
444 this, &QDeclarativeSatelliteSource::satellitesInUseUpdateReceived);
446 m_name = m_source->sourceName();
447 m_source->setUpdateInterval(m_updateInterval);
448 m_updateInterval = m_source->updateInterval();
451 m_defaultSourceUsed =
false;
454 if (oldName != name())
457 if (oldIsValid != isValid())
458 emit validityChanged();
460 if (oldActive != isActive())
461 emit activeChanged();
463 if (oldUpdateInterval != updateInterval())
464 emit updateIntervalChanged();
466 if (m_startRequested) {
467 m_startRequested =
false;
470 if (m_singleUpdateRequested) {
471 m_singleUpdateRequested =
false;
472 executeSingleUpdate(m_singleUpdateDesiredTimeout);
476void QDeclarativeSatelliteSource::handleSingleUpdateReceived()
478 if (m_singleUpdate) {
479 m_singleUpdate =
false;
480 if (m_active && !m_regularUpdates) {
482 emit activeChanged();
487void QDeclarativeSatelliteSource::executeStart()
490 m_regularUpdates =
true;
493 emit activeChanged();
495 m_source->startUpdates();
499void QDeclarativeSatelliteSource::executeSingleUpdate(
int timeout)
502 m_singleUpdate =
true;
505 emit activeChanged();
507 m_source->requestUpdate(timeout);
511void QDeclarativeSatelliteSource::parameter_append(PluginParameterProperty *prop,
512 QDeclarativePluginParameter *parameter)
514 auto *src =
static_cast<QDeclarativeSatelliteSource *>(prop->object);
515 src->m_parameters.append(parameter);
518qsizetype QDeclarativeSatelliteSource::parameter_count(PluginParameterProperty *prop)
520 return static_cast<QDeclarativeSatelliteSource *>(prop->object)->m_parameters.size();
523QDeclarativePluginParameter *
524QDeclarativeSatelliteSource::parameter_at(PluginParameterProperty *prop, qsizetype index)
526 return static_cast<QDeclarativeSatelliteSource *>(prop->object)->m_parameters[index];
529void QDeclarativeSatelliteSource::parameter_clear(PluginParameterProperty *prop)
531 auto *src =
static_cast<QDeclarativeSatelliteSource *>(prop->object);
532 src->m_parameters.clear();