diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2019-05-02 18:53:35 +0200 |
---|---|---|
committer | paolo <paolo.angelelli@qt.io> | 2019-07-24 16:25:44 +0200 |
commit | f8694e1f3430b7851fc90e26c6d778a86219379a (patch) | |
tree | fbe92684c4458431bf29d8b68d8cddea7b8e496a /tests | |
parent | 17e3f08377c34d301401fbd3c40b525790fcd9a5 (diff) | |
download | qtlocation-f8694e1f3430b7851fc90e26c6d778a86219379a.tar.gz |
Allow setting backend properties of positioning plugins
This change adds a pair of setter/getter to specify positioning backend
properties at runtime, both in QGeoPositionInfoSource and
QDeclarativePositionSource.
Task-number: QTBUG-66304
Change-Id: Iea9421fb708879bee5c62c4afaf45cbda57f50bb
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative_core/tst_positionsource.qml | 8 | ||||
-rw-r--r-- | tests/auto/positionplugin/plugin.cpp | 29 | ||||
-rw-r--r-- | tests/auto/positionplugin/positionplugin.pro | 2 |
3 files changed, 33 insertions, 6 deletions
diff --git a/tests/auto/declarative_core/tst_positionsource.qml b/tests/auto/declarative_core/tst_positionsource.qml index 9b78936b..7b787a0c 100644 --- a/tests/auto/declarative_core/tst_positionsource.qml +++ b/tests/auto/declarative_core/tst_positionsource.qml @@ -187,7 +187,7 @@ TestCase { compare(directionValidSpyWParams.count, 0) compare(directionSpyWParams.count, 0) - + compare(testingSourceWParams.backendProperty("altitude"), altitudeParameter.value) testingSourceWParams.active = true; tryCompare(updateSpyWParams, "count", 1, 1500); @@ -199,23 +199,25 @@ TestCase { fuzzyCompare(testingSourceWParams.position.direction, 45, 0.1) verify(!testingSourceWParams.position.speedValid) verify(isNaN(testingSourceWParams.position.speed)) + testingSourceWParams.setBackendProperty("altitude", 24.24) tryCompare(updateSpyWParams, "count", 2, 1500); compare(testingSourceWParams.position.coordinate.longitude, 0.2); compare(testingSourceWParams.position.coordinate.latitude, 0.2); - compare(testingSourceWParams.position.coordinate.altitude, altitudeParameter.value); + compare(testingSourceWParams.position.coordinate.altitude, 24.24); compare(directionValidSpyWParams.count, 1) compare(directionSpyWParams.count, 2) fuzzyCompare(testingSourceWParams.position.direction, 45, 0.1) verify(testingSourceWParams.position.speedValid) verify(testingSourceWParams.position.speed > 10000) + compare(testingSourceWParams.backendProperty("altitude"), 24.24) testingSourceWParams.active = false; wait(2500); compare(updateSpyWParams.count, 2); compare(testingSourceWParams.position.coordinate.longitude, 0.2); compare(testingSourceWParams.position.coordinate.latitude, 0.2); - compare(testingSourceWParams.position.coordinate.altitude, altitudeParameter.value); + compare(testingSourceWParams.position.coordinate.altitude, 24.24); compare(directionValidSpyWParams.count, 1) compare(directionSpyWParams.count, 2) fuzzyCompare(testingSourceWParams.position.direction, 45, 0.1) diff --git a/tests/auto/positionplugin/plugin.cpp b/tests/auto/positionplugin/plugin.cpp index b6016b95..9d5c7dd5 100644 --- a/tests/auto/positionplugin/plugin.cpp +++ b/tests/auto/positionplugin/plugin.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ #include <QtPositioning/qgeopositioninfosource.h> +#include <QtPositioning/private/qgeopositioninfosource_p.h> #include <QtPositioning/qgeopositioninfosourcefactory.h> #include <QObject> #include <QtPlugin> @@ -65,15 +66,38 @@ private slots: void doTimeout(); }; +class DummySourcePrivate : public QGeoPositionInfoSourcePrivate +{ +public: + bool setBackendProperty(const QString &name, QVariant value) override + { + if (name == QStringLiteral("altitude")) { + m_altitude = value.toReal(); + return true; + } + return false; + } + QVariant backendProperty(const QString &name) const override + { + if (name == QStringLiteral("altitude")) + return m_altitude; + return QVariant(); + } + + qreal m_altitude = 0.0; +}; + DummySource::DummySource(const QVariantMap ¶meters, QObject *parent) : - QGeoPositionInfoSource(parent), + QGeoPositionInfoSource(*new DummySourcePrivate, parent), timer(new QTimer(this)), timeoutTimer(new QTimer(this)), singleTimer(new QTimer(this)), lastPosition(QGeoCoordinate(0,0), QDateTime::currentDateTime()) { + DummySourcePrivate *dd = static_cast<DummySourcePrivate *>(QGeoPositionInfoSourcePrivate::get(*this)); if (parameters.contains(QStringLiteral("test.source.altitude"))) { const qreal alti = parameters.value(QStringLiteral("test.source.altitude")).toReal(); + dd->m_altitude = alti; QGeoCoordinate crd = lastPosition.coordinate(); crd.setAltitude(alti); lastPosition.setCoordinate(crd); @@ -157,6 +181,7 @@ DummySource::~DummySource() void DummySource::updatePosition() { + DummySourcePrivate *dd = static_cast<DummySourcePrivate *>(QGeoPositionInfoSourcePrivate::get(*this)); timeoutTimer->stop(); singleTimer->stop(); @@ -164,7 +189,7 @@ void DummySource::updatePosition() QGeoCoordinate coord(lastPosition.coordinate().latitude() + 0.1, lastPosition.coordinate().longitude() + 0.1, - lastPosition.coordinate().altitude()); + dd->m_altitude); QGeoPositionInfo info(coord, now); info.setAttribute(QGeoPositionInfo::Direction, lastPosition.coordinate().azimuthTo(coord)); diff --git a/tests/auto/positionplugin/positionplugin.pro b/tests/auto/positionplugin/positionplugin.pro index 9ccd030f..84d08ac0 100644 --- a/tests/auto/positionplugin/positionplugin.pro +++ b/tests/auto/positionplugin/positionplugin.pro @@ -1,5 +1,5 @@ TARGET = qtposition_testplugin -QT += positioning +QT += positioning-private PLUGIN_TYPE = position PLUGIN_CLASS_NAME = QGeoPositionInfoSourceFactoryTest |