summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@theqtcompany.com>2016-03-01 16:24:40 +0100
committerMichal Klocek <michal.klocek@theqtcompany.com>2016-03-17 06:56:11 +0000
commitde165175549642c7fefa901d41ee96ef0702879c (patch)
treec89145289e0a7147870bef06bfb8755440837d10
parent3d8da84e368f87386f14287b10fb6d08e3ce2b48 (diff)
downloadqtlocation-de165175549642c7fefa901d41ee96ef0702879c.tar.gz
Remove QGeoMapController from QGeoMap
Refactor code to use QGeoCameraData directly. All functionality related to zoom, center boundary checks are now handled in QDeclaratvieGeoMap class. This makes handling of center and zoomLevel properties much simpler and less error prone, since camera data can not be modified along the call stack. As result we avoid forwarding change signals back and forth: * qgeodeclarativegeomap::setCenter -> qgeomapcontroller::setCenter * qgeomapcontroller::setCenter -> qgeomap::setCameraData * qgeomap::setCameraData -> qgeomacontroller::cameraDataChanged * qgeomapcontroller::cameraDataChanged -> emit qdecalartivegeomap::centerChanged Call always setCenter and setZoomLevel on qdeclarativegeomap instance instead. Introduce initialize() method to handle cases where map plugin is loaded and scenegraph geometery is not yet set. This is required to correctly handle new boundary checks to limit grey areas. Change-Id: I6066cefd4a648dc76333dc241d1f261451a32e9c Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r--src/imports/location/qdeclarativegeomap.cpp164
-rw-r--r--src/imports/location/qdeclarativegeomap_p.h7
-rw-r--r--src/imports/location/qquickgeomapgesturearea.cpp13
-rw-r--r--src/location/maps/maps.pri2
-rw-r--r--src/location/maps/qgeocameradata.cpp4
-rw-r--r--src/location/maps/qgeomap.cpp42
-rw-r--r--src/location/maps/qgeomap_p.h7
-rw-r--r--src/location/maps/qgeomap_p_p.h1
-rw-r--r--src/location/maps/qgeomapcontroller.cpp215
-rw-r--r--src/location/maps/qgeomapcontroller_p.h112
-rw-r--r--src/location/maps/qgeotiledmap.cpp106
-rw-r--r--src/location/maps/qgeotiledmap_p.h3
-rw-r--r--src/location/maps/qgeotiledmap_p_p.h3
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmap_nokia.cpp3
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/declarative_ui/tst_map.qml35
-rw-r--r--tests/auto/qgeomapcontroller/qgeomapcontroller.pro7
-rw-r--r--tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp369
-rw-r--r--tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp1
19 files changed, 183 insertions, 912 deletions
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp
index c9dfe189..2878d3b6 100644
--- a/src/imports/location/qdeclarativegeomap.cpp
+++ b/src/imports/location/qdeclarativegeomap.cpp
@@ -39,7 +39,6 @@
#include "qdeclarativegeomapcopyrightsnotice_p.h"
#include "qdeclarativegeoserviceprovider_p.h"
#include "qdeclarativegeomaptype_p.h"
-#include "qgeomapcontroller_p.h"
#include "qgeomappingmanager_p.h"
#include "qgeocameracapabilities_p.h"
#include "qgeomap_p.h"
@@ -173,17 +172,16 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent)
m_plugin(0),
m_serviceProvider(0),
m_mappingManager(0),
- m_center(51.5073,-0.1277), //London city center
m_activeMapType(0),
m_gestureArea(new QQuickGeoMapGestureArea(this)),
m_map(0),
m_error(QGeoServiceProvider::NoError),
- m_zoomLevel(8.0),
m_color(QColor::fromRgbF(0.9, 0.9, 0.9)),
m_componentCompleted(false),
m_mappingManagerInitialized(false),
m_pendingFitViewport(false),
- m_copyrightsVisible(true)
+ m_copyrightsVisible(true),
+ m_maximumViewportLatitude(0.0)
{
setAcceptHoverEvents(false);
setAcceptedMouseButtons(Qt::LeftButton);
@@ -195,6 +193,8 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent)
m_activeMapType = new QDeclarativeGeoMapType(QGeoMapType(QGeoMapType::NoMap,
tr("No Map"),
tr("No Map"), false, false, 0), this);
+ m_cameraData.setCenter(QGeoCoordinate(51.5073,-0.1277)); //London city center
+ m_cameraData.setZoomLevel(8.0);
}
QDeclarativeGeoMap::~QDeclarativeGeoMap()
@@ -275,6 +275,29 @@ void QDeclarativeGeoMap::setError(QGeoServiceProvider::Error error, const QStrin
emit errorChanged();
}
+void QDeclarativeGeoMap::initialize()
+{
+ // try to keep center change signal in the end
+ bool centerHasChanged = false;
+
+ setMinimumZoomLevel(m_map->minimumZoomForMapSize(width(), height()));
+
+ // set latitude bundary check
+ m_maximumViewportLatitude = m_map->maximumLatitudeForZoom(m_cameraData.zoomLevel());
+ QGeoCoordinate center = m_cameraData.center();
+ center.setLatitude(qBound(-m_maximumViewportLatitude, center.latitude(), m_maximumViewportLatitude));
+
+ if (center != m_cameraData.center()) {
+ centerHasChanged = true;
+ m_cameraData.setCenter(center);
+ }
+
+ m_map->setCameraData(m_cameraData);
+
+ if (centerHasChanged)
+ emit centerChanged(m_cameraData.center());
+}
+
/*!
\internal
*/
@@ -475,7 +498,6 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
m_map = m_mappingManager->createMap(this);
m_gestureArea->setMap(m_map);
- m_map->setActiveMapType(QGeoMapType());
QList<QGeoMapType> types = m_mappingManager->supportedMapTypes();
for (int i = 0; i < types.size(); ++i) {
QDeclarativeGeoMapType *type = new QDeclarativeGeoMapType(types[i], this);
@@ -486,16 +508,10 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
QDeclarativeGeoMapType *type = m_supportedMapTypes.at(0);
m_activeMapType = type;
m_map->setActiveMapType(type->mapType());
+ } else {
+ m_map->setActiveMapType(m_activeMapType->mapType());
}
- // Map tiles are built in this call. m_map->minimumZoom() becomes operational
- // after this has been called at least once, after creation.
- m_map->resize(width(), height());
-
- // once mappingManagerInitilized_ is set, zoomLevel() returns the default initialised
- // zoom level of the map (controller). Overwrite it here to whatever the user chose.
- m_map->mapController()->setZoom(m_zoomLevel);
-
//The zoom level limits are only restricted by the plugins values, if the user has set a more
//strict zoom level limit before initialization nothing is done here.
//minimum zoom level might be changed to limit gray bundaries
@@ -506,8 +522,14 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
|| m_mappingManager->cameraCapabilities().maximumZoomLevel() < m_gestureArea->maximumZoomLevel())
setMaximumZoomLevel(m_mappingManager->cameraCapabilities().maximumZoomLevel());
- // Finally, set the center too
- m_map->mapController()->setCenter(m_center);
+
+ // Map tiles are built in this call. m_map->minimumZoom() becomes operational
+ // after this has been called at least once, after creation.
+
+ if (width() > 0 && height() > 0) {
+ m_map->resize(width(), height());
+ initialize();
+ }
m_copyrights = new QDeclarativeGeoMapCopyrightNotice(this);
connect(m_map, SIGNAL(copyrightsChanged(QImage)),
@@ -521,15 +543,6 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
SIGNAL(updateRequired()),
this,
SLOT(update()));
- connect(m_map->mapController(),
- SIGNAL(centerChanged(QGeoCoordinate)),
- this,
- SIGNAL(centerChanged(QGeoCoordinate)));
- connect(m_map->mapController(),
- SIGNAL(zoomChanged(qreal)),
- this,
- SLOT(mapZoomLevelChanged(qreal)));
-
// set visibility of copyright notice
m_copyrights->setCopyrightsVisible(m_copyrightsVisible);
@@ -540,7 +553,6 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
emit minimumZoomLevelChanged();
emit maximumZoomLevelChanged();
- emit zoomLevelChanged(m_zoomLevel);
emit supportedMapTypesChanged();
emit activeMapTypeChanged();
@@ -569,11 +581,14 @@ QDeclarativeGeoServiceProvider *QDeclarativeGeoMap::plugin() const
*/
void QDeclarativeGeoMap::setMinimumZoomLevel(qreal minimumZoomLevel)
{
- if (m_gestureArea && minimumZoomLevel >= 0) {
+
+ if (minimumZoomLevel >= 0) {
qreal oldMinimumZoomLevel = this->minimumZoomLevel();
- if (m_mappingManagerInitialized) {
- minimumZoomLevel = qBound(m_map->minimumZoom(),minimumZoomLevel,m_mappingManager->cameraCapabilities().maximumZoomLevel());
- }
+ if (m_mappingManagerInitialized)
+ minimumZoomLevel = qBound(m_mappingManager->cameraCapabilities().minimumZoomLevel(), minimumZoomLevel, maximumZoomLevel());
+ double minimumViewportZoomLevel = m_map->minimumZoomForMapSize(width(),height());
+ if (minimumZoomLevel < minimumViewportZoomLevel)
+ minimumZoomLevel = minimumViewportZoomLevel;
m_gestureArea->setMinimumZoomLevel(minimumZoomLevel);
@@ -616,11 +631,10 @@ qreal QDeclarativeGeoMap::minimumZoomLevel() const
*/
void QDeclarativeGeoMap::setMaximumZoomLevel(qreal maximumZoomLevel)
{
- if (m_gestureArea && maximumZoomLevel >= 0) {
+ if (maximumZoomLevel >= 0) {
qreal oldMaximumZoomLevel = this->maximumZoomLevel();
- if (m_mappingManagerInitialized) {
- maximumZoomLevel = qBound(m_map->minimumZoom(),double(maximumZoomLevel),m_mappingManager->cameraCapabilities().maximumZoomLevel());
- }
+ if (m_mappingManagerInitialized)
+ maximumZoomLevel = qBound(minimumZoomLevel(), double(maximumZoomLevel), m_mappingManager->cameraCapabilities().maximumZoomLevel());
m_gestureArea->setMaximumZoomLevel(maximumZoomLevel);
@@ -661,24 +675,34 @@ qreal QDeclarativeGeoMap::maximumZoomLevel() const
*/
void QDeclarativeGeoMap::setZoomLevel(qreal zoomLevel)
{
- if (m_zoomLevel == zoomLevel || zoomLevel < 0)
+ if (m_cameraData.zoomLevel() == zoomLevel || zoomLevel < 0)
return;
+ //small optiomatization to avoid double setCameraData
+ bool centerHasChanged = false;
+
if (m_mappingManagerInitialized) {
- m_zoomLevel = qBound(minimumZoomLevel(), zoomLevel, maximumZoomLevel());
- m_map->mapController()->setZoom(m_zoomLevel);
+ m_cameraData.setZoomLevel(qBound(minimumZoomLevel(), zoomLevel, maximumZoomLevel()));
+ m_maximumViewportLatitude = m_map->maximumLatitudeForZoom(m_cameraData.zoomLevel());
+ QGeoCoordinate coord = m_cameraData.center();
+ coord.setLatitude(qBound(-m_maximumViewportLatitude, coord.latitude(), m_maximumViewportLatitude));
+ if (coord != m_cameraData.center()) {
+ centerHasChanged = true;
+ m_cameraData.setCenter(coord);
+ }
+ m_map->setCameraData(m_cameraData);
} else {
- m_zoomLevel = zoomLevel;
+ m_cameraData.setZoomLevel(zoomLevel);
}
- emit zoomLevelChanged(zoomLevel);
+
+ if (centerHasChanged)
+ emit centerChanged(m_cameraData.center());
+ emit zoomLevelChanged(m_cameraData.zoomLevel());
}
qreal QDeclarativeGeoMap::zoomLevel() const
{
- if (m_mappingManagerInitialized)
- return m_map->mapController()->zoom();
- else
- return m_zoomLevel;
+ return m_cameraData.zoomLevel();
}
/*!
@@ -691,28 +715,27 @@ qreal QDeclarativeGeoMap::zoomLevel() const
*/
void QDeclarativeGeoMap::setCenter(const QGeoCoordinate &center)
{
- if (!m_mappingManagerInitialized && center == m_center)
+ if (center == m_cameraData.center())
return;
if (!center.isValid())
return;
- m_center = center;
-
- if (m_center.isValid() && m_mappingManagerInitialized) {
- m_map->mapController()->setCenter(m_center);
- update();
+ if (m_mappingManagerInitialized) {
+ QGeoCoordinate coord(center);
+ coord.setLatitude(qBound(-m_maximumViewportLatitude, center.latitude(), m_maximumViewportLatitude));
+ m_cameraData.setCenter(coord);
+ m_map->setCameraData(m_cameraData);
} else {
- emit centerChanged(m_center);
+ m_cameraData.setCenter(center);
}
+
+ emit centerChanged(m_cameraData.center());
}
QGeoCoordinate QDeclarativeGeoMap::center() const
{
- if (m_mappingManagerInitialized)
- return m_map->mapController()->center();
- else
- return m_center;
+ return m_cameraData.center();
}
@@ -869,22 +892,11 @@ void QDeclarativeGeoMap::fitViewportToGeoShape()
qreal newZoom = std::log10(zoomRatio) / std::log10(0.5);
- newZoom = std::floor(qMax(minimumZoomLevel(), (m_map->mapController()->zoom() + newZoom)));
+ newZoom = std::floor(qMax(minimumZoomLevel(), (zoomLevel() + newZoom)));
setProperty("zoomLevel", QVariant::fromValue(newZoom));
}
/*!
- \internal
-*/
-void QDeclarativeGeoMap::mapZoomLevelChanged(qreal zoom)
-{
- if (zoom == m_zoomLevel)
- return;
- m_zoomLevel = zoom;
- emit zoomLevelChanged(m_zoomLevel);
-}
-
-/*!
\qmlproperty list<MapType> QtLocation::Map::supportedMapTypes
This read-only property holds the set of \l{MapType}{map types} supported by this map.
@@ -943,7 +955,12 @@ void QDeclarativeGeoMap::pan(int dx, int dy)
{
if (!m_mappingManagerInitialized)
return;
- m_map->mapController()->pan(dx, dy);
+ if (dx == 0 && dy == 0)
+ return;
+ QGeoCoordinate coord = m_map->itemPositionToCoordinate(
+ QDoubleVector2D(m_map->width() / 2 + dx,
+ m_map->height() / 2 + dy));
+ setCenter(coord);
}
@@ -1218,14 +1235,19 @@ QDeclarativeGeoMapType * QDeclarativeGeoMap::activeMapType() const
void QDeclarativeGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
m_gestureArea->setSize(newGeometry.size());
+ QQuickItem::geometryChanged(newGeometry, oldGeometry);
- if (!m_mappingManagerInitialized)
+ if (!m_mappingManagerInitialized || !newGeometry.size().isValid())
return;
m_map->resize(newGeometry.width(), newGeometry.height());
- //Them minimum allowed zoom level to limit gray bundaries might have changed
- setMinimumZoomLevel(m_map->minimumZoom());
- QQuickItem::geometryChanged(newGeometry, oldGeometry);
+
+
+ if (!oldGeometry.size().isValid()) // TBD: see following commit
+ initialize();
+ else
+ setMinimumZoomLevel(m_map->minimumZoomForMapSize(newGeometry.width(), newGeometry.height()));
+
/*!
The fitViewportTo*() functions depend on a valid map geometry.
@@ -1343,7 +1365,7 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine)
zoomRatio = bboxHeight / height();
qreal newZoom = std::log10(zoomRatio) / std::log10(0.5);
- newZoom = std::floor(qMax(minimumZoomLevel(), (m_map->mapController()->zoom() + newZoom)));
+ newZoom = std::floor(qMax(minimumZoomLevel(), (zoomLevel() + newZoom)));
setProperty("zoomLevel", QVariant::fromValue(newZoom));
// as map quick items retain the same screen size after the camera zooms in/out
diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h
index 06c39640..3db1aed2 100644
--- a/src/imports/location/qdeclarativegeomap_p.h
+++ b/src/imports/location/qdeclarativegeomap_p.h
@@ -168,10 +168,9 @@ protected:
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
void setError(QGeoServiceProvider::Error error, const QString &errorString);
-
+ void initialize();
private Q_SLOTS:
void mappingManagerInitialized();
- void mapZoomLevelChanged(qreal zoom);
void pluginReady();
void onMapChildrenChanged();
@@ -186,7 +185,6 @@ private:
QDeclarativeGeoServiceProvider *m_plugin;
QGeoServiceProvider *m_serviceProvider;
QGeoMappingManager *m_mappingManager;
- QGeoCoordinate m_center;
QDeclarativeGeoMapType *m_activeMapType;
QList<QDeclarativeGeoMapType *> m_supportedMapTypes;
QList<QDeclarativeGeoMapItemView *> m_mapViews;
@@ -197,13 +195,14 @@ private:
QMutex m_updateMutex;
QString m_errorString;
QGeoServiceProvider::Error m_error;
- qreal m_zoomLevel;
QGeoShape m_region;
QColor m_color;
+ QGeoCameraData m_cameraData;
bool m_componentCompleted;
bool m_mappingManagerInitialized;
bool m_pendingFitViewport;
bool m_copyrightsVisible;
+ double m_maximumViewportLatitude;
friend class QDeclarativeGeoMapItem;
friend class QDeclarativeGeoMapItemView;
diff --git a/src/imports/location/qquickgeomapgesturearea.cpp b/src/imports/location/qquickgeomapgesturearea.cpp
index 629c9658..1a3b3c16 100644
--- a/src/imports/location/qquickgeomapgesturearea.cpp
+++ b/src/imports/location/qquickgeomapgesturearea.cpp
@@ -36,7 +36,6 @@
#include "qquickgeomapgesturearea_p.h"
#include "qdeclarativegeomap_p.h"
-#include "qgeomapcontroller_p.h"
#include "error_messages.h"
#include <QtGui/QGuiApplication>
@@ -325,7 +324,7 @@ void QQuickGeoMapGestureArea::setMap(QGeoMap *map)
m_map = map;
m_flick.m_animation = new QQuickGeoCoordinateAnimation(this);
- m_flick.m_animation->setTargetObject(m_map->mapController());
+ m_flick.m_animation->setTargetObject(m_declarativeMap);
m_flick.m_animation->setProperty(QStringLiteral("center"));
m_flick.m_animation->setEasing(QEasingCurve(QEasingCurve::OutQuad));
connect(m_flick.m_animation, &QQuickAbstractAnimation::stopped, this, &QQuickGeoMapGestureArea::handleFlickAnimationStopped);
@@ -701,7 +700,7 @@ void QQuickGeoMapGestureArea::handleWheelEvent(QWheelEvent *event)
QPointF mapCenterPoint(m_map->width() / 2.0 + dx, m_map->height() / 2.0 + dy);
QGeoCoordinate mapCenterCoordinate = m_map->itemPositionToCoordinate(QDoubleVector2D(mapCenterPoint), false);
- m_map->mapController()->setCenter(mapCenterCoordinate);
+ m_declarativeMap->setCenter(mapCenterCoordinate);
}
event->accept();
}
@@ -1152,7 +1151,7 @@ void QQuickGeoMapGestureArea::updatePan()
mapCenterPoint.setY(m_map->height() / 2.0 - dy);
mapCenterPoint.setX(m_map->width() / 2.0 - dx);
QGeoCoordinate animationStartCoordinate = m_map->itemPositionToCoordinate(QDoubleVector2D(mapCenterPoint), false);
- m_map->mapController()->setCenter(animationStartCoordinate);
+ m_declarativeMap->setCenter(animationStartCoordinate);
}
/*!
@@ -1207,14 +1206,14 @@ void QQuickGeoMapGestureArea::startFlick(int dx, int dy, int timeMs)
if (timeMs < 0)
return;
- QGeoCoordinate animationStartCoordinate = m_map->mapController()->center();
+ QGeoCoordinate animationStartCoordinate = m_declarativeMap->center();
if (m_flick.m_animation->isRunning())
m_flick.m_animation->stop();
- QGeoCoordinate animationEndCoordinate = m_map->mapController()->center();
+ QGeoCoordinate animationEndCoordinate = m_declarativeMap->center();
m_flick.m_animation->setDuration(timeMs);
- double zoom = pow(2.0, m_map->mapController()->zoom());
+ double zoom = pow(2.0, m_declarativeMap->zoomLevel());
double longitude = animationStartCoordinate.longitude() - (dx / zoom);
double latitude = animationStartCoordinate.latitude() + (dy / zoom);
diff --git a/src/location/maps/maps.pri b/src/location/maps/maps.pri
index 69e6f62b..c8e28bab 100644
--- a/src/location/maps/maps.pri
+++ b/src/location/maps/maps.pri
@@ -25,7 +25,6 @@ PRIVATE_HEADERS += \
maps/qgeocodingmanagerengine_p.h \
maps/qgeocodingmanager_p.h \
maps/qgeomaneuver_p.h \
- maps/qgeomapcontroller_p.h \
maps/qgeotiledmapscene_p.h \
maps/qgeotilerequestmanager_p.h \
maps/qgeomap_p.h \
@@ -65,7 +64,6 @@ SOURCES += \
maps/qgeocodingmanager.cpp \
maps/qgeocodingmanagerengine.cpp \
maps/qgeomaneuver.cpp \
- maps/qgeomapcontroller.cpp \
maps/qgeotilerequestmanager.cpp \
maps/qgeomap.cpp \
maps/qgeomappingmanager.cpp \
diff --git a/src/location/maps/qgeocameradata.cpp b/src/location/maps/qgeocameradata.cpp
index a45d855a..23586082 100644
--- a/src/location/maps/qgeocameradata.cpp
+++ b/src/location/maps/qgeocameradata.cpp
@@ -59,11 +59,11 @@ public:
QGeoCameraDataPrivate::QGeoCameraDataPrivate()
: QSharedData(),
- m_center(-27.5, 153),
+ m_center(0, 0),
m_bearing(0.0),
m_tilt(0.0),
m_roll(0.0),
- m_zoomLevel(9.0) {}
+ m_zoomLevel(0.0) {}
QGeoCameraDataPrivate::QGeoCameraDataPrivate(const QGeoCameraDataPrivate &rhs)
: QSharedData(rhs),
diff --git a/src/location/maps/qgeomap.cpp b/src/location/maps/qgeomap.cpp
index 4cc2bbfe..7817553c 100644
--- a/src/location/maps/qgeomap.cpp
+++ b/src/location/maps/qgeomap.cpp
@@ -37,8 +37,8 @@
#include "qgeomap_p.h"
#include "qgeomap_p_p.h"
#include "qgeocameracapabilities_p.h"
-#include "qgeomapcontroller_p.h"
#include "qgeomappingmanagerengine_p.h"
+#include <QDebug>
QT_BEGIN_NAMESPACE
@@ -51,14 +51,6 @@ QGeoMap::~QGeoMap()
{
}
-QGeoMapController *QGeoMap::mapController()
-{
- Q_D(QGeoMap);
- if (!d->m_controller)
- d->m_controller = new QGeoMapController(this);
- return d->m_controller;
-}
-
void QGeoMap::resize(int width, int height)
{
Q_D(QGeoMap);
@@ -119,11 +111,6 @@ const QGeoMapType QGeoMap::activeMapType() const
return d->m_activeMapType;
}
-double QGeoMap::minimumZoom() const
-{
- Q_D(const QGeoMap);
- return d->m_minimumZoom;
-}
QGeoCameraCapabilities QGeoMap::cameraCapabilities() const
{
@@ -149,9 +136,7 @@ QGeoMapPrivate::QGeoMapPrivate(QGeoMappingManagerEngine *engine)
m_width(0),
m_height(0),
m_aspectRatio(0.0),
- m_minimumZoom(0.0),
m_engine(engine),
- m_controller(0),
m_activeMapType(QGeoMapType())
{
}
@@ -169,31 +154,6 @@ void QGeoMapPrivate::setCameraData(const QGeoCameraData &cameraData)
QGeoCameraData oldCameraData = m_cameraData;
m_cameraData = cameraData;
- if (!m_engine.isNull()) {
- QGeoCameraCapabilities capabilities = m_engine->cameraCapabilities();
- if (m_cameraData.zoomLevel() < capabilities.minimumZoomLevel())
- m_cameraData.setZoomLevel(capabilities.minimumZoomLevel());
-
- if (m_cameraData.zoomLevel() > capabilities.maximumZoomLevel())
- m_cameraData.setZoomLevel(capabilities.maximumZoomLevel());
-
- if (!capabilities.supportsBearing())
- m_cameraData.setBearing(0.0);
-
- if (capabilities.supportsTilting()) {
- if (m_cameraData.tilt() < capabilities.minimumTilt())
- m_cameraData.setTilt(capabilities.minimumTilt());
-
- if (m_cameraData.tilt() > capabilities.maximumTilt())
- m_cameraData.setTilt(capabilities.maximumTilt());
- } else {
- m_cameraData.setTilt(0.0);
- }
-
- if (!capabilities.supportsRolling())
- m_cameraData.setRoll(0.0);
- }
-
// Do not call this expensive function if the width is 0, since it will get called
// anyway when it is resized to a width > 0.
// this is mainly an optimization to the initialization of the geomap, which would otherwise
diff --git a/src/location/maps/qgeomap_p.h b/src/location/maps/qgeomap_p.h
index 7747347f..e2af2eda 100644
--- a/src/location/maps/qgeomap_p.h
+++ b/src/location/maps/qgeomap_p.h
@@ -70,23 +70,22 @@ class Q_LOCATION_EXPORT QGeoMap : public QObject
public:
virtual ~QGeoMap();
- QGeoMapController *mapController();
-
void resize(int width, int height);
int width() const;
int height() const;
QGeoCameraData cameraData() const;
+ QGeoCameraCapabilities cameraCapabilities() const;
void setActiveMapType(const QGeoMapType mapType);
const QGeoMapType activeMapType() const;
virtual QGeoCoordinate itemPositionToCoordinate(const QDoubleVector2D &pos, bool clipToViewport = true) const = 0;
virtual QDoubleVector2D coordinateToItemPosition(const QGeoCoordinate &coordinate, bool clipToViewport = true) const = 0;
- double minimumZoom() const;
+ virtual double minimumZoomForMapSize(int width, int height) const = 0;
+ virtual double maximumLatitudeForZoom(double zoomLevel) const = 0;
virtual void prefetchData();
virtual void clearData();
- QGeoCameraCapabilities cameraCapabilities() const;
protected:
QGeoMap(QGeoMapPrivate &dd, QObject *parent = 0);
diff --git a/src/location/maps/qgeomap_p_p.h b/src/location/maps/qgeomap_p_p.h
index 1d1c9a13..3b996ecc 100644
--- a/src/location/maps/qgeomap_p_p.h
+++ b/src/location/maps/qgeomap_p_p.h
@@ -77,7 +77,6 @@ protected:
int m_width;
int m_height;
double m_aspectRatio;
- double m_minimumZoom;
QPointer<QGeoMappingManagerEngine> m_engine;
QGeoMapController *m_controller;
QGeoCameraData m_cameraData;
diff --git a/src/location/maps/qgeomapcontroller.cpp b/src/location/maps/qgeomapcontroller.cpp
deleted file mode 100644
index 661839fe..00000000
--- a/src/location/maps/qgeomapcontroller.cpp
+++ /dev/null
@@ -1,215 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgeomapcontroller_p.h"
-
-#include "qgeomap_p.h"
-#include <QtPositioning/private/qgeoprojection_p.h>
-
-#include <QPointF>
-
-QT_BEGIN_NAMESPACE
-
-QGeoMapController::QGeoMapController(QGeoMap *map)
- : QObject(map),
- map_(map)
-{
- oldCameraData_ = map_->cameraData();
-
- connect(map_,
- SIGNAL(cameraDataChanged(QGeoCameraData)),
- this,
- SLOT(cameraDataChanged(QGeoCameraData)));
-}
-
-QGeoMapController::~QGeoMapController() {}
-
-void QGeoMapController::cameraDataChanged(const QGeoCameraData &cameraData)
-{
- if (oldCameraData_.center() != cameraData.center())
- emit centerChanged(cameraData.center());
-
- if (oldCameraData_.bearing() != cameraData.bearing())
- emit bearingChanged(cameraData.bearing());
-
- if (oldCameraData_.tilt() != cameraData.tilt())
- emit tiltChanged(cameraData.tilt());
-
- if (oldCameraData_.roll() != cameraData.roll())
- emit rollChanged(cameraData.roll());
-
- if (oldCameraData_.zoomLevel() != cameraData.zoomLevel())
- emit zoomChanged(cameraData.zoomLevel());
-
- oldCameraData_ = cameraData;
-}
-
-QGeoCoordinate QGeoMapController::center() const
-{
- return map_->cameraData().center();
-}
-
-void QGeoMapController::setCenter(const QGeoCoordinate &center)
-{
- QGeoCameraData cd = map_->cameraData();
-
- if (center == cd.center())
- return;
-
- cd.setCenter(center);
- map_->setCameraData(cd);
-}
-
-void QGeoMapController::setLatitude(qreal latitude)
-{
- QGeoCameraData cd = map_->cameraData();
-
- if (latitude == cd.center().latitude())
- return;
-
- QGeoCoordinate coord(latitude, cd.center().longitude(), cd.center().altitude());
- cd.setCenter(coord);
- map_->setCameraData(cd);
-}
-
-void QGeoMapController::setLongitude(qreal longitude)
-{
- QGeoCameraData cd = map_->cameraData();
-
- if (longitude == cd.center().longitude())
- return;
-
- QGeoCoordinate coord(cd.center().latitude(), longitude, cd.center().altitude());
- cd.setCenter(coord);
- map_->setCameraData(cd);
-}
-
-
-void QGeoMapController::setAltitude(qreal altitude)
-{
- QGeoCameraData cd = map_->cameraData();
-
- if (altitude == cd.center().altitude())
- return;
-
- QGeoCoordinate coord(cd.center().latitude(), cd.center().longitude(), altitude);
- cd.setCenter(coord);
- map_->setCameraData(cd);
-}
-
-qreal QGeoMapController::bearing() const
-{
- return map_->cameraData().bearing();
-}
-
-void QGeoMapController::setBearing(qreal bearing)
-{
- QGeoCameraData cd = map_->cameraData();
-
- if (bearing == cd.bearing())
- return;
-
- cd.setBearing(bearing);
- map_->setCameraData(cd);
-}
-
-qreal QGeoMapController::tilt() const
-{
- return map_->cameraData().tilt();
-}
-
-void QGeoMapController::setTilt(qreal tilt)
-{
- QGeoCameraData cd = map_->cameraData();
-
- if (tilt == cd.tilt())
- return;
-
- cd.setTilt(tilt);
- map_->setCameraData(cd);
-}
-
-qreal QGeoMapController::roll() const
-{
- return map_->cameraData().roll();
-}
-
-void QGeoMapController::setRoll(qreal roll)
-{
- QGeoCameraData cd = map_->cameraData();
-
- if (roll == cd.roll())
- return;
-
- cd.setRoll(roll);
- map_->setCameraData(cd);
-}
-
-qreal QGeoMapController::zoom() const
-{
- return map_->cameraData().zoomLevel();
-}
-
-void QGeoMapController::setZoom(qreal zoom)
-{
- QGeoCameraData cd = map_->cameraData();
-
- if (zoom == cd.zoomLevel())
- return;
-
- cd.setZoomLevel(zoom);
- map_->setCameraData(cd);
-}
-
-void QGeoMapController::pan(qreal dx, qreal dy)
-{
- if (dx == 0 && dy == 0)
- return;
- QGeoCameraData cd = map_->cameraData();
- QGeoCoordinate coord = map_->itemPositionToCoordinate(
- QDoubleVector2D(map_->width() / 2 + dx,
- map_->height() / 2 + dy));
-
-
- // keep altitude as it was
- coord.setAltitude(cd.center().altitude());
- if (coord.isValid()) {
- cd.setCenter(coord);
- map_->setCameraData(cd);
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/location/maps/qgeomapcontroller_p.h b/src/location/maps/qgeomapcontroller_p.h
deleted file mode 100644
index 06f2b926..00000000
--- a/src/location/maps/qgeomapcontroller_p.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef QGEOMAPCONTROLLER_P_H
-#define QGEOMAPCONTROLLER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QObject>
-
-#include "qgeocoordinate.h"
-#include "qgeocameradata_p.h"
-
-QT_BEGIN_NAMESPACE
-
-class QGeoMap;
-
-
-class Q_LOCATION_EXPORT QGeoMapController : public QObject
-{
- Q_OBJECT
-
- Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged)
- Q_PROPERTY(qreal bearing READ bearing WRITE setBearing NOTIFY bearingChanged)
- Q_PROPERTY(qreal tilt READ tilt WRITE setTilt NOTIFY tiltChanged)
- Q_PROPERTY(qreal roll READ roll WRITE setRoll NOTIFY rollChanged)
- Q_PROPERTY(qreal zoom READ zoom WRITE setZoom NOTIFY zoomChanged)
-
-public:
- QGeoMapController(QGeoMap *map);
- ~QGeoMapController();
-
- QGeoCoordinate center() const;
- void setCenter(const QGeoCoordinate &center);
-
- void setLatitude(qreal latitude);
- void setLongitude(qreal longitude);
- void setAltitude(qreal altitude);
-
- qreal bearing() const;
- void setBearing(qreal bearing);
-
- qreal tilt() const;
- void setTilt(qreal tilt);
-
- qreal roll() const;
- void setRoll(qreal roll);
-
- qreal zoom() const;
- void setZoom(qreal zoom);
-
- void pan(qreal dx, qreal dy);
-
-private Q_SLOTS:
- void cameraDataChanged(const QGeoCameraData &cameraData);
-
-Q_SIGNALS:
- void centerChanged(const QGeoCoordinate &center);
- void bearingChanged(qreal bearing);
- void tiltChanged(qreal tilt);
- void rollChanged(qreal roll);
- void zoomChanged(qreal zoom);
-
-private:
- QGeoMap *map_;
- QGeoCameraData oldCameraData_;
-};
-
-QT_END_NAMESPACE
-
-#endif // QGEOMAPCONTROLLER_P_H
diff --git a/src/location/maps/qgeotiledmap.cpp b/src/location/maps/qgeotiledmap.cpp
index 3705bfca..13d01fc6 100644
--- a/src/location/maps/qgeotiledmap.cpp
+++ b/src/location/maps/qgeotiledmap.cpp
@@ -103,19 +103,6 @@ QSGNode *QGeoTiledMap::updateSceneGraph(QSGNode *oldNode, QQuickWindow *window)
return d->updateSceneGraph(oldNode, window);
}
-// This method returns the minimum zoom level that this specific qgeomap type allows
-// at a given canvas size (width,height) and for a given tile size (usually 256).
-double QGeoTiledMap::minimumZoomLevel(int width, int height, int tileSize) const
-{
- double maxSize = qMax(width,height);
- double numTiles = maxSize / tileSize;
- double minZoom = std::log(numTiles) / std::log(2.0);
- const QGeoCameraCapabilities capa = cameraCapabilities();
- if (capa.isValid())
- minZoom = qMax(minZoom, capa.minimumZoomLevel());
- return minZoom;
-}
-
void QGeoTiledMap::prefetchData()
{
Q_D(QGeoTiledMap);
@@ -175,6 +162,38 @@ QDoubleVector2D QGeoTiledMap::coordinateToItemPosition(const QGeoCoordinate &coo
return pos;
}
+// This method returns the minimum zoom level that this specific qgeomap type allows
+// at a given canvas size (width,height) and for a given tile size (usually 256).
+double QGeoTiledMap::minimumZoomForMapSize(int width, int height) const
+{
+ Q_D(const QGeoTiledMap);
+ double maxSize = qMax(width,height);
+ double numTiles = maxSize / d->m_visibleTiles->tileSize();
+ return std::log(numTiles) / std::log(2.0);
+}
+
+// This method recalculates the "no-trespassing" limits for the map center.
+// This has to be done when:
+// 1) the map is resized, because the meters per pixel remain the same, but
+// the amount of pixels between the center and the borders changes
+// 2) when the zoom level changes, because the amount of pixels between the center
+// and the borders stays the same, but the meters per pixel change
+double QGeoTiledMap::maximumLatitudeForZoom(double zoomLevel) const
+{
+ Q_D(const QGeoTiledMap);
+ double mapEdgeSize = std::pow(2.0,zoomLevel);
+ mapEdgeSize *= d->m_visibleTiles->tileSize();
+
+ // At init time weird things happen
+ int clampedWindowHeight = (d->m_height > mapEdgeSize) ? mapEdgeSize : d->m_height;
+
+ // Use the window height divided by 2 as the topmost allowed center, with respect to the map size in pixels
+ double mercatorTopmost = (clampedWindowHeight * 0.5) / mapEdgeSize ;
+ QGeoCoordinate topMost = QGeoProjection::mercatorToCoord(QDoubleVector2D(0.0,mercatorTopmost));
+
+ return topMost.latitude();
+}
+
QGeoTiledMapPrivate::QGeoTiledMapPrivate(QGeoTiledMappingManagerEngine *engine)
: QGeoMapPrivate(engine),
m_cache(engine->tileCache()),
@@ -184,8 +203,7 @@ QGeoTiledMapPrivate::QGeoTiledMapPrivate(QGeoTiledMappingManagerEngine *engine)
m_tileRequests(0),
m_maxZoomLevel(static_cast<int>(std::ceil(engine->cameraCapabilities().maximumZoomLevel()))),
m_minZoomLevel(static_cast<int>(std::ceil(engine->cameraCapabilities().minimumZoomLevel()))),
- m_prefetchStyle(QGeoTiledMap::PrefetchTwoNeighbourLayers),
- m_centerLatitudinalBound(0.0)
+ m_prefetchStyle(QGeoTiledMap::PrefetchTwoNeighbourLayers)
{
int tileSize = engine->tileSize().width();
QString pluginString(engine->managerName() + QLatin1Char('_') + QString::number(engine->managerVersion()));
@@ -208,7 +226,6 @@ QGeoTiledMapPrivate::~QGeoTiledMapPrivate()
// However: how to ensure this is done in rendering thread?
}
-
void QGeoTiledMapPrivate::prefetchTiles()
{
if (m_tileRequests) {
@@ -264,6 +281,8 @@ void QGeoTiledMapPrivate::prefetchTiles()
void QGeoTiledMapPrivate::changeCameraData(const QGeoCameraData &oldCameraData)
{
+ Q_UNUSED(oldCameraData) // TODO: taking care in following commit
+
// For zoomlevel, "snap" 0.01 either side of a whole number.
// This is so that when we turn off bilinear scaling, we're
// snapped to the exact pixel size of the tiles
@@ -277,24 +296,6 @@ void QGeoTiledMapPrivate::changeCameraData(const QGeoCameraData &oldCameraData)
m_cameraData.setZoomLevel(izl);
}
- double oldZoomLevel = oldCameraData.zoomLevel();
- if (m_cameraData.zoomLevel() != oldZoomLevel) {
- // Zoom level changed: recompute latitudinal border for the center
- updateCenterLatitudinalBound(m_visibleTiles->tileSize(),m_cameraData.zoomLevel());
- }
-
- QGeoCoordinate coord = m_cameraData.center();
- if (coord.isValid()) {
- double lat = coord.latitude();
- if (m_mapScene->verticalLock())
- lat = oldCameraData.center().latitude();
-
- // Clamp center latitude to prevent gray borders
- lat = qBound(-m_centerLatitudinalBound, lat, m_centerLatitudinalBound);
- coord.setLatitude(lat);
- }
- m_cameraData.setCenter(coord);
-
m_visibleTiles->setCameraData(m_cameraData);
m_mapScene->setCameraData(m_cameraData);
@@ -324,27 +325,6 @@ void QGeoTiledMapPrivate::updateScene()
q->update();
}
-// This method recalculates the "no-trespassing" limits for the map center.
-// This has to be done when:
-// 1) the map is resized, because the meters per pixel remain the same, but
-// the amount of pixels between the center and the borders changes
-// 2) when the zoom level changes, because the amount of pixels between the center
-// and the borders stays the same, but the meters per pixel change
-void QGeoTiledMapPrivate::updateCenterLatitudinalBound(int tileSize, double zoomLevel)
-{
- double mapEdgeSize = std::pow(2.0,zoomLevel);
- mapEdgeSize *= tileSize;
-
- // At init time weird things happen
- int clampedWindowHeight = (m_height > mapEdgeSize) ? mapEdgeSize : m_height;
-
- // Use the window height divided by 2 as the topmost allowed center, with respect to the map size in pixels
- double mercatorTopmost = (clampedWindowHeight * 0.5) / mapEdgeSize ;
- QGeoCoordinate topMost = QGeoProjection::mercatorToCoord(QDoubleVector2D(0.0,mercatorTopmost));
-
- m_centerLatitudinalBound = topMost.latitude();
-}
-
void QGeoTiledMapPrivate::changeActiveMapType(const QGeoMapType mapType)
{
m_visibleTiles->setMapType(mapType);
@@ -365,21 +345,6 @@ void QGeoTiledMapPrivate::mapResized(int width, int height)
m_mapScene->setScreenSize(QSize(width, height));
m_visibleTiles->setScreenSize(QSize(width, height));
m_prefetchTiles->setScreenSize(QSize(width, height));
- // Keep the following step order:
- // 1) Update the minimum zoom level
- m_minimumZoom = q->minimumZoomLevel(width, height, m_visibleTiles->tileSize());
-
- // 2) clamp the current zoom level in the camera data, which will have to be
- // propagated in the QDeclarativeGeoMap
- QGeoCameraData camData = q->cameraData();
- double zoomLevel = camData.zoomLevel();
- zoomLevel = qMax(m_minimumZoom,zoomLevel); // The correct zoom level. Will be set later
-
- // 3) Since the map size changed, recompute latitudinal bound for the center.
- // This is re-done, despite being already in changeCameraData, because
- // changeCameraData triggers it only on zoomLevel changed, which might not
- // be the case.
- updateCenterLatitudinalBound(m_visibleTiles->tileSize(), zoomLevel);
if (width > 0 && height > 0 && m_cache) {
// absolute minimum size: one tile each side of display, 32-bit colour
@@ -394,6 +359,7 @@ void QGeoTiledMapPrivate::mapResized(int width, int height)
int newSize = qMax(m_cache->minTextureUsage(), texCacheSize);
m_cache->setMinTextureUsage(newSize);
}
+
q->evaluateCopyrights(m_visibleTiles->createTiles());
}
diff --git a/src/location/maps/qgeotiledmap_p.h b/src/location/maps/qgeotiledmap_p.h
index 051264ff..6c735e86 100644
--- a/src/location/maps/qgeotiledmap_p.h
+++ b/src/location/maps/qgeotiledmap_p.h
@@ -86,13 +86,14 @@ public:
QGeoCoordinate itemPositionToCoordinate(const QDoubleVector2D &pos, bool clipToViewport = true) const Q_DECL_OVERRIDE;
QDoubleVector2D coordinateToItemPosition(const QGeoCoordinate &coordinate, bool clipToViewport = true) const Q_DECL_OVERRIDE;
+ double minimumZoomForMapSize(int width, int height) const Q_DECL_OVERRIDE;
+ double maximumLatitudeForZoom(double zoomLevel) const Q_DECL_OVERRIDE;
void prefetchData() Q_DECL_OVERRIDE;
void clearData() Q_DECL_OVERRIDE;
protected:
QSGNode *updateSceneGraph(QSGNode *, QQuickWindow *window) Q_DECL_OVERRIDE;
virtual void evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles);
- double minimumZoomLevel(int width, int height, int tileSize) const;
private Q_SLOTS:
void handleTileVersionChanged();
diff --git a/src/location/maps/qgeotiledmap_p_p.h b/src/location/maps/qgeotiledmap_p_p.h
index 6a7ceec9..d0c7b9d6 100644
--- a/src/location/maps/qgeotiledmap_p_p.h
+++ b/src/location/maps/qgeotiledmap_p_p.h
@@ -90,7 +90,6 @@ protected:
private:
void updateScene();
- void updateCenterLatitudinalBound(int tileSize, double zoomLevel);
private:
QAbstractGeoTileCache *m_cache;
@@ -101,7 +100,7 @@ private:
int m_maxZoomLevel;
int m_minZoomLevel;
QGeoTiledMap::PrefetchStyle m_prefetchStyle;
- double m_centerLatitudinalBound;
+ bool m_geomoteryUpdated;
Q_DISABLE_COPY(QGeoTiledMapPrivate)
};
diff --git a/src/plugins/geoservices/nokia/qgeotiledmap_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmap_nokia.cpp
index 98777d09..d83ad0f9 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmap_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotiledmap_nokia.cpp
@@ -36,7 +36,6 @@
#include "qgeotiledmap_nokia.h"
#include "qgeotiledmappingmanagerengine_nokia.h"
-#include "qgeomapcontroller_p.h"
#include <QDebug>
#include <QObject>
@@ -71,7 +70,7 @@ void QGeoTiledMapNokia::evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTile
if (m_engine.isNull())
return;
- const QString copyrightsString = m_engine->evaluateCopyrightsText(activeMapType(), mapController()->zoom(), visibleTiles);
+ const QString copyrightsString = m_engine->evaluateCopyrightsText(activeMapType(), cameraData().zoomLevel(), visibleTiles);
if (width() > 0 && height() > 0 && ((copyrightsString.isNull() && m_copyrightsSlab.isNull()) || copyrightsString != m_lastCopyrightsString)) {
QFont font("Sans Serif");
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 81013b2c..e3236deb 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -53,7 +53,6 @@ qtHaveModule(location) {
qgeotiledmap \
qgeotilespec \
qgeoroutexmlparser \
- qgeomapcontroller \
maptype \
nokia_services \
qgeocameratiles
diff --git a/tests/auto/declarative_ui/tst_map.qml b/tests/auto/declarative_ui/tst_map.qml
index c6620635..5f02962d 100644
--- a/tests/auto/declarative_ui/tst_map.qml
+++ b/tests/auto/declarative_ui/tst_map.qml
@@ -128,6 +128,41 @@ Item {
compare(map.center.latitude, 12)
}
+ function test_map_clamp()
+ {
+ //valid
+ map.center = QtPositioning.coordinate(10.0, 20.5, 30.8)
+ map.zoomLevel = 2.0
+
+ compare(map.center.latitude, 10)
+ compare(map.center.longitude, 20.5)
+ compare(map.center.altitude, 30.8)
+
+ //negative values
+ map.center = QtPositioning.coordinate(-50, -20, 100)
+ map.zoomLevel = 1.0
+
+ compare(map.center.latitude, -50)
+ compare(map.center.longitude, -20)
+ compare(map.center.altitude, 100)
+
+ //clamped center negative
+ map.center = QtPositioning.coordinate(-89, -45, 0)
+ map.zoomLevel = 1.0
+
+ fuzzyCompare(map.center.latitude, -80.8728, 0.001)
+ compare(map.center.longitude, -45)
+ compare(map.center.altitude, 0)
+
+ //clamped center positive
+ map.center = QtPositioning.coordinate(86, 38, 0)
+ map.zoomLevel = 1.0
+
+ fuzzyCompare(map.center.latitude, 80.8728, 0.001)
+ compare(map.center.longitude, 38)
+ compare(map.center.altitude, 0)
+ }
+
function test_zoom_limits()
{
map.center.latitude = 30
diff --git a/tests/auto/qgeomapcontroller/qgeomapcontroller.pro b/tests/auto/qgeomapcontroller/qgeomapcontroller.pro
deleted file mode 100644
index 545d41f5..00000000
--- a/tests/auto/qgeomapcontroller/qgeomapcontroller.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-TEMPLATE = app
-CONFIG += testcase
-TARGET = tst_qgeomapcontroller
-
-SOURCES += tst_qgeomapcontroller.cpp
-
-QT += location-private positioning-private testlib
diff --git a/tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp b/tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp
deleted file mode 100644
index a5650e42..00000000
--- a/tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp
+++ /dev/null
@@ -1,369 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/QString>
-#include <QtTest/QtTest>
-#include <QtTest/QSignalSpy>
-#include <QtLocation/QGeoServiceProvider>
-#include <QtLocation/private/qgeotiledmap_p.h>
-#include <QtLocation/private/qgeomappingmanager_p.h>
-#include <QtLocation/private/qgeomapcontroller_p.h>
-#include <QtLocation/private/qgeocameracapabilities_p.h>
-#include <cmath> /* for std::abs(double) */
-
-QT_USE_NAMESPACE
-
-class QGeoTiledMapTest: public QGeoTiledMap
-{
- Q_OBJECT
-public:
- QGeoTiledMapTest(QGeoTiledMappingManagerEngine *engine, QObject *parent = 0)
- : QGeoTiledMap(engine, parent) {}
-public:
- using QGeoTiledMap::setCameraData;
-};
-
-class tst_QGeoMapController : public QObject
-{
- Q_OBJECT
-
-public:
- tst_QGeoMapController();
- ~tst_QGeoMapController();
-
-private:
- void clearSignalSpies();
-
-private Q_SLOTS:
- void initTestCase();
- void signalsConstructedTest();
- void constructorTest_data();
- void constructorTest();
- void centerTest();
- void bearingTest();
- void tiltTest();
- void rollTest();
- void panTest();
- void zoomTest();
-
-private:
- QScopedPointer<QGeoTiledMapTest> m_map;
- QScopedPointer<QSignalSpy> m_signalCenterChanged;
- QScopedPointer<QSignalSpy> m_signalBearingChanged;
- QScopedPointer<QSignalSpy> m_signalTiltChanged;
- QScopedPointer<QSignalSpy> m_signalRollChanged;
- QScopedPointer<QSignalSpy> m_signalZoomChanged;
-};
-
-tst_QGeoMapController::tst_QGeoMapController()
-{
-}
-
-tst_QGeoMapController::~tst_QGeoMapController()
-{
-}
-
-void tst_QGeoMapController::initTestCase()
-{
- // Set custom path since CI doesn't install test plugins
-#ifdef Q_OS_WIN
- QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() +
- QStringLiteral("/../../../../plugins"));
-#else
- QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() +
- QStringLiteral("/../../../plugins"));
-#endif
- QGeoServiceProvider *provider = new QGeoServiceProvider("qmlgeo.test.plugin");
- provider->setAllowExperimental(true);
- QGeoMappingManager *mappingManager = provider->mappingManager();
- QVERIFY2(provider->error() == QGeoServiceProvider::NoError, "Could not load plugin: " + provider->errorString().toLatin1());
-
- m_map.reset(static_cast<QGeoTiledMapTest*>(mappingManager->createMap(this)));
- QVERIFY(m_map);
- m_map->resize(100, 100);
-
- m_signalCenterChanged.reset(new QSignalSpy(m_map->mapController(), &QGeoMapController::centerChanged));
- m_signalBearingChanged.reset(new QSignalSpy(m_map->mapController(), &QGeoMapController::bearingChanged));
- m_signalTiltChanged.reset(new QSignalSpy(m_map->mapController(), &QGeoMapController::tiltChanged));
- m_signalRollChanged.reset(new QSignalSpy(m_map->mapController(), &QGeoMapController::rollChanged));
- m_signalZoomChanged.reset(new QSignalSpy(m_map->mapController(), &QGeoMapController::zoomChanged));
-}
-
-void tst_QGeoMapController::clearSignalSpies()
-{
- m_signalCenterChanged->clear();
- m_signalBearingChanged->clear();
- m_signalTiltChanged->clear();
- m_signalRollChanged->clear();
- m_signalZoomChanged->clear();
-}
-
-void tst_QGeoMapController::signalsConstructedTest()
-{
- QVERIFY(m_signalCenterChanged->isValid());
- QVERIFY(m_signalBearingChanged->isValid());
- QVERIFY(m_signalTiltChanged->isValid());
- QVERIFY(m_signalRollChanged->isValid());
- QVERIFY(m_signalZoomChanged->isValid());
-}
-
-void tst_QGeoMapController::constructorTest_data()
-{
- QTest::addColumn<QGeoCoordinate>("center");
- QTest::addColumn<QGeoCoordinate>("expectedCenter");
- QTest::addColumn<double>("bearing");
- QTest::addColumn<double>("tilt");
- QTest::addColumn<double>("roll");
- QTest::addColumn<double>("zoom");
- QTest::newRow("zeros") << QGeoCoordinate() << QGeoCoordinate() << 0.0 << 0.0 << 0.0 << 0.0;
- QTest::newRow("valid") << QGeoCoordinate(10.0, 20.5, 30.8) << QGeoCoordinate(10.0, 20.5, 30.8) << 0.1 << 0.2 << 0.3 << 2.0;
- QTest::newRow("negative values") << QGeoCoordinate(-50, -20, 100) << QGeoCoordinate(-50, -20, 100) << -0.1 << -0.2 << -0.3 << 1.0;
- QTest::newRow("clamped center negative") << QGeoCoordinate(-89, -45, 0) << QGeoCoordinate(-80.8728, -45, 0) << -0.1 << -0.2 << -0.3 << 1.0;
- QTest::newRow("clamped center positive") << QGeoCoordinate(86, 38, 0) << QGeoCoordinate(80.8728, 38, 0) << -0.1 << -0.2 << -0.3 << 1.0;
-}
-
-bool almostEqual(float x, float y) // qFuzzyCompare is too strict for this test
-{
- const float epsilon = 1e-5;
- return std::abs(x - y) <= epsilon * std::abs(x);
- // see Knuth section 4.2.2 pages 217-218
-}
-
-void tst_QGeoMapController::constructorTest()
-{
- QFETCH(QGeoCoordinate, center);
- QFETCH(QGeoCoordinate, expectedCenter);
- QFETCH(double, bearing);
- QFETCH(double, tilt);
- QFETCH(double, roll);
- QFETCH(double, zoom);
-
- // test whether the map controller picks up the camera data
- // from the map during construction
- QGeoCameraData cameraData;
- cameraData.setCenter(center);
- cameraData.setBearing(bearing);
- cameraData.setTilt(tilt);
- cameraData.setRoll(roll);
- cameraData.setZoomLevel(zoom);
- m_map->setCameraData(cameraData);
- QGeoMapController mapController(m_map.data());
-
-
- // make sure the values come out the same
- // also make sure the values match what they were actually set to
- if (qIsNaN(cameraData.center().longitude())) {
- QVERIFY(qIsNaN(mapController.center().longitude()));
- } else {
- QCOMPARE(mapController.center().longitude(), expectedCenter.longitude());
- }
- if (qIsNaN(cameraData.center().altitude())) {
- QVERIFY(qIsNaN(mapController.center().altitude()));
- } else {
- QCOMPARE(mapController.center().altitude(), expectedCenter.altitude());
- }
-
- // Verify that the latitude is either what was set or that it has been clamped correctly
- if (qIsNaN(cameraData.center().latitude())) {
- QVERIFY(qIsNaN(mapController.center().latitude()));
- } else {
- QVERIFY(almostEqual(mapController.center().latitude(), expectedCenter.latitude()));
- }
-
- QCOMPARE(mapController.zoom(), cameraData.zoomLevel());
- QCOMPARE(mapController.zoom(), zoom);
-
- if (m_map->cameraCapabilities().supportsBearing()){
- QCOMPARE(mapController.bearing(), cameraData.bearing());
- QCOMPARE(mapController.bearing(), bearing);
- }
- if (m_map->cameraCapabilities().supportsTilting()){
- QCOMPARE(mapController.tilt(), cameraData.tilt());
- QCOMPARE(mapController.tilt(), tilt);
- }
- if (m_map->cameraCapabilities().supportsRolling()){
- QCOMPARE(mapController.roll(), cameraData.roll());
- QCOMPARE(mapController.roll(), roll);
- }
-}
-
-void tst_QGeoMapController::centerTest()
-{
- QGeoCameraData cameraData;
- cameraData.setCenter(QGeoCoordinate(10.0,-20.4,30.8));
- m_map->setCameraData(cameraData);
- QGeoMapController mapController(m_map.data());
- QCOMPARE(mapController.center(),QGeoCoordinate(10.0,-20.4,30.8));
-
- QGeoCoordinate coord(10.0,20.4,30.8);
- clearSignalSpies();
- mapController.setCenter(coord);
-
- // check correct signal is triggered
- QCOMPARE(m_signalCenterChanged->count(),1);
- QCOMPARE(m_signalBearingChanged->count(),0);
- QCOMPARE(m_signalTiltChanged->count(),0);
- QCOMPARE(m_signalRollChanged->count(),0);
- QCOMPARE(m_signalZoomChanged->count(),0);
-
- QCOMPARE(mapController.center(),QGeoCoordinate(10.0,20.4,30.8));
-
- mapController.setCenter(QGeoCoordinate(10.0,20.4,30.9));
- QCOMPARE(mapController.center(),QGeoCoordinate(10.0,20.4,30.9));
-}
-
-void tst_QGeoMapController::bearingTest()
-{
- if (m_map->cameraCapabilities().supportsBearing()){
- qreal bearing = 1.4;
-
- QGeoCameraData cameraData;
- cameraData.setBearing(bearing);
- m_map->setCameraData(cameraData);
- QGeoMapController mapController(m_map.data());
- QCOMPARE(mapController.bearing(),bearing);
-
- clearSignalSpies();
- mapController.setBearing(-1.5);
- QCOMPARE(mapController.bearing(),-1.5);
-
- // check correct signal is triggered
- QCOMPARE(m_signalCenterChanged->count(),0);
- QCOMPARE(m_signalBearingChanged->count(),1);
- QCOMPARE(m_signalTiltChanged->count(),0);
- QCOMPARE(m_signalRollChanged->count(),0);
- QCOMPARE(m_signalZoomChanged->count(),0);
- }
-}
-
-void tst_QGeoMapController::tiltTest()
-{
- if (m_map->cameraCapabilities().supportsTilting()){
- qreal tilt = m_map->cameraCapabilities().maximumTilt();
-
- QGeoCameraData cameraData;
- cameraData.setTilt(tilt);
- m_map->setCameraData(cameraData);
- QGeoMapController mapController(m_map.data());
- QCOMPARE(mapController.tilt(),tilt);
-
- tilt = m_map->cameraCapabilities().minimumTilt();
- clearSignalSpies();
- mapController.setTilt(tilt);
- QCOMPARE(mapController.tilt(),tilt);
-
- // check correct signal is triggered
- QCOMPARE(m_signalCenterChanged->count(),0);
- QCOMPARE(m_signalBearingChanged->count(),0);
- QCOMPARE(m_signalTiltChanged->count(),1);
- QCOMPARE(m_signalRollChanged->count(),0);
- QCOMPARE(m_signalZoomChanged->count(),0);
- }
-}
-
-void tst_QGeoMapController::rollTest()
-{
- if (m_map->cameraCapabilities().supportsRolling()){
- qreal roll = 1.4;
-
- QGeoCameraData cameraData;
- cameraData.setRoll(roll);
- m_map->setCameraData(cameraData);
- QGeoMapController mapController(m_map.data());
- QCOMPARE(mapController.roll(),roll);
-
- clearSignalSpies();
- mapController.setRoll(-1.5);
- QCOMPARE(mapController.roll(),-1.5);
-
- // check correct signal is triggered
- QCOMPARE(m_signalCenterChanged->count(),0);
- QCOMPARE(m_signalBearingChanged->count(),0);
- QCOMPARE(m_signalTiltChanged->count(),0);
- QCOMPARE(m_signalRollChanged->count(),1);
- QCOMPARE(m_signalZoomChanged->count(),0);
- }
-}
-
-void tst_QGeoMapController::panTest()
-{
- QGeoMapController mapController(m_map.data());
-
- mapController.setCenter(QGeoCoordinate(-1.0,-2.4,3.8));
-
- // check that pan of zero leaves the camera centre unaltered
- mapController.pan(0, 0);
- QCOMPARE(mapController.center().altitude(), 3.8);
- QCOMPARE(mapController.center().latitude(), -1.0);
- QCOMPARE(mapController.center().longitude(), -2.4);
-
- qreal dx = 13.1;
- qreal dy = -9.3;
- clearSignalSpies();
- mapController.pan(dx, dy);
-
- // rather than verify the exact new position, we check that the position has changed and the altitude
- // is unaffected
- QCOMPARE(mapController.center().altitude(), 3.8);
- QVERIFY(qFuzzyCompare(mapController.center().latitude(), -1.0) == false);
- QVERIFY(qFuzzyCompare(mapController.center().longitude(), -2.4) == false);
-
- // check correct signal is triggered
- QCOMPARE(m_signalCenterChanged->count(),1);
- QCOMPARE(m_signalBearingChanged->count(),0);
- QCOMPARE(m_signalTiltChanged->count(),0);
- QCOMPARE(m_signalRollChanged->count(),0);
- QCOMPARE(m_signalZoomChanged->count(),0);
-}
-
-void tst_QGeoMapController::zoomTest()
-{
- QGeoCameraData cameraData;
- cameraData.setZoomLevel(1.4);
- m_map->setCameraData(cameraData);
- QGeoMapController mapController(m_map.data());
-
- QCOMPARE(mapController.zoom(),1.4);
- mapController.setZoom(1.4);
- QCOMPARE(mapController.zoom(),1.4);
- clearSignalSpies();
- mapController.setZoom(1.5);
- QCOMPARE(mapController.zoom(),1.5);
-
- // check correct signal is triggered
- QCOMPARE(m_signalCenterChanged->count(),0);
- QCOMPARE(m_signalBearingChanged->count(),0);
- QCOMPARE(m_signalTiltChanged->count(),0);
- QCOMPARE(m_signalRollChanged->count(),0);
- QCOMPARE(m_signalZoomChanged->count(),1);
-}
-
-
-QTEST_MAIN(tst_QGeoMapController)
-
-#include "tst_qgeomapcontroller.moc"
diff --git a/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp b/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp
index a8f053e9..7a75e52a 100644
--- a/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp
+++ b/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp
@@ -40,7 +40,6 @@
#include <QtLocation/QGeoServiceProvider>
#include <QtLocation/private/qgeotiledmap_p.h>
#include <QtLocation/private/qgeomappingmanager_p.h>
-#include <QtLocation/private/qgeomapcontroller_p.h>
#include <QtLocation/private/qgeocameracapabilities_p.h>
QT_USE_NAMESPACE