Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qdeclarativesatellitesource.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 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
5
7
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)
70{
71}
72
74
85{
86 return m_active;
87}
88
101{
102 return m_source != nullptr;
103}
104
111{
112 return m_source ? m_source->updateInterval() : m_updateInterval;
113}
114
139
155{
156 return m_source ? m_source->sourceName() : m_name;
157}
158
168QQmlListProperty<QDeclarativePluginParameter> QDeclarativeSatelliteSource::parameters()
169{
170 return QQmlListProperty<QDeclarativePluginParameter>(this, nullptr,
171 parameter_append,
172 parameter_count,
173 parameter_at,
174 parameter_clear);
175}
176
185QList<QGeoSatelliteInfo> QDeclarativeSatelliteSource::satellitesInUse() const
186{
187 return m_satellitesInUse;
188}
189
196QList<QGeoSatelliteInfo> QDeclarativeSatelliteSource::satellitesInView() const
197{
198 return m_satellitesInView;
199}
200
202{
203 if (m_updateInterval == updateInterval)
204 return;
205
206 const auto oldInterval = m_updateInterval;
207
208 if (m_source) {
209 m_source->setUpdateInterval(updateInterval);
210 // The above call can set some other interval, for example if desired
211 // updateInterval is less than minimum supported update interval. So
212 // we need to read the value back explicitly.
213 m_updateInterval = m_source->updateInterval();
214 } else {
215 m_updateInterval = updateInterval;
216 }
217 if (oldInterval != m_updateInterval)
219}
220
222{
223 if (active == m_active)
224 return;
225
226 if (active)
227 start();
228 else
229 stop();
230}
231
233{
234 if ((m_name == name) || (name.isEmpty() && m_defaultSourceUsed))
235 return;
236
237 if (m_componentComplete && m_parametersInitialized) {
238 createSource(name); // it will update name and emit, if needed
239 } else {
240 m_name = name;
242 }
243}
244
246{
247 m_componentComplete = true;
248 m_parametersInitialized = true;
249 for (QDeclarativePluginParameter *p: std::as_const(m_parameters)) {
250 if (!p->isInitialized()) {
251 m_parametersInitialized = false;
253 this, &QDeclarativeSatelliteSource::onParameterInitialized,
255 }
256 }
257
258 if (m_parametersInitialized)
259 createSource(m_name);
260}
261
270{
271 if (m_source)
272 return m_source->setBackendProperty(name, value);
273 return false;
274}
275
284{
285 return m_source ? m_source->backendProperty(name) : QVariant{};
286}
287
305{
306 if (m_componentComplete && m_parametersInitialized) {
307 executeSingleUpdate(timeout);
308 } else {
309 m_singleUpdateDesiredTimeout = timeout;
310 m_singleUpdateRequested = true;
311 }
312}
313
324{
325 if (m_componentComplete && m_parametersInitialized)
326 executeStart();
327 else
328 m_startRequested = true;
329}
330
340{
341 if (m_source) {
342 m_source->stopUpdates();
343 m_regularUpdates = false;
344
345 if (m_active && !m_singleUpdate) {
346 m_active = false;
348 }
349 } else {
350 m_startRequested = false;
351 }
352}
353
354void QDeclarativeSatelliteSource::sourceErrorReceived(const QGeoSatelliteInfoSource::Error error)
355{
356 const auto oldError = m_error;
357 m_error = static_cast<SourceError>(error);
358 if (m_error != oldError)
360
361 // if an error occurred during single update, the update is stopped, so we
362 // need to change the active state.
363 if (m_singleUpdate) {
364 m_singleUpdate = false;
365 if (m_active && !m_regularUpdates) {
366 m_active = false;
368 }
369 }
370}
371
372void QDeclarativeSatelliteSource::onParameterInitialized()
373{
374 m_parametersInitialized = true;
375 for (QDeclarativePluginParameter *p: std::as_const(m_parameters)) {
376 if (!p->isInitialized()) {
377 m_parametersInitialized = false;
378 break;
379 }
380 }
381
382 // m_componentComplete == true here
383 if (m_parametersInitialized)
384 createSource(m_name);
385}
386
387void QDeclarativeSatelliteSource::satellitesInViewUpdateReceived(const QList<QGeoSatelliteInfo> &satellites)
388{
389 m_satellitesInView = satellites;
391 handleSingleUpdateReceived();
392}
393
394void QDeclarativeSatelliteSource::satellitesInUseUpdateReceived(const QList<QGeoSatelliteInfo> &satellites)
395{
396 m_satellitesInUse = satellites;
398 handleSingleUpdateReceived();
399}
400
401QVariantMap QDeclarativeSatelliteSource::parameterMap() const
402{
404 for (const auto *parameter : std::as_const(m_parameters))
405 map.insert(parameter->name(), parameter->value());
406 return map;
407}
408
409void QDeclarativeSatelliteSource::createSource(const QString &newName)
410{
411 if (m_source && m_source->sourceName() == newName)
412 return;
413
414 const auto oldName = name();
415 const bool oldIsValid = isValid();
416 const bool oldActive = isActive();
417 const auto oldUpdateInterval = updateInterval();
418
419 if (m_source) {
420 m_source->disconnect(this);
421 m_source->stopUpdates();
422 m_source.reset(nullptr);
423 m_active = false;
424 }
425
426 if (!newName.isEmpty()) {
427 m_source.reset(QGeoSatelliteInfoSource::createSource(newName, parameterMap(), nullptr));
428 m_defaultSourceUsed = false;
429 } else {
430 m_source.reset(QGeoSatelliteInfoSource::createDefaultSource(parameterMap(), nullptr));
431 m_defaultSourceUsed = true;
432 }
433
434 if (m_source) {
436 this, &QDeclarativeSatelliteSource::sourceErrorReceived);
438 this, &QDeclarativeSatelliteSource::satellitesInViewUpdateReceived);
440 this, &QDeclarativeSatelliteSource::satellitesInUseUpdateReceived);
441
442 m_name = m_source->sourceName();
443 m_source->setUpdateInterval(m_updateInterval);
444 m_updateInterval = m_source->updateInterval();
445 } else {
446 m_name = newName;
447 m_defaultSourceUsed = false;
448 }
449
450 if (oldName != name())
452
453 if (oldIsValid != isValid())
455
456 if (oldActive != isActive())
458
459 if (oldUpdateInterval != updateInterval())
461
462 if (m_startRequested) {
463 m_startRequested = false;
464 executeStart();
465 }
466 if (m_singleUpdateRequested) {
467 m_singleUpdateRequested = false;
468 executeSingleUpdate(m_singleUpdateDesiredTimeout);
469 }
470}
471
472void QDeclarativeSatelliteSource::handleSingleUpdateReceived()
473{
474 if (m_singleUpdate) {
475 m_singleUpdate = false;
476 if (m_active && !m_regularUpdates) {
477 m_active = false;
479 }
480 }
481}
482
483void QDeclarativeSatelliteSource::executeStart()
484{
485 if (m_source) {
486 m_regularUpdates = true;
487 if (!m_active) {
488 m_active = true;
490 }
491 m_source->startUpdates();
492 }
493}
494
495void QDeclarativeSatelliteSource::executeSingleUpdate(int timeout)
496{
497 if (m_source) {
498 m_singleUpdate = true;
499 if (!m_active) {
500 m_active = true;
502 }
503 m_source->requestUpdate(timeout);
504 }
505}
506
507void QDeclarativeSatelliteSource::parameter_append(PluginParameterProperty *prop,
509{
510 auto *src = static_cast<QDeclarativeSatelliteSource *>(prop->object);
511 src->m_parameters.append(parameter);
512}
513
514qsizetype QDeclarativeSatelliteSource::parameter_count(PluginParameterProperty *prop)
515{
516 return static_cast<QDeclarativeSatelliteSource *>(prop->object)->m_parameters.size();
517}
518
520QDeclarativeSatelliteSource::parameter_at(PluginParameterProperty *prop, qsizetype index)
521{
522 return static_cast<QDeclarativeSatelliteSource *>(prop->object)->m_parameters[index];
523}
524
525void QDeclarativeSatelliteSource::parameter_clear(PluginParameterProperty *prop)
526{
527 auto *src = static_cast<QDeclarativeSatelliteSource *>(prop->object);
528 src->m_parameters.clear();
529}
530
bool m_active
void stop()
\qmlmethod SatelliteSource::stop()
QDeclarativeSatelliteSource()
\qmltype SatelliteSource \inqmlmodule QtPositioning
QList< QGeoSatelliteInfo > satellitesInUse
void start()
\qmlmethod SatelliteSource::start()
void update(int timeout=0)
\qmlmethod SatelliteSource::update(int timeout = 0)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
bool isValid() const
\qmlproperty bool SatelliteSource::valid \readonly
QQmlListProperty< QDeclarativePluginParameter > parameters
\qmlproperty list<PluginParameter> SatelliteSource::parameters \readonly \qmldefault
bool isActive() const
\qmlproperty bool SatelliteSource::active
Q_INVOKABLE QVariant backendProperty(const QString &name) const
\qmlmethod var SatelliteSource::backendProperty(string name)
QList< QGeoSatelliteInfo > satellitesInView
Q_INVOKABLE bool setBackendProperty(const QString &name, const QVariant &value)
\qmlmethod bool SatelliteSource::setBackendProperty(string name, var value)
static QGeoSatelliteInfoSource * createSource(const QString &sourceName, QObject *parent)
Creates and returns a source with the given parent, by loading the plugin named sourceName.
Error
The Error enumeration represents the errors which can occur.
static QGeoSatelliteInfoSource * createDefaultSource(QObject *parent)
Creates and returns a source with the specified parent that reads from the system's default source of...
void satellitesInViewUpdated(const QList< QGeoSatelliteInfo > &satellites)
If startUpdates() or requestUpdate() is called, this signal is emitted when an update is available on...
void satellitesInUseUpdated(const QList< QGeoSatelliteInfo > &satellites)
If startUpdates() or requestUpdate() is called, this signal is emitted when an update is available on...
void errorOccurred(QGeoSatelliteInfoSource::Error)
This signal is emitted after an error occurred.
qsizetype size() const noexcept
Definition qlist.h:397
void append(parameter_type t)
Definition qlist.h:458
void clear()
Definition qlist.h:434
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
QMap< QString, QString > map
[6]
cache insert(employee->id(), employee)
Combined button and popup list for selecting options.
@ SingleShotConnection
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint index
[2]
GLbitfield GLuint64 timeout
[4]
GLenum src
GLuint name
GLfloat GLfloat p
[1]
#define emit
ptrdiff_t qsizetype
Definition qtypes.h:165