diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2021-01-22 14:14:49 +0100 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2021-01-26 17:20:35 +0100 |
commit | 37ff0744c8c5f15606dbc2391b630ea433c3c939 (patch) | |
tree | 57bee3560bae24dd574ea330d28f9aa26c3fb126 | |
parent | 82bc59433ba56139730382881438996c63cad68d (diff) | |
download | qtlocation-37ff0744c8c5f15606dbc2391b630ea433c3c939.tar.gz |
QtPositioning: remove QGeoPositionInfoSource::updateTimeout signal
A new Error::UpdateTimeoutError enum value is introduced instead.
An errorOccurred() signal with this value is used to notify about update
timeouts.
As a result, an updateTimeout() signal is also removed from QML
PositionSource object (QDeclarativePositionSource C++ class). It's also
replaced by the sourceErrorChanged() signal with
PositionSource.UpdateTimeoutError error value.
Apart from that - several more warnings in the unit tests are fixed.
[ChangeLog][QtPositioning][Important Behavior Changes] Removed
QGeoPositionInfoSource::updateTimeout() signal.
Use QGeoPositionInfoSource::errorOccurred() with a new
Error::UpdateTimeoutError value instead.
Removed PositionSource::updateTimeout() signal from QML.
Use PositionSource::sourceErrorChanged() with a new
PositionSource.UpdateTimeoutError value instead.
Task-number: QTBUG-90491
Change-Id: I7458382a5cb7fdea192b3924baf9e86ee28d1028
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
21 files changed, 142 insertions, 124 deletions
diff --git a/examples/positioning/logfilepositionsource/logfilepositionsource.cpp b/examples/positioning/logfilepositionsource/logfilepositionsource.cpp index 9c414c60..6c6c3180 100644 --- a/examples/positioning/logfilepositionsource/logfilepositionsource.cpp +++ b/examples/positioning/logfilepositionsource/logfilepositionsource.cpp @@ -96,10 +96,12 @@ void LogFilePositionSource::requestUpdate(int /*timeout*/) { // For simplicity, ignore timeout - assume that if data is not available // now, no data will be added to the file later - if (logFile->canReadLine()) + if (logFile->canReadLine()) { readNextPosition(); - else - emit updateTimeout(); + } else { + lastError = QGeoPositionInfoSource::UpdateTimeoutError; + emit QGeoPositionInfoSource::errorOccurred(lastError); + } } void LogFilePositionSource::readNextPosition() @@ -128,5 +130,5 @@ void LogFilePositionSource::readNextPosition() QGeoPositionInfoSource::Error LogFilePositionSource::error() const { - return QGeoPositionInfoSource::NoError; + return lastError; } diff --git a/examples/positioning/logfilepositionsource/logfilepositionsource.h b/examples/positioning/logfilepositionsource/logfilepositionsource.h index 027dabd4..aca72ab2 100644 --- a/examples/positioning/logfilepositionsource/logfilepositionsource.h +++ b/examples/positioning/logfilepositionsource/logfilepositionsource.h @@ -82,6 +82,7 @@ private: QFile *logFile; QTimer *timer; QGeoPositionInfo lastPosition; + Error lastError = QGeoPositionInfoSource::NoError; }; #endif diff --git a/src/plugins/position/android/src/qgeopositioninfosource_android.cpp b/src/plugins/position/android/src/qgeopositioninfosource_android.cpp index 0cf68c6d..4bff1da6 100644 --- a/src/plugins/position/android/src/qgeopositioninfosource_android.cpp +++ b/src/plugins/position/android/src/qgeopositioninfosource_android.cpp @@ -160,7 +160,7 @@ void QGeoPositionInfoSourceAndroid::requestUpdate(int timeout) return; if (timeout != 0 && timeout < minimumUpdateInterval()) { - emit updateTimeout(); + setError(QGeoPositionInfoSource::UpdateTimeoutError); return; } @@ -218,7 +218,7 @@ void QGeoPositionInfoSourceAndroid::requestTimeout() const int count = queuedSingleUpdates.count(); if (!count) { - emit updateTimeout(); + setError(QGeoPositionInfoSource::UpdateTimeoutError); return; } diff --git a/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm b/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm index ee8be31d..a4d1753a 100644 --- a/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm +++ b/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm @@ -259,7 +259,7 @@ void QGeoPositionInfoSourceCL::requestUpdate(int timeout) { // Get a single update within timeframe if (timeout < minimumUpdateInterval() && timeout != 0) - emit updateTimeout(); + setError(QGeoPositionInfoSource::UpdateTimeoutError); else if (enableLocationManager()) { // This will force LM to generate a new update [m_locationManager stopUpdatingLocation]; @@ -277,7 +277,7 @@ void QGeoPositionInfoSourceCL::timerEvent( QTimerEvent * event ) { // Update timed out? if (event->timerId() == m_updateTimer) { - emit updateTimeout(); + setError(QGeoPositionInfoSource::UpdateTimeoutError); // Only timeout once since last data setTimeoutInterval(0); diff --git a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp index d133a675..8fbd0a78 100644 --- a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp +++ b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.cpp @@ -127,7 +127,7 @@ void QGeoPositionInfoSourceGeoclueMaster::positionUpdateFailed() m_lastVelocityIsFresh = false; if (m_running && !m_regularUpdateTimedOut) { m_regularUpdateTimedOut = true; - emit updateTimeout(); + setError(QGeoPositionInfoSource::UpdateTimeoutError); } } @@ -182,6 +182,12 @@ void QGeoPositionInfoSourceGeoclueMaster::velocityUpdateFailed() m_lastVelocityIsFresh = false; } +void QGeoPositionInfoSourceGeoclueMaster::setError(QGeoPositionInfoSource::Error error) +{ + m_error = error; + emit errorOccurred(m_error); +} + void QGeoPositionInfoSourceGeoclueMaster::updateVelocity(VelocityFields fields, int timestamp, double speed, double direction, double climb) @@ -329,7 +335,7 @@ void QGeoPositionInfoSourceGeoclueMaster::stopUpdates() void QGeoPositionInfoSourceGeoclueMaster::requestUpdate(int timeout) { if (timeout < minimumUpdateInterval() && timeout != 0) { - emit updateTimeout(); + setError(QGeoPositionInfoSource::UpdateTimeoutError); return; } if (m_requestTimer.isActive()) { @@ -368,7 +374,7 @@ void QGeoPositionInfoSourceGeoclueMaster::positionProviderChanged(const QString if (service.isEmpty() || path.isEmpty()) { if (!m_regularUpdateTimedOut) { m_regularUpdateTimedOut = true; - emit updateTimeout(); + setError(QGeoPositionInfoSource::UpdateTimeoutError); } return; } @@ -405,7 +411,7 @@ void QGeoPositionInfoSourceGeoclueMaster::requestUpdateTimeout() qCDebug(lcPositioningGeoclue) << "request update timeout occurred."; // If we end up here, there has not been valid position update. - emit updateTimeout(); + setError(QGeoPositionInfoSource::UpdateTimeoutError); // Only stop positioning if regular updates not active. if (!m_running) { @@ -476,15 +482,12 @@ void QGeoPositionInfoSourceGeoclueMaster::configurePositionSource() break; default: qWarning("QGeoPositionInfoSourceGeoclueMaster unknown preferred method."); - m_error = UnknownSourceError; - emit QGeoPositionInfoSource::errorOccurred(m_error); + setError(QGeoPositionInfoSource::UnknownSourceError); return; } - if (!created) { - m_error = UnknownSourceError; - emit QGeoPositionInfoSource::errorOccurred(m_error); - } + if (!created) + setError(QGeoPositionInfoSource::UnknownSourceError); } QGeoPositionInfoSource::Error QGeoPositionInfoSourceGeoclueMaster::error() const diff --git a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.h b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.h index b9c4774a..ce39605b 100644 --- a/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.h +++ b/src/plugins/position/geoclue/qgeopositioninfosource_geocluemaster.h @@ -119,6 +119,8 @@ private: double climb); void velocityUpdateFailed(); + void setError(QGeoPositionInfoSource::Error error); + private: QGeoclueMaster *m_master; diff --git a/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp b/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp index 7ca76ae5..622c074f 100644 --- a/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp +++ b/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp @@ -185,7 +185,7 @@ void QGeoPositionInfoSourceGeoclue2::stopUpdates() void QGeoPositionInfoSourceGeoclue2::requestUpdate(int timeout) { if (timeout < minimumUpdateInterval() && timeout != 0) { - emit updateTimeout(); + setError(QGeoPositionInfoSource::UpdateTimeoutError); return; } @@ -382,7 +382,7 @@ void QGeoPositionInfoSourceGeoclue2::requestUpdateTimeout() { qCDebug(lcPositioningGeoclue2) << "Request update timeout occurred"; - emit updateTimeout(); + setError(QGeoPositionInfoSource::UpdateTimeoutError); stopClient(); } diff --git a/src/plugins/position/positionpoll/qgeoareamonitor_polling.cpp b/src/plugins/position/positionpoll/qgeoareamonitor_polling.cpp index cd480bab..0c2912f7 100644 --- a/src/plugins/position/positionpoll/qgeoareamonitor_polling.cpp +++ b/src/plugins/position/positionpoll/qgeoareamonitor_polling.cpp @@ -471,6 +471,7 @@ void QGeoAreaMonitorPolling::positionError(const QGeoPositionInfoSource::Error e lastError = QGeoAreaMonitorSource::UnknownSourceError; break; case QGeoPositionInfoSource::ClosedError: + case QGeoPositionInfoSource::UpdateTimeoutError: lastError = QGeoAreaMonitorSource::InsufficientPositionInfo; break; case QGeoPositionInfoSource::NoError: diff --git a/src/plugins/position/simulator/qgeopositioninfosource_simulator.cpp b/src/plugins/position/simulator/qgeopositioninfosource_simulator.cpp index 3849e9ad..c42d921e 100644 --- a/src/plugins/position/simulator/qgeopositioninfosource_simulator.cpp +++ b/src/plugins/position/simulator/qgeopositioninfosource_simulator.cpp @@ -138,7 +138,7 @@ void QGeoPositionInfoSourceSimulator::requestUpdate(int timeout) if (!requestTimer->isActive()) { // Get a single update within timeframe if (timeout < minimumUpdateInterval() && timeout != 0) - emit updateTimeout(); + setError(QGeoPositionInfoSource::UpdateTimeoutError); else { requestTimer->start(timeout * qreal(0.75)); } @@ -151,7 +151,7 @@ void QGeoPositionInfoSourceSimulator::updatePosition() lastPosition = Simulator::toPositionInfo(*qtPositionInfo()); emit positionUpdated(lastPosition); } else { - emit updateTimeout(); + setError(QGeoPositionInfoSource::UpdateTimeoutError); } } diff --git a/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp b/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp index 46164273..a8e9816f 100644 --- a/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp +++ b/src/plugins/position/winrt/qgeopositioninfosource_winrt.cpp @@ -395,7 +395,8 @@ void QGeoPositionInfoSourceWinRT::requestUpdate(int timeout) setError(QGeoPositionInfoSource::NoError); if (timeout != 0 && timeout < minimumUpdateInterval()) { - emit updateTimeout(); + d->positionError = QGeoPositionInfoSource::UpdateTimeoutError; + emit QGeoPositionInfoSource::errorOccurred(d->positionError); return; } @@ -432,7 +433,8 @@ void QGeoPositionInfoSourceWinRT::singleUpdateTimeOut() QMutexLocker locker(&d->mutex); if (d->singleUpdateTimer.isActive()) { - emit updateTimeout(); + d->positionError = QGeoPositionInfoSource::UpdateTimeoutError; + emit QGeoPositionInfoSource::errorOccurred(d->positionError); if (!d->updatesOngoing) stopHandler(); } diff --git a/src/positioning/qgeopositioninfosource.cpp b/src/positioning/qgeopositioninfosource.cpp index d8cc89d7..42e2bdae 100644 --- a/src/positioning/qgeopositioninfosource.cpp +++ b/src/positioning/qgeopositioninfosource.cpp @@ -501,11 +501,13 @@ QGeoPositionInfoSource::QGeoPositionInfoSource(QGeoPositionInfoSourcePrivate &dd If setUpdateInterval() has not been called, the source will emit updates as soon as they become available. - An updateTimeout() signal will be emitted if this QGeoPositionInfoSource subclass determines - that it will not be able to provide regular updates. This could happen if a satellite fix is - lost or if a hardware error is detected. Position updates will recommence if the data becomes - available later on. The updateTimeout() signal will not be emitted again until after the - periodic updates resume. + An errorOccurred() signal with the \l {QGeoPositionInfoSource::Error::} + {UpdateTimeoutError} will be emitted if this QGeoPositionInfoSource subclass + determines that it will not be able to provide regular updates. This could + happen if a satellite fix is lost or if a hardware error is detected. + Position updates will recommence if the data becomes available later on. + The \l {QGeoPositionInfoSource::Error::}{UpdateTimeoutError} error will not + be emitted again until after the periodic updates resume. On iOS, starting from version 8, Core Location framework requires additional entries in the application's Info.plist with keys NSLocationAlwaysUsageDescription or @@ -530,7 +532,8 @@ QGeoPositionInfoSource::QGeoPositionInfoSource(QGeoPositionInfoSourcePrivate &dd Attempts to get the current position and emit positionUpdated() with this information. If the current position cannot be found within the given \a timeout (in milliseconds) or if \a timeout is less than the value returned by - minimumUpdateInterval(), updateTimeout() is emitted. + minimumUpdateInterval(), an errorOccurred() signal with the + \l {QGeoPositionInfoSource::Error::}{UpdateTimeoutError} is emitted. If the timeout is zero, the timeout defaults to a reasonable timeout period as appropriate for the source. @@ -561,28 +564,10 @@ QGeoPositionInfoSource::QGeoPositionInfoSource(QGeoPositionInfoSourcePrivate &dd */ /*! - \fn void QGeoPositionInfoSource::updateTimeout(); - - If requestUpdate() was called, this signal will be emitted if the current position could not - be retrieved within the specified timeout. - - If startUpdates() has been called, this signal will be emitted if this QGeoPositionInfoSource - subclass determines that it will not be able to provide further regular updates. This signal - will not be emitted again until after the regular updates resume. - - While the triggering of this signal may be considered an error condition, it does not - imply the emission of the \c error() signal. Only the emission of \c updateTimeout() is required - to indicate a timeout. -*/ - -/*! \fn void QGeoPositionInfoSource::errorOccurred(QGeoPositionInfoSource::Error positioningError) This signal is emitted after an error occurred. The \a positioningError parameter describes the type of error that occurred. - - This signal is not emitted when an updateTimeout() has occurred. - */ /*! @@ -597,6 +582,13 @@ QGeoPositionInfoSource::QGeoPositionInfoSource(QGeoPositionInfoSourcePrivate &dd regular updates will resume. \value NoError No error has occurred. \value UnknownSourceError An unidentified error occurred. + \value [since 6.2] UpdateTimeoutError If requestUpdate() was called, this + error indicates that the current position could not be retrieved within + the specified timeout. If startUpdates() was called, this error + indicates that this QGeoPositionInfoSource subclass determined that it + will not be able to provide further regular updates. In the latter case + the error would not be emitted again until after the regular updates + resume. */ /*! diff --git a/src/positioning/qgeopositioninfosource.h b/src/positioning/qgeopositioninfosource.h index b5d85a6a..c2ed23dd 100644 --- a/src/positioning/qgeopositioninfosource.h +++ b/src/positioning/qgeopositioninfosource.h @@ -59,9 +59,10 @@ public: AccessError = 0, ClosedError = 1, UnknownSourceError = 2, - NoError = 3 + NoError = 3, + UpdateTimeoutError = 4 }; - Q_ENUMS(Error) + Q_ENUM(Error) enum PositioningMethod { NoPositioningMethods = 0x00000000, @@ -105,7 +106,6 @@ public Q_SLOTS: Q_SIGNALS: void positionUpdated(const QGeoPositionInfo &update); - void updateTimeout(); void errorOccurred(QGeoPositionInfoSource::Error); void supportedPositioningMethodsChanged(); diff --git a/src/positioning/qnmeapositioninfosource.cpp b/src/positioning/qnmeapositioninfosource.cpp index 131fe52a..fa4dffd2 100644 --- a/src/positioning/qnmeapositioninfosource.cpp +++ b/src/positioning/qnmeapositioninfosource.cpp @@ -620,7 +620,7 @@ void QNmeaPositionInfoSourcePrivate::requestUpdate(int msec) return; if (msec <= 0 || msec < m_source->minimumUpdateInterval()) { - emit m_source->updateTimeout(); + m_source->setError(QGeoPositionInfoSource::UpdateTimeoutError); return; } @@ -631,7 +631,7 @@ void QNmeaPositionInfoSourcePrivate::requestUpdate(int msec) bool initialized = initialize(); if (!initialized) { - emit m_source->updateTimeout(); + m_source->setError(QGeoPositionInfoSource::UpdateTimeoutError); return; } @@ -642,7 +642,7 @@ void QNmeaPositionInfoSourcePrivate::requestUpdate(int msec) void QNmeaPositionInfoSourcePrivate::updateRequestTimeout() { m_requestTimer->stop(); - emit m_source->updateTimeout(); + m_source->setError(QGeoPositionInfoSource::UpdateTimeoutError); } void QNmeaPositionInfoSourcePrivate::notifyNewUpdate(QGeoPositionInfo *update, bool hasFix) @@ -710,7 +710,7 @@ void QNmeaPositionInfoSourcePrivate::emitPendingUpdate() if (m_noUpdateLastInterval && !m_updateTimeoutSent) { m_updateTimeoutSent = true; m_pendingUpdate = QGeoPositionInfo(); // Invalid already, but clear just in case. - emit m_source->updateTimeout(); + m_source->setError(QGeoPositionInfoSource::UpdateTimeoutError); } m_noUpdateLastInterval = true; } diff --git a/src/positioningquick/qdeclarativepositionsource.cpp b/src/positioningquick/qdeclarativepositionsource.cpp index b3723956..f3b64b66 100644 --- a/src/positioningquick/qdeclarativepositionsource.cpp +++ b/src/positioningquick/qdeclarativepositionsource.cpp @@ -114,21 +114,6 @@ QT_BEGIN_NAMESPACE */ -/*! - \qmlsignal PositionSource::updateTimeout() - - If \l update() was called, this signal is emitted if the current position could not be - retrieved within a certain amount of time. - - If \l start() was called, this signal is emitted if the position engine determines that - it is not able to provide further regular updates. - - \since Qt Positioning 5.5 - - \sa QGeoPositionInfoSource::updateTimeout() -*/ - - QDeclarativePositionSource::QDeclarativePositionSource() : m_positionSource(0), m_preferredPositioningMethods(NoPositioningMethods), m_nmeaFile(0), m_nmeaSocket(0), m_active(false), m_singleUpdate(false), m_updateInterval(0), @@ -214,8 +199,6 @@ void QDeclarativePositionSource::tryAttach(const QString &newName, bool useFallb this, SLOT(positionUpdateReceived(QGeoPositionInfo))); connect(m_positionSource, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error)), this, SLOT(sourceErrorReceived(QGeoPositionInfoSource::Error))); - connect(m_positionSource, SIGNAL(updateTimeout()), - this, SLOT(updateTimeoutReceived())); m_positionSource->setUpdateInterval(m_updateInterval); m_positionSource->setPreferredPositioningMethods( @@ -334,8 +317,6 @@ void QDeclarativePositionSource::setNmeaSource(const QUrl &nmeaSource) this, SLOT(positionUpdateReceived(QGeoPositionInfo))); connect(m_positionSource, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error)), this, SLOT(sourceErrorReceived(QGeoPositionInfoSource::Error))); - connect(m_positionSource, SIGNAL(updateTimeout()), - this, SLOT(updateTimeoutReceived())); setPosition(m_positionSource->lastKnownPosition()); if (m_active && !m_singleUpdate) { @@ -385,8 +366,6 @@ void QDeclarativePositionSource::socketConnected() this, &QDeclarativePositionSource::positionUpdateReceived); connect(m_positionSource, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error)), this, SLOT(sourceErrorReceived(QGeoPositionInfoSource::Error))); - connect(m_positionSource, SIGNAL(updateTimeout()), - this, SLOT(updateTimeoutReceived())); setPosition(m_positionSource->lastKnownPosition()); @@ -427,8 +406,10 @@ void QDeclarativePositionSource::socketError(QAbstractSocket::SocketError error) } -void QDeclarativePositionSource::updateTimeoutReceived() +void QDeclarativePositionSource::handleUpdateTimeout() { + m_sourceError = QDeclarativePositionSource::UpdateTimeoutError; + if (!m_active) return; @@ -440,8 +421,6 @@ void QDeclarativePositionSource::updateTimeoutReceived() m_active = false; emit activeChanged(); } - - emit updateTimeout(); } /*! @@ -777,6 +756,9 @@ void QDeclarativePositionSource::positionUpdateReceived(const QGeoPositionInfo & regular updates will resume. \li PositionSource.NoError - No error has occurred. \li PositionSource.UnknownSourceError - An unidentified error occurred. + \li PositionSource.UpdateTimeoutError - The current position could not be + retrieved within the specified timeout, or this PositionSource determined + that it will not be able to provide further regular updates. \li PositionSource.SocketError - An error occurred while connecting to an nmea source using a socket. \endlist @@ -908,6 +890,8 @@ void QDeclarativePositionSource::sourceErrorReceived(const QGeoPositionInfoSourc m_sourceError = QDeclarativePositionSource::AccessError; else if (error == QGeoPositionInfoSource::ClosedError) m_sourceError = QDeclarativePositionSource::ClosedError; + else if (error == QGeoPositionInfoSource::UpdateTimeoutError) + handleUpdateTimeout(); // also sets m_sourceError else if (error == QGeoPositionInfoSource::NoError) return; //nothing to do else diff --git a/src/positioningquick/qdeclarativepositionsource_p.h b/src/positioningquick/qdeclarativepositionsource_p.h index aadb8772..96bc69f8 100644 --- a/src/positioningquick/qdeclarativepositionsource_p.h +++ b/src/positioningquick/qdeclarativepositionsource_p.h @@ -99,6 +99,7 @@ public: ClosedError = QGeoPositionInfoSource::ClosedError, UnknownSourceError = QGeoPositionInfoSource::UnknownSourceError, NoError = QGeoPositionInfoSource::NoError, + UpdateTimeoutError = QGeoPositionInfoSource::UpdateTimeoutError, //Leave a gap for future error enum values in QGeoPositionInfoSource::Error SocketError = 100 @@ -149,17 +150,16 @@ Q_SIGNALS: void sourceErrorChanged(); void nameChanged(); void validityChanged(); - void updateTimeout(); private Q_SLOTS: void positionUpdateReceived(const QGeoPositionInfo &update); void sourceErrorReceived(const QGeoPositionInfoSource::Error error); void socketConnected(); void socketError(QAbstractSocket::SocketError error); - void updateTimeoutReceived(); void onParameterInitialized(); private: + void handleUpdateTimeout(); void setPosition(const QGeoPositionInfo &pi); void setSource(QGeoPositionInfoSource *source); bool parametersReady(); diff --git a/tests/applications/positioning_backend/widget.cpp b/tests/applications/positioning_backend/widget.cpp index 627ae2d6..ea1739de 100644 --- a/tests/applications/positioning_backend/widget.cpp +++ b/tests/applications/positioning_backend/widget.cpp @@ -45,8 +45,6 @@ Widget::Widget(LogWidget *logWidget, QWidget *parent) : connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(setInterval(int))); - connect(m_posSource, SIGNAL(updateTimeout()), - this, SLOT(positionTimedOut())); ui->groupBox->setLayout(ui->gridLayout); ui->horizontalSlider->setMinimum(m_posSource->minimumUpdateInterval()); @@ -102,9 +100,15 @@ void Widget::positionTimedOut() void Widget::errorChanged(QGeoPositionInfoSource::Error err) { - ui->labelErrorState->setText(QString::number(err)); - m_posSource->stopUpdates(); - ui->checkBox->setChecked(false); + if (err == QGeoPositionInfoSource::UpdateTimeoutError) { + // handle timeout + positionTimedOut(); + } else { + // handle other errors + ui->labelErrorState->setText(QString::number(err)); + m_posSource->stopUpdates(); + ui->checkBox->setChecked(false); + } } Widget::~Widget() diff --git a/tests/auto/positionplugin/plugin.cpp b/tests/auto/positionplugin/plugin.cpp index b888a53c..441bbf45 100644 --- a/tests/auto/positionplugin/plugin.cpp +++ b/tests/auto/positionplugin/plugin.cpp @@ -60,6 +60,7 @@ private: QTimer *singleTimer; QGeoPositionInfo lastPosition; QDateTime lastUpdateTime; + Error lastError = QGeoPositionInfoSource::NoError; private slots: void updatePosition(); @@ -113,7 +114,7 @@ DummySource::DummySource(const QVariantMap ¶meters, QObject *parent) : QGeoPositionInfoSource::Error DummySource::error() const { - return QGeoPositionInfoSource::NoError; + return lastError; } @@ -207,7 +208,8 @@ void DummySource::doTimeout() { timeoutTimer->stop(); singleTimer->stop(); - emit updateTimeout(); + lastError = QGeoPositionInfoSource::UpdateTimeoutError; + emit QGeoPositionInfoSource::errorOccurred(lastError); } diff --git a/tests/auto/qgeoareamonitor/logfilepositionsource.cpp b/tests/auto/qgeoareamonitor/logfilepositionsource.cpp index a613d6ea..94c463a4 100644 --- a/tests/auto/qgeoareamonitor/logfilepositionsource.cpp +++ b/tests/auto/qgeoareamonitor/logfilepositionsource.cpp @@ -76,10 +76,12 @@ void LogFilePositionSource::requestUpdate(int /*timeout*/) { // For simplicity, ignore timeout - assume that if data is not available // now, no data will be added to the file later - if (logFile->canReadLine()) + if (logFile->canReadLine()) { readNextPosition(); - else - emit updateTimeout(); + } else { + lastError = QGeoPositionInfoSource::UpdateTimeoutError; + emit errorOccurred(lastError); + } } void LogFilePositionSource::readNextPosition() @@ -108,5 +110,5 @@ void LogFilePositionSource::readNextPosition() QGeoPositionInfoSource::Error LogFilePositionSource::error() const { - return QGeoPositionInfoSource::NoError; + return lastError; } diff --git a/tests/auto/qgeoareamonitor/logfilepositionsource.h b/tests/auto/qgeoareamonitor/logfilepositionsource.h index c284109e..370b2113 100644 --- a/tests/auto/qgeoareamonitor/logfilepositionsource.h +++ b/tests/auto/qgeoareamonitor/logfilepositionsource.h @@ -61,6 +61,7 @@ private: QFile *logFile; QTimer *timer; QGeoPositionInfo lastPosition; + Error lastError = QGeoPositionInfoSource::NoError; }; #endif diff --git a/tests/auto/qgeopositioninfosource/testqgeopositioninfosource.cpp b/tests/auto/qgeopositioninfosource/testqgeopositioninfosource.cpp index 953d885a..b165fd50 100644 --- a/tests/auto/qgeopositioninfosource/testqgeopositioninfosource.cpp +++ b/tests/auto/qgeopositioninfosource/testqgeopositioninfosource.cpp @@ -326,7 +326,7 @@ void TestQGeoPositionInfoSource::lastKnownPosition() m_source->setPreferredPositioningMethods(positioningMethod); QSignalSpy spy(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy timeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); int time_out = 7000; m_source->setUpdateInterval(time_out); m_source->startUpdates(); @@ -423,7 +423,7 @@ void TestQGeoPositionInfoSource::startUpdates_testIntervals() { CHECK_SOURCE_VALID; QSignalSpy spy(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy timeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->setUpdateInterval(7000); int interval = m_source->updateInterval(); @@ -451,7 +451,7 @@ void TestQGeoPositionInfoSource::startUpdates_testIntervalChangesWhileRunning() CHECK_SOURCE_VALID; QSignalSpy spy(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy timeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->setUpdateInterval(0); m_source->startUpdates(); m_source->setUpdateInterval(0); @@ -499,7 +499,7 @@ void TestQGeoPositionInfoSource::startUpdates_testDefaultInterval() CHECK_SOURCE_VALID; QSignalSpy spy(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy timeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->startUpdates(); for (int i = 0; i < 3; i++) { @@ -515,7 +515,7 @@ void TestQGeoPositionInfoSource::startUpdates_testZeroInterval() CHECK_SOURCE_VALID; QSignalSpy spy(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy timeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->setUpdateInterval(0); m_source->startUpdates(); for (int i = 0; i < 3; i++) { @@ -530,7 +530,7 @@ void TestQGeoPositionInfoSource::startUpdates_moreThanOnce() CHECK_SOURCE_VALID; QSignalSpy spy(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy timeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->setUpdateInterval(0); m_source->startUpdates(); @@ -549,7 +549,7 @@ void TestQGeoPositionInfoSource::stopUpdates() CHECK_SOURCE_VALID; QSignalSpy spy(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy timeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->setUpdateInterval(7000); m_source->startUpdates(); for (int i = 0; i < 2; i++) { @@ -578,9 +578,12 @@ void TestQGeoPositionInfoSource::requestUpdate() { CHECK_SOURCE_VALID; QFETCH(int, timeout); - QSignalSpy spy(m_source, SIGNAL(updateTimeout())); + QSignalSpy spy(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->requestUpdate(timeout); QTRY_COMPARE(spy.count(), 1); + const QList<QVariant> arguments = spy.takeFirst(); + const auto error = arguments.at(0).value<QGeoPositionInfoSource::Error>(); + QCOMPARE(error, QGeoPositionInfoSource::UpdateTimeoutError); } void TestQGeoPositionInfoSource::requestUpdate_data() @@ -595,7 +598,7 @@ void TestQGeoPositionInfoSource::requestUpdate_validTimeout() CHECK_SOURCE_VALID; QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy spyTimeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->requestUpdate(7000); @@ -606,7 +609,7 @@ void TestQGeoPositionInfoSource::requestUpdate_defaultTimeout() { CHECK_SOURCE_VALID; QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy spyTimeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->requestUpdate(0); @@ -619,10 +622,13 @@ void TestQGeoPositionInfoSource::requestUpdate_timeoutLessThanMinimumInterval() { CHECK_SOURCE_VALID; - QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy spyTimeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->requestUpdate(1); QTRY_COMPARE_WITH_TIMEOUT(spyTimeout.count(), 1, 1000); + const QList<QVariant> arguments = spyTimeout.takeFirst(); + const auto error = arguments.at(0).value<QGeoPositionInfoSource::Error>(); + QCOMPARE(error, QGeoPositionInfoSource::UpdateTimeoutError); } // TC_ID_3_x_3 : Call requestUpdate() with same value repeatedly @@ -631,7 +637,7 @@ void TestQGeoPositionInfoSource::requestUpdate_repeatedCalls() CHECK_SOURCE_VALID; QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy spyTimeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->requestUpdate(7000); @@ -647,7 +653,7 @@ void TestQGeoPositionInfoSource::requestUpdate_overlappingCalls() CHECK_SOURCE_VALID; QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy spyTimeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->requestUpdate(7000); m_source->requestUpdate(7000); @@ -661,7 +667,7 @@ void TestQGeoPositionInfoSource::requestUpdateAfterStartUpdates_ZeroInterval() CHECK_SOURCE_VALID; QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy spyTimeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->setUpdateInterval(0); m_source->startUpdates(); @@ -685,7 +691,7 @@ void TestQGeoPositionInfoSource::requestUpdateAfterStartUpdates_SmallInterval() CHECK_SOURCE_VALID; QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy spyTimeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->setUpdateInterval(10000); m_source->startUpdates(); @@ -708,7 +714,7 @@ void TestQGeoPositionInfoSource::requestUpdateBeforeStartUpdates_ZeroInterval() CHECK_SOURCE_VALID; QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy spyTimeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->requestUpdate(7000); @@ -729,7 +735,7 @@ void TestQGeoPositionInfoSource::requestUpdateBeforeStartUpdates_SmallInterval() { CHECK_SOURCE_VALID; QSignalSpy spyUpdate(m_source, SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy spyTimeout(m_source, SIGNAL(updateTimeout())); + QSignalSpy spyTimeout(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); m_source->requestUpdate(7000); @@ -748,11 +754,14 @@ void TestQGeoPositionInfoSource::removeSlotForRequestTimeout() { CHECK_SOURCE_VALID; - bool i = connect(m_source, SIGNAL(updateTimeout()), this, SLOT(test_slot1())); + bool i = connect(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error)), + this, SLOT(test_slot1())); QVERIFY(i == true); - i = connect(m_source, SIGNAL(updateTimeout()), this, SLOT(test_slot2())); + i = connect(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error)), + this, SLOT(test_slot2())); QVERIFY(i == true); - i = disconnect(m_source, SIGNAL(updateTimeout()), this, SLOT(test_slot1())); + i = disconnect(m_source, SIGNAL(errorOccurred(QGeoPositionInfoSource::Error)), + this, SLOT(test_slot1())); QVERIFY(i == true); m_source->requestUpdate(-1); diff --git a/tests/auto/qnmeapositioninfosource/tst_qnmeapositioninfosource.cpp b/tests/auto/qnmeapositioninfosource/tst_qnmeapositioninfosource.cpp index 51f996fb..44f7508a 100644 --- a/tests/auto/qnmeapositioninfosource/tst_qnmeapositioninfosource.cpp +++ b/tests/auto/qnmeapositioninfosource/tst_qnmeapositioninfosource.cpp @@ -137,13 +137,16 @@ void tst_QNmeaPositionInfoSource::lastKnownPosition() // source may need requestUpdate() or startUpdates() to be called to // trigger reading of data channel - QSignalSpy spyTimeout(proxy->source(), SIGNAL(updateTimeout())); + QSignalSpy spyTimeout(proxy->source(), SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); proxy->source()->requestUpdate(proxy->source()->minimumUpdateInterval()); QTRY_COMPARE(spyTimeout.count(), 1); + const QList<QVariant> arguments = spyTimeout.takeFirst(); + const auto error = arguments.at(0).value<QGeoPositionInfoSource::Error>(); + QCOMPARE(error, QGeoPositionInfoSource::UpdateTimeoutError); // If an update is received and startUpdates() or requestUpdate() hasn't // been called, it should still be available through lastKnownPosition() - QDateTime dt = QDateTime::currentDateTime().toUTC(); + QDateTime dt = QDateTime::currentDateTimeUtc(); proxy->feedUpdate(dt); QTRY_COMPARE(proxy->source()->lastKnownPosition().timestamp(), dt); @@ -251,12 +254,12 @@ void tst_QNmeaPositionInfoSource::startUpdates_withTimeout() QNmeaPositionInfoSourceProxy *proxy = static_cast<QNmeaPositionInfoSourceProxy*>(factory.createProxy(&source)); QSignalSpy spyUpdate(proxy->source(), SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy spyTimeout(proxy->source(), SIGNAL(updateTimeout())); + QSignalSpy spyTimeout(proxy->source(), SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); proxy->source()->setUpdateInterval(1000); proxy->source()->startUpdates(); - QDateTime dt = QDateTime::currentDateTime().toUTC(); + QDateTime dt = QDateTime::currentDateTimeUtc(); if (m_mode == QNmeaPositionInfoSource::SimulationMode) { // the first sentence primes the simulation @@ -279,6 +282,9 @@ void tst_QNmeaPositionInfoSource::startUpdates_withTimeout() spyUpdate.clear(); QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() == 0) && (spyTimeout.count() == 1), 7500); + const QList<QVariant> arguments = spyTimeout.takeFirst(); + const auto error = arguments.at(0).value<QGeoPositionInfoSource::Error>(); + QCOMPARE(error, QGeoPositionInfoSource::UpdateTimeoutError); spyTimeout.clear(); QTRY_VERIFY_WITH_TIMEOUT((spyUpdate.count() == 1) && (spyTimeout.count() == 0), 7500); @@ -310,6 +316,9 @@ void tst_QNmeaPositionInfoSource::startUpdates_withTimeout() // dt + 6900 QTRY_VERIFY(spyUpdate.count() == 0 && spyTimeout.count() == 1); + const QList<QVariant> arguments = spyTimeout.takeFirst(); + const auto error = arguments.at(0).value<QGeoPositionInfoSource::Error>(); + QCOMPARE(error, QGeoPositionInfoSource::UpdateTimeoutError); spyTimeout.clear(); proxy->feedBytes(QLocationTestUtils::createRmcSentence(dt.addSecs(7)).toLatin1()); @@ -475,14 +484,16 @@ void tst_QNmeaPositionInfoSource::requestUpdate() QNmeaPositionInfoSourceProxy *proxy = static_cast<QNmeaPositionInfoSourceProxy*>(factory.createProxy(&source)); QSignalSpy spyUpdate(proxy->source(), SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy spyTimeout(proxy->source(), SIGNAL(updateTimeout())); + QSignalSpy spyTimeout(proxy->source(), SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); QDateTime dt; proxy->source()->requestUpdate(100); QTRY_COMPARE(spyTimeout.count(), 1); + auto error = spyTimeout[0][0].value<QGeoPositionInfoSource::Error>(); + QCOMPARE(error, QGeoPositionInfoSource::UpdateTimeoutError); spyTimeout.clear(); - dt = QDateTime::currentDateTime().toUTC(); + dt = QDateTime::currentDateTimeUtc(); proxy->feedUpdate(dt); proxy->source()->requestUpdate(); QTRY_COMPARE(spyUpdate.count(), 1); @@ -491,7 +502,7 @@ void tst_QNmeaPositionInfoSource::requestUpdate() spyUpdate.clear(); // delay the update and expect it to be emitted after 300ms - dt = QDateTime::currentDateTime().toUTC(); + dt = QDateTime::currentDateTimeUtc(); proxy->source()->requestUpdate(1000); QTest::qWait(300); proxy->feedUpdate(dt); @@ -500,12 +511,14 @@ void tst_QNmeaPositionInfoSource::requestUpdate() QCOMPARE(spyTimeout.count(), 0); spyUpdate.clear(); - // delay the update and expect updateTimeout() to be emitted - dt = QDateTime::currentDateTime().toUTC(); + // delay the update and expect errorOccurred() to be emitted + dt = QDateTime::currentDateTimeUtc(); proxy->source()->requestUpdate(500); QTest::qWait(1000); proxy->feedUpdate(dt); QCOMPARE(spyTimeout.count(), 1); + error = spyTimeout[0][0].value<QGeoPositionInfoSource::Error>(); + QCOMPARE(error, QGeoPositionInfoSource::UpdateTimeoutError); QCOMPARE(spyUpdate.count(), 0); spyUpdate.clear(); } @@ -517,14 +530,14 @@ void tst_QNmeaPositionInfoSource::requestUpdate_after_start() QNmeaPositionInfoSourceProxy *proxy = static_cast<QNmeaPositionInfoSourceProxy*>(factory.createProxy(&source)); QSignalSpy spyUpdate(proxy->source(), SIGNAL(positionUpdated(QGeoPositionInfo))); - QSignalSpy spyTimeout(proxy->source(), SIGNAL(updateTimeout())); + QSignalSpy spyTimeout(proxy->source(), SIGNAL(errorOccurred(QGeoPositionInfoSource::Error))); // Start updates with 500ms interval and requestUpdate() with 100ms // timeout. Feed an update, and it should be emitted immediately due to // the requestUpdate(). The update should not be emitted again after that // (i.e. the startUpdates() interval should not cause it to be re-emitted). - QDateTime dt = QDateTime::currentDateTime().toUTC(); + QDateTime dt = QDateTime::currentDateTimeUtc(); proxy->source()->setUpdateInterval(500); proxy->source()->startUpdates(); proxy->source()->requestUpdate(100); @@ -566,7 +579,7 @@ void tst_QNmeaPositionInfoSource::testWithBadNmea_data() QTest::addColumn<QList<QDateTime> >("dateTimes"); QTest::addColumn<UpdateTriggerMethod>("trigger"); - QDateTime firstDateTime = QDateTime::currentDateTime().toUTC(); + QDateTime firstDateTime = QDateTime::currentDateTimeUtc(); QByteArray bad = QLocationTestUtils::createRmcSentence(firstDateTime.addSecs(1)).toLatin1(); bad = bad.mid(bad.length()/2); QDateTime lastDateTime = firstDateTime.addSecs(2); |