summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@theqtcompany.com>2016-03-01 19:35:00 +0100
committerMichal Klocek <michal.klocek@theqtcompany.com>2016-03-17 06:56:33 +0000
commite176f25daeb3d80af1fd701000fda065064227e1 (patch)
tree78c52d64b23eba8f5da1b9449edf70106350c942
parent3cf9f339f2a319d99e81feebb6f5f1e428eec51c (diff)
downloadqtlocation-e176f25daeb3d80af1fd701000fda065064227e1.tar.gz
Reduce setCameraData calls to minimum
Remove checks for cameraCapabilities during each setCameraData call. This checks are already performed on plugin initialization. Refactor QGeoMapPrivate to reduce resize calls. Rename updateRequired to sgNodeChanged to reflect real useage. Add setter setSize for QGeoMap. Change-Id: If4e3501fa99a8a97cbc471990837b08c43b8e723 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r--src/imports/location/qdeclarativegeomap.cpp12
-rw-r--r--src/location/maps/qgeomap.cpp64
-rw-r--r--src/location/maps/qgeomap_p.h9
-rw-r--r--src/location/maps/qgeomap_p_p.h10
-rw-r--r--src/location/maps/qgeotiledmap.cpp40
-rw-r--r--src/location/maps/qgeotiledmap_p_p.h5
-rw-r--r--tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp2
7 files changed, 53 insertions, 89 deletions
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp
index 2da6c3b9..b39f38c3 100644
--- a/src/imports/location/qdeclarativegeomap.cpp
+++ b/src/imports/location/qdeclarativegeomap.cpp
@@ -531,7 +531,7 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
// after this has been called at least once, after creation.
if (!m_initialized && width() > 0 && height() > 0) {
- m_map->resize(width(), height());
+ m_map->setSize(QSize(width(), height()));
initialize();
}
@@ -543,17 +543,13 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
connect(m_copyrights.data(), SIGNAL(linkActivated(QString)),
this, SIGNAL(copyrightLinkActivated(QString)));
- connect(m_map,
- SIGNAL(updateRequired()),
- this,
- SLOT(update()));
+ connect(m_map, &QGeoMap::sgNodeChanged, this, &QQuickItem::update);
// set visibility of copyright notice
m_copyrights->setCopyrightsVisible(m_copyrightsVisible);
// This prefetches a buffer around the map
m_map->prefetchData();
- m_map->update();
emit minimumZoomLevelChanged();
emit maximumZoomLevelChanged();
@@ -1247,15 +1243,13 @@ void QDeclarativeGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF
if (!m_map || !newGeometry.size().isValid())
return;
- m_map->resize(newGeometry.width(), newGeometry.height());
-
+ m_map->setSize(newGeometry.size().toSize());
if (!m_initialized)
initialize();
else
setMinimumZoomLevel(m_map->minimumZoomForMapSize(newGeometry.width(), newGeometry.height()));
-
/*!
The fitViewportTo*() functions depend on a valid map geometry.
If they were called prior to the first resize they cause
diff --git a/src/location/maps/qgeomap.cpp b/src/location/maps/qgeomap.cpp
index 7817553c..c3b01a3e 100644
--- a/src/location/maps/qgeomap.cpp
+++ b/src/location/maps/qgeomap.cpp
@@ -51,24 +51,31 @@ QGeoMap::~QGeoMap()
{
}
-void QGeoMap::resize(int width, int height)
+void QGeoMap::setSize(const QSize& size)
{
Q_D(QGeoMap);
- d->resize(width, height);
- // always emit this signal to trigger items to redraw
- emit cameraDataChanged(d->m_cameraData);
+ if (size == d->m_size)
+ return;
+ d->m_size = size;
+ d->changeMapSize(size);
+}
+
+QSize QGeoMap::size() const
+{
+ Q_D(const QGeoMap);
+ return d->m_size;
}
int QGeoMap::width() const
{
Q_D(const QGeoMap);
- return d->m_width;
+ return d->m_size.width();
}
int QGeoMap::height() const
{
Q_D(const QGeoMap);
- return d->m_height;
+ return d->m_size.height();
}
void QGeoMap::setCameraData(const QGeoCameraData &cameraData)
@@ -76,11 +83,8 @@ void QGeoMap::setCameraData(const QGeoCameraData &cameraData)
Q_D(QGeoMap);
if (cameraData == d->m_cameraData)
return;
-
- d->setCameraData(cameraData);
-
- update();
-
+ d->m_cameraData = cameraData;
+ d->changeCameraData(cameraData);
emit cameraDataChanged(d->m_cameraData);
}
@@ -90,19 +94,14 @@ QGeoCameraData QGeoMap::cameraData() const
return d->m_cameraData;
}
-void QGeoMap::update()
-{
- emit updateRequired();
-}
-
void QGeoMap::setActiveMapType(const QGeoMapType type)
{
Q_D(QGeoMap);
+ if (type == d->m_activeMapType)
+ return;
d->m_activeMapType = type;
d->changeActiveMapType(type);
- d->setCameraData(d->m_cameraData);
emit activeMapTypeChanged();
- update();
}
const QGeoMapType QGeoMap::activeMapType() const
@@ -133,9 +132,6 @@ void QGeoMap::clearData()
QGeoMapPrivate::QGeoMapPrivate(QGeoMappingManagerEngine *engine)
: QObjectPrivate(),
- m_width(0),
- m_height(0),
- m_aspectRatio(0.0),
m_engine(engine),
m_activeMapType(QGeoMapType())
{
@@ -143,32 +139,6 @@ QGeoMapPrivate::QGeoMapPrivate(QGeoMappingManagerEngine *engine)
QGeoMapPrivate::~QGeoMapPrivate()
{
- // controller_ is a child of map_, don't need to delete it here
-
- // TODO map items are not deallocated!
- // However: how to ensure this is done in rendering thread?
-}
-
-void QGeoMapPrivate::setCameraData(const QGeoCameraData &cameraData)
-{
- QGeoCameraData oldCameraData = m_cameraData;
- m_cameraData = cameraData;
-
- // 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
- // call changeCameraData four or more times
- if (m_width > 0)
- changeCameraData(oldCameraData);
-}
-
-void QGeoMapPrivate::resize(int width, int height)
-{
- m_width = width;
- m_height = height;
- m_aspectRatio = 1.0 * m_width / m_height;
- mapResized(width, height);
- setCameraData(m_cameraData);
}
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeomap_p.h b/src/location/maps/qgeomap_p.h
index e2af2eda..8f7642d4 100644
--- a/src/location/maps/qgeomap_p.h
+++ b/src/location/maps/qgeomap_p.h
@@ -70,10 +70,12 @@ class Q_LOCATION_EXPORT QGeoMap : public QObject
public:
virtual ~QGeoMap();
- void resize(int width, int height);
+ void setSize(const QSize& size);
+ QSize size() const;
int width() const;
int height() const;
+
QGeoCameraData cameraData() const;
QGeoCameraCapabilities cameraCapabilities() const;
@@ -92,12 +94,9 @@ protected:
void setCameraData(const QGeoCameraData &cameraData);
virtual QSGNode *updateSceneGraph(QSGNode *node, QQuickWindow *window) = 0;
-public Q_SLOTS:
- void update();
-
Q_SIGNALS:
void cameraDataChanged(const QGeoCameraData &cameraData);
- void updateRequired();
+ void sgNodeChanged();
void activeMapTypeChanged();
void copyrightsChanged(const QImage &copyrightsImage);
void copyrightsChanged(const QString &copyrightsHtml);
diff --git a/src/location/maps/qgeomap_p_p.h b/src/location/maps/qgeomap_p_p.h
index 3b996ecc..f09d55c2 100644
--- a/src/location/maps/qgeomap_p_p.h
+++ b/src/location/maps/qgeomap_p_p.h
@@ -50,6 +50,7 @@
#include "qgeocameradata_p.h"
#include "qgeomaptype_p.h"
#include <QtCore/private/qobject_p.h>
+#include <QtCore/QSize>
QT_BEGIN_NAMESPACE
@@ -65,18 +66,13 @@ public:
QGeoMapPrivate(QGeoMappingManagerEngine *engine);
virtual ~QGeoMapPrivate();
- void setCameraData(const QGeoCameraData &cameraData);
- void resize(int width, int height);
-
protected:
- virtual void mapResized(int width, int height) = 0;
+ virtual void changeMapSize(const QSize &size) = 0;
virtual void changeCameraData(const QGeoCameraData &oldCameraData) = 0;
virtual void changeActiveMapType(const QGeoMapType mapType) = 0;
protected:
- int m_width;
- int m_height;
- double m_aspectRatio;
+ QSize m_size;
QPointer<QGeoMappingManagerEngine> m_engine;
QGeoMapController *m_controller;
QGeoCameraData m_cameraData;
diff --git a/src/location/maps/qgeotiledmap.cpp b/src/location/maps/qgeotiledmap.cpp
index 13d01fc6..99af8ab5 100644
--- a/src/location/maps/qgeotiledmap.cpp
+++ b/src/location/maps/qgeotiledmap.cpp
@@ -185,7 +185,7 @@ double QGeoTiledMap::maximumLatitudeForZoom(double zoomLevel) const
mapEdgeSize *= d->m_visibleTiles->tileSize();
// At init time weird things happen
- int clampedWindowHeight = (d->m_height > mapEdgeSize) ? mapEdgeSize : d->m_height;
+ int clampedWindowHeight = (height() > mapEdgeSize) ? mapEdgeSize : 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 ;
@@ -279,27 +279,30 @@ void QGeoTiledMapPrivate::prefetchTiles()
}
}
-void QGeoTiledMapPrivate::changeCameraData(const QGeoCameraData &oldCameraData)
+void QGeoTiledMapPrivate::changeCameraData(const QGeoCameraData &cameraData)
{
- Q_UNUSED(oldCameraData) // TODO: taking care in following commit
+ Q_Q(QGeoTiledMap);
// 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
- int izl = static_cast<int>(std::floor(m_cameraData.zoomLevel()));
- float delta = m_cameraData.zoomLevel() - izl;
+ QGeoCameraData cam = cameraData;
+ int izl = static_cast<int>(std::floor(cam.zoomLevel()));
+ float delta = cam.zoomLevel() - izl;
+
if (delta > 0.5) {
izl++;
delta -= 1.0;
}
if (qAbs(delta) < 0.01) {
- m_cameraData.setZoomLevel(izl);
+ cam.setZoomLevel(izl);
}
- m_visibleTiles->setCameraData(m_cameraData);
- m_mapScene->setCameraData(m_cameraData);
+ m_visibleTiles->setCameraData(cam);
+ m_mapScene->setCameraData(cam);
updateScene();
+ q->sgNodeChanged();
}
void QGeoTiledMapPrivate::updateScene()
@@ -322,13 +325,14 @@ void QGeoTiledMapPrivate::updateScene()
}
if (!cachedTiles.isEmpty())
- q->update();
+ emit q->sgNodeChanged();
}
void QGeoTiledMapPrivate::changeActiveMapType(const QGeoMapType mapType)
{
m_visibleTiles->setMapType(mapType);
m_prefetchTiles->setMapType(mapType);
+ updateScene();
}
void QGeoTiledMapPrivate::changeTileVersion(int version)
@@ -338,18 +342,19 @@ void QGeoTiledMapPrivate::changeTileVersion(int version)
updateScene();
}
-void QGeoTiledMapPrivate::mapResized(int width, int height)
+void QGeoTiledMapPrivate::changeMapSize(const QSize& size)
{
Q_Q(QGeoTiledMap);
- m_mapScene->setScreenSize(QSize(width, height));
- m_visibleTiles->setScreenSize(QSize(width, height));
- m_prefetchTiles->setScreenSize(QSize(width, height));
+ m_visibleTiles->setScreenSize(size);
+ m_prefetchTiles->setScreenSize(size);
+ m_mapScene->setScreenSize(size);
- if (width > 0 && height > 0 && m_cache) {
+
+ if (!size.isEmpty() && m_cache) {
// absolute minimum size: one tile each side of display, 32-bit colour
- int texCacheSize = (width + m_visibleTiles->tileSize() * 2) *
- (height + m_visibleTiles->tileSize() * 2) * 4;
+ int texCacheSize = (size.width() + m_visibleTiles->tileSize() * 2) *
+ (size.height() + m_visibleTiles->tileSize() * 2) * 4;
// multiply by 3 so the 'recent' list in the cache is big enough for
// an entire display of tiles
@@ -361,6 +366,7 @@ void QGeoTiledMapPrivate::mapResized(int width, int height)
}
q->evaluateCopyrights(m_visibleTiles->createTiles());
+ updateScene();
}
void QGeoTiledMapPrivate::updateTile(const QGeoTileSpec &spec)
@@ -371,7 +377,7 @@ void QGeoTiledMapPrivate::updateTile(const QGeoTileSpec &spec)
QSharedPointer<QGeoTileTexture> tex = m_tileRequests->tileTexture(spec);
if (!tex.isNull()) {
m_mapScene->addTile(spec, tex);
- q->update();
+ emit q->sgNodeChanged();
}
}
}
diff --git a/src/location/maps/qgeotiledmap_p_p.h b/src/location/maps/qgeotiledmap_p_p.h
index d0c7b9d6..c1b190bf 100644
--- a/src/location/maps/qgeotiledmap_p_p.h
+++ b/src/location/maps/qgeotiledmap_p_p.h
@@ -74,7 +74,6 @@ public:
~QGeoTiledMapPrivate();
QSGNode *updateSceneGraph(QSGNode *node, QQuickWindow *window);
- void resized(int width, int height);
QGeoCoordinate itemPositionToCoordinate(const QDoubleVector2D &pos) const;
QDoubleVector2D coordinateToItemPosition(const QGeoCoordinate &coordinate) const;
@@ -83,8 +82,8 @@ public:
void prefetchTiles();
protected:
- void mapResized(int width, int height) Q_DECL_OVERRIDE;
- void changeCameraData(const QGeoCameraData &oldCameraData) Q_DECL_OVERRIDE;
+ void changeMapSize(const QSize& size) Q_DECL_OVERRIDE;
+ void changeCameraData(const QGeoCameraData &cameraData) Q_DECL_OVERRIDE;
void changeActiveMapType(const QGeoMapType mapType) Q_DECL_OVERRIDE;
void changeTileVersion(int version);
diff --git a/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp b/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp
index 7a75e52a..e7026cff 100644
--- a/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp
+++ b/tests/auto/qgeotiledmap/tst_qgeotiledmap.cpp
@@ -109,7 +109,7 @@ void tst_QGeoTiledMap::initTestCase()
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(16, 16);
+ m_map->setSize(QSize(16, 16));
m_fetcher = static_cast<QGeoTileFetcherTest*>(m_map->m_engine->tileFetcher());
m_tilesCounter.reset(new FetchTileCounter());
connect(m_fetcher, SIGNAL(tileFetched(const QGeoTileSpec&)), m_tilesCounter.data(), SLOT(tileFetched(const QGeoTileSpec&)));