Commit de9f2428 authored by dogmaphobic's avatar dogmaphobic

Fixes to Offline Map Cache

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