Commit c1cdc0fe authored by Gus Grubba's avatar Gus Grubba

Do not cache map tiles if data persistence is disabled

parent a8d0bc33
...@@ -45,7 +45,7 @@ struct stQGeoTileCacheQGCMapTypes { ...@@ -45,7 +45,7 @@ struct stQGeoTileCacheQGCMapTypes {
//-- IMPORTANT //-- IMPORTANT
// Changes here must reflect those in QGeoTiledMappingManagerEngineQGC.cpp // Changes here must reflect those in QGeoTiledMappingManagerEngineQGC.cpp
stQGeoTileCacheQGCMapTypes kMapTypes[] = { static stQGeoTileCacheQGCMapTypes kMapTypes[] = {
#ifndef QGC_LIMITED_MAPS #ifndef QGC_LIMITED_MAPS
{"Google Street Map", UrlFactory::GoogleMap}, {"Google Street Map", UrlFactory::GoogleMap},
{"Google Satellite Map", UrlFactory::GoogleSatellite}, {"Google Satellite Map", UrlFactory::GoogleSatellite},
...@@ -69,7 +69,7 @@ stQGeoTileCacheQGCMapTypes kMapTypes[] = { ...@@ -69,7 +69,7 @@ stQGeoTileCacheQGCMapTypes kMapTypes[] = {
#define NUM_MAPS (sizeof(kMapTypes) / sizeof(stQGeoTileCacheQGCMapTypes)) #define NUM_MAPS (sizeof(kMapTypes) / sizeof(stQGeoTileCacheQGCMapTypes))
stQGeoTileCacheQGCMapTypes kMapboxTypes[] = { static stQGeoTileCacheQGCMapTypes kMapboxTypes[] = {
{"Mapbox Street Map", UrlFactory::MapboxStreets}, {"Mapbox Street Map", UrlFactory::MapboxStreets},
{"Mapbox Satellite Map", UrlFactory::MapboxSatellite}, {"Mapbox Satellite Map", UrlFactory::MapboxSatellite},
{"Mapbox High Contrast Map",UrlFactory::MapboxHighContrast}, {"Mapbox High Contrast Map",UrlFactory::MapboxHighContrast},
...@@ -88,7 +88,7 @@ stQGeoTileCacheQGCMapTypes kMapboxTypes[] = { ...@@ -88,7 +88,7 @@ stQGeoTileCacheQGCMapTypes kMapboxTypes[] = {
#define NUM_MAPBOXMAPS (sizeof(kMapboxTypes) / sizeof(stQGeoTileCacheQGCMapTypes)) #define NUM_MAPBOXMAPS (sizeof(kMapboxTypes) / sizeof(stQGeoTileCacheQGCMapTypes))
stQGeoTileCacheQGCMapTypes kEsriTypes[] = { static stQGeoTileCacheQGCMapTypes kEsriTypes[] = {
{"Esri Street Map", UrlFactory::EsriWorldStreet}, {"Esri Street Map", UrlFactory::EsriWorldStreet},
{"Esri Satellite Map", UrlFactory::EsriWorldSatellite}, {"Esri Satellite Map", UrlFactory::EsriWorldSatellite},
{"Esri Terrain Map", UrlFactory::EsriTerrain} {"Esri Terrain Map", UrlFactory::EsriTerrain}
...@@ -96,7 +96,7 @@ stQGeoTileCacheQGCMapTypes kEsriTypes[] = { ...@@ -96,7 +96,7 @@ stQGeoTileCacheQGCMapTypes kEsriTypes[] = {
#define NUM_ESRIMAPS (sizeof(kEsriTypes) / sizeof(stQGeoTileCacheQGCMapTypes)) #define NUM_ESRIMAPS (sizeof(kEsriTypes) / sizeof(stQGeoTileCacheQGCMapTypes))
stQGeoTileCacheQGCMapTypes kElevationTypes[] = { static stQGeoTileCacheQGCMapTypes kElevationTypes[] = {
{"Airmap Elevation Data", UrlFactory::AirmapElevation} {"Airmap Elevation Data", UrlFactory::AirmapElevation}
}; };
...@@ -107,7 +107,7 @@ static const char* kMaxMemCacheKey = "MaxMemoryCache"; ...@@ -107,7 +107,7 @@ static const char* kMaxMemCacheKey = "MaxMemoryCache";
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Singleton // Singleton
static QGCMapEngine* kMapEngine = NULL; static QGCMapEngine* kMapEngine = nullptr;
QGCMapEngine* QGCMapEngine*
getQGCMapEngine() getQGCMapEngine()
{ {
...@@ -125,7 +125,7 @@ destroyMapEngine() ...@@ -125,7 +125,7 @@ destroyMapEngine()
{ {
if(kMapEngine) { if(kMapEngine) {
delete kMapEngine; delete kMapEngine;
kMapEngine = NULL; kMapEngine = nullptr;
} }
} }
...@@ -275,15 +275,19 @@ QGCMapEngine::cacheTile(UrlFactory::MapType type, int x, int y, int z, const QBy ...@@ -275,15 +275,19 @@ QGCMapEngine::cacheTile(UrlFactory::MapType type, int x, int y, int z, const QBy
void void
QGCMapEngine::cacheTile(UrlFactory::MapType type, const QString& hash, const QByteArray& image, const QString& format, qulonglong set) QGCMapEngine::cacheTile(UrlFactory::MapType type, const QString& hash, const QByteArray& image, const QString& format, qulonglong set)
{ {
AppSettings* appSettings = qgcApp()->toolbox()->settingsManager()->appSettings();
//-- If we are allowed to persist data, save tile to cache
if(!appSettings->disableAllPersistence()->rawValue().toBool()) {
QGCSaveTileTask* task = new QGCSaveTileTask(new QGCCacheTile(hash, image, format, type, set)); QGCSaveTileTask* task = new QGCSaveTileTask(new QGCCacheTile(hash, image, format, type, set));
_worker.enqueueTask(task); _worker.enqueueTask(task);
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QString QString
QGCMapEngine::getTileHash(UrlFactory::MapType type, int x, int y, int z) QGCMapEngine::getTileHash(UrlFactory::MapType type, int x, int y, int z)
{ {
return QString().sprintf("%04d%08d%08d%03d", (int)type, x, y, z); return QString().sprintf("%04d%08d%08d%03d", static_cast<int>(type), x, y, z);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -291,7 +295,7 @@ UrlFactory::MapType ...@@ -291,7 +295,7 @@ UrlFactory::MapType
QGCMapEngine::hashToType(const QString& hash) QGCMapEngine::hashToType(const QString& hash)
{ {
QString type = hash.mid(0,4); QString type = hash.mid(0,4);
return (UrlFactory::MapType)type.toInt(); return static_cast<UrlFactory::MapType>(type.toInt());
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -321,7 +325,7 @@ QGCMapEngine::getTileCount(int zoom, double topleftLon, double topleftLat, doubl ...@@ -321,7 +325,7 @@ QGCMapEngine::getTileCount(int zoom, double topleftLon, double topleftLat, doubl
set.tileX1 = long2elevationTileX(bottomRightLon, zoom); set.tileX1 = long2elevationTileX(bottomRightLon, zoom);
set.tileY1 = lat2elevationTileY(topleftLat, zoom); set.tileY1 = lat2elevationTileY(topleftLat, zoom);
} }
set.tileCount = (quint64)((quint64)set.tileX1 - (quint64)set.tileX0 + 1) * (quint64)((quint64)set.tileY1 - (quint64)set.tileY0 + 1); set.tileCount = (static_cast<quint64>(set.tileX1) - static_cast<quint64>(set.tileX0) + 1) * (static_cast<quint64>(set.tileY1) - static_cast<quint64>(set.tileY0) + 1);
set.tileSize = UrlFactory::averageSizeForType(mapType) * set.tileCount; set.tileSize = UrlFactory::averageSizeForType(mapType) * set.tileCount;
return set; return set;
} }
...@@ -330,14 +334,14 @@ QGCMapEngine::getTileCount(int zoom, double topleftLon, double topleftLat, doubl ...@@ -330,14 +334,14 @@ QGCMapEngine::getTileCount(int zoom, double topleftLon, double topleftLat, doubl
int int
QGCMapEngine::long2tileX(double lon, int z) QGCMapEngine::long2tileX(double lon, int z)
{ {
return (int)(floor((lon + 180.0) / 360.0 * pow(2.0, z))); return static_cast<int>(floor((lon + 180.0) / 360.0 * pow(2.0, z)));
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int int
QGCMapEngine::lat2tileY(double lat, int z) QGCMapEngine::lat2tileY(double lat, int z)
{ {
return (int)(floor((1.0 - log( tan(lat * M_PI/180.0) + 1.0 / cos(lat * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, z))); return static_cast<int>(floor((1.0 - log( tan(lat * M_PI/180.0) + 1.0 / cos(lat * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, z)));
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -345,7 +349,7 @@ int ...@@ -345,7 +349,7 @@ int
QGCMapEngine::long2elevationTileX(double lon, int z) QGCMapEngine::long2elevationTileX(double lon, int z)
{ {
Q_UNUSED(z); Q_UNUSED(z);
return (int)(floor((lon + 180.0) / srtm1TileSize)); return static_cast<int>(floor((lon + 180.0) / srtm1TileSize));
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -353,7 +357,7 @@ int ...@@ -353,7 +357,7 @@ int
QGCMapEngine::lat2elevationTileY(double lat, int z) QGCMapEngine::lat2elevationTileY(double lat, int z)
{ {
Q_UNUSED(z); Q_UNUSED(z);
return (int)(floor((lat + 90.0) / srtm1TileSize)); return static_cast<int>(floor((lat + 90.0) / srtm1TileSize));
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -458,13 +462,13 @@ QGCMapEngine::bigSizeToString(quint64 size) ...@@ -458,13 +462,13 @@ QGCMapEngine::bigSizeToString(quint64 size)
if(size < 1024) if(size < 1024)
return kLocale.toString(size); return kLocale.toString(size);
else if(size < 1024 * 1024) else if(size < 1024 * 1024)
return kLocale.toString((double)size / 1024.0, 'f', 1) + "kB"; return kLocale.toString(static_cast<double>(size) / 1024.0, 'f', 1) + "kB";
else if(size < 1024 * 1024 * 1024) else if(size < 1024 * 1024 * 1024)
return kLocale.toString((double)size / (1024.0 * 1024.0), 'f', 1) + "MB"; return kLocale.toString(static_cast<double>(size) / (1024.0 * 1024.0), 'f', 1) + "MB";
else if(size < 1024.0 * 1024.0 * 1024.0 * 1024.0) else if(size < 1024.0 * 1024.0 * 1024.0 * 1024.0)
return kLocale.toString((double)size / (1024.0 * 1024.0 * 1024.0), 'f', 1) + "GB"; return kLocale.toString(static_cast<double>(size) / (1024.0 * 1024.0 * 1024.0), 'f', 1) + "GB";
else else
return kLocale.toString((double)size / (1024.0 * 1024.0 * 1024.0 * 1024), 'f', 1) + "TB"; return kLocale.toString(static_cast<double>(size) / (1024.0 * 1024.0 * 1024.0 * 1024), 'f', 1) + "TB";
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -479,7 +483,7 @@ void ...@@ -479,7 +483,7 @@ void
QGCMapEngine::_updateTotals(quint32 totaltiles, quint64 totalsize, quint32 defaulttiles, quint64 defaultsize) QGCMapEngine::_updateTotals(quint32 totaltiles, quint64 totalsize, quint32 defaulttiles, quint64 defaultsize)
{ {
emit updateTotals(totaltiles, totalsize, defaulttiles, defaultsize); emit updateTotals(totaltiles, totalsize, defaulttiles, defaultsize);
quint64 maxSize = (quint64)getMaxDiskCache() * 1024L * 1024L; quint64 maxSize = static_cast<quint64>(getMaxDiskCache()) * 1024L * 1024L;
if(!_prunning && defaultsize > maxSize) { if(!_prunning && defaultsize > maxSize) {
//-- Prune Disk Cache //-- Prune Disk Cache
_prunning = true; _prunning = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment