diff options
Diffstat (limited to 'src/location')
29 files changed, 368 insertions, 88 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeocodemodel.cpp b/src/location/declarativemaps/qdeclarativegeocodemodel.cpp index 43ce95a9..a73f9341 100644 --- a/src/location/declarativemaps/qdeclarativegeocodemodel.cpp +++ b/src/location/declarativemaps/qdeclarativegeocodemodel.cpp @@ -42,6 +42,7 @@ #include <QtPositioning/QGeoCircle> #include <QtLocation/QGeoServiceProvider> #include <QtLocation/QGeoCodingManager> +#include <QtLocation/private/qgeocodereply_p.h> #include <QtPositioning/QGeoPolygon> QT_BEGIN_NAMESPACE @@ -389,6 +390,7 @@ void QDeclarativeGeocodeModel::geocodeFinished(QGeoCodeReply *reply) reply->deleteLater(); reply_ = 0; int oldCount = declarativeLocations_.count(); + // const QVariantMap &extraData = QGeoCodeReplyPrivate::get(*reply)->extraData(); setLocations(reply->locations()); setError(NoError, QString()); setStatus(QDeclarativeGeocodeModel::Ready); diff --git a/src/location/declarativemaps/qdeclarativegeocodemodel_p.h b/src/location/declarativemaps/qdeclarativegeocodemodel_p.h index 6c8f533b..e2361045 100644 --- a/src/location/declarativemaps/qdeclarativegeocodemodel_p.h +++ b/src/location/declarativemaps/qdeclarativegeocodemodel_p.h @@ -52,8 +52,8 @@ #include <QtLocation/private/qdeclarativegeoserviceprovider_p.h> #include <QtLocation/qgeocodereply.h> -#include <QtPositioning/private/qdeclarativegeoaddress_p.h> -#include <QtPositioning/private/qdeclarativegeolocation_p.h> +#include <QtPositioningQuick/private/qdeclarativegeoaddress_p.h> +#include <QtPositioningQuick/private/qdeclarativegeolocation_p.h> #include <QtQml/qqml.h> #include <QtQml/QQmlParserStatus> diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp index 63587efe..3c73ca12 100644 --- a/src/location/declarativemaps/qdeclarativegeomap.cpp +++ b/src/location/declarativemaps/qdeclarativegeomap.cpp @@ -1305,7 +1305,7 @@ void QDeclarativeGeoMap::setVisibleRegion(const QGeoShape &shape) return; } - fitViewportToGeoShape(); + fitViewportToGeoShape(m_visibleRegion); } QGeoShape QDeclarativeGeoMap::visibleRegion() const @@ -1445,39 +1445,6 @@ QMargins QDeclarativeGeoMap::mapMargins() const , height() - va.height() - va.y()); } -// TODO: offer the possibility to specify the margins. -void QDeclarativeGeoMap::fitViewportToGeoShape() -{ - if (m_map->geoProjection().projectionType() == QGeoProjection::ProjectionWebMercator) { - // This case remains handled here, and not inside QGeoMap*::fitViewportToGeoRectangle, - // in order to honor animations on center and zoomLevel - const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(m_map->geoProjection()); - const int borderSize = 10; - const QMargins borders(borderSize, borderSize, borderSize, borderSize); - - if (!m_map || !m_visibleRegion.isValid()) - return; - - const QMargins margins = borders + mapMargins(); - const QPair<QGeoCoordinate, qreal> fitData = p.fitViewportToGeoRectangle(m_visibleRegion, - margins); - if (!fitData.first.isValid()) - return; - - // position camera to the center of bounding box - setProperty("center", QVariant::fromValue(fitData.first)); // not using setCenter(centerCoordinate) to honor a possible animation set on the center property - - if (!qIsFinite(fitData.second)) - return; - double newZoom = qMax<double>(minimumZoomLevel(), fitData.second); - setProperty("zoomLevel", QVariant::fromValue(newZoom)); // not using setZoomLevel(newZoom) to honor a possible animation set on the zoomLevel property - } else if (m_map->capabilities() & QGeoMap::SupportsFittingViewportToGeoRectangle) { - // Animations cannot be honored in this case, as m_map acts as a black box - m_map->fitViewportToGeoRectangle(m_visibleRegion); - } -} - - /*! \qmlproperty list<MapType> QtLocation::Map::supportedMapTypes @@ -1604,6 +1571,64 @@ void QDeclarativeGeoMap::clearData() } /*! + \qmlmethod void QtLocation::Map::fitViewportToGeoShape(geoShape, margins) + + Fits the viewport to a specific geo shape. + The margins are in screen pixels. + + \note If the projection used by the plugin is not WebMercator, and the plugin does not have fitting to + shape capability, this method will do nothing. + + \sa visibleRegion + \since 5.13 +*/ +void QDeclarativeGeoMap::fitViewportToGeoShape(const QGeoShape &shape, QVariant margins) +{ + QMargins m(10, 10, 10, 10); // lets defaults to 10 if margins is invalid + switch (margins.type()) { + case QMetaType::Int: + case QMetaType::Double: { + const int value = int(margins.toDouble()); + m = QMargins(value, value, value, value); + } + break; + // ToDo: Support distinct margins in some QML form. Perhaps QRect? + default: + break; + } + fitViewportToGeoShape(shape, m); +} + +void QDeclarativeGeoMap::fitViewportToGeoShape(const QGeoShape &shape, const QMargins &borders) +{ + if (!m_map || !shape.isValid()) + return; + + if (m_map->geoProjection().projectionType() == QGeoProjection::ProjectionWebMercator) { + // This case remains handled here, and not inside QGeoMap*::fitViewportToGeoRectangle, + // in order to honor animations on center and zoomLevel + const QMargins margins = borders + mapMargins(); + const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(m_map->geoProjection()); + const QPair<QGeoCoordinate, qreal> fitData = p.fitViewportToGeoRectangle(shape.boundingGeoRectangle(), + margins); + if (!fitData.first.isValid()) + return; + + // position camera to the center of bounding box + setProperty("center", QVariant::fromValue(fitData.first)); // not using setCenter(centerCoordinate) to honor a possible animation set on the center property + + if (!qIsFinite(fitData.second)) + return; + double newZoom = qMax<double>(minimumZoomLevel(), fitData.second); + setProperty("zoomLevel", QVariant::fromValue(newZoom)); // not using setZoomLevel(newZoom) to honor a possible animation set on the zoomLevel property + } else if (m_map->capabilities() & QGeoMap::SupportsFittingViewportToGeoRectangle) { + // Animations cannot be honored in this case, as m_map acts as a black box + m_map->fitViewportToGeoRectangle(m_visibleRegion, borders); + } + // else out of luck +} + +/*! \qmlproperty string QtLocation::Map::errorString This read-only property holds the textual presentation of the latest mapping provider error. @@ -2205,7 +2230,7 @@ void QDeclarativeGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF Multiple fitViewportTo*() calls replace each other. */ if (m_pendingFitViewport && width() && height()) { - fitViewportToGeoShape(); + fitViewportToGeoShape(m_visibleRegion); m_pendingFitViewport = false; } diff --git a/src/location/declarativemaps/qdeclarativegeomap_p.h b/src/location/declarativemaps/qdeclarativegeomap_p.h index f59f6f54..3cbefe79 100644 --- a/src/location/declarativemaps/qdeclarativegeomap_p.h +++ b/src/location/declarativemaps/qdeclarativegeomap_p.h @@ -198,6 +198,8 @@ public: Q_INVOKABLE void pan(int dx, int dy); Q_INVOKABLE void prefetchData(); // optional hint for prefetch Q_INVOKABLE void clearData(); + Q_INVOKABLE void fitViewportToGeoShape(const QGeoShape &shape, QVariant margins); + void fitViewportToGeoShape(const QGeoShape &shape, const QMargins &borders = QMargins(10, 10, 10, 10)); QString errorString() const; QGeoServiceProvider::Error error() const; @@ -278,7 +280,6 @@ private: void populateMap(); void populateParameters(); void fitViewportToMapItemsRefine(bool refine, bool onlyVisible); - void fitViewportToGeoShape(); bool isInteractive(); void attachCopyrightNotice(bool initialVisibility); void detachCopyrightNotice(bool currentVisibility); diff --git a/src/location/declarativemaps/qdeclarativegeoroute.cpp b/src/location/declarativemaps/qdeclarativegeoroute.cpp index 09ed46ab..64aeb656 100644 --- a/src/location/declarativemaps/qdeclarativegeoroute.cpp +++ b/src/location/declarativemaps/qdeclarativegeoroute.cpp @@ -352,6 +352,35 @@ QList<QObject *> QDeclarativeGeoRoute::legs() } /*! + \qmlproperty Object Route::extendedAttributes + + This property holds the extended attributes of the route and is a map. + These attributes are plugin specific, and can be empty. + + Consult the \l {Qt Location#Plugin References and Parameters}{plugin documentation} + for what attributes are supported and how they should be used. + + Note, due to limitations of the QQmlPropertyMap, it is not possible + to declaratively specify the attributes in QML, assignment of attributes keys + and values can only be accomplished by JavaScript. + + \since QtLocation 5.13 +*/ +QQmlPropertyMap *QDeclarativeGeoRoute::extendedAttributes() const +{ + if (!m_extendedAttributes) { + QDeclarativeGeoRoute *self = const_cast<QDeclarativeGeoRoute *>(this); + self->m_extendedAttributes = new QQmlPropertyMap(self); + // Fill it + const QVariantMap &xAttrs = route_.extendedAttributes(); + const QStringList &keys = xAttrs.keys(); + for (const QString &key: keys) + self->m_extendedAttributes->insert(key, xAttrs.value(key)); + } + return m_extendedAttributes; +} + +/*! \qmlmethod bool QtLocation::Route::equals(Route other) This method performs deep comparison. diff --git a/src/location/declarativemaps/qdeclarativegeoroute_p.h b/src/location/declarativemaps/qdeclarativegeoroute_p.h index 98d08e98..767e21ea 100644 --- a/src/location/declarativemaps/qdeclarativegeoroute_p.h +++ b/src/location/declarativemaps/qdeclarativegeoroute_p.h @@ -69,6 +69,7 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoRoute : public QObject Q_PROPERTY(QQmlListProperty<QDeclarativeGeoRouteSegment> segments READ segments CONSTANT) Q_PROPERTY(QDeclarativeGeoRouteQuery *routeQuery READ routeQuery REVISION 11) Q_PROPERTY(QList<QObject *> legs READ legs CONSTANT REVISION 12) + Q_PROPERTY(QObject *extendedAttributes READ extendedAttributes CONSTANT REVISION 12) public: explicit QDeclarativeGeoRoute(QObject *parent = 0); @@ -91,6 +92,7 @@ public: const QGeoRoute &route() const; QDeclarativeGeoRouteQuery *routeQuery(); QList<QObject *> legs(); + QQmlPropertyMap *extendedAttributes() const; Q_INVOKABLE bool equals(QDeclarativeGeoRoute *other) const; @@ -111,6 +113,8 @@ private: QList<QDeclarativeGeoRouteSegment *> segments_; QList<QObject *> legs_; bool segmentsDirty_ = true; + QQmlPropertyMap *m_extendedAttributes = nullptr; + friend class QDeclarativeRouteMapItem; }; diff --git a/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp b/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp index f4cdc6bf..23ea5666 100644 --- a/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp +++ b/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp @@ -50,6 +50,7 @@ #include <QtPositioning/private/qdoublevector2d_p.h> #include <QtPositioning/private/qclipperutils_p.h> +#include <QtPositioning/private/qgeopolygon_p.h> /* poly2tri triangulator includes */ #include <clip2tri.h> @@ -318,6 +319,7 @@ QDeclarativePolygonMapItem::QDeclarativePolygonMapItem(QQuickItem *parent) : QDeclarativeGeoMapItemBase(parent), border_(this), color_(Qt::transparent), dirtyMaterial_(true), updatingGeometry_(false) { + geopath_ = QGeoPolygonEager(); setFlag(ItemHasContents, true); QObject::connect(&border_, SIGNAL(colorChanged(QColor)), this, SLOT(markSourceDirtyAndUpdate())); @@ -611,7 +613,7 @@ void QDeclarativePolygonMapItem::setGeoShape(const QGeoShape &shape) if (shape == geopath_) return; - geopath_ = shape; + geopath_ = QGeoPathEager(shape); regenerateCache(); geometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); borderGeometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp index 2fb3098d..2bed0896 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp @@ -54,6 +54,7 @@ #include <QtGui/private/qtriangulator_p.h> #include <QtPositioning/private/qclipperutils_p.h> +#include <QtPositioning/private/qgeopath_p.h> #include <array> QT_BEGIN_NAMESPACE @@ -738,6 +739,7 @@ bool QGeoMapPolylineGeometry::contains(const QPointF &point) const QDeclarativePolylineMapItem::QDeclarativePolylineMapItem(QQuickItem *parent) : QDeclarativeGeoMapItemBase(parent), line_(this), dirtyMaterial_(true), updatingGeometry_(false) { + geopath_ = QGeoPathEager(); setFlag(ItemHasContents, true); QObject::connect(&line_, SIGNAL(colorChanged(QColor)), this, SLOT(updateAfterLinePropertiesChanged())); @@ -806,7 +808,7 @@ void QDeclarativePolylineMapItem::setPath(const QGeoPath &path) if (geopath_.path() == path.path()) return; - geopath_ = path; + geopath_ = QGeoPathEager(path); regenerateCache(); geometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); markSourceDirtyAndUpdate(); @@ -1135,18 +1137,8 @@ const QGeoShape &QDeclarativePolylineMapItem::geoShape() const void QDeclarativePolylineMapItem::setGeoShape(const QGeoShape &shape) { - if (shape == geopath_) - return; - const QGeoPath geopath(shape); // if shape isn't a path, path will be created as a default-constructed path - const bool pathHasChanged = geopath.path() != geopath_.path(); - geopath_ = geopath; - - regenerateCache(); - geometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); - markSourceDirtyAndUpdate(); - if (pathHasChanged) - emit pathChanged(); + setPath(geopath); } QGeoMap::ItemType QDeclarativePolylineMapItem::itemType() const diff --git a/src/location/declarativeplaces/qdeclarativeplace_p.h b/src/location/declarativeplaces/qdeclarativeplace_p.h index 67d2c8df..309bd64c 100644 --- a/src/location/declarativeplaces/qdeclarativeplace_p.h +++ b/src/location/declarativeplaces/qdeclarativeplace_p.h @@ -55,7 +55,7 @@ #include <QtQml/QQmlPropertyMap> #include <QtLocation/QPlace> -#include <QtPositioning/private/qdeclarativegeolocation_p.h> +#include <QtPositioningQuick/private/qdeclarativegeolocation_p.h> #include <QtLocation/private/qdeclarativecategory_p.h> #include <QtLocation/private/qdeclarativecontactdetail_p.h> #include <QtLocation/private/qdeclarativesupplier_p.h> diff --git a/src/location/declarativeplaces/qdeclarativesearchmodelbase.cpp b/src/location/declarativeplaces/qdeclarativesearchmodelbase.cpp index b9f782cf..8bbe7f64 100644 --- a/src/location/declarativeplaces/qdeclarativesearchmodelbase.cpp +++ b/src/location/declarativeplaces/qdeclarativesearchmodelbase.cpp @@ -46,6 +46,8 @@ #include <QtLocation/QPlaceSearchReply> #include <QtPositioning/QGeoCircle> #include <QtPositioning/QGeoPolygon> +#include <QtLocation/private/qdeclarativegeoroute_p.h> +#include <QtLocation/private/qplacesearchrequest_p.h> QT_BEGIN_NAMESPACE @@ -102,18 +104,36 @@ QVariant QDeclarativeSearchModelBase::searchArea() const void QDeclarativeSearchModelBase::setSearchArea(const QVariant &searchArea) { QGeoShape s; - + QDeclarativeGeoRoute *route = nullptr; + bool routeSearchArea = false; if (searchArea.userType() == qMetaTypeId<QGeoRectangle>()) s = searchArea.value<QGeoRectangle>(); else if (searchArea.userType() == qMetaTypeId<QGeoCircle>()) s = searchArea.value<QGeoCircle>(); else if (searchArea.userType() == qMetaTypeId<QGeoShape>()) s = searchArea.value<QGeoShape>(); + else if (searchArea.type() == qMetaTypeId<QObject *>()) { + route = searchArea.value<QDeclarativeGeoRoute *>(); + if (!route) + return; + routeSearchArea = true; + } - if (m_request.searchArea() == s) + QPlaceSearchRequestPrivate *rp = QPlaceSearchRequestPrivate::get(m_request); + // Invalidating the other thing + if (routeSearchArea) + m_request.setSearchArea(QGeoShape()); + else + rp->routeSearchArea = QGeoRoute(); + + if (m_request.searchArea() == s + && (!route || rp->routeSearchArea == route->route())) return; - m_request.setSearchArea(s); + if (routeSearchArea) + rp->routeSearchArea = route->route(); + else + m_request.setSearchArea(s); emit searchAreaChanged(); } diff --git a/src/location/doc/src/plugins/osm.qdoc b/src/location/doc/src/plugins/osm.qdoc index 649d3bed..1fbb7d3e 100644 --- a/src/location/doc/src/plugins/osm.qdoc +++ b/src/location/doc/src/plugins/osm.qdoc @@ -69,6 +69,11 @@ a prefix. \li Url string set when making network requests to the geocoding server. This parameter should be set to a valid server url with the correct osm API. If not specified the default \l {http://nominatim.openstreetmap.org/}{url} will be used. \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/location/labs/qdeclarativenavigator.cpp b/src/location/labs/qdeclarativenavigator.cpp index 0bf5035f..86c2b85a 100644 --- a/src/location/labs/qdeclarativenavigator.cpp +++ b/src/location/labs/qdeclarativenavigator.cpp @@ -141,7 +141,7 @@ QT_BEGIN_NAMESPACE /*! \qmlproperty Route Qt.labs.location::Navigator::currentRoute - This read-only property holds the current route the navigator following. + This read-only property holds the current route the navigator is following. This can be the same as \l route, or can be different, if the navigator cannot follow the user-specified route. For example if the position coming from \l positionSource is considerably @@ -152,6 +152,18 @@ QT_BEGIN_NAMESPACE */ /*! + \qmlproperty RouteLeg Qt.labs.location::Navigator::currentRouteLeg + + This read-only property holds the current route leg the navigator is following. + This is always a part of \l currentRoute, and so the property \l RouteLeg::overallRoute + of currentRouteLeg will hold the same route as \l currentRoute. + + \sa RouteLeg + + \since 5.13 +*/ + +/*! \qmlproperty int Qt.labs.location::Navigator::currentSegment This read-only property holds the index of the current RouteSegment in the \l currentRoute. @@ -179,9 +191,29 @@ QDeclarativeNavigatorPrivate::QDeclarativeNavigatorPrivate(QParameterizableObjec { } -void QDeclarativeNavigatorPrivate::updateReadyState() +void QDeclarativeNavigatorPrivate::clearCachedData() { - qobject_cast<QDeclarativeNavigator *>(q)->updateReadyState(); + const bool routeChanged = !m_currentRoute.isNull(); + const bool routeLegChanged = !m_currentRouteLeg.isNull(); + const bool segmentChanged = m_currentSegment != 0; + + if (m_currentRoute) + m_currentRoute->deleteLater(); + m_currentRoute = nullptr; + + if (m_currentRouteLeg) + m_currentRouteLeg->deleteLater(); + m_currentRouteLeg = nullptr; + + m_currentSegment = 0; + + QDeclarativeNavigator *qq = qobject_cast<QDeclarativeNavigator *>(q); + if (routeChanged) + qq->currentRouteChanged(); + if (routeLegChanged) + qq->currentRouteLegChanged(); + if (segmentChanged) + qq->currentSegmentChanged(); } @@ -220,11 +252,10 @@ void QDeclarativeNavigator::setMap(QDeclarativeGeoMap *map) return; d_ptr->m_params->m_map = map; - QDeclarativeNavigatorPrivate *dptr = d_ptr.data(); connect(map, &QObject::destroyed, this, - [this, dptr]() { + [this]() { this->mapChanged(); - dptr->updateReadyState(); + this->updateReadyState(); }); emit mapChanged(); updateReadyState(); @@ -270,11 +301,10 @@ void QDeclarativeNavigator::setPositionSource(QDeclarativePositionSource *positi return; d_ptr->m_params->m_positionSource = positionSource; - QDeclarativeNavigatorPrivate *dptr = d_ptr.data(); QObject::connect(positionSource, &QObject::destroyed, - [this, dptr]() { + [this]() { this->positionSourceChanged(); - dptr->updateReadyState(); + this->updateReadyState(); } ); emit positionSourceChanged(); @@ -316,6 +346,13 @@ QDeclarativeGeoRoute *QDeclarativeNavigator::currentRoute() const return d_ptr->m_currentRoute.data(); } +QDeclarativeGeoRouteLeg *QDeclarativeNavigator::currentRouteLeg() const +{ + if (!d_ptr->m_ready || !d_ptr->m_navigator->active()) + return nullptr; + return d_ptr->m_currentRouteLeg.data(); +} + int QDeclarativeNavigator::currentSegment() const { if (!d_ptr->m_ready || !d_ptr->m_navigator->active()) @@ -379,6 +416,9 @@ void QDeclarativeNavigator::stop() if (d_ptr->m_navigator->active()) d_ptr->m_active = d_ptr->m_navigator->stop(); + + // clear cached data + d_ptr->clearCachedData(); } void QDeclarativeNavigator::pluginReady() @@ -409,6 +449,7 @@ bool QDeclarativeNavigator::ensureEngine() connect(d_ptr->m_navigator.get(), &QAbstractNavigator::waypointReached, this, &QDeclarativeNavigator::waypointReached); connect(d_ptr->m_navigator.get(), &QAbstractNavigator::destinationReached, this, &QDeclarativeNavigator::destinationReached); connect(d_ptr->m_navigator.get(), &QAbstractNavigator::currentRouteChanged, this, &QDeclarativeNavigator::onCurrentRouteChanged); + connect(d_ptr->m_navigator.get(), &QAbstractNavigator::currentRouteLegChanged, this, &QDeclarativeNavigator::onCurrentRouteLegChanged); connect(d_ptr->m_navigator.get(), &QAbstractNavigator::currentSegmentChanged, this, &QDeclarativeNavigator::onCurrentSegmentChanged); connect(d_ptr->m_navigator.get(), &QAbstractNavigator::activeChanged, this, [this](bool active){ d_ptr->m_active = active; @@ -440,6 +481,14 @@ void QDeclarativeNavigator::onCurrentRouteChanged(const QGeoRoute &route) emit currentRouteChanged(); } +void QDeclarativeNavigator::onCurrentRouteLegChanged(const QGeoRouteLeg &routeLeg) +{ + if (d_ptr->m_currentRoute) + d_ptr->m_currentRouteLeg->deleteLater(); + d_ptr->m_currentRouteLeg = new QDeclarativeGeoRouteLeg(routeLeg, this); + emit currentRouteLegChanged(); +} + void QDeclarativeNavigator::onCurrentSegmentChanged(int segment) { d_ptr->m_currentSegment = segment; diff --git a/src/location/labs/qdeclarativenavigator_p.h b/src/location/labs/qdeclarativenavigator_p.h index 13884c41..2a425e70 100644 --- a/src/location/labs/qdeclarativenavigator_p.h +++ b/src/location/labs/qdeclarativenavigator_p.h @@ -59,9 +59,11 @@ class QDeclarativeGeoServiceProvider; class QDeclarativeGeoMap; class QNavigationManager; class QDeclarativeGeoRoute; +class QDeclarativeGeoRouteLeg; class QDeclarativePositionSource; class QDeclarativeGeoWaypoint; class QGeoRoute; +class QGeoRouteLeg; class QGeoRouteSegment; class QDeclarativeNavigatorPrivate; class QDeclarativeGeoRouteSegment; @@ -77,6 +79,7 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeNavigator : public QParameterizableO Q_PROPERTY(bool navigatorReady READ navigatorReady NOTIFY navigatorReadyChanged) Q_PROPERTY(bool trackPositionSource READ trackPositionSource WRITE setTrackPositionSource NOTIFY trackPositionSourceChanged) Q_PROPERTY(QDeclarativeGeoRoute *currentRoute READ currentRoute NOTIFY currentRouteChanged) + Q_PROPERTY(QDeclarativeGeoRouteLeg *currentRouteLeg READ currentRouteLeg NOTIFY currentRouteChanged) Q_PROPERTY(int currentSegment READ currentSegment NOTIFY currentSegmentChanged) Q_INTERFACES(QQmlParserStatus) @@ -113,6 +116,7 @@ public: bool trackPositionSource() const; QDeclarativeGeoRoute *currentRoute() const; + QDeclarativeGeoRouteLeg *currentRouteLeg() const; int currentSegment() const; signals: @@ -127,6 +131,7 @@ signals: void routeChanged(); void positionSourceChanged(); void currentRouteChanged(); + void currentRouteLegChanged(); void currentSegmentChanged(); private: @@ -136,6 +141,7 @@ private: private slots: void onCurrentRouteChanged(const QGeoRoute &route); + void onCurrentRouteLegChanged(const QGeoRouteLeg &routeLeg); void onCurrentSegmentChanged(int segment); private: diff --git a/src/location/labs/qdeclarativenavigator_p_p.h b/src/location/labs/qdeclarativenavigator_p_p.h index 229ead1e..8849ec7a 100644 --- a/src/location/labs/qdeclarativenavigator_p_p.h +++ b/src/location/labs/qdeclarativenavigator_p_p.h @@ -59,6 +59,7 @@ class QDeclarativeGeoServiceProvider; class QDeclarativeGeoMap; class QNavigationManager; class QDeclarativeGeoRoute; +class QDeclarativeGeoRouteLeg; class QDeclarativePositionSource; class QGeoMapParameter; class QDeclarativeGeoRouteSegment; @@ -81,12 +82,14 @@ class QDeclarativeNavigatorPrivate public: QDeclarativeNavigatorPrivate(QParameterizableObject *q_); - void updateReadyState(); + void clearCachedData(); + QParameterizableObject *q = nullptr; QSharedPointer<QDeclarativeNavigatorParams> m_params; QScopedPointer<QAbstractNavigator> m_navigator; QDeclarativeGeoServiceProvider *m_plugin = nullptr; QPointer<QDeclarativeGeoRoute> m_currentRoute; + QPointer<QDeclarativeGeoRouteLeg> m_currentRouteLeg; int m_currentSegment = 0; bool m_active = false; bool m_completed = false; diff --git a/src/location/labs/qmapobjectview.cpp b/src/location/labs/qmapobjectview.cpp index 2ffc27bc..7a7d7d3d 100644 --- a/src/location/labs/qmapobjectview.cpp +++ b/src/location/labs/qmapobjectview.cpp @@ -89,7 +89,8 @@ QGeoMapObject::Type QMapObjectViewPrivate::type() const */ -QMapObjectViewPrivateDefault::QMapObjectViewPrivateDefault(const QMapObjectViewPrivate &other) : QMapObjectViewPrivate(other.q) +QMapObjectViewPrivateDefault::QMapObjectViewPrivateDefault(const QMapObjectViewPrivate &other) +: QMapObjectViewPrivate(other.q), m_model(other.model()), m_delegate(other.delegate()) { } @@ -98,6 +99,26 @@ QMapObjectViewPrivateDefault::~QMapObjectViewPrivateDefault() } +QVariant QMapObjectViewPrivateDefault::model() const +{ + return m_model; +} + +void QMapObjectViewPrivateDefault::setModel(const QVariant &model) +{ + m_model = model; +} + +QQmlComponent *QMapObjectViewPrivateDefault::delegate() const +{ + return m_delegate; +} + +void QMapObjectViewPrivateDefault::setDelegate(QQmlComponent *delegate) +{ + m_delegate = delegate; +} + QMapObjectViewPrivateDefault::QMapObjectViewPrivateDefault(QGeoMapObject *q) : QMapObjectViewPrivate(q) { @@ -108,6 +129,17 @@ QGeoMapObjectPrivate *QMapObjectViewPrivateDefault::clone() return new QMapObjectViewPrivateDefault(*this); } +bool QMapObjectViewPrivateDefault::equals(const QGeoMapObjectPrivate &other) const +{ + if (other.type() != type()) + return false; + + const QMapObjectViewPrivate &o = static_cast<const QMapObjectViewPrivate &>(other); + return (QGeoMapObjectPrivate::equals(o) + && model() == o.model() + && delegate() == o.delegate()); +} + /* QMapObjectView @@ -160,10 +192,11 @@ void QMapObjectView::classBegin() void QMapObjectView::componentComplete() { QGeoMapObject::componentComplete(); - if (m_delegate) - m_delegateModel->setDelegate(m_delegate); - if (m_model.isValid()) - m_delegateModel->setModel(m_model); + QMapObjectViewPrivate *d = static_cast<QMapObjectViewPrivate *>(d_ptr.data()); + if (d->delegate()) + m_delegateModel->setDelegate(d->delegate()); + if (d->model().isValid()) + m_delegateModel->setModel(d->model()); m_delegateModel->componentComplete(); } @@ -175,7 +208,8 @@ void QMapObjectView::componentComplete() */ QVariant QMapObjectView::model() const { - return m_model; + const QMapObjectViewPrivate *d = static_cast<const QMapObjectViewPrivate *>(d_ptr.data()); + return d->model(); } /*! @@ -187,14 +221,16 @@ QVariant QMapObjectView::model() const */ QQmlComponent *QMapObjectView::delegate() const { - return m_delegate; + const QMapObjectViewPrivate *d = static_cast<const QMapObjectViewPrivate *>(d_ptr.data()); + return d->delegate(); } void QMapObjectView::setModel(QVariant model) { - if (m_model == model) + QMapObjectViewPrivate *d = static_cast<QMapObjectViewPrivate *>(d_ptr.data()); + if (d->model() == model) return; - m_model = model; + d->setModel(model); if (d_ptr->m_componentCompleted) m_delegateModel->setModel(model); @@ -204,9 +240,10 @@ void QMapObjectView::setModel(QVariant model) void QMapObjectView::setDelegate(QQmlComponent *delegate) { - if (m_delegate == delegate) + QMapObjectViewPrivate *d = static_cast<QMapObjectViewPrivate *>(d_ptr.data()); + if (d->delegate() == delegate) return; - m_delegate = delegate; + d->setDelegate(delegate); if (d_ptr->m_componentCompleted) m_delegateModel->setDelegate(delegate); diff --git a/src/location/labs/qmapobjectview_p.h b/src/location/labs/qmapobjectview_p.h index 49b80883..5e85aa7a 100644 --- a/src/location/labs/qmapobjectview_p.h +++ b/src/location/labs/qmapobjectview_p.h @@ -103,8 +103,6 @@ protected: void flushDelegateModel(); void flushUserAddedMapObjects(); - QVariant m_model; - QQmlComponent *m_delegate = nullptr; QQmlDelegateModel *m_delegateModel = nullptr; QVector<QPointer<QGeoMapObject>> m_instantiatedMapObjects; QVector<QPointer<QGeoMapObject>> m_pendingMapObjects; diff --git a/src/location/labs/qmapobjectview_p_p.h b/src/location/labs/qmapobjectview_p_p.h index 7550e209..e283f1b0 100644 --- a/src/location/labs/qmapobjectview_p_p.h +++ b/src/location/labs/qmapobjectview_p_p.h @@ -65,6 +65,11 @@ public: QMapObjectViewPrivate(QGeoMapObject *q); ~QMapObjectViewPrivate() override; + virtual QVariant model() const = 0; + virtual void setModel(const QVariant &model) = 0; + virtual QQmlComponent *delegate() const = 0; + virtual void setDelegate(QQmlComponent *delegate) = 0; + virtual QGeoMapObject::Type type() const override final; }; @@ -75,10 +80,18 @@ public: QMapObjectViewPrivateDefault(const QMapObjectViewPrivate &other); ~QMapObjectViewPrivateDefault() override; + virtual QVariant model() const override; + virtual void setModel(const QVariant &model) override; + virtual QQmlComponent *delegate() const override; + virtual void setDelegate(QQmlComponent *delegate) override; // QGeoMapObjectPrivate interface public: QGeoMapObjectPrivate *clone() override; + bool equals(const QGeoMapObjectPrivate &other) const override; + + QVariant m_model; + QQmlComponent *m_delegate = nullptr; }; QT_END_NAMESPACE diff --git a/src/location/location.pro b/src/location/location.pro index 1535a85e..1b541b9e 100644 --- a/src/location/location.pro +++ b/src/location/location.pro @@ -1,5 +1,5 @@ TARGET = QtLocation -QT = core-private positioning-private +QT = core-private positioning-private positioningquick-private android { # adding qtconcurrent dependency here for the osm plugin QT += concurrent diff --git a/src/location/maps/qgeocodereply.cpp b/src/location/maps/qgeocodereply.cpp index 5fefb6fe..9fbede9c 100644 --- a/src/location/maps/qgeocodereply.cpp +++ b/src/location/maps/qgeocodereply.cpp @@ -97,6 +97,13 @@ QGeoCodeReply::QGeoCodeReply(QObject *parent) : QObject(parent), d_ptr(new QGeoCodeReplyPrivate()) {} +QGeoCodeReply::QGeoCodeReply(QGeoCodeReplyPrivate &dd, QObject *parent) + : QObject(parent), + d_ptr(&dd) +{ + +} + /*! Constructs a geocode reply with a given \a error and \a errorString and the specified \a parent. */ @@ -335,4 +342,19 @@ QGeoCodeReplyPrivate::QGeoCodeReplyPrivate(QGeoCodeReply::Error error, const QSt QGeoCodeReplyPrivate::~QGeoCodeReplyPrivate() {} +QVariantMap QGeoCodeReplyPrivate::extraData() const +{ + return QVariantMap(); +} + +const QGeoCodeReplyPrivate *QGeoCodeReplyPrivate::get(const QGeoCodeReply &reply) +{ + return reply.d_ptr; +} + +QGeoCodeReplyPrivate *QGeoCodeReplyPrivate::get(QGeoCodeReply &reply) +{ + return reply.d_ptr; +} + QT_END_NAMESPACE diff --git a/src/location/maps/qgeocodereply.h b/src/location/maps/qgeocodereply.h index c41e740d..c2395f10 100644 --- a/src/location/maps/qgeocodereply.h +++ b/src/location/maps/qgeocodereply.h @@ -85,6 +85,7 @@ Q_SIGNALS: protected: explicit QGeoCodeReply(QObject *parent = nullptr); + explicit QGeoCodeReply(QGeoCodeReplyPrivate &dd, QObject *parent = nullptr); void setError(Error error, const QString &errorString); void setFinished(bool finished); @@ -99,6 +100,7 @@ protected: private: QGeoCodeReplyPrivate *d_ptr; Q_DISABLE_COPY(QGeoCodeReply) + friend class QGeoCodeReplyPrivate; }; QT_END_NAMESPACE diff --git a/src/location/maps/qgeocodereply_p.h b/src/location/maps/qgeocodereply_p.h index fefe7883..3f77497b 100644 --- a/src/location/maps/qgeocodereply_p.h +++ b/src/location/maps/qgeocodereply_p.h @@ -48,22 +48,28 @@ // We mean it. // +#include <QtLocation/private/qlocationglobal_p.h> #include "qgeocodereply.h" #include "qgeoshape.h" #include <QList> +#include <QVariantMap> QT_BEGIN_NAMESPACE class QGeoLocation; -class QGeoCodeReplyPrivate +class Q_LOCATION_PRIVATE_EXPORT QGeoCodeReplyPrivate { public: QGeoCodeReplyPrivate(); QGeoCodeReplyPrivate(QGeoCodeReply::Error error, const QString &errorString); - ~QGeoCodeReplyPrivate(); + virtual ~QGeoCodeReplyPrivate(); + + virtual QVariantMap extraData() const; + static const QGeoCodeReplyPrivate *get(const QGeoCodeReply &reply); + static QGeoCodeReplyPrivate *get(QGeoCodeReply &reply); QGeoCodeReply::Error error; QString errorString; diff --git a/src/location/maps/qgeomap.cpp b/src/location/maps/qgeomap.cpp index 963ef6bd..bf5e557d 100644 --- a/src/location/maps/qgeomap.cpp +++ b/src/location/maps/qgeomap.cpp @@ -135,9 +135,10 @@ bool QGeoMap::anchorCoordinateToPoint(const QGeoCoordinate &coordinate, const QP return false; } -bool QGeoMap::fitViewportToGeoRectangle(const QGeoRectangle &rectangle) +bool QGeoMap::fitViewportToGeoRectangle(const QGeoRectangle &rectangle, const QMargins &borders) { Q_UNUSED(rectangle) + Q_UNUSED(borders) return false; } diff --git a/src/location/maps/qgeomap_p.h b/src/location/maps/qgeomap_p.h index 874b300f..c0af9e10 100644 --- a/src/location/maps/qgeomap_p.h +++ b/src/location/maps/qgeomap_p.h @@ -150,7 +150,7 @@ public: virtual bool setBearing(qreal bearing, const QGeoCoordinate &coordinate); virtual QGeoShape visibleRegion() const; virtual bool anchorCoordinateToPoint(const QGeoCoordinate &coordinate, const QPointF &anchorPoint); - virtual bool fitViewportToGeoRectangle(const QGeoRectangle &rectangle); + virtual bool fitViewportToGeoRectangle(const QGeoRectangle &rectangle, const QMargins &borders); virtual void setCopyrightVisible(bool visible); virtual void removeMapObject(QGeoMapObject *obj); diff --git a/src/location/maps/qgeoroute.cpp b/src/location/maps/qgeoroute.cpp index 799fe7f1..ef54e4aa 100644 --- a/src/location/maps/qgeoroute.cpp +++ b/src/location/maps/qgeoroute.cpp @@ -321,6 +321,26 @@ QList<QGeoRouteLeg> QGeoRoute::routeLegs() const return d_ptr->routeLegs(); } +/*! + Sets the extended attributes \a extendedAttributes associated with this route. + + \since 5.13 +*/ +void QGeoRoute::setExtendedAttributes(const QVariantMap &extendedAttributes) +{ + d_ptr->setExtendedAttributes(extendedAttributes); +} + +/*! + Returns the extended attributes associated with this route. + + \since 5.13 +*/ +QVariantMap QGeoRoute::extendedAttributes() const +{ + return d_ptr->extendedAttributes(); +} + /******************************************************************************* *******************************************************************************/ @@ -361,7 +381,7 @@ bool QGeoRoutePrivate::equals(const QGeoRoutePrivate &other) const s2 = s2.nextRouteSegment(); } - return ((id() == other.id()) + return ( (id() == other.id()) && (request() == other.request()) && (bounds() == other.bounds()) && (travelTime() == other.travelTime()) @@ -369,7 +389,8 @@ bool QGeoRoutePrivate::equals(const QGeoRoutePrivate &other) const && (travelMode() == other.travelMode()) && (path() == other.path()) && (metadata() == other.metadata()) - && (routeLegs() == other.routeLegs())); + && (routeLegs() == other.routeLegs()) + && (extendedAttributes() == other.extendedAttributes()) ); } void QGeoRoutePrivate::setId(const QString &id) @@ -472,6 +493,16 @@ QList<QGeoRouteLeg> QGeoRoutePrivate::routeLegs() const return QList<QGeoRouteLeg>(); } +void QGeoRoutePrivate::setExtendedAttributes(const QVariantMap &/*extendedAttributes*/) +{ + +} + +QVariantMap QGeoRoutePrivate::extendedAttributes() const +{ + return QVariantMap(); +} + void QGeoRoutePrivate::setLegIndex(int /*idx*/) { @@ -514,7 +545,8 @@ QGeoRoutePrivateDefault::QGeoRoutePrivateDefault(const QGeoRoutePrivateDefault & m_path(other.m_path), m_legs(other.m_legs), m_firstSegment(other.m_firstSegment), - m_numSegments(other.m_numSegments){} + m_numSegments(other.m_numSegments), + m_extendedAttributes(other.m_extendedAttributes) {} // Purposedly ignoring legIndex and parentRoute QGeoRoutePrivateDefault::~QGeoRoutePrivateDefault() {} @@ -636,6 +668,16 @@ QList<QGeoRouteLeg> QGeoRoutePrivateDefault::routeLegs() const return m_legs; } +void QGeoRoutePrivateDefault::setExtendedAttributes(const QVariantMap &extendedAttributes) +{ + m_extendedAttributes = extendedAttributes; +} + +QVariantMap QGeoRoutePrivateDefault::extendedAttributes() const +{ + return m_extendedAttributes; +} + void QGeoRoutePrivateDefault::setLegIndex(int idx) { if (idx >= 0) diff --git a/src/location/maps/qgeoroute.h b/src/location/maps/qgeoroute.h index 381152e3..363ca61b 100644 --- a/src/location/maps/qgeoroute.h +++ b/src/location/maps/qgeoroute.h @@ -90,6 +90,9 @@ public: void setRouteLegs(const QList<QGeoRouteLeg> &legs); QList<QGeoRouteLeg> routeLegs() const; + void setExtendedAttributes(const QVariantMap &extendedAttributes); + QVariantMap extendedAttributes() const; + protected: QGeoRoute(const QExplicitlySharedDataPointer<QGeoRoutePrivate> &dd); QExplicitlySharedDataPointer<QGeoRoutePrivate> &d(); diff --git a/src/location/maps/qgeoroute_p.h b/src/location/maps/qgeoroute_p.h index 39f96c48..721d00b9 100644 --- a/src/location/maps/qgeoroute_p.h +++ b/src/location/maps/qgeoroute_p.h @@ -55,6 +55,7 @@ #include "qgeoroutesegment.h" #include <QSharedData> +#include <QVariantMap> #include <QScopedPointer> QT_BEGIN_NAMESPACE @@ -100,6 +101,9 @@ public: virtual void setRouteLegs(const QList<QGeoRouteLeg> &legs); virtual QList<QGeoRouteLeg> routeLegs() const; + virtual void setExtendedAttributes(const QVariantMap &extendedAttributes); + virtual QVariantMap extendedAttributes() const; + virtual QString engineName() const = 0; virtual int segmentsCount() const = 0; @@ -153,6 +157,9 @@ public: virtual void setRouteLegs(const QList<QGeoRouteLeg> &legs) override; virtual QList<QGeoRouteLeg> routeLegs() const override; + void setExtendedAttributes(const QVariantMap &extendedAttributes) override; + QVariantMap extendedAttributes() const override; + // QGeoRouteLeg API virtual void setLegIndex(int idx) override; virtual int legIndex() const override; @@ -175,6 +182,7 @@ public: QGeoRouteSegment m_firstSegment; mutable int m_numSegments; QScopedPointer<QGeoRoute> m_containingRoute; + QVariantMap m_extendedAttributes; int m_legIndex = 0; }; diff --git a/src/location/maps/qgeotilerequestmanager.cpp b/src/location/maps/qgeotilerequestmanager.cpp index d4d94ad0..aa6de94d 100644 --- a/src/location/maps/qgeotilerequestmanager.cpp +++ b/src/location/maps/qgeotilerequestmanager.cpp @@ -240,6 +240,6 @@ void QGeoTileRequestManagerPrivate::tileError(const QGeoTileSpec &tile, const QS } } -#include "qgeotilerequestmanager.moc" - QT_END_NAMESPACE + +#include "qgeotilerequestmanager.moc" diff --git a/src/location/maps/qnavigationmanagerengine_p.h b/src/location/maps/qnavigationmanagerengine_p.h index 0852b3ea..e7b3876c 100644 --- a/src/location/maps/qnavigationmanagerengine_p.h +++ b/src/location/maps/qnavigationmanagerengine_p.h @@ -60,11 +60,18 @@ class QGeoMap; class QGeoMapParameter; class QMapRouteObject; class QGeoRoute; +class QGeoRouteLeg; class QNavigationManager; class QNavigationManagerEnginePrivate; class QDeclarativeNavigatorParams; class QDeclarativeGeoWaypoint; +/* + This class is not supposed to react on QDeclarativeNavigator properties changes. + This class is meant to react only on start, stop and setTrackPosition. + Upon start(), it is supposed to fetch all info from the QDeclarativeNavigatorParams that the engine is supposed + to inject. +*/ class Q_LOCATION_PRIVATE_EXPORT QAbstractNavigator: public QObject { Q_OBJECT @@ -89,6 +96,7 @@ signals: void waypointReached(const QDeclarativeGeoWaypoint *pos); void destinationReached(); void currentRouteChanged(const QGeoRoute &route); + void currentRouteLegChanged(const QGeoRouteLeg &route); void currentSegmentChanged(int segment); private: diff --git a/src/location/places/qplacesearchrequest_p.h b/src/location/places/qplacesearchrequest_p.h index fdff89b8..73360926 100644 --- a/src/location/places/qplacesearchrequest_p.h +++ b/src/location/places/qplacesearchrequest_p.h @@ -56,6 +56,7 @@ #include <QtCore/QList> #include <QtLocation/private/qlocationglobal_p.h> #include <QtCore/QVariant> +#include <QtLocation/QGeoRoute> QT_BEGIN_NAMESPACE @@ -79,6 +80,7 @@ public: QString recommendationId; QLocation::VisibilityScope visibilityScope; QPlaceSearchRequest::RelevanceHint relevanceHint; + QGeoRoute routeSearchArea; int limit; QVariant searchContext; bool related = false; |