diff options
Diffstat (limited to 'src/location')
25 files changed, 412 insertions, 51 deletions
diff --git a/src/location/configure.json b/src/location/configure.json index 4de6e865..bfa3d6f2 100644 --- a/src/location/configure.json +++ b/src/location/configure.json @@ -37,7 +37,7 @@ "condition": [ "features.opengl", "features.c++14", - "!config.qnx && (!config.win32 || config.mingw)" + "!config.qnx && !config.intel_icc && (!config.win32 || config.mingw)" ], "output": [ "privateFeature" ] }, diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp index be08c3a4..b9f62fad 100644 --- a/src/location/declarativemaps/qdeclarativegeomap.cpp +++ b/src/location/declarativemaps/qdeclarativegeomap.cpp @@ -46,6 +46,7 @@ #include <QtPositioning/QGeoCircle> #include <QtPositioning/QGeoRectangle> #include <QtPositioning/QGeoPath> +#include <QtPositioning/QGeoPolygon> #include <QtQuick/QQuickWindow> #include <QtQuick/QSGRectangleNode> #include <QtQuick/private/qquickwindow_p.h> @@ -189,7 +190,11 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent) m_activeMapType = new QDeclarativeGeoMapType(QGeoMapType(QGeoMapType::NoMap, tr("No Map"), - tr("No Map"), false, false, 0, QByteArrayLiteral("")), this); + tr("No Map"), + false, false, + 0, + QByteArrayLiteral(""), + QGeoCameraCapabilities()), this); m_cameraData.setCenter(QGeoCoordinate(51.5073,-0.1277)); //London city center m_cameraData.setZoomLevel(8.0); @@ -217,8 +222,18 @@ QDeclarativeGeoMap::~QDeclarativeGeoMap() m_map->clearMapItems(); } - if (!m_mapViews.isEmpty()) - qDeleteAll(m_mapViews); + // This forces the destruction of the associated items now, not when QObject destructor is called, at which point + // QDeclarativeGeoMap is long gone + if (!m_mapViews.isEmpty()) { + for (QDeclarativeGeoMapItemView *v : qAsConst(m_mapViews)) { + if (!v) + continue; + if (v->parent() == this) + delete v; + else + v->removeInstantiatedItems(); + } + } // remove any map items associations for (int i = 0; i < m_mapItems.count(); ++i) { if (m_mapItems.at(i)) @@ -692,7 +707,12 @@ void QDeclarativeGeoMap::mappingManagerInitialized() } else { m_activeMapType = new QDeclarativeGeoMapType(QGeoMapType(QGeoMapType::NoMap, tr("No Map"), - tr("No Map"), false, false, 0, QByteArrayLiteral("")), this); + tr("No Map"), + false, + false, + 0, + QByteArrayLiteral(""), + QGeoCameraCapabilities()), this); } } @@ -1248,22 +1268,22 @@ QGeoShape QDeclarativeGeoMap::visibleRegion() const return m_visibleRegion; const QList<QDoubleVector2D> &visibleRegion = m_map->geoProjection().visibleRegion(); - QGeoPath path; + QGeoPolygon poly; for (int i = 0; i < visibleRegion.size(); ++i) { const QDoubleVector2D &c = visibleRegion.at(i); // If a segment spans more than half of the map longitudinally, split in 2. if (i && qAbs(visibleRegion.at(i-1).x() - c.x()) >= 0.5) { // This assumes a segment is never >= 1.0 (whole map span) QDoubleVector2D extraPoint = (visibleRegion.at(i-1) + c) * 0.5; - path.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(extraPoint)); + poly.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(extraPoint)); } - path.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(c)); + poly.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(c)); } if (visibleRegion.size() >= 2 && qAbs(visibleRegion.last().x() - visibleRegion.first().x()) >= 0.5) { QDoubleVector2D extraPoint = (visibleRegion.last() + visibleRegion.first()) * 0.5; - path.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(extraPoint)); + poly.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(extraPoint)); } - return path.boundingGeoRectangle(); + return poly; } /*! @@ -1380,6 +1400,61 @@ QQmlListProperty<QDeclarativeGeoMapType> QDeclarativeGeoMap::supportedMapTypes() } /*! + \qmlmethod void QtLocation::Map::setBearing(real bearing, coordinate coordinate) + + Sets the bearing for the map to \a bearing, rotating it around \a coordinate. + If the Plugin used for the Map supports bearing, the valid range for \a bearing is between 0 and 360. + If the Plugin used for the Map does not support bearing, or if the map is tilted and \a coordinate happens + to be behind the camera, or if the map is not ready (see \l mapReady), calling this method will have no effect. + + The release of this API with Qt 5.10 is a Technology Preview. + + \since 5.10 +*/ +void QDeclarativeGeoMap::setBearing(qreal bearing, const QGeoCoordinate &coordinate) +{ + if (!m_map) + return; + + const QDoubleVector2D coordWrapped = m_map->geoProjection().geoToWrappedMapProjection(coordinate); + if (!m_map->geoProjection().isProjectable(coordWrapped)) + return; + + const QPointF rotationPoint = m_map->geoProjection().wrappedMapProjectionToItemPosition(coordWrapped).toPointF(); + + // First set bearing + setBearing(bearing); + // then reanchor + setCenter(m_map->geoProjection().anchorCoordinateToPoint(coordinate, rotationPoint)); +} + +/*! + \qmlmethod void QtLocation::Map::alignCoordinateToPoint(coordinate coordinate, QPointF point) + + Aligns \a coordinate to \a point. + This method effectively extends the functionality offered by the \l center qml property, allowing + to align a coordinate to point of the Map element other than its center. + This is useful in those applications where the center of the scene (e.g., a cursor) is not to be + placed exactly in the center of the map. + + If the map is tilted, and \a coordinate happens to be behind the camera, or if the map is not ready + (see \l mapReady), calling this method will have no effect. + + The release of this API with Qt 5.10 is a Technology Preview. + + \sa center + + \since 5.10 +*/ +void QDeclarativeGeoMap::alignCoordinateToPoint(const QGeoCoordinate &coordinate, const QPointF &point) +{ + if (!m_map) + return; + + setCenter(m_map->geoProjection().anchorCoordinateToPoint(coordinate, point)); +} + +/*! \qmlmethod coordinate QtLocation::Map::toCoordinate(QPointF position, bool clipToViewPort) Returns the coordinate which corresponds to the \a position relative to the map item. @@ -1869,6 +1944,47 @@ void QDeclarativeGeoMap::removeMapItemGroup(QDeclarativeGeoMapItemGroup *itemGro } /*! + \qmlmethod void QtLocation::Map::removeMapItemView(MapItemView itemView) + + Removes \a itemView and the items instantiated by it from the Map. + + \sa MapItemView, addMapItemView + + \since 5.10 +*/ +void QDeclarativeGeoMap::removeMapItemView(QDeclarativeGeoMapItemView *itemView) +{ + if (!itemView || itemView->map_ != this) // can't remove a view that is already added to another map + return; + + itemView->removeInstantiatedItems(); + itemView->map_ = 0; + // it can be removed from the list at this point, since no operations that require a Map have to be done + // anymore on destruction. + m_mapViews.removeOne(itemView); +} + +/*! + \qmlmethod void QtLocation::Map::addMapItemView(MapItemView itemView) + + Adds \a itemView to the Map. + + \sa MapItemView, removeMapItemView + + \since 5.10 +*/ +void QDeclarativeGeoMap::addMapItemView(QDeclarativeGeoMapItemView *itemView) +{ + if (!itemView || itemView->map_) // can't add a view twice + return; + + // Not appending it to m_mapViews because it seems unnecessary even if the + // itemView is a child of this (in which case it would be destroyed + m_mapViews.append(itemView); + setupMapView(itemView); +} + +/*! \qmlproperty MapType QtLocation::Map::activeMapType \brief Access to the currently active \l{MapType}{map type}. @@ -2136,7 +2252,7 @@ bool QDeclarativeGeoMap::sendTouchEvent(QTouchEvent *event) auto touchPointGrabberItem = [touchDevice, windowPriv](const QTouchEvent::TouchPoint &point) -> QQuickItem* { if (QQuickEventPoint *eventPointer = windowPriv->pointerEventInstance(touchDevice)->pointById(point.id())) - return eventPointer->grabber(); + return eventPointer->grabberItem(); return nullptr; }; diff --git a/src/location/declarativemaps/qdeclarativegeomap_p.h b/src/location/declarativemaps/qdeclarativegeomap_p.h index f357d322..e552affe 100644 --- a/src/location/declarativemaps/qdeclarativegeomap_p.h +++ b/src/location/declarativemaps/qdeclarativegeomap_p.h @@ -156,12 +156,18 @@ public: QQmlListProperty<QDeclarativeGeoMapType> supportedMapTypes(); + Q_INVOKABLE void setBearing(qreal bearing, const QGeoCoordinate &coordinate); + Q_INVOKABLE void alignCoordinateToPoint(const QGeoCoordinate &coordinate, const QPointF &point); + Q_INVOKABLE void removeMapItem(QDeclarativeGeoMapItemBase *item); Q_INVOKABLE void addMapItem(QDeclarativeGeoMapItemBase *item); Q_INVOKABLE void addMapItemGroup(QDeclarativeGeoMapItemGroup *itemGroup); Q_INVOKABLE void removeMapItemGroup(QDeclarativeGeoMapItemGroup *itemGroup); + Q_INVOKABLE void removeMapItemView(QDeclarativeGeoMapItemView *itemView); + Q_INVOKABLE void addMapItemView(QDeclarativeGeoMapItemView *itemView); + Q_INVOKABLE void clearMapItems(); QList<QObject *> mapItems(); diff --git a/src/location/declarativemaps/qdeclarativegeomapitemview.cpp b/src/location/declarativemaps/qdeclarativegeomapitemview.cpp index 8207caa5..24ed6700 100644 --- a/src/location/declarativemaps/qdeclarativegeomapitemview.cpp +++ b/src/location/declarativemaps/qdeclarativegeomapitemview.cpp @@ -431,6 +431,9 @@ void QDeclarativeGeoMapItemView::instantiateAllItems() fitViewport(); } +/* + * used internally +*/ void QDeclarativeGeoMapItemView::removeItemData(QDeclarativeGeoMapItemViewItemData *itemData) { if (!itemData) diff --git a/src/location/declarativemaps/qdeclarativegeomapitemview_p.h b/src/location/declarativemaps/qdeclarativegeomapitemview_p.h index 8c83e37d..8f1a081f 100644 --- a/src/location/declarativemaps/qdeclarativegeomapitemview_p.h +++ b/src/location/declarativemaps/qdeclarativegeomapitemview_p.h @@ -141,6 +141,7 @@ private: int m_readyIncubators; bool m_repopulating; + friend class QDeclarativeGeoMap; friend class QDeclarativeGeoMapItemViewItemData; friend class MapItemViewDelegateIncubator; }; diff --git a/src/location/declarativemaps/qdeclarativegeomaptype.cpp b/src/location/declarativemaps/qdeclarativegeomaptype.cpp index 86444aa4..7e40d414 100644 --- a/src/location/declarativemaps/qdeclarativegeomaptype.cpp +++ b/src/location/declarativemaps/qdeclarativegeomaptype.cpp @@ -57,7 +57,8 @@ QT_BEGIN_NAMESPACE QDeclarativeGeoMapType::QDeclarativeGeoMapType(const QGeoMapType mapType, QObject *parent) : QObject(parent), - mapType_(mapType) {} + mapType_(mapType), + cameraCapabilities_(new QDeclarativeGeoCameraCapabilities(mapType.cameraCapabilities(), this)) {} QDeclarativeGeoMapType::~QDeclarativeGeoMapType() {} @@ -131,4 +132,116 @@ bool QDeclarativeGeoMapType::night() const return mapType_.night(); } +/*! + \qmlproperty CameraCapabilities MapType::cameraCapabilities + \since Qt Location 5.10 + + This property holds the camera capabilities for this map type. +*/ +QDeclarativeGeoCameraCapabilities *QDeclarativeGeoMapType::cameraCapabilities() const +{ + return cameraCapabilities_; +} + +/*! + \qmlproperty VariantMap MapType::metadata + \since Qt Location 5.10 + + This property holds optional, extra metadata related to a specific map type. + The content of this property is entirely plugin-specific. +*/ +QVariantMap QDeclarativeGeoMapType::metadata() const +{ + return mapType_.metadata(); +} + +/* + * QDeclarativeGeoCameraCapabilities implementation + */ + +/*! + \qmltype CameraCapabilities + \instantiates QDeclarativeGeoCameraCapabilities + \inherits QObject + \inqmlmodule QtLocation + \ingroup qml-QtLocation5-maps + \since Qt Location 5.10 + + \brief The CameraCapabilities type holds information about the camera capabilities for a specific map type. + + This includes the map minimum and maximum zoom level, minimum and maximum tilt angle and + minimum and maximum field of view. +*/ + +QDeclarativeGeoCameraCapabilities::QDeclarativeGeoCameraCapabilities(const QGeoCameraCapabilities &cameraCaps, QObject *parent) + : QObject(parent), cameraCaps_(cameraCaps) +{ + +} + +QDeclarativeGeoCameraCapabilities::~QDeclarativeGeoCameraCapabilities() +{ + +} + +/*! + \qmlproperty qreal CameraCapabilities::minimumZoomLevel + + This read-only property holds the minimum available zoom level with this map type. +*/ +qreal QDeclarativeGeoCameraCapabilities::minimumZoomLevel() const +{ + return cameraCaps_.minimumZoomLevelAt256(); +} + +/*! + \qmlproperty qreal CameraCapabilities::maximumZoomLevel + + This read-only property holds the maximum available zoom level with this map type. +*/ +qreal QDeclarativeGeoCameraCapabilities::maximumZoomLevel() const +{ + return cameraCaps_.maximumZoomLevelAt256(); +} + +/*! + \qmlproperty qreal CameraCapabilities::minimumTilt + + This read-only property holds the minimum available tilt with this map type. +*/ +qreal QDeclarativeGeoCameraCapabilities::minimumTilt() const +{ + return cameraCaps_.minimumTilt(); +} + +/*! + \qmlproperty qreal CameraCapabilities::maximumTilt + + This read-only property holds the maximum available tilt with this map type. +*/ +qreal QDeclarativeGeoCameraCapabilities::maximumTilt() const +{ + return cameraCaps_.maximumTilt(); +} + +/*! + \qmlproperty qreal CameraCapabilities::minimumFieldOfView + + This read-only property holds the minimum available field of view with this map type. +*/ +qreal QDeclarativeGeoCameraCapabilities::minimumFieldOfView() const +{ + return cameraCaps_.minimumFieldOfView(); +} + +/*! + \qmlproperty qreal CameraCapabilities::maximumFieldOfView + + This read-only property holds the maximum available field of view with this map type. +*/ +qreal QDeclarativeGeoCameraCapabilities::maximumFieldOfView() const +{ + return cameraCaps_.maximumFieldOfView(); +} + QT_END_NAMESPACE diff --git a/src/location/declarativemaps/qdeclarativegeomaptype_p.h b/src/location/declarativemaps/qdeclarativegeomaptype_p.h index 7b449aa0..5d99083d 100644 --- a/src/location/declarativemaps/qdeclarativegeomaptype_p.h +++ b/src/location/declarativemaps/qdeclarativegeomaptype_p.h @@ -56,6 +56,31 @@ QT_BEGIN_NAMESPACE +class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoCameraCapabilities: public QObject +{ + Q_OBJECT + Q_PROPERTY(qreal minimumZoomLevel READ minimumZoomLevel CONSTANT) + Q_PROPERTY(qreal maximumZoomLevel READ maximumZoomLevel CONSTANT) + Q_PROPERTY(qreal minimumTilt READ minimumTilt CONSTANT) + Q_PROPERTY(qreal maximumTilt READ maximumTilt CONSTANT) + Q_PROPERTY(qreal minimumFieldOfView READ minimumFieldOfView CONSTANT) + Q_PROPERTY(qreal maximumFieldOfView READ maximumFieldOfView CONSTANT) + +public: + QDeclarativeGeoCameraCapabilities(const QGeoCameraCapabilities &cameraCaps, QObject *parent = 0); + ~QDeclarativeGeoCameraCapabilities(); + + qreal minimumZoomLevel() const; + qreal maximumZoomLevel() const; + qreal minimumTilt() const; + qreal maximumTilt() const; + qreal minimumFieldOfView() const; + qreal maximumFieldOfView() const; + +private: + QGeoCameraCapabilities cameraCaps_; +}; + class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoMapType : public QObject { Q_OBJECT @@ -66,6 +91,8 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoMapType : public QObject Q_PROPERTY(QString description READ description CONSTANT) Q_PROPERTY(bool mobile READ mobile CONSTANT) Q_PROPERTY(bool night READ night CONSTANT REVISION 1) + Q_PROPERTY(QDeclarativeGeoCameraCapabilities *cameraCapabilities READ cameraCapabilities CONSTANT) + Q_PROPERTY(QVariantMap metadata READ metadata CONSTANT) public: enum MapStyle { @@ -91,11 +118,14 @@ public: QString description() const; bool mobile() const; bool night() const; + QDeclarativeGeoCameraCapabilities *cameraCapabilities() const; + QVariantMap metadata() const; const QGeoMapType mapType() { return mapType_; } private: QGeoMapType mapType_; + QDeclarativeGeoCameraCapabilities *cameraCapabilities_; }; QT_END_NAMESPACE diff --git a/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp b/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp index 94bd63c8..0383c0c4 100644 --- a/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp +++ b/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp @@ -722,6 +722,7 @@ void QDeclarativeGeoRouteQuery::componentComplete() \li RouteQuery.DirtRoadFeature - Consider dirt roads when planning the route \li RouteQuery.ParksFeature - Consider parks when planning the route \li RouteQuery.MotorPoolLaneFeature - Consider motor pool lanes when planning the route + \li RouteQuery.TrafficFeature - Consider traffic when planning the route \endlist \sa setFeatureWeight, featureWeight diff --git a/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h b/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h index 3dfd2ce6..18486ac8 100644 --- a/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h +++ b/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h @@ -238,7 +238,8 @@ public: TunnelFeature = QGeoRouteRequest::TunnelFeature, DirtRoadFeature = QGeoRouteRequest::DirtRoadFeature, ParksFeature = QGeoRouteRequest::ParksFeature, - MotorPoolLaneFeature = QGeoRouteRequest::MotorPoolLaneFeature + MotorPoolLaneFeature = QGeoRouteRequest::MotorPoolLaneFeature, + TrafficFeature = QGeoRouteRequest::TrafficFeature }; Q_DECLARE_FLAGS(FeatureTypes, FeatureType) diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp index 2c6d3ba4..a97271aa 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp @@ -494,6 +494,27 @@ void QDeclarativePolylineMapItem::setPath(const QJSValue &value) } /*! + \qmlmethod int MapPolyline::setPath(geopath path) + + Sets the \l path using a \l QGeoPath type. + + \since 5.10 + + \sa path +*/ +void QDeclarativePolylineMapItem::setPath(const QGeoPath &path) +{ + if (geopath_.path() == path.path()) + return; + + geopath_ = path; + regenerateCache(); + geometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); + markSourceDirtyAndUpdate(); + emit pathChanged(); +} + +/*! \internal */ void QDeclarativePolylineMapItem::setPathFromGeoList(const QList<QGeoCoordinate> &path) diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h b/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h index ec57c980..6b3c42e9 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h @@ -141,6 +141,7 @@ public: QJSValue path() const; virtual void setPath(const QJSValue &value); + Q_INVOKABLE void setPath(const QGeoPath &path); bool contains(const QPointF &point) const Q_DECL_OVERRIDE; const QGeoShape &geoShape() const Q_DECL_OVERRIDE; diff --git a/src/location/declarativemaps/qquickgeomapgesturearea.cpp b/src/location/declarativemaps/qquickgeomapgesturearea.cpp index 4f949ad0..d62ae8cf 100644 --- a/src/location/declarativemaps/qquickgeomapgesturearea.cpp +++ b/src/location/declarativemaps/qquickgeomapgesturearea.cpp @@ -84,18 +84,6 @@ static qreal distanceBetweenTouchPoints(const QPointF &p1, const QPointF &p2) return QLineF(p1, p2).length(); } -// Returns the new map center after anchoring coordinate to anchorPoint on the screen -// Approach: find the displacement in (wrapped) mercator space, and apply that to the center -static QGeoCoordinate anchorCoordinateToPoint(QGeoMap &map, const QGeoCoordinate &coordinate, const QPointF &anchorPoint) -{ - QDoubleVector2D centerProj = map.geoProjection().geoToWrappedMapProjection(map.cameraData().center()); - QDoubleVector2D coordProj = map.geoProjection().geoToWrappedMapProjection(coordinate); - - QDoubleVector2D anchorProj = map.geoProjection().itemPositionToWrappedMapProjection(QDoubleVector2D(anchorPoint)); - // Y-clamping done in mercatorToCoord - return map.geoProjection().wrappedMapProjectionToGeo(centerProj + coordProj - anchorProj); -} - static qreal angleFromPoints(const QPointF &p1, const QPointF &p2) { return QLineF(p1, p2).angle(); @@ -255,6 +243,8 @@ QT_BEGIN_NAMESPACE MapGestureArea objects are used as part of a Map, to provide for panning, flicking and pinch-to-zoom gesture used on touch displays, as well as two finger rotation and two finger parallel vertical sliding to tilt the map. + On platforms supporting \l QWheelEvent, using the scroll wheel alone, or in combination with + key modifiers Shift or Control will also zoom, rotate or tilt the map, respectively. A MapGestureArea is automatically created with a new Map and available with the \l{Map::gesture}{gesture} property. This is the only way @@ -951,15 +941,26 @@ void QQuickGeoMapGestureArea::handleWheelEvent(QWheelEvent *event) const QGeoCoordinate &wheelGeoPos = m_map->geoProjection().itemPositionToCoordinate(QDoubleVector2D(event->posF()), false); const QPointF &preZoomPoint = event->posF(); - const double zoomLevelDelta = event->angleDelta().y() * qreal(0.001); - // Gesture area should always honor maxZL, but Map might not. - m_declarativeMap->setZoomLevel(qMin<qreal>(m_declarativeMap->zoomLevel() + zoomLevelDelta, maximumZoomLevel()), - false); - const QPointF &postZoomPoint = m_map->geoProjection().coordinateToItemPosition(wheelGeoPos, false).toPointF(); - - if (preZoomPoint != postZoomPoint) // need to re-anchor the wheel geoPos to the event position - m_declarativeMap->setCenter(anchorCoordinateToPoint(*m_map, wheelGeoPos, preZoomPoint)); - + // Not using AltModifier as, for some reason, it causes angleDelta to be 0 + if (event->modifiers() & Qt::ShiftModifier && rotationEnabled()) { + // First set bearing + const double bearingDelta = event->angleDelta().y() * qreal(0.05); + m_declarativeMap->setBearing(m_declarativeMap->bearing() + bearingDelta); + // then reanchor + m_declarativeMap->setCenter(m_map->geoProjection().anchorCoordinateToPoint(wheelGeoPos, preZoomPoint)); + } else if (event->modifiers() & Qt::ControlModifier && tiltEnabled()) { + const double tiltDelta = event->angleDelta().y() * qreal(0.05); + m_declarativeMap->setTilt(m_declarativeMap->tilt() + tiltDelta); + } else if (pinchEnabled()) { + const double zoomLevelDelta = event->angleDelta().y() * qreal(0.001); + // Gesture area should always honor maxZL, but Map might not. + m_declarativeMap->setZoomLevel(qMin<qreal>(m_declarativeMap->zoomLevel() + zoomLevelDelta, maximumZoomLevel()), + false); + const QPointF &postZoomPoint = m_map->geoProjection().coordinateToItemPosition(wheelGeoPos, false).toPointF(); + + if (preZoomPoint != postZoomPoint) // need to re-anchor the wheel geoPos to the event position + m_declarativeMap->setCenter(m_map->geoProjection().anchorCoordinateToPoint(wheelGeoPos, preZoomPoint)); + } event->accept(); } #endif @@ -1705,7 +1706,7 @@ bool QQuickGeoMapGestureArea::canStartPan() */ void QQuickGeoMapGestureArea::updatePan() { - QGeoCoordinate animationStartCoordinate = anchorCoordinateToPoint(*m_map, m_startCoord, m_touchPointsCentroid); + QGeoCoordinate animationStartCoordinate = m_map->geoProjection().anchorCoordinateToPoint(m_startCoord, m_touchPointsCentroid); m_declarativeMap->setCenter(animationStartCoordinate); } diff --git a/src/location/doc/qtlocation.qdocconf b/src/location/doc/qtlocation.qdocconf index 695860a0..464e8e76 100644 --- a/src/location/doc/qtlocation.qdocconf +++ b/src/location/doc/qtlocation.qdocconf @@ -16,7 +16,7 @@ qhp.QtLocation.indexRoot = qhp.QtLocation.filterAttributes = qtlocation $QT_VERSION qtrefdoc qhp.QtLocation.customFilters.Qt.name = QtLocation $QT_VERSION -qhp.QtLocation.customFilters.Qt.filterAttributes = qtLocation $QT_VERSION +qhp.QtLocation.customFilters.Qt.filterAttributes = qtlocation $QT_VERSION qhp.QtLocation.subprojects = classes qml examples qhp.QtLocation.subprojects.classes.title = C++ Classes qhp.QtLocation.subprojects.classes.indexTitle = Qt Location C++ Classes @@ -43,6 +43,8 @@ sourcedirs += .. \ examplesinstallpath = location +manifestmeta.highlighted.names = "QtLocation/Map Viewer (QML)" + exampledirs += ../../../examples/location \ snippets/ diff --git a/src/location/location.pro b/src/location/location.pro index a951ebd6..f91a20d0 100644 --- a/src/location/location.pro +++ b/src/location/location.pro @@ -26,7 +26,6 @@ OTHER_FILES += doc/src/*.qdoc # show .qdoc files in Qt Creator PUBLIC_HEADERS += \ qlocation.h \ - qlocationglobal_p.h \ qlocationglobal.h PRIVATE_HEADERS += \ diff --git a/src/location/maps/qgeomappingmanagerengine.cpp b/src/location/maps/qgeomappingmanagerengine.cpp index ffc0f065..187b30eb 100644 --- a/src/location/maps/qgeomappingmanagerengine.cpp +++ b/src/location/maps/qgeomappingmanagerengine.cpp @@ -154,7 +154,13 @@ QGeoCameraCapabilities QGeoMappingManagerEngine::cameraCapabilities(int mapId) c { Q_UNUSED(mapId) Q_D(const QGeoMappingManagerEngine); - return d->capabilities_; + + if (mapId == 0) + return d->capabilities_; + int idx = mapId - 1; + if (idx >= supportedMapTypes().size()) + return d->capabilities_; + return supportedMapTypes().at(idx).cameraCapabilities(); } void QGeoMappingManagerEngine::setCameraCapabilities(const QGeoCameraCapabilities &capabilities) diff --git a/src/location/maps/qgeomappingmanagerengine_p.h b/src/location/maps/qgeomappingmanagerengine_p.h index 0f347d73..dd4aa681 100644 --- a/src/location/maps/qgeomappingmanagerengine_p.h +++ b/src/location/maps/qgeomappingmanagerengine_p.h @@ -90,7 +90,7 @@ public: QList<QGeoMapType> supportedMapTypes() const; // the class is private, so this can be virtual here for now. - virtual QGeoCameraCapabilities cameraCapabilities(int mapId = 0) const; + QGeoCameraCapabilities cameraCapabilities(int mapId = 0) const; void setLocale(const QLocale &locale); QLocale locale() const; diff --git a/src/location/maps/qgeomaptype.cpp b/src/location/maps/qgeomaptype.cpp index 34781451..c4635998 100644 --- a/src/location/maps/qgeomaptype.cpp +++ b/src/location/maps/qgeomaptype.cpp @@ -46,8 +46,11 @@ QGeoMapType::QGeoMapType(const QGeoMapType &other) : d_ptr(other.d_ptr) {} QGeoMapType::QGeoMapType(QGeoMapType::MapStyle style, const QString &name, - const QString &description, bool mobile, bool night, int mapId, QByteArray pluginName) -: d_ptr(new QGeoMapTypePrivate(style, name, description, mobile, night, mapId, pluginName)) + const QString &description, bool mobile, bool night, int mapId, + const QByteArray &pluginName, + const QGeoCameraCapabilities &cameraCapabilities, + const QVariantMap &metadata) +: d_ptr(new QGeoMapTypePrivate(style, name, description, mobile, night, mapId, pluginName, cameraCapabilities, metadata)) { } @@ -107,6 +110,16 @@ QByteArray QGeoMapType::pluginName() const return d_ptr->pluginName_; } +QGeoCameraCapabilities QGeoMapType::cameraCapabilities() const +{ + return d_ptr->cameraCapabilities_; +} + +QVariantMap QGeoMapType::metadata() const +{ + return d_ptr->metadata_; +} + QGeoMapTypePrivate::QGeoMapTypePrivate() : style_(QGeoMapType::NoMap), mobile_(false), night_(false), mapId_(0) { @@ -114,15 +127,18 @@ QGeoMapTypePrivate::QGeoMapTypePrivate() QGeoMapTypePrivate::QGeoMapTypePrivate(const QGeoMapTypePrivate &other) : QSharedData(other), style_(other.style_), name_(other.name_), description_(other.description_), - mobile_(other.mobile_), night_(other.night_), mapId_(other.mapId_), pluginName_(other.pluginName_) + mobile_(other.mobile_), night_(other.night_), mapId_(other.mapId_), pluginName_(other.pluginName_), + cameraCapabilities_(other.cameraCapabilities_), metadata_(other.metadata_) { } QGeoMapTypePrivate::QGeoMapTypePrivate(QGeoMapType::MapStyle style, const QString &name, const QString &description, bool mobile, bool night, - int mapId, QByteArray pluginName) + int mapId, const QByteArray &pluginName, + const QGeoCameraCapabilities &cameraCapabilities, + const QVariantMap &metadata) : style_(style), name_(name), description_(description), mobile_(mobile), night_(night), - mapId_(mapId), pluginName_(pluginName) + mapId_(mapId), pluginName_(pluginName), cameraCapabilities_(cameraCapabilities), metadata_(metadata) { } @@ -134,7 +150,8 @@ bool QGeoMapTypePrivate::operator==(const QGeoMapTypePrivate &other) const { return pluginName_ == other.pluginName_ && style_ == other.style_ && name_ == other.name_ && description_ == other.description_ && mobile_ == other.mobile_ && night_ == other.night_ && - mapId_ == other.mapId_; + mapId_ == other.mapId_ && cameraCapabilities_ == other.cameraCapabilities_ && + metadata_ == other.metadata_; } QT_END_NAMESPACE diff --git a/src/location/maps/qgeomaptype_p.h b/src/location/maps/qgeomaptype_p.h index 4b5cb0d0..3ce0e95a 100644 --- a/src/location/maps/qgeomaptype_p.h +++ b/src/location/maps/qgeomaptype_p.h @@ -51,6 +51,8 @@ #include <QtCore/QString> #include <QtCore/QSharedDataPointer> #include <QtLocation/private/qlocationglobal_p.h> +#include <QtLocation/private/qgeocameracapabilities_p.h> +#include <QVariantMap> QT_BEGIN_NAMESPACE @@ -59,7 +61,7 @@ class QGeoMapTypePrivate; class Q_LOCATION_PRIVATE_EXPORT QGeoMapType { public: - enum MapStyle { + enum MapStyle { // ### Qt6: change this to be a QFlags instead, or remove. NoMap = 0, StreetMap, SatelliteMapDay, @@ -77,7 +79,9 @@ public: QGeoMapType(); QGeoMapType(const QGeoMapType &other); QGeoMapType(MapStyle style, const QString &name, const QString &description, bool mobile, - bool night, int mapId, QByteArray pluginName); + bool night, int mapId, const QByteArray &pluginName, + const QGeoCameraCapabilities &cameraCapabilities, + const QVariantMap &metadata = QVariantMap()); ~QGeoMapType(); QGeoMapType &operator = (const QGeoMapType &other); @@ -92,6 +96,8 @@ public: bool night() const; int mapId() const; QByteArray pluginName() const; + QGeoCameraCapabilities cameraCapabilities() const; + QVariantMap metadata() const; private: QSharedDataPointer<QGeoMapTypePrivate> d_ptr; diff --git a/src/location/maps/qgeomaptype_p_p.h b/src/location/maps/qgeomaptype_p_p.h index 039c0962..e66991ab 100644 --- a/src/location/maps/qgeomaptype_p_p.h +++ b/src/location/maps/qgeomaptype_p_p.h @@ -50,9 +50,10 @@ #include <QMetaType> #include <QString> +#include <QVariantMap> #include <QByteArray> #include <QSharedData> - +#include "qgeocameracapabilities_p.h" #include "qgeomaptype_p.h" QT_BEGIN_NAMESPACE @@ -62,7 +63,9 @@ class QGeoMapTypePrivate : public QSharedData public: QGeoMapTypePrivate(); QGeoMapTypePrivate(QGeoMapType::MapStyle style, const QString &name, const QString &description, bool mobile, - bool night, int mapId, QByteArray pluginName); + bool night, int mapId, const QByteArray &pluginName, + const QGeoCameraCapabilities &cameraCapabilities, + const QVariantMap &metadata); QGeoMapTypePrivate(const QGeoMapTypePrivate &other); ~QGeoMapTypePrivate(); @@ -77,6 +80,8 @@ public: bool night_; int mapId_; QByteArray pluginName_; + QGeoCameraCapabilities cameraCapabilities_; + QVariantMap metadata_; }; QT_END_NAMESPACE diff --git a/src/location/maps/qgeoprojection.cpp b/src/location/maps/qgeoprojection.cpp index fcf9a350..1df174fb 100644 --- a/src/location/maps/qgeoprojection.cpp +++ b/src/location/maps/qgeoprojection.cpp @@ -73,6 +73,17 @@ QGeoProjection::~QGeoProjection() } +QGeoCoordinate QGeoProjection::anchorCoordinateToPoint(const QGeoCoordinate &coordinate, const QPointF &anchorPoint) const +{ + // Approach: find the displacement in (wrapped) mercator space, and apply that to the center + QDoubleVector2D centerProj = geoToWrappedMapProjection(cameraData().center()); + QDoubleVector2D coordProj = geoToWrappedMapProjection(coordinate); + + QDoubleVector2D anchorProj = itemPositionToWrappedMapProjection(QDoubleVector2D(anchorPoint)); + // Y-clamping done in mercatorToCoord + return wrappedMapProjectionToGeo(centerProj + coordProj - anchorProj); +} + /* * QGeoProjectionWebMercator implementation */ @@ -576,6 +587,11 @@ void QGeoProjectionWebMercator::updateVisibleRegion() } } +QGeoCameraData QGeoProjectionWebMercator::cameraData() const +{ + return m_cameraData; +} + /* * * Line implementation diff --git a/src/location/maps/qgeoprojection_p.h b/src/location/maps/qgeoprojection_p.h index 76e11af0..ca81df3a 100644 --- a/src/location/maps/qgeoprojection_p.h +++ b/src/location/maps/qgeoprojection_p.h @@ -92,6 +92,12 @@ public: virtual QDoubleVector2D geoToWrappedMapProjection(const QGeoCoordinate &coordinate) const = 0; virtual QGeoCoordinate wrappedMapProjectionToGeo(const QDoubleVector2D &wrappedProjection) const = 0; virtual QMatrix4x4 quickItemTransformation(const QGeoCoordinate &coordinate, const QPointF &anchorPoint, qreal zoomLevel) const = 0; + + // Returns the new map center after anchoring coordinate to anchorPoint on the screen + QGeoCoordinate anchorCoordinateToPoint(const QGeoCoordinate &coordinate, const QPointF &anchorPoint) const; + +private: + virtual QGeoCameraData cameraData() const = 0; }; class Q_LOCATION_PRIVATE_EXPORT QGeoProjectionWebMercator : public QGeoProjection @@ -133,6 +139,7 @@ public: private: void setupCamera(); void updateVisibleRegion(); + QGeoCameraData cameraData() const Q_DECL_OVERRIDE; public: struct Line2D diff --git a/src/location/maps/qgeorouterequest.cpp b/src/location/maps/qgeorouterequest.cpp index 753d2ee9..a1b32d85 100644 --- a/src/location/maps/qgeorouterequest.cpp +++ b/src/location/maps/qgeorouterequest.cpp @@ -134,6 +134,8 @@ QT_BEGIN_NAMESPACE Consider parks when planning the route. \value MotorPoolLaneFeature Consider motor pool lanes when planning the route. + \value TrafficFeature + Consider the current traffic situation when planning the route. Since QtLocation 5.10 */ /*! diff --git a/src/location/maps/qgeorouterequest.h b/src/location/maps/qgeorouterequest.h index 6fcc7ad3..cf89d13d 100644 --- a/src/location/maps/qgeorouterequest.h +++ b/src/location/maps/qgeorouterequest.h @@ -70,7 +70,8 @@ public: TunnelFeature = 0x00000010, DirtRoadFeature = 0x00000020, ParksFeature = 0x00000040, - MotorPoolLaneFeature = 0x00000080 + MotorPoolLaneFeature = 0x00000080, + TrafficFeature = 0x00000100 }; Q_DECLARE_FLAGS(FeatureTypes, FeatureType) diff --git a/src/location/maps/qgeotilefetcher.cpp b/src/location/maps/qgeotilefetcher.cpp index 70ebbcd1..bab75034 100644 --- a/src/location/maps/qgeotilefetcher.cpp +++ b/src/location/maps/qgeotilefetcher.cpp @@ -126,7 +126,7 @@ void QGeoTileFetcher::requestNextTile() const QGeoCameraCapabilities & cameraCaps = d->engine_->cameraCapabilities(ts.mapId()); // the ZL in QGeoTileSpec is relative to the native tile size of the provider. // It gets denormalized in QGeoTiledMap. - if (ts.zoom() < cameraCaps.minimumZoomLevel() || ts.zoom() > cameraCaps.maximumZoomLevel()) + if (ts.zoom() < cameraCaps.minimumZoomLevel() || ts.zoom() > cameraCaps.maximumZoomLevel() || !fetchingEnabled()) return; QGeoTiledMapReply *reply = getTileImage(ts); @@ -189,6 +189,11 @@ bool QGeoTileFetcher::initialized() const return true; } +bool QGeoTileFetcher::fetchingEnabled() const +{ + return true; +} + void QGeoTileFetcher::handleReply(QGeoTiledMapReply *reply, const QGeoTileSpec &spec) { Q_D(QGeoTileFetcher); diff --git a/src/location/maps/qgeotilefetcher_p.h b/src/location/maps/qgeotilefetcher_p.h index d052a8a8..88880424 100644 --- a/src/location/maps/qgeotilefetcher_p.h +++ b/src/location/maps/qgeotilefetcher_p.h @@ -89,6 +89,7 @@ protected: void timerEvent(QTimerEvent *event); QAbstractGeoTileCache::CacheAreas cacheHint() const; virtual bool initialized() const; + virtual bool fetchingEnabled() const; private: |