summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@theqtcompany.com>2015-11-18 19:21:21 +0100
committerMichal Klocek <michal.klocek@theqtcompany.com>2015-12-07 11:11:37 +0000
commite70502b14a6b78067c18a4645570c077453c34ea (patch)
treee93850d0ee06cd1d1b220e123dea81f6eb630739
parent3faac8cc62a9101902baebbda348e7da9921cce4 (diff)
downloadqtlocation-e70502b14a6b78067c18a4645570c077453c34ea.tar.gz
Add clearData() call to map qml api
Add clearData call to clear texture, memory and disk cache. Update mapviewer example and add "prefetchData" and "clearData" to Tools menu. Task-number: QTBUG-47292 Change-Id: Ifc71a3652688d1403f5b011ef231b59381c17ee3 Reviewed-by: Harald Meyer <dev@meh.at> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r--examples/location/mapviewer/mapviewer.qml6
-rw-r--r--examples/location/mapviewer/menus/MainMenu.qml2
-rw-r--r--src/imports/location/qdeclarativegeomap.cpp12
-rw-r--r--src/imports/location/qdeclarativegeomap_p.h1
-rw-r--r--src/location/maps/qabstractgeotilecache_p.h1
-rw-r--r--src/location/maps/qgeofiletilecache.cpp13
-rw-r--r--src/location/maps/qgeofiletilecache_p.h1
-rw-r--r--src/location/maps/qgeomap.cpp5
-rw-r--r--src/location/maps/qgeomap_p.h2
-rw-r--r--src/location/maps/qgeotiledmap.cpp6
-rw-r--r--src/location/maps/qgeotiledmap_p.h1
11 files changed, 50 insertions, 0 deletions
diff --git a/examples/location/mapviewer/mapviewer.qml b/examples/location/mapviewer/mapviewer.qml
index bcc2c919..eca51485 100644
--- a/examples/location/mapviewer/mapviewer.qml
+++ b/examples/location/mapviewer/mapviewer.qml
@@ -221,6 +221,12 @@ ApplicationWindow {
stackView.currentItem.selectLanguage.connect(setLanguage)
stackView.currentItem.closeForm.connect(stackView.closeForm)
break
+ case "Clear":
+ map.clearData()
+ break
+ case "Prefetch":
+ map.prefetchData()
+ break
default:
console.log("Unsupported operation")
}
diff --git a/examples/location/mapviewer/menus/MainMenu.qml b/examples/location/mapviewer/menus/MainMenu.qml
index 3dc3e9fb..7054c40d 100644
--- a/examples/location/mapviewer/menus/MainMenu.qml
+++ b/examples/location/mapviewer/menus/MainMenu.qml
@@ -125,6 +125,8 @@ MenuBar {
item.triggered.connect(function() {toggleMapState("FollowMe")})
addItem(qsTr("Language")).triggered.connect(function(){selectTool("Language")})
+ addItem(qsTr("Prefetch Map Data")).triggered.connect(function(){selectTool("Prefetch")})
+ addItem(qsTr("Clear Map Data")).triggered.connect(function(){selectTool("Clear")})
}
}
}
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp
index d9981b69..80208a9b 100644
--- a/src/imports/location/qdeclarativegeomap.cpp
+++ b/src/imports/location/qdeclarativegeomap.cpp
@@ -908,6 +908,18 @@ void QDeclarativeGeoMap::prefetchData()
}
/*!
+ \qmlmethod void QtLocation::Map::clearData()
+
+ Clears map data collected by the currently selected plugin.
+ \note This method will delete cached files.
+ \sa plugin
+*/
+void QDeclarativeGeoMap::clearData()
+{
+ m_map->clearData();
+}
+
+/*!
\qmlproperty string QtLocation::Map::errorString
This read-only property holds the textual presentation of the latest mapping provider error.
diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h
index 22450ec1..fb36104a 100644
--- a/src/imports/location/qdeclarativegeomap_p.h
+++ b/src/imports/location/qdeclarativegeomap_p.h
@@ -127,6 +127,7 @@ public:
Q_INVOKABLE void fitViewportToMapItems();
Q_INVOKABLE void pan(int dx, int dy);
Q_INVOKABLE void prefetchData(); // optional hint for prefetch
+ Q_INVOKABLE void clearData();
QString errorString() const;
QGeoServiceProvider::Error error() const;
diff --git a/src/location/maps/qabstractgeotilecache_p.h b/src/location/maps/qabstractgeotilecache_p.h
index e368066f..141aa9b4 100644
--- a/src/location/maps/qabstractgeotilecache_p.h
+++ b/src/location/maps/qabstractgeotilecache_p.h
@@ -102,6 +102,7 @@ public:
virtual int maxTextureUsage() const = 0;
virtual int minTextureUsage() const = 0;
virtual int textureUsage() const = 0;
+ virtual void clearAll() = 0;
virtual QSharedPointer<QGeoTileTexture> get(const QGeoTileSpec &spec) = 0;
diff --git a/src/location/maps/qgeofiletilecache.cpp b/src/location/maps/qgeofiletilecache.cpp
index 6202f7fb..3d381dc2 100644
--- a/src/location/maps/qgeofiletilecache.cpp
+++ b/src/location/maps/qgeofiletilecache.cpp
@@ -261,6 +261,19 @@ int QGeoFileTileCache::textureUsage() const
return textureCache_.totalCost();
}
+void QGeoFileTileCache::clearAll()
+{
+ textureCache_.clear();
+ memoryCache_.clear();
+ diskCache_.clear();
+ QDir dir(directory_);
+ dir.setNameFilters(QStringList() << QLatin1String("*-*-*-*.*"));
+ dir.setFilter(QDir::Files);
+ foreach (QString dirFile, dir.entryList()) {
+ dir.remove(dirFile);
+ }
+}
+
QSharedPointer<QGeoTileTexture> QGeoFileTileCache::get(const QGeoTileSpec &spec)
{
QSharedPointer<QGeoTileTexture> tt = textureCache_.object(spec);
diff --git a/src/location/maps/qgeofiletilecache_p.h b/src/location/maps/qgeofiletilecache_p.h
index 8afb4c8d..bd3e684b 100644
--- a/src/location/maps/qgeofiletilecache_p.h
+++ b/src/location/maps/qgeofiletilecache_p.h
@@ -115,6 +115,7 @@ public:
int maxTextureUsage() const Q_DECL_OVERRIDE;
int minTextureUsage() const Q_DECL_OVERRIDE;
int textureUsage() const Q_DECL_OVERRIDE;
+ void clearAll() Q_DECL_OVERRIDE;
QSharedPointer<QGeoTileTexture> get(const QGeoTileSpec &spec) Q_DECL_OVERRIDE;
diff --git a/src/location/maps/qgeomap.cpp b/src/location/maps/qgeomap.cpp
index edc64839..c035f616 100644
--- a/src/location/maps/qgeomap.cpp
+++ b/src/location/maps/qgeomap.cpp
@@ -132,6 +132,11 @@ void QGeoMap::prefetchData()
}
+void QGeoMap::clearData()
+{
+
+}
+
QGeoMapPrivate::QGeoMapPrivate(QGeoMappingManagerEngine *engine)
: QObjectPrivate(),
m_width(0),
diff --git a/src/location/maps/qgeomap_p.h b/src/location/maps/qgeomap_p.h
index 58a020dc..acc928ea 100644
--- a/src/location/maps/qgeomap_p.h
+++ b/src/location/maps/qgeomap_p.h
@@ -84,9 +84,11 @@ public:
virtual QGeoCoordinate itemPositionToCoordinate(const QDoubleVector2D &pos, bool clipToViewport = true) const = 0;
virtual QDoubleVector2D coordinateToItemPosition(const QGeoCoordinate &coordinate, bool clipToViewport = true) const = 0;
virtual void prefetchData();
+ virtual void clearData();
QGeoCameraCapabilities cameraCapabilities();
+
protected:
QGeoMap(QGeoMapPrivate &dd, QObject *parent = 0);
void setCameraData(const QGeoCameraData &cameraData);
diff --git a/src/location/maps/qgeotiledmap.cpp b/src/location/maps/qgeotiledmap.cpp
index d561c011..97747049 100644
--- a/src/location/maps/qgeotiledmap.cpp
+++ b/src/location/maps/qgeotiledmap.cpp
@@ -103,6 +103,12 @@ void QGeoTiledMap::prefetchData()
d->prefetchTiles();
}
+void QGeoTiledMap::clearData()
+{
+ Q_D(QGeoTiledMap);
+ d->m_cache->clearAll();
+}
+
void QGeoTiledMap::handleTileVersionChanged()
{
Q_D(QGeoTiledMap);
diff --git a/src/location/maps/qgeotiledmap_p.h b/src/location/maps/qgeotiledmap_p.h
index 111056d2..87dac5d1 100644
--- a/src/location/maps/qgeotiledmap_p.h
+++ b/src/location/maps/qgeotiledmap_p.h
@@ -86,6 +86,7 @@ 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;
void prefetchData() Q_DECL_OVERRIDE;
+ void clearData() Q_DECL_OVERRIDE;
protected:
QSGNode *updateSceneGraph(QSGNode *, QQuickWindow *window) Q_DECL_OVERRIDE;