diff options
-rw-r--r-- | src/positioning/qgeopositioninfosource.cpp | 8 | ||||
-rw-r--r-- | src/positioning/qgeopositioninfosource.h | 1 | ||||
-rw-r--r-- | src/positioningquick/qdeclarativepositionsource.cpp | 30 | ||||
-rw-r--r-- | src/positioningquick/qdeclarativepositionsource_p.h | 1 |
4 files changed, 31 insertions, 9 deletions
diff --git a/src/positioning/qgeopositioninfosource.cpp b/src/positioning/qgeopositioninfosource.cpp index 02aa1aa3..cafb4f8a 100644 --- a/src/positioning/qgeopositioninfosource.cpp +++ b/src/positioning/qgeopositioninfosource.cpp @@ -476,4 +476,12 @@ QStringList QGeoPositionInfoSource::availableSources() \value UnknownSourceError An unidentified error occurred. */ +/*! + \fn void QGeoPositionInfoSource::supportedPositioningMethodsChanged() + + This signal is emitted after the supportedPositioningMethods change. + + \since Qt 5.12 +*/ + QT_END_NAMESPACE diff --git a/src/positioning/qgeopositioninfosource.h b/src/positioning/qgeopositioninfosource.h index 24784462..7fe02270 100644 --- a/src/positioning/qgeopositioninfosource.h +++ b/src/positioning/qgeopositioninfosource.h @@ -101,6 +101,7 @@ Q_SIGNALS: void positionUpdated(const QGeoPositionInfo &update); void updateTimeout(); void error(QGeoPositionInfoSource::Error); + void supportedPositioningMethodsChanged(); private: Q_DISABLE_COPY(QGeoPositionInfoSource) diff --git a/src/positioningquick/qdeclarativepositionsource.cpp b/src/positioningquick/qdeclarativepositionsource.cpp index ec462f23..c9fd2c8e 100644 --- a/src/positioningquick/qdeclarativepositionsource.cpp +++ b/src/positioningquick/qdeclarativepositionsource.cpp @@ -177,11 +177,10 @@ void QDeclarativePositionSource::setName(const QString &newName) PositioningMethods previousPositioningMethods = supportedPositioningMethods(); PositioningMethods previousPreferredPositioningMethods = preferredPositioningMethods(); - delete m_positionSource; if (newName.isEmpty()) - m_positionSource = QGeoPositionInfoSource::createDefaultSource(this); + setSource(QGeoPositionInfoSource::createDefaultSource(this)); else - m_positionSource = QGeoPositionInfoSource::createSource(newName, this); + setSource(QGeoPositionInfoSource::createSource(newName, this)); if (m_positionSource) { connect(m_positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)), @@ -280,8 +279,7 @@ void QDeclarativePositionSource::setNmeaSource(const QUrl &nmeaSource) // because QNmeaPositionInfoSource can be bound only to a one file. delete m_nmeaSocket; m_nmeaSocket = 0; - delete m_positionSource; - m_positionSource = 0; + setSource(nullptr); setPosition(QGeoPositionInfo()); // Create the NMEA source based on the given data. QML has automatically set QUrl // type to point to correct path. If the file is not found, check if the file actually @@ -296,7 +294,7 @@ void QDeclarativePositionSource::setNmeaSource(const QUrl &nmeaSource) #ifdef QDECLARATIVE_POSITION_DEBUG qDebug() << "QDeclarativePositionSource NMEA File was found: " << localFileName; #endif - m_positionSource = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::SimulationMode); + setSource(new QNmeaPositionInfoSource(QNmeaPositionInfoSource::SimulationMode)); (qobject_cast<QNmeaPositionInfoSource *>(m_positionSource))->setUserEquivalentRangeError(2.5); // it is internally multiplied by 2 in qlocationutils_readGga (qobject_cast<QNmeaPositionInfoSource *>(m_positionSource))->setDevice(m_nmeaFile); connect(m_positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)), @@ -345,9 +343,9 @@ void QDeclarativePositionSource::socketConnected() // because QNmeaPositionInfoSource can be bound only to a one file. delete m_nmeaFile; m_nmeaFile = 0; - delete m_positionSource; + setSource(nullptr); - m_positionSource = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::RealTimeMode); + setSource(new QNmeaPositionInfoSource(QNmeaPositionInfoSource::RealTimeMode)); (qobject_cast<QNmeaPositionInfoSource *>(m_positionSource))->setDevice(m_nmeaSocket); connect(m_positionSource, &QNmeaPositionInfoSource::positionUpdated, @@ -419,6 +417,20 @@ void QDeclarativePositionSource::setPosition(const QGeoPositionInfo &pi) emit positionChanged(); } +void QDeclarativePositionSource::setSource(QGeoPositionInfoSource *source) +{ + if (m_positionSource) + delete m_positionSource; + + if (!source) { + m_positionSource = nullptr; + } else { + m_positionSource = source; + connect(m_positionSource, &QGeoPositionInfoSource::supportedPositioningMethodsChanged, + this, &QDeclarativePositionSource::supportedPositioningMethodsChanged); + } +} + /*! \internal */ @@ -712,7 +724,7 @@ void QDeclarativePositionSource::componentComplete() PositioningMethods previousPositioningMethods = supportedPositioningMethods(); PositioningMethods previousPreferredPositioningMethods = preferredPositioningMethods(); - m_positionSource = QGeoPositionInfoSource::createDefaultSource(this); + setSource(QGeoPositionInfoSource::createDefaultSource(this)); if (m_positionSource) { connect(m_positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdateReceived(QGeoPositionInfo))); diff --git a/src/positioningquick/qdeclarativepositionsource_p.h b/src/positioningquick/qdeclarativepositionsource_p.h index bb9b618a..39bcd899 100644 --- a/src/positioningquick/qdeclarativepositionsource_p.h +++ b/src/positioningquick/qdeclarativepositionsource_p.h @@ -153,6 +153,7 @@ private Q_SLOTS: private: void setPosition(const QGeoPositionInfo &pi); + void setSource(QGeoPositionInfoSource *source); QGeoPositionInfoSource *m_positionSource; QDeclarativePosition m_position; |