diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-11-18 18:16:12 +0100 |
---|---|---|
committer | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-11-23 14:05:04 +0000 |
commit | 608c17acaf124a9f6b83316e03a40b8d01fef92e (patch) | |
tree | 18b6ae4f23189982f537532484f865028d7d93b9 | |
parent | 775dc837ecc5cd71a34cb8b87225a9196df7cff1 (diff) | |
download | qtlocation-608c17acaf124a9f6b83316e03a40b8d01fef92e.tar.gz |
Remove fitViewportToGeoShape from map qml api
Use visibleRegion to fit the map's viewport
[ChangeLog][Map] Remove fitViewportToGeoShape from map qml api
Change-Id: I378329602a5c1f4cceda327f7abcca61c1217564
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
-rw-r--r-- | src/imports/location/qdeclarativegeomap.cpp | 83 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeomap_p.h | 1 | ||||
-rw-r--r-- | src/location/doc/src/qtlocation-changes.qdoc | 12 | ||||
-rw-r--r-- | tests/auto/declarative_ui/tst_map_error.qml | 8 | ||||
-rw-r--r-- | tests/auto/declarative_ui/tst_map_item_fit_viewport.qml | 8 |
5 files changed, 11 insertions, 101 deletions
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index 117641ce..d401fe21 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -1176,89 +1176,6 @@ void QDeclarativeGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF } -// TODO Remove this function -> BC break -/*! - \qmlmethod void QtLocation::Map::fitViewportToGeoShape(QGeoShape shape) - - \internal - - Fits the current viewport to the boundary of the shape. The camera is positioned - in the center of the shape, and at the largest integral zoom level possible which - allows the whole shape to be visible on screen - -*/ -void QDeclarativeGeoMap::fitViewportToGeoShape(const QVariant &variantShape) -{ - if (!m_map || !m_mappingManagerInitialized) - return; - - QGeoShape shape; - - if (variantShape.userType() == qMetaTypeId<QGeoRectangle>()) - shape = variantShape.value<QGeoRectangle>(); - else if (variantShape.userType() == qMetaTypeId<QGeoCircle>()) - shape = variantShape.value<QGeoCircle>(); - else if (variantShape.userType() == qMetaTypeId<QGeoShape>()) - shape = variantShape.value<QGeoShape>(); - - if (!shape.isValid()) - return; - - double bboxWidth; - double bboxHeight; - QGeoCoordinate centerCoordinate; - - switch (shape.type()) { - case QGeoShape::RectangleType: - { - QGeoRectangle rect = shape; - QDoubleVector2D topLeftPoint = m_map->coordinateToItemPosition(rect.topLeft(), false); - QDoubleVector2D botRightPoint = m_map->coordinateToItemPosition(rect.bottomRight(), false); - bboxWidth = qAbs(topLeftPoint.x() - botRightPoint.x()); - bboxHeight = qAbs(topLeftPoint.y() - botRightPoint.y()); - centerCoordinate = rect.center(); - break; - } - case QGeoShape::CircleType: - { - QGeoCircle circle = shape; - centerCoordinate = circle.center(); - QGeoCoordinate edge = centerCoordinate.atDistanceAndAzimuth(circle.radius(), 90); - QDoubleVector2D centerPoint = m_map->coordinateToItemPosition(centerCoordinate, false); - QDoubleVector2D edgePoint = m_map->coordinateToItemPosition(edge, false); - bboxWidth = qAbs(centerPoint.x() - edgePoint.x()) * 2; - bboxHeight = bboxWidth; - break; - } - case QGeoShape::UnknownType: - //Fallthrough to default - default: - return; - } - - // position camera to the center of bounding box - setProperty("center", QVariant::fromValue(centerCoordinate)); - - //If the shape is empty we just change centerposition, not zoom - if (bboxHeight == 0 && bboxWidth == 0) - return; - - // adjust zoom - double bboxWidthRatio = bboxWidth / (bboxWidth + bboxHeight); - double mapWidthRatio = width() / (width() + height()); - double zoomRatio; - - if (bboxWidthRatio > mapWidthRatio) - zoomRatio = bboxWidth / width(); - else - zoomRatio = bboxHeight / height(); - - qreal newZoom = std::log10(zoomRatio) / std::log10(0.5); - - newZoom = std::floor(qMax(minimumZoomLevel(), (m_map->mapController()->zoom() + newZoom))); - setProperty("zoomLevel", QVariant::fromValue(newZoom)); -} - /*! \qmlmethod void QtLocation::Map::fitViewportToMapItems() diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h index acfdd4f5..22450ec1 100644 --- a/src/imports/location/qdeclarativegeomap_p.h +++ b/src/imports/location/qdeclarativegeomap_p.h @@ -124,7 +124,6 @@ public: QQuickGeoMapGestureArea *gesture(); - Q_INVOKABLE void fitViewportToGeoShape(const QVariant &shape); Q_INVOKABLE void fitViewportToMapItems(); Q_INVOKABLE void pan(int dx, int dy); Q_INVOKABLE void prefetchData(); // optional hint for prefetch diff --git a/src/location/doc/src/qtlocation-changes.qdoc b/src/location/doc/src/qtlocation-changes.qdoc index 0645c088..a901751b 100644 --- a/src/location/doc/src/qtlocation-changes.qdoc +++ b/src/location/doc/src/qtlocation-changes.qdoc @@ -33,12 +33,14 @@ \b{\l{QtLocation::Map}{Map} Component} \list \li removed wheelAngleChanged() signal - \li added \l[QML]{QtLocation::Map}{error} property - \li added \l[QML]{QtLocation::Map}{errorString} property - \li added \l[QML]{QtLocation::Map}{copyrightLinkActivated} signal + \li added \l[QML]{QtLocation::Map::}{error} property + \li added \l[QML]{QtLocation::Map::}{errorString} property + \li added \l[QML]{QtLocation::Map::}{copyrightLinkActivated} signal \li removed toScreenPosition() method - \li added \l[QML]{QtLocation::Map}{fromCoordinate}() method - \li replaced cameraStopped() method with \l[QML]{QtLocation::Map}{prefetchData}() method + \li added \l[QML]{QtLocation::Map::}{fromCoordinate}() method + \li replaced cameraStopped() method with \l[QML]{QtLocation::Map::}{prefetchData} method + \li replaced fitViewportToGeoShape() method with \l[QML]{QtLocation::Map::}{visibleRegion} property + \endlist \b{\l{QtLocation::MapGestureArea}{MapGestureArea} Component} diff --git a/tests/auto/declarative_ui/tst_map_error.qml b/tests/auto/declarative_ui/tst_map_error.qml index 68752f11..aaa58e6c 100644 --- a/tests/auto/declarative_ui/tst_map_error.qml +++ b/tests/auto/declarative_ui/tst_map_error.qml @@ -193,14 +193,6 @@ Item { map_no_plugin.fitViewportToMapItems() } - function test_map_fitViewportToGeoShape() - { - map_no_plugin.fitViewportToGeoShape(QtPositioning.circle(coordinate,1000)) - verify(map_no_plugin.center != coordinate) - map_error_plugin.fitViewportToGeoShape(QtPositioning.circle(coordinate,1000)) - verify(map_error_plugin.center != coordinate) - } - function test_map_setVisibleRegion() { map_no_plugin.visibleRegion = QtPositioning.circle(coordinate,1000) diff --git a/tests/auto/declarative_ui/tst_map_item_fit_viewport.qml b/tests/auto/declarative_ui/tst_map_item_fit_viewport.qml index 55fbd348..8671d05d 100644 --- a/tests/auto/declarative_ui/tst_map_item_fit_viewport.qml +++ b/tests/auto/declarative_ui/tst_map_item_fit_viewport.qml @@ -322,7 +322,7 @@ Item { verify(!is_coord_on_screen(fitRect.topLeft)) verify(!is_coord_on_screen(fitRect.bottomRight)) - map.fitViewportToGeoShape(fitRect) + map.visibleRegion = fitRect visualInspectionPoint() calculate_fit_circle_bounds() //Rectangle should be visible, not circle @@ -331,7 +331,7 @@ Item { verify(is_coord_on_screen(fitRect.topLeft)) verify(is_coord_on_screen(fitRect.bottomRight)) - map.fitViewportToGeoShape(fitCircle) + map.visibleRegion = fitCircle visualInspectionPoint() calculate_fit_circle_bounds() //Circle should be visible, not rectangle @@ -340,7 +340,7 @@ Item { verify(!is_coord_on_screen(fitRect.topLeft)) verify(!is_coord_on_screen(fitRect.bottomRight)) - map.fitViewportToGeoShape(fitInvalidShape) + map.visibleRegion = fitInvalidShape visualInspectionPoint() calculate_fit_circle_bounds() //Invalid shape, map should be in the same position as before @@ -349,7 +349,7 @@ Item { verify(!is_coord_on_screen(fitRect.topLeft)) verify(!is_coord_on_screen(fitRect.bottomRight)) - map.fitViewportToGeoShape(fitEmptyRect) + map.visibleRegion = fitEmptyRect visualInspectionPoint() calculate_fit_circle_bounds() //Empty shape, map should change centerlocation, empty rect visible |