Commit a681941a authored by dogmaphobic's avatar dogmaphobic

Fixes to Offline Map Cache

parent 6920c117
...@@ -20,7 +20,8 @@ Rectangle ...@@ -20,7 +20,8 @@ Rectangle
property bool checked: false property bool checked: false
property bool complete: false property bool complete: false
property alias text: nameLabel.text property alias text: nameLabel.text
property alias size: sizeLabel.text property int tiles: 0
property string size: ""
signal clicked() signal clicked()
...@@ -40,6 +41,7 @@ Rectangle ...@@ -40,6 +41,7 @@ Rectangle
horizontalAlignment: Text.AlignRight horizontalAlignment: Text.AlignRight
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
color: __showHighlight ? __qgcPal.buttonHighlightText : __qgcPal.buttonText color: __showHighlight ? __qgcPal.buttonHighlightText : __qgcPal.buttonText
text: __mapButton.size + (tiles > 0 ? " (" + tiles + " tiles)" : "")
} }
Item { Item {
width: ScreenTools.defaultFontPixelWidth * 2 width: ScreenTools.defaultFontPixelWidth * 2
......
...@@ -32,7 +32,7 @@ Q_DECLARE_METATYPE(QList<QGCTile*>) ...@@ -32,7 +32,7 @@ Q_DECLARE_METATYPE(QList<QGCTile*>)
static const char* kDbFileName = "qgcMapCache.db"; static const char* kDbFileName = "qgcMapCache.db";
static QLocale kLocale; static QLocale kLocale;
#define CACHE_PATH_VERSION "100" #define CACHE_PATH_VERSION "300"
struct stQGeoTileCacheQGCMapTypes { struct stQGeoTileCacheQGCMapTypes {
const char* name; const char* name;
...@@ -144,15 +144,29 @@ QGCMapEngine::~QGCMapEngine() ...@@ -144,15 +144,29 @@ QGCMapEngine::~QGCMapEngine()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
QGCMapEngine::init() QGCMapEngine::_wipeOldCaches()
{ {
//-- Delete old style cache (if present) QString oldCacheDir;
#ifdef __mobile__
oldCacheDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QLatin1String("/QGCMapCache55");
#else
oldCacheDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/QGCMapCache55");
#endif
_wipeDirectory(oldCacheDir);
#ifdef __mobile__ #ifdef __mobile__
QString oldCacheDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QLatin1String("/QGCMapCache55"); oldCacheDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QLatin1String("/QGCMapCache100");
#else #else
QString oldCacheDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/QGCMapCache55"); oldCacheDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/QGCMapCache100");
#endif #endif
_wipeDirectory(oldCacheDir); _wipeDirectory(oldCacheDir);
}
//-----------------------------------------------------------------------------
void
QGCMapEngine::init()
{
//-- Delete old style caches (if present)
_wipeOldCaches();
//-- Figure out cache path //-- Figure out cache path
#ifdef __mobile__ #ifdef __mobile__
QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QLatin1String("/QGCMapCache" CACHE_PATH_VERSION); QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QLatin1String("/QGCMapCache" CACHE_PATH_VERSION);
...@@ -398,7 +412,7 @@ QGCMapEngine::bigSizeToString(quint64 size) ...@@ -398,7 +412,7 @@ QGCMapEngine::bigSizeToString(quint64 size)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QString QString
QGCMapEngine::numberToString(quint32 number) QGCMapEngine::numberToString(quint64 number)
{ {
return kLocale.toString(number); return kLocale.toString(number);
} }
...@@ -408,7 +422,7 @@ void ...@@ -408,7 +422,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 = getMaxDiskCache() * 1024 * 1024; quint64 maxSize = (quint64)getMaxDiskCache() * 1024L * 1024L;
if(!_prunning && defaultsize > maxSize) { if(!_prunning && defaultsize > maxSize) {
//-- Prune Disk Cache //-- Prune Disk Cache
_prunning = true; _prunning = true;
......
...@@ -96,7 +96,7 @@ public: ...@@ -96,7 +96,7 @@ public:
static QString getTileHash (UrlFactory::MapType type, int x, int y, int z); static QString getTileHash (UrlFactory::MapType type, int x, int y, int z);
static UrlFactory::MapType getTypeFromName (const QString &name); static UrlFactory::MapType getTypeFromName (const QString &name);
static QString bigSizeToString (quint64 size); static QString bigSizeToString (quint64 size);
static QString numberToString (quint32 number); static QString numberToString (quint64 number);
static int concurrentDownloads (UrlFactory::MapType type); static int concurrentDownloads (UrlFactory::MapType type);
private slots: private slots:
...@@ -107,7 +107,8 @@ signals: ...@@ -107,7 +107,8 @@ signals:
void updateTotals (quint32 totaltiles, quint64 totalsize, quint32 defaulttiles, quint64 defaultsize); void updateTotals (quint32 totaltiles, quint64 totalsize, quint32 defaulttiles, quint64 defaultsize);
private: private:
bool _wipeDirectory(const QString& dirPath); void _wipeOldCaches ();
bool _wipeDirectory (const QString& dirPath);
private: private:
QGCCacheWorker _worker; QGCCacheWorker _worker;
......
...@@ -28,17 +28,18 @@ QGC_LOGGING_CATEGORY(QGCCachedTileSetLog, "QGCCachedTileSetLog") ...@@ -28,17 +28,18 @@ QGC_LOGGING_CATEGORY(QGCCachedTileSetLog, "QGCCachedTileSetLog")
#define TILE_BATCH_SIZE 256 #define TILE_BATCH_SIZE 256
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QGCCachedTileSet::QGCCachedTileSet(const QString& name, const QString& description) QGCCachedTileSet::QGCCachedTileSet(const QString& name)
: _name(name) : _name(name)
, _description(description)
, _topleftLat(0.0) , _topleftLat(0.0)
, _topleftLon(0.0) , _topleftLon(0.0)
, _bottomRightLat(0.0) , _bottomRightLat(0.0)
, _bottomRightLon(0.0) , _bottomRightLon(0.0)
, _numTiles(0) , _totalTileCount(0)
, _tilesSize(0) , _totalTileSize(0)
, _savedTiles(0) , _uniqueTileCount(0)
, _savedSize(0) , _uniqueTileSize(0)
, _savedTileCount(0)
, _savedTileSize(0)
, _minZoom(3) , _minZoom(3)
, _maxZoom(3) , _maxZoom(3)
, _defaultSet(false) , _defaultSet(false)
...@@ -72,30 +73,44 @@ QGCCachedTileSet::errorCountStr() ...@@ -72,30 +73,44 @@ QGCCachedTileSet::errorCountStr()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QString QString
QGCCachedTileSet::numTilesStr() QGCCachedTileSet::totalTileCountStr()
{ {
return QGCMapEngine::numberToString(_numTiles); return QGCMapEngine::numberToString(_totalTileCount);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QString QString
QGCCachedTileSet::tilesSizeStr() QGCCachedTileSet::totalTilesSizeStr()
{ {
return QGCMapEngine::bigSizeToString(_tilesSize); return QGCMapEngine::bigSizeToString(_totalTileSize);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QString QString
QGCCachedTileSet::savedTilesStr() QGCCachedTileSet::uniqueTileSizeStr()
{ {
return QGCMapEngine::numberToString(_savedTiles); return QGCMapEngine::bigSizeToString(_uniqueTileSize);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QString QString
QGCCachedTileSet::savedSizeStr() QGCCachedTileSet::uniqueTileCountStr()
{ {
return QGCMapEngine::bigSizeToString(_savedSize); return QGCMapEngine::numberToString(_uniqueTileCount);
}
//-----------------------------------------------------------------------------
QString
QGCCachedTileSet::savedTileCountStr()
{
return QGCMapEngine::numberToString(_savedTileCount);
}
//-----------------------------------------------------------------------------
QString
QGCCachedTileSet::savedTileSizeStr()
{
return QGCMapEngine::bigSizeToString(_savedTileSize);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -103,12 +118,12 @@ QString ...@@ -103,12 +118,12 @@ QString
QGCCachedTileSet::downloadStatus() QGCCachedTileSet::downloadStatus()
{ {
if(_defaultSet) { if(_defaultSet) {
return tilesSizeStr(); return totalTilesSizeStr();
} }
if(_numTiles == _savedTiles) { if(_totalTileCount <= _savedTileCount) {
return savedSizeStr(); return savedTileSizeStr();
} else { } else {
return savedSizeStr() + " / " + tilesSizeStr(); return savedTileSizeStr() + " / " + totalTilesSizeStr();
} }
} }
...@@ -128,8 +143,8 @@ QGCCachedTileSet::createDownloadTask() ...@@ -128,8 +143,8 @@ QGCCachedTileSet::createDownloadTask()
if(_manager) if(_manager)
connect(task, &QGCMapTask::error, _manager, &QGCMapEngineManager::taskError); connect(task, &QGCMapTask::error, _manager, &QGCMapEngineManager::taskError);
getQGCMapEngine()->addTask(task); getQGCMapEngine()->addTask(task);
emit numTilesChanged(); emit totalTileCountChanged();
emit tilesSizeChanged(); emit totalTilesSizeChanged();
_batchRequested = true; _batchRequested = true;
} }
...@@ -164,6 +179,7 @@ QGCCachedTileSet::_tileListFetched(QList<QGCTile *> tiles) ...@@ -164,6 +179,7 @@ QGCCachedTileSet::_tileListFetched(QList<QGCTile *> tiles)
_noMoreTiles = true; _noMoreTiles = true;
} }
if(!tiles.size()) { if(!tiles.size()) {
_doneWithDownload();
return; return;
} }
//-- If this is the first time, create Network Manager //-- If this is the first time, create Network Manager
...@@ -176,23 +192,33 @@ QGCCachedTileSet::_tileListFetched(QList<QGCTile *> tiles) ...@@ -176,23 +192,33 @@ QGCCachedTileSet::_tileListFetched(QList<QGCTile *> tiles)
_prepareDownload(); _prepareDownload();
} }
//-----------------------------------------------------------------------------
void QGCCachedTileSet::_doneWithDownload()
{
if(!_errorCount) {
_totalTileCount = _savedTileCount;
_totalTileSize = _savedTileSize;
//-- Too expensive to compute the real size now. Estimate it for the time being.
quint32 avg = _savedTileSize / _savedTileCount;
_uniqueTileSize = _uniqueTileCount * avg;
}
emit totalTileCountChanged();
emit totalTilesSizeChanged();
emit savedTileSizeChanged();
emit savedTileCountChanged();
emit uniqueTileSizeChanged();
_downloading = false;
emit downloadingChanged();
emit completeChanged();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void QGCCachedTileSet::_prepareDownload() void QGCCachedTileSet::_prepareDownload()
{ {
if(!_tilesToDownload.count()) { if(!_tilesToDownload.count()) {
//-- Are we done? //-- Are we done?
if(_noMoreTiles) { if(_noMoreTiles) {
if(!_errorCount) { _doneWithDownload();
_numTiles = _savedTiles;
_tilesSize = _savedSize;
}
emit numTilesChanged();
emit tilesSizeChanged();
emit savedSizeChanged();
emit savedTilesChanged();
_downloading = false;
emit downloadingChanged();
emit completeChanged();
} else { } else {
if(!_batchRequested) if(!_batchRequested)
createDownloadTask(); createDownloadTask();
...@@ -253,15 +279,17 @@ QGCCachedTileSet::_networkReplyFinished() ...@@ -253,15 +279,17 @@ QGCCachedTileSet::_networkReplyFinished()
QGCUpdateTileDownloadStateTask* task = new QGCUpdateTileDownloadStateTask(_id, QGCTile::StateComplete, hash); QGCUpdateTileDownloadStateTask* task = new QGCUpdateTileDownloadStateTask(_id, QGCTile::StateComplete, hash);
getQGCMapEngine()->addTask(task); getQGCMapEngine()->addTask(task);
//-- Updated cached (downloaded) data //-- Updated cached (downloaded) data
_savedSize += image.size(); _savedTileSize += image.size();
_savedTiles++; _savedTileCount++;
emit savedSizeChanged(); emit savedTileSizeChanged();
emit savedTilesChanged(); emit savedTileCountChanged();
//-- Update estimate //-- Update estimate
if(_savedTiles % 10 == 0) { if(_savedTileCount % 10 == 0) {
quint32 avg = _savedSize / _savedTiles; quint32 avg = _savedTileSize / _savedTileCount;
_tilesSize = avg * _numTiles; _totalTileSize = avg * _totalTileCount;
emit tilesSizeChanged(); _uniqueTileSize = avg * _uniqueTileCount;
emit totalTilesSizeChanged();
emit uniqueTileSizeChanged();
} }
} }
//-- Setup a new download //-- Setup a new download
......
This diff is collapsed.
This diff is collapsed.
...@@ -60,7 +60,7 @@ private: ...@@ -60,7 +60,7 @@ private:
void _resetCacheDatabase (QGCMapTask* mtask); void _resetCacheDatabase (QGCMapTask* mtask);
void _pruneCache (QGCMapTask* mtask); void _pruneCache (QGCMapTask* mtask);
bool _findTile (const QString hash); quint64 _findTile (const QString hash);
bool _findTileSetID (const QString name, quint64& setID); bool _findTileSetID (const QString name, quint64& setID);
void _updateSetTotals (QGCCachedTileSet* set); void _updateSetTotals (QGCCachedTileSet* set);
bool _init (); bool _init ();
......
...@@ -127,10 +127,10 @@ QGCMapEngineManager::_tileSetFetched(QGCCachedTileSet* tileSet) ...@@ -127,10 +127,10 @@ QGCMapEngineManager::_tileSetFetched(QGCCachedTileSet* tileSet)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
QGCMapEngineManager::startDownload(const QString& name, const QString& description, const QString& mapType, const QImage& image) QGCMapEngineManager::startDownload(const QString& name, const QString& mapType)
{ {
if(_totalSet.tileSize) { if(_totalSet.tileSize) {
QGCCachedTileSet* set = new QGCCachedTileSet(name, description); QGCCachedTileSet* set = new QGCCachedTileSet(name);
set->setMapTypeStr(mapType); set->setMapTypeStr(mapType);
set->setTopleftLat(_topleftLat); set->setTopleftLat(_topleftLat);
set->setTopleftLon(_topleftLon); set->setTopleftLon(_topleftLon);
...@@ -138,11 +138,9 @@ QGCMapEngineManager::startDownload(const QString& name, const QString& descripti ...@@ -138,11 +138,9 @@ QGCMapEngineManager::startDownload(const QString& name, const QString& descripti
set->setBottomRightLon(_bottomRightLon); set->setBottomRightLon(_bottomRightLon);
set->setMinZoom(_minZoom); set->setMinZoom(_minZoom);
set->setMaxZoom(_maxZoom); set->setMaxZoom(_maxZoom);
set->setTilesSize(_totalSet.tileSize); set->setTotalTileSize(_totalSet.tileSize);
set->setNumTiles(_totalSet.tileCount); set->setTotalTileCount(_totalSet.tileCount);
set->setType(QGCMapEngine::getTypeFromName(mapType)); set->setType(QGCMapEngine::getTypeFromName(mapType));
if(!image.isNull())
set->setThumbNail(image);
QGCCreateTileSetTask* task = new QGCCreateTileSetTask(set); QGCCreateTileSetTask* task = new QGCCreateTileSetTask(set);
//-- Create Tile Set (it will also create a list of tiles to download) //-- Create Tile Set (it will also create a list of tiles to download)
connect(task, &QGCCreateTileSetTask::tileSetSaved, this, &QGCMapEngineManager::_tileSetSaved); connect(task, &QGCCreateTileSetTask::tileSetSaved, this, &QGCMapEngineManager::_tileSetSaved);
...@@ -329,10 +327,10 @@ QGCMapEngineManager::_updateTotals(quint32 totaltiles, quint64 totalsize, quint3 ...@@ -329,10 +327,10 @@ QGCMapEngineManager::_updateTotals(quint32 totaltiles, quint64 totalsize, quint3
QGCCachedTileSet* set = qobject_cast<QGCCachedTileSet*>(_tileSets.get(i)); QGCCachedTileSet* set = qobject_cast<QGCCachedTileSet*>(_tileSets.get(i));
Q_ASSERT(set); Q_ASSERT(set);
if (set->defaultSet()) { if (set->defaultSet()) {
set->setSavedSize(totalsize); set->setSavedTileSize(totalsize);
set->setSavedTiles(totaltiles); set->setSavedTileCount(totaltiles);
set->setNumTiles(defaulttiles); set->setTotalTileCount(defaulttiles);
set->setTilesSize(defaultsize); set->setTotalTileSize(defaultsize);
return; return;
} }
} }
......
...@@ -49,7 +49,7 @@ public: ...@@ -49,7 +49,7 @@ public:
Q_INVOKABLE void loadTileSets (); Q_INVOKABLE void loadTileSets ();
Q_INVOKABLE void updateForCurrentView (double lon0, double lat0, double lon1, double lat1, int minZoom, int maxZoom, const QString& mapName); Q_INVOKABLE void updateForCurrentView (double lon0, double lat0, double lon1, double lat1, int minZoom, int maxZoom, const QString& mapName);
Q_INVOKABLE void startDownload (const QString& name, const QString& description, const QString& mapType, const QImage& image = QImage()); Q_INVOKABLE void startDownload (const QString& name, const QString& mapType);
Q_INVOKABLE void saveSetting (const QString& key, const QString& value); Q_INVOKABLE void saveSetting (const QString& key, const QString& value);
Q_INVOKABLE QString loadSetting (const QString& key, const QString& defaultValue); Q_INVOKABLE QString loadSetting (const QString& key, const QString& defaultValue);
Q_INVOKABLE void deleteTileSet (QGCCachedTileSet* tileSet); Q_INVOKABLE void deleteTileSet (QGCCachedTileSet* tileSet);
......
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