diff options
-rw-r--r-- | src/location/doc/src/plugins/osm.qdoc | 3 | ||||
-rw-r--r-- | src/plugins/geoservices/osm/qgeocodereplyosm.cpp | 22 | ||||
-rw-r--r-- | src/plugins/geoservices/osm/qgeocodereplyosm.h | 6 | ||||
-rw-r--r-- | src/plugins/geoservices/osm/qgeocodingmanagerengineosm.cpp | 6 | ||||
-rw-r--r-- | src/plugins/geoservices/osm/qgeocodingmanagerengineosm.h | 1 | ||||
-rw-r--r-- | src/positioning/qdeclarativegeolocation.cpp | 15 | ||||
-rw-r--r-- | src/positioning/qdeclarativegeolocation_p.h | 6 | ||||
-rw-r--r-- | src/positioning/qgeolocation.cpp | 27 | ||||
-rw-r--r-- | src/positioning/qgeolocation.h | 4 | ||||
-rw-r--r-- | src/positioning/qgeolocation_p.h | 2 | ||||
-rw-r--r-- | tests/auto/declarative_core/tst_geocoding.qml | 24 | ||||
-rw-r--r-- | tests/auto/geotestplugin/qgeocodingmanagerengine_test.h | 53 | ||||
-rw-r--r-- | tests/auto/qgeolocation/tst_qgeolocation.cpp | 32 | ||||
-rw-r--r-- | tests/auto/qgeolocation/tst_qgeolocation.h | 2 |
14 files changed, 190 insertions, 13 deletions
diff --git a/src/location/doc/src/plugins/osm.qdoc b/src/location/doc/src/plugins/osm.qdoc index 9e0a9842..1fbb7d3e 100644 --- a/src/location/doc/src/plugins/osm.qdoc +++ b/src/location/doc/src/plugins/osm.qdoc @@ -71,6 +71,9 @@ a prefix. \note The API documentation is available at \l {https://wiki.openstreetmap.org/wiki/Nominatim}{Project OSM Nominatim}. \li osm.geocoding.debug_query \li Instructs the plugin to inject the query url to nominatim into the geocode reply, for debugging purposes. + \li osm.geocoding.include_extended_data + \li Instructs the plugin to include Nominatim-specific information (such as geometry and class) into the returned Location + objects, exposed as extendedAttributes. \row \li osm.mapping.cache.directory \li Absolute path to map tile cache directory used as network disk cache. diff --git a/src/plugins/geoservices/osm/qgeocodereplyosm.cpp b/src/plugins/geoservices/osm/qgeocodereplyosm.cpp index 11bdaa6c..0bdf4bf9 100644 --- a/src/plugins/geoservices/osm/qgeocodereplyosm.cpp +++ b/src/plugins/geoservices/osm/qgeocodereplyosm.cpp @@ -49,8 +49,8 @@ QT_BEGIN_NAMESPACE -QGeoCodeReplyOsm::QGeoCodeReplyOsm(QNetworkReply *reply, QObject *parent) -: QGeoCodeReply(*new QGeoCodeReplyOsmPrivate, parent) +QGeoCodeReplyOsm::QGeoCodeReplyOsm(QNetworkReply *reply, bool includeExtraData, QObject *parent) +: QGeoCodeReply(*new QGeoCodeReplyOsmPrivate, parent), m_includeExtraData(includeExtraData) { if (!reply) { setError(UnknownError, QStringLiteral("Null reply")); @@ -98,6 +98,20 @@ static QGeoAddress parseAddressObject(const QJsonObject &object) return address; } +static void injectExtra(QGeoLocation &location, const QJsonObject &object) +{ + QVariantMap extra; + static const QList<QString> extraKeys = { QStringLiteral("geojson"), + QStringLiteral("class") }; + + for (const auto k: extraKeys) { + if (object.contains(k)) + extra[k] = object.value(k).toVariant(); + } + + location.setExtendedAttributes(extra); +} + void QGeoCodeReplyOsm::networkReplyFinished() { QNetworkReply *reply = static_cast<QNetworkReply *>(sender()); @@ -121,6 +135,8 @@ void QGeoCodeReplyOsm::networkReplyFinished() location.setCoordinate(coordinate); location.setAddress(parseAddressObject(object)); + if (m_includeExtraData) + injectExtra(location, object); locations.append(location); setLocations(locations); @@ -154,6 +170,8 @@ void QGeoCodeReplyOsm::networkReplyFinished() location.setCoordinate(coordinate); location.setBoundingBox(rectangle); location.setAddress(parseAddressObject(object)); + if (m_includeExtraData) + injectExtra(location, object); locations.append(location); } diff --git a/src/plugins/geoservices/osm/qgeocodereplyosm.h b/src/plugins/geoservices/osm/qgeocodereplyosm.h index b81b8b84..f00a8bb2 100644 --- a/src/plugins/geoservices/osm/qgeocodereplyosm.h +++ b/src/plugins/geoservices/osm/qgeocodereplyosm.h @@ -51,12 +51,15 @@ class QGeoCodeReplyOsm : public QGeoCodeReply Q_OBJECT public: - explicit QGeoCodeReplyOsm(QNetworkReply *reply, QObject *parent = 0); + explicit QGeoCodeReplyOsm(QNetworkReply *reply, bool includeExtraData = false, QObject *parent = 0); ~QGeoCodeReplyOsm(); private Q_SLOTS: void networkReplyFinished(); void networkReplyError(QNetworkReply::NetworkError error); + +private: + bool m_includeExtraData = false; }; class QGeoCodeReplyOsmPrivate : public QGeoCodeReplyPrivate @@ -66,7 +69,6 @@ public: ~QGeoCodeReplyOsmPrivate(); QVariantMap extraData() const override; - bool m_includeGeometry = false; QVariantMap m_extraData; }; diff --git a/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.cpp b/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.cpp index 9403cfa8..b2744551 100644 --- a/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.cpp +++ b/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.cpp @@ -88,6 +88,8 @@ QGeoCodingManagerEngineOsm::QGeoCodingManagerEngineOsm(const QVariantMap ¶me if (parameters.contains(QStringLiteral("osm.geocoding.debug_query"))) m_debugQuery = parameters.value(QStringLiteral("osm.geocoding.debug_query")).toBool(); + if (parameters.contains(QStringLiteral("osm.geocoding.include_extended_data"))) + m_includeExtraData = parameters.value(QStringLiteral("osm.geocoding.include_extended_data")).toBool(); *error = QGeoServiceProvider::NoError; errorString->clear(); @@ -129,7 +131,7 @@ QGeoCodeReply *QGeoCodingManagerEngineOsm::geocode(const QString &address, int l QNetworkReply *reply = m_networkManager->get(request); - QGeoCodeReplyOsm *geocodeReply = new QGeoCodeReplyOsm(reply, this); + QGeoCodeReplyOsm *geocodeReply = new QGeoCodeReplyOsm(reply, m_includeExtraData, this); if (m_debugQuery) { QGeoCodeReplyOsmPrivate *replyPrivate = static_cast<QGeoCodeReplyOsmPrivate *>(QGeoCodeReplyPrivate::get(*geocodeReply)); @@ -165,7 +167,7 @@ QGeoCodeReply *QGeoCodingManagerEngineOsm::reverseGeocode(const QGeoCoordinate & QNetworkReply *reply = m_networkManager->get(request); - QGeoCodeReplyOsm *geocodeReply = new QGeoCodeReplyOsm(reply, this); + QGeoCodeReplyOsm *geocodeReply = new QGeoCodeReplyOsm(reply, m_includeExtraData, this); if (m_debugQuery) { QGeoCodeReplyOsmPrivate *replyPrivate = static_cast<QGeoCodeReplyOsmPrivate *>(QGeoCodeReplyPrivate::get(*geocodeReply)); diff --git a/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.h b/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.h index 2bc15715..7a54fa43 100644 --- a/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.h +++ b/src/plugins/geoservices/osm/qgeocodingmanagerengineosm.h @@ -72,6 +72,7 @@ private: QByteArray m_userAgent; QString m_urlPrefix; bool m_debugQuery = false; + bool m_includeExtraData = false; }; QT_END_NAMESPACE diff --git a/src/positioning/qdeclarativegeolocation.cpp b/src/positioning/qdeclarativegeolocation.cpp index 9e3b71e5..c06fcff2 100644 --- a/src/positioning/qdeclarativegeolocation.cpp +++ b/src/positioning/qdeclarativegeolocation.cpp @@ -75,15 +75,24 @@ QT_USE_NAMESPACE \endcode */ +/*! + \qmlproperty VariantMap QDeclarativeGeoLocation::extendedAttributes + + This property holds the extended attributes for this Location. + Extended attributes are backend-dependent and can be location-dependent. + + \since 5.13 +*/ + QDeclarativeGeoLocation::QDeclarativeGeoLocation(QObject *parent) -: QObject(parent), m_address(0) +: QObject(parent) { setLocation(QGeoLocation()); } QDeclarativeGeoLocation::QDeclarativeGeoLocation(const QGeoLocation &src, QObject *parent) -: QObject(parent), m_address(0) +: QObject(parent) { setLocation(src); } @@ -109,6 +118,7 @@ void QDeclarativeGeoLocation::setLocation(const QGeoLocation &src) setCoordinate(src.coordinate()); setBoundingBox(src.boundingBox()); + setProperty("extendedAttributes", src.extendedAttributes()); } QGeoLocation QDeclarativeGeoLocation::location() const @@ -117,6 +127,7 @@ QGeoLocation QDeclarativeGeoLocation::location() const retValue.setAddress(m_address ? m_address->address() : QGeoAddress()); retValue.setCoordinate(m_coordinate); retValue.setBoundingBox(m_boundingBox); + retValue.setExtendedAttributes(m_extendedAttributes); return retValue; } diff --git a/src/positioning/qdeclarativegeolocation_p.h b/src/positioning/qdeclarativegeolocation_p.h index a02d7b45..0cc0dc61 100644 --- a/src/positioning/qdeclarativegeolocation_p.h +++ b/src/positioning/qdeclarativegeolocation_p.h @@ -52,6 +52,7 @@ // #include <QtCore/QObject> +#include <QtCore/QVariantMap> #include <QtPositioning/QGeoLocation> #include <QtPositioning/qgeorectangle.h> #include <QtPositioning/private/qdeclarativegeoaddress_p.h> @@ -66,6 +67,7 @@ class Q_POSITIONING_EXPORT QDeclarativeGeoLocation : public QObject Q_PROPERTY(QDeclarativeGeoAddress *address READ address WRITE setAddress NOTIFY addressChanged) Q_PROPERTY(QGeoCoordinate coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged) Q_PROPERTY(QGeoRectangle boundingBox READ boundingBox WRITE setBoundingBox NOTIFY boundingBoxChanged) + Q_PROPERTY(QVariantMap extendedAttributes MEMBER m_extendedAttributes NOTIFY extendedAttributesChanged REVISION 13) public: explicit QDeclarativeGeoLocation(QObject *parent = 0); @@ -87,11 +89,13 @@ Q_SIGNALS: void addressChanged(); void coordinateChanged(); void boundingBoxChanged(); + void extendedAttributesChanged(); private: - QDeclarativeGeoAddress *m_address; + QDeclarativeGeoAddress *m_address = nullptr; QGeoRectangle m_boundingBox; QGeoCoordinate m_coordinate; + QVariantMap m_extendedAttributes; }; QT_END_NAMESPACE diff --git a/src/positioning/qgeolocation.cpp b/src/positioning/qgeolocation.cpp index 62e1a6a3..dd34112f 100644 --- a/src/positioning/qgeolocation.cpp +++ b/src/positioning/qgeolocation.cpp @@ -53,6 +53,7 @@ QGeoLocationPrivate::QGeoLocationPrivate(const QGeoLocationPrivate &other) this->address = other.address; this->coordinate = other.coordinate; this->viewport = other.viewport; + this->extendedAttributes = other.extendedAttributes; } QGeoLocationPrivate::~QGeoLocationPrivate() @@ -63,7 +64,8 @@ bool QGeoLocationPrivate::operator==(const QGeoLocationPrivate &other) const { return (this->address == other.address && this->coordinate == other.coordinate - && this->viewport == other.viewport); + && this->viewport == other.viewport + && this->extendedAttributes == other.extendedAttributes); } @@ -72,7 +74,7 @@ bool QGeoLocationPrivate::isEmpty() const return (address.isEmpty() && !coordinate.isValid() && viewport.isEmpty() - ); + && extendedAttributes.isEmpty()); } /*! @@ -193,6 +195,27 @@ void QGeoLocation::setBoundingBox(const QGeoRectangle &boundingBox) } /*! + Returns the extended attributes associated to this location. + Extended attributes are backend-dependent and can be location-dependent. + + \since 5.13 +*/ +QVariantMap QGeoLocation::extendedAttributes() const +{ + return d->extendedAttributes; +} + +/*! + Sets the extended attributes of the location. + + \since 5.13 +*/ +void QGeoLocation::setExtendedAttributes(const QVariantMap &data) +{ + d->extendedAttributes = data; +} + +/*! Returns true if all fields of the location are 0; otherwise returns false. */ bool QGeoLocation::isEmpty() const diff --git a/src/positioning/qgeolocation.h b/src/positioning/qgeolocation.h index 580b2fb3..ff1dbcd9 100644 --- a/src/positioning/qgeolocation.h +++ b/src/positioning/qgeolocation.h @@ -70,8 +70,10 @@ public: void setAddress(const QGeoAddress &address); QGeoCoordinate coordinate() const; void setCoordinate(const QGeoCoordinate &position); - QGeoRectangle boundingBox() const; + QGeoRectangle boundingBox() const; // ### Qt6: change this into QGeoShape geometry void setBoundingBox(const QGeoRectangle &box); + QVariantMap extendedAttributes() const; + void setExtendedAttributes(const QVariantMap &data); bool isEmpty() const; diff --git a/src/positioning/qgeolocation_p.h b/src/positioning/qgeolocation_p.h index a12e4cb4..a9ce639d 100644 --- a/src/positioning/qgeolocation_p.h +++ b/src/positioning/qgeolocation_p.h @@ -55,6 +55,7 @@ #include <QtPositioning/QGeoAddress> #include <QtPositioning/QGeoCoordinate> #include <QtPositioning/QGeoRectangle> +#include <QVariantMap> QT_BEGIN_NAMESPACE @@ -73,6 +74,7 @@ public: QGeoAddress address; QGeoCoordinate coordinate; QGeoRectangle viewport; + QVariantMap extendedAttributes; }; QT_END_NAMESPACE diff --git a/tests/auto/declarative_core/tst_geocoding.qml b/tests/auto/declarative_core/tst_geocoding.qml index 1eadf870..16843528 100644 --- a/tests/auto/declarative_core/tst_geocoding.qml +++ b/tests/auto/declarative_core/tst_geocoding.qml @@ -272,6 +272,14 @@ Item { ] } + Plugin { + id: extendedPlugin; + name: "qmlgeo.test.plugin"; + allowExperimental: true + PluginParameter { name: "finishRequestImmediately"; value: false} + PluginParameter { name: "includeExtendedData"; value: true } + } + GeocodeModel {id: testModel; plugin: testPlugin2} SignalSpy {id: locationsSpy; target: testModel; signalName: "locationsChanged"} SignalSpy {id: countSpy; target: testModel; signalName: "countChanged"} @@ -297,6 +305,9 @@ Item { GeocodeModel {id: automaticModel; plugin: autoPlugin; query: automaticAddress1; autoUpdate: true} SignalSpy {id: automaticLocationsSpy; target: automaticModel; signalName: "locationsChanged"} + GeocodeModel {id: extendedModel; plugin: extendedPlugin; query: automaticAddress1; autoUpdate: true} + SignalSpy {id: extendedLocationsSpy; target: extendedModel; signalName: "locationsChanged"} + TestCase { name: "GeocodeModelGeocoding" function clear_slack_model() { @@ -546,6 +557,19 @@ Item { compare (automaticModel.count, 3) } + function test_geocode_extended_attributes() { + compare (extendedModel.count, 6) // should be something already + compare (extendedLocationsSpy.count, 3) + compare(extendedModel.get(0).extendedAttributes + ["QGeoCodingManagerEngineTest_locationExtendedAttribute"], 42) + // change query and its contents and verify that autoupdate occurs + extendedModel.query = automaticCoordinate1 + tryCompare(extendedLocationsSpy, "count", 4) + compare (extendedModel.count, 3) + compare(extendedModel.get(0).extendedAttributes + ["QGeoCodingManagerEngineTest_locationExtendedAttribute"], 42) + } + function test_delayed_geocode() { // basic delayed response slackModel.reset() diff --git a/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h b/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h index ecbb60d1..5a8ff451 100644 --- a/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h +++ b/tests/auto/geotestplugin/qgeocodingmanagerengine_test.h @@ -35,20 +35,39 @@ #include <QtPositioning/qgeoaddress.h> #include <QtPositioning/qgeolocation.h> #include <qgeocodereply.h> +#include <QtLocation/private/qgeocodereply_p.h> #include <QtPositioning/QGeoShape> #include <QTimer> #include <QDebug> #include <QTimerEvent> +#include <QVariantMap> QT_USE_NAMESPACE +class GeocodeReplyTestPrivate : public QGeoCodeReplyPrivate +{ +public: + GeocodeReplyTestPrivate() + { + } + ~GeocodeReplyTestPrivate() + { + } + QVariantMap extraData() const override + { + return m_extraData; + } + + QVariantMap m_extraData; +}; + class GeocodeReplyTest :public QGeoCodeReply { Q_OBJECT public: - GeocodeReplyTest(QObject *parent = 0) : QGeoCodeReply (parent) {} + GeocodeReplyTest(QObject *parent = 0) : QGeoCodeReply (*new GeocodeReplyTestPrivate, parent) {} void callAddLocation ( const QGeoLocation & location ) {addLocation(location);} void callSetError ( Error error, const QString & errorString ) {setError(error, errorString);} @@ -82,6 +101,11 @@ public: finishRequestImmediately_ = qvariant_cast<bool>(parameters.value("finishRequestImmediately")); if (parameters.contains("validateWellKnownValues")) validateWellKnownValues_ = qvariant_cast<bool>(parameters.value("validateWellKnownValues")); + if (parameters.contains("includeExtendedData")) { + includeExtendedData_ = qvariant_cast<bool>(parameters.value("includeExtendedData")); + extendedLocationData_["QGeoCodingManagerEngineTest_locationExtendedAttribute"] = 42; + extendedReplyData_["QGeoCodingManagerEngineTest_extraData"] = 43; + } setLocale(QLocale (QLocale::German, QLocale::Germany)); } @@ -105,6 +129,8 @@ public: if (errorCode_ == QGeoCodeReply::NoError) setLocations(geocodeReply_, searchString, limit, offset); + if (includeExtendedData_) + injectExtra(geocodeReply_, extendedReplyData_); if (finishRequestImmediately_) { // check if we should finish with error @@ -126,6 +152,8 @@ public: geocodeReply_ = new GeocodeReplyTest(); connect(geocodeReply_, SIGNAL(aborted()), this, SLOT(requestAborted())); geocodeReply_->callSetViewport(bounds); + if (includeExtendedData_) + injectExtra(geocodeReply_, extendedReplyData_); if (address.street().startsWith("error")) { errorString_ = address.street(); @@ -184,6 +212,8 @@ public: address.setStreet(searchString); address.setCounty(QString::number(offset)); location.setAddress(address); + if (includeExtendedData_) + injectExtra(location, extendedLocationData_); reply->callAddLocation(location); } } @@ -195,6 +225,8 @@ public: for (int i = 0; i < count; ++i) { QGeoLocation location; location.setAddress(address); + if (includeExtendedData_) + injectExtra(location, extendedLocationData_); reply->callAddLocation(location); } } @@ -204,6 +236,8 @@ public: for (int i = 0; i < coordinate.longitude(); ++i) { QGeoLocation location; location.setCoordinate(coordinate); + if (includeExtendedData_) + injectExtra(location, extendedLocationData_); reply->callAddLocation(location); } } @@ -215,6 +249,8 @@ public: setLocations(geocodeReply_, coordinate); geocodeReply_->callSetViewport(bounds); + if (includeExtendedData_) + injectExtra(geocodeReply_, extendedReplyData_); if (coordinate.latitude() > 70) { errorString_ = "error"; @@ -256,7 +292,20 @@ protected: emit finished(geocodeReply_); } + static void injectExtra(QGeoCodeReply *reply, const QVariantMap &extra) + { + GeocodeReplyTestPrivate *replyPrivate + = static_cast<GeocodeReplyTestPrivate *>(QGeoCodeReplyPrivate::get(*reply)); + replyPrivate->m_extraData = extra; + } + + static void injectExtra(QGeoLocation &location, const QVariantMap &extra) + { + location.setExtendedAttributes(extra); + } + private: + bool includeExtendedData_ = false; bool validateWellKnownValues_; bool finishRequestImmediately_; bool supported_; @@ -264,6 +313,8 @@ private: int timerId_; QGeoCodeReply::Error errorCode_; QString errorString_; + QVariantMap extendedLocationData_; + QVariantMap extendedReplyData_; }; #endif diff --git a/tests/auto/qgeolocation/tst_qgeolocation.cpp b/tests/auto/qgeolocation/tst_qgeolocation.cpp index 9e40b0b0..bb1f47f9 100644 --- a/tests/auto/qgeolocation/tst_qgeolocation.cpp +++ b/tests/auto/qgeolocation/tst_qgeolocation.cpp @@ -57,6 +57,7 @@ void tst_QGeoLocation::constructor() QCOMPARE(m_location.address(), m_address); QCOMPARE(m_location.coordinate(), m_coordinate); QCOMPARE(m_location.boundingBox(), m_viewport); + QCOMPARE(m_location.extendedAttributes(), m_extendedAttributes); } void tst_QGeoLocation::copy_constructor() @@ -123,6 +124,16 @@ void tst_QGeoLocation::viewport() QVERIFY(m_location.boundingBox() != qgeoboundingboxcopy); } +void tst_QGeoLocation::extendedAttributes() +{ + m_extendedAttributes = QVariantMap({{ "foo" , 42 }}); + m_location.setExtendedAttributes(m_extendedAttributes); + QCOMPARE(m_location.extendedAttributes(), m_extendedAttributes); + + m_extendedAttributes["foo"] = 41; + QVERIFY(m_location.extendedAttributes() != m_extendedAttributes); +} + void tst_QGeoLocation::operators() { QGeoAddress qgeoaddresscopy; @@ -131,6 +142,7 @@ void tst_QGeoLocation::operators() qgeoaddresscopy.setCountryCode("DEU"); QGeoCoordinate qgeocoordinatecopy (32.324 , 41.324 , 24.55); + QVariantMap extendedAttributesCopy {{ "foo" , 42 }}; m_address.setCity("Madrid"); m_address.setCountry("Spain"); @@ -140,8 +152,11 @@ void tst_QGeoLocation::operators() m_coordinate.setLongitude(38.43443); m_coordinate.setAltitude(634.21); + m_extendedAttributes["foo"] = 43; + m_location.setAddress(m_address); m_location.setCoordinate(m_coordinate); + m_location.setExtendedAttributes(m_extendedAttributes); //Create a copy and see that they are the same QGeoLocation qgeolocationcopy(m_location); @@ -152,9 +167,15 @@ void tst_QGeoLocation::operators() qgeolocationcopy.setAddress(qgeoaddresscopy); QVERIFY(!(m_location == qgeolocationcopy)); QVERIFY(m_location != qgeolocationcopy); + qgeolocationcopy.setAddress(m_address); qgeolocationcopy.setCoordinate(qgeocoordinatecopy); QVERIFY(!(m_location == qgeolocationcopy)); QVERIFY(m_location != qgeolocationcopy); + qgeolocationcopy.setCoordinate(m_coordinate); + qgeolocationcopy.setExtendedAttributes(extendedAttributesCopy); + QVERIFY(!(m_location == qgeolocationcopy)); + QVERIFY(m_location != qgeolocationcopy); + //delete qgeolocationcopy; //Asign and test that they are the same @@ -195,6 +216,8 @@ void tst_QGeoLocation::comparison() otherLocation.setCoordinate(QGeoCoordinate(12,13)); } else if (dataField == "viewport"){ otherLocation.setBoundingBox(QGeoRectangle(QGeoCoordinate(1,2), 0.5,0.5)); + } else if (dataField == "extendedAttributes"){ + otherLocation.setExtendedAttributes(QVariantMap({{"foo", 44}})); } else { qFatal("Unknown data field to test"); } @@ -209,6 +232,7 @@ void tst_QGeoLocation::comparison_data() QTest::newRow("no change") << "no change"; QTest::newRow("address") << "address"; QTest::newRow("coordinate") << "coordinate"; + QTest::newRow("extendedAttributes") << "extendedAttributes"; } void tst_QGeoLocation::isEmpty() @@ -222,6 +246,8 @@ void tst_QGeoLocation::isEmpty() boundingBox.setBottomRight(QGeoCoordinate(-1, 1)); QVERIFY(!boundingBox.isEmpty()); + QVariantMap extendedAttributes({{"foo", 11}}); + QGeoLocation location; QVERIFY(location.isEmpty()); @@ -243,6 +269,12 @@ void tst_QGeoLocation::isEmpty() QVERIFY(!location.isEmpty()); location.setBoundingBox(QGeoRectangle()); QVERIFY(location.isEmpty()); + + // extended attributes + location.setExtendedAttributes(extendedAttributes); + QVERIFY(!location.isEmpty()); + location.setExtendedAttributes(QVariantMap()); + QVERIFY(location.isEmpty()); } QTEST_APPLESS_MAIN(tst_QGeoLocation); diff --git a/tests/auto/qgeolocation/tst_qgeolocation.h b/tests/auto/qgeolocation/tst_qgeolocation.h index 182cad27..a2bf6649 100644 --- a/tests/auto/qgeolocation/tst_qgeolocation.h +++ b/tests/auto/qgeolocation/tst_qgeolocation.h @@ -62,6 +62,7 @@ private Q_SLOTS: void address(); void coordinate(); void viewport(); + void extendedAttributes(); void operators(); void comparison(); void comparison_data(); @@ -74,6 +75,7 @@ private: QGeoAddress m_address; QGeoCoordinate m_coordinate; QGeoRectangle m_viewport; + QVariantMap m_extendedAttributes; }; Q_DECLARE_METATYPE( QGeoCoordinate::CoordinateFormat); |