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
......
...@@ -39,36 +39,38 @@ class QGCCachedTileSet : public QObject ...@@ -39,36 +39,38 @@ class QGCCachedTileSet : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
QGCCachedTileSet (const QString& name, const QString& description); QGCCachedTileSet (const QString& name);
~QGCCachedTileSet (); ~QGCCachedTileSet ();
Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString description READ description CONSTANT) Q_PROPERTY(QString mapTypeStr READ mapTypeStr CONSTANT)
Q_PROPERTY(QString mapTypeStr READ mapTypeStr CONSTANT) Q_PROPERTY(double topleftLon READ topleftLon CONSTANT)
Q_PROPERTY(double topleftLon READ topleftLon CONSTANT) Q_PROPERTY(double topleftLat READ topleftLat CONSTANT)
Q_PROPERTY(double topleftLat READ topleftLat CONSTANT) Q_PROPERTY(double bottomRightLon READ bottomRightLon CONSTANT)
Q_PROPERTY(double bottomRightLon READ bottomRightLon CONSTANT) Q_PROPERTY(double bottomRightLat READ bottomRightLat CONSTANT)
Q_PROPERTY(double bottomRightLat READ bottomRightLat CONSTANT) Q_PROPERTY(int minZoom READ minZoom CONSTANT)
Q_PROPERTY(int minZoom READ minZoom CONSTANT) Q_PROPERTY(int maxZoom READ maxZoom CONSTANT)
Q_PROPERTY(int maxZoom READ maxZoom CONSTANT) Q_PROPERTY(quint32 totalTileCount READ totalTileCount NOTIFY totalTileCountChanged)
Q_PROPERTY(quint32 numTiles READ numTiles NOTIFY numTilesChanged) Q_PROPERTY(QString totalTileCountStr READ totalTileCountStr NOTIFY totalTileCountChanged)
Q_PROPERTY(QString numTilesStr READ numTilesStr NOTIFY numTilesChanged) Q_PROPERTY(quint64 totalTilesSize READ totalTilesSize NOTIFY totalTilesSizeChanged)
Q_PROPERTY(quint64 tilesSize READ tilesSize NOTIFY tilesSizeChanged) Q_PROPERTY(QString totalTilesSizeStr READ totalTilesSizeStr NOTIFY totalTilesSizeChanged)
Q_PROPERTY(QString tilesSizeStr READ tilesSizeStr NOTIFY tilesSizeChanged) Q_PROPERTY(quint32 uniqueTileCount READ uniqueTileCount NOTIFY uniqueTileCountChanged)
Q_PROPERTY(quint32 savedTiles READ savedTiles NOTIFY savedTilesChanged) Q_PROPERTY(QString uniqueTileCountStr READ uniqueTileCountStr NOTIFY uniqueTileCountChanged)
Q_PROPERTY(QString savedTilesStr READ savedTilesStr NOTIFY savedTilesChanged) Q_PROPERTY(quint64 uniqueTileSize READ uniqueTileSize NOTIFY uniqueTileSizeChanged)
Q_PROPERTY(quint64 savedSize READ savedSize NOTIFY savedSizeChanged) Q_PROPERTY(QString uniqueTileSizeStr READ uniqueTileSizeStr NOTIFY uniqueTileSizeChanged)
Q_PROPERTY(QString savedSizeStr READ savedSizeStr NOTIFY savedSizeChanged) Q_PROPERTY(quint32 savedTileCount READ savedTileCount NOTIFY savedTileCountChanged)
Q_PROPERTY(QString downloadStatus READ downloadStatus NOTIFY savedSizeChanged) Q_PROPERTY(QString savedTileCountStr READ savedTileCountStr NOTIFY savedTileCountChanged)
Q_PROPERTY(QDateTime creationDate READ creationDate CONSTANT) Q_PROPERTY(quint64 savedTileSize READ savedTileSize NOTIFY savedTileSizeChanged)
Q_PROPERTY(bool complete READ complete NOTIFY completeChanged) Q_PROPERTY(QString savedTileSizeStr READ savedTileSizeStr NOTIFY savedTileSizeChanged)
Q_PROPERTY(bool defaultSet READ defaultSet CONSTANT) Q_PROPERTY(QString downloadStatus READ downloadStatus NOTIFY savedTileSizeChanged)
Q_PROPERTY(quint64 setID READ setID CONSTANT) Q_PROPERTY(QDateTime creationDate READ creationDate CONSTANT)
Q_PROPERTY(bool deleting READ deleting NOTIFY deletingChanged) Q_PROPERTY(bool complete READ complete NOTIFY completeChanged)
Q_PROPERTY(bool downloading READ downloading NOTIFY downloadingChanged) Q_PROPERTY(bool defaultSet READ defaultSet CONSTANT)
Q_PROPERTY(quint32 errorCount READ errorCount NOTIFY errorCountChanged) Q_PROPERTY(quint64 setID READ setID CONSTANT)
Q_PROPERTY(QString errorCountStr READ errorCountStr NOTIFY errorCountChanged) Q_PROPERTY(bool deleting READ deleting NOTIFY deletingChanged)
Q_PROPERTY(QImage thumbNail READ thumbNail CONSTANT) Q_PROPERTY(bool downloading READ downloading NOTIFY downloadingChanged)
Q_PROPERTY(quint32 errorCount READ errorCount NOTIFY errorCountChanged)
Q_PROPERTY(QString errorCountStr READ errorCountStr NOTIFY errorCountChanged)
Q_INVOKABLE void createDownloadTask (); Q_INVOKABLE void createDownloadTask ();
Q_INVOKABLE void resumeDownloadTask (); Q_INVOKABLE void resumeDownloadTask ();
...@@ -77,46 +79,49 @@ public: ...@@ -77,46 +79,49 @@ public:
void setManager (QGCMapEngineManager* mgr); void setManager (QGCMapEngineManager* mgr);
QString name () { return _name; } QString name () { return _name; }
QString description () { return _description; }
QString mapTypeStr () { return _mapTypeStr; } QString mapTypeStr () { return _mapTypeStr; }
double topleftLat () { return _topleftLat; } double topleftLat () { return _topleftLat; }
double topleftLon () { return _topleftLon; } double topleftLon () { return _topleftLon; }
double bottomRightLat () { return _bottomRightLat; } double bottomRightLat () { return _bottomRightLat; }
double bottomRightLon () { return _bottomRightLon; } double bottomRightLon () { return _bottomRightLon; }
quint32 numTiles () { return (quint32)_numTiles; } quint32 totalTileCount () { return (quint32)_totalTileCount; }
QString numTilesStr (); QString totalTileCountStr ();
quint64 tilesSize () { return (quint64)_tilesSize; } quint64 totalTilesSize () { return (quint64)_totalTileSize; }
QString tilesSizeStr (); QString totalTilesSizeStr ();
quint32 savedTiles () { return (quint32)_savedTiles; } quint32 uniqueTileCount () { return _uniqueTileCount; }
QString savedTilesStr (); QString uniqueTileCountStr ();
quint64 savedSize () { return (quint64)_savedSize; } quint64 uniqueTileSize () { return _uniqueTileSize; }
QString savedSizeStr (); QString uniqueTileSizeStr ();
quint32 savedTileCount () { return (quint32)_savedTileCount; }
QString savedTileCountStr ();
quint64 savedTileSize () { return (quint64)_savedTileSize; }
QString savedTileSizeStr ();
QString downloadStatus (); QString downloadStatus ();
int minZoom () { return _minZoom; } int minZoom () { return _minZoom; }
int maxZoom () { return _maxZoom; } int maxZoom () { return _maxZoom; }
QDateTime creationDate () { return _creationDate; } QDateTime creationDate () { return _creationDate; }
quint64 id () { return _id; } quint64 id () { return _id; }
UrlFactory::MapType type () { return _type; } UrlFactory::MapType type () { return _type; }
bool complete () { return _defaultSet || (_numTiles == _savedTiles); } bool complete () { return _defaultSet || (_totalTileCount <= _savedTileCount); }
bool defaultSet () { return _defaultSet; } bool defaultSet () { return _defaultSet; }
quint64 setID () { return _id; } quint64 setID () { return _id; }
bool deleting () { return _deleting; } bool deleting () { return _deleting; }
bool downloading () { return _downloading; } bool downloading () { return _downloading; }
quint32 errorCount () { return _errorCount; } quint32 errorCount () { return _errorCount; }
QString errorCountStr (); QString errorCountStr ();
QImage thumbNail () { return _thumbNail; }
void setName (QString name) { _name = name; } void setName (QString name) { _name = name; }
void setDescription (QString desc) { _description = desc; }
void setMapTypeStr (QString typeStr) { _mapTypeStr = typeStr; } void setMapTypeStr (QString typeStr) { _mapTypeStr = typeStr; }
void setTopleftLat (double lat) { _topleftLat = lat; } void setTopleftLat (double lat) { _topleftLat = lat; }
void setTopleftLon (double lon) { _topleftLon = lon; } void setTopleftLon (double lon) { _topleftLon = lon; }
void setBottomRightLat (double lat) { _bottomRightLat = lat; } void setBottomRightLat (double lat) { _bottomRightLat = lat; }
void setBottomRightLon (double lon) { _bottomRightLon = lon; } void setBottomRightLon (double lon) { _bottomRightLon = lon; }
void setNumTiles (quint32 num) { _numTiles = num; } void setTotalTileCount (quint32 num) { _totalTileCount = num; emit totalTileCountChanged(); }
void setTilesSize (quint64 size) { _tilesSize = size; } void setUniqueTileCount (quint32 num) { _uniqueTileCount = num; }
void setSavedTiles (quint32 num) { _savedTiles = num; emit savedTilesChanged(); } void setUniqueTileSize (quint64 size) { _uniqueTileSize = size; }
void setSavedSize (quint64 size) { _savedSize = size; emit savedSizeChanged(); } void setTotalTileSize (quint64 size) { _totalTileSize = size; emit totalTilesSizeChanged(); }
void setSavedTileCount (quint32 num) { _savedTileCount = num; emit savedTileCountChanged(); }
void setSavedTileSize (quint64 size) { _savedTileSize = size; emit savedTileSizeChanged(); }
void setMinZoom (int zoom) { _minZoom = zoom; } void setMinZoom (int zoom) { _minZoom = zoom; }
void setMaxZoom (int zoom) { _maxZoom = zoom; } void setMaxZoom (int zoom) { _maxZoom = zoom; }
void setCreationDate (QDateTime date) { _creationDate = date; } void setCreationDate (QDateTime date) { _creationDate = date; }
...@@ -125,15 +130,16 @@ public: ...@@ -125,15 +130,16 @@ public:
void setDefaultSet (bool def) { _defaultSet = def; } void setDefaultSet (bool def) { _defaultSet = def; }
void setDeleting (bool del) { _deleting = del; emit deletingChanged(); } void setDeleting (bool del) { _deleting = del; emit deletingChanged(); }
void setDownloading (bool down) { _downloading = down; } void setDownloading (bool down) { _downloading = down; }
void setThumbNail (const QImage& thumb) { _thumbNail = thumb; }
signals: signals:
void deletingChanged (); void deletingChanged ();
void downloadingChanged (); void downloadingChanged ();
void numTilesChanged (); void totalTileCountChanged ();
void tilesSizeChanged (); void uniqueTileCountChanged ();
void savedTilesChanged (); void uniqueTileSizeChanged ();
void savedSizeChanged (); void totalTilesSizeChanged ();
void savedTileCountChanged ();
void savedTileSizeChanged ();
void completeChanged (); void completeChanged ();
void errorCountChanged (); void errorCountChanged ();
...@@ -144,19 +150,21 @@ private slots: ...@@ -144,19 +150,21 @@ private slots:
private: private:
void _prepareDownload (); void _prepareDownload ();
void _doneWithDownload ();
private: private:
QString _name; QString _name;
QString _description;
QString _mapTypeStr; QString _mapTypeStr;
double _topleftLat; double _topleftLat;
double _topleftLon; double _topleftLon;
double _bottomRightLat; double _bottomRightLat;
double _bottomRightLon; double _bottomRightLon;
quint32 _numTiles; quint32 _totalTileCount;
quint64 _tilesSize; quint64 _totalTileSize;
quint32 _savedTiles; quint32 _uniqueTileCount;
quint64 _savedSize; quint64 _uniqueTileSize;
quint32 _savedTileCount;
quint64 _savedTileSize;
int _minZoom; int _minZoom;
int _maxZoom; int _maxZoom;
bool _defaultSet; bool _defaultSet;
...@@ -173,7 +181,6 @@ private: ...@@ -173,7 +181,6 @@ private:
bool _noMoreTiles; bool _noMoreTiles;
bool _batchRequested; bool _batchRequested;
QGCMapEngineManager* _manager; QGCMapEngineManager* _manager;
QImage _thumbNail;
}; };
#endif // QGC_MAP_TILE_SET_H #endif // QGC_MAP_TILE_SET_H
......
...@@ -168,7 +168,9 @@ QGCCacheWorker::run() ...@@ -168,7 +168,9 @@ QGCCacheWorker::run()
_updateTimeout = SHORT_TIMEOUT; _updateTimeout = SHORT_TIMEOUT;
} }
if(!count || (time(0) - _lastUpdate > _updateTimeout)) { if(!count || (time(0) - _lastUpdate > _updateTimeout)) {
_updateTotals(); if(_valid) {
_updateTotals();
}
} }
} else { } else {
//-- Wait a bit before shutting things down //-- Wait a bit before shutting things down
...@@ -298,14 +300,11 @@ QGCCacheWorker::_getTileSets(QGCMapTask* mtask) ...@@ -298,14 +300,11 @@ QGCCacheWorker::_getTileSets(QGCMapTask* mtask)
QGCFetchTileSetTask* task = static_cast<QGCFetchTileSetTask*>(mtask); QGCFetchTileSetTask* task = static_cast<QGCFetchTileSetTask*>(mtask);
QSqlQuery query(*_db); QSqlQuery query(*_db);
QString s = QString("SELECT * FROM TileSets ORDER BY defaultSet DESC, name ASC"); QString s = QString("SELECT * FROM TileSets ORDER BY defaultSet DESC, name ASC");
qCDebug(QGCTileCacheLog) << "_getTileSets(): " << s;
if(query.exec(s)) { if(query.exec(s)) {
while(query.next()) { while(query.next()) {
QString name = query.value("name").toString(); QString name = query.value("name").toString();
QString desc = query.value("description").toString(); QGCCachedTileSet* set = new QGCCachedTileSet(name);
//-- Original database had description as NOT NULL
if(desc.isEmpty())
desc = " ";
QGCCachedTileSet* set = new QGCCachedTileSet(name, desc);
set->setId(query.value("setID").toULongLong()); set->setId(query.value("setID").toULongLong());
set->setMapTypeStr(query.value("typeStr").toString()); set->setMapTypeStr(query.value("typeStr").toString());
set->setTopleftLat(query.value("topleftLat").toDouble()); set->setTopleftLat(query.value("topleftLat").toDouble());
...@@ -315,19 +314,9 @@ QGCCacheWorker::_getTileSets(QGCMapTask* mtask) ...@@ -315,19 +314,9 @@ QGCCacheWorker::_getTileSets(QGCMapTask* mtask)
set->setMinZoom(query.value("minZoom").toInt()); set->setMinZoom(query.value("minZoom").toInt());
set->setMaxZoom(query.value("maxZoom").toInt()); set->setMaxZoom(query.value("maxZoom").toInt());
set->setType((UrlFactory::MapType)query.value("type").toInt()); set->setType((UrlFactory::MapType)query.value("type").toInt());
set->setNumTiles(query.value("numTiles").toUInt()); set->setTotalTileCount(query.value("numTiles").toUInt());
set->setTilesSize(query.value("tilesSize").toULongLong());
set->setDefaultSet(query.value("defaultSet").toInt() != 0); set->setDefaultSet(query.value("defaultSet").toInt() != 0);
set->setCreationDate(QDateTime::fromTime_t(query.value("date").toUInt())); set->setCreationDate(QDateTime::fromTime_t(query.value("date").toUInt()));
//-- Load thumbnail (if not default set)
if(!set->defaultSet()) {
int w = query.value("thumbW").toInt();
int h = query.value("thumbH").toInt();
if(w && h) {
QByteArray ba = query.value("thumbNail").toByteArray();
set->setThumbNail(QImage((uchar*)(void*)ba.data(), w, h, QImage::Format_RGB32));
}
}
_updateSetTotals(set); _updateSetTotals(set);
//-- Object created here must be moved to app thread to be used there //-- Object created here must be moved to app thread to be used there
set->moveToThread(QApplication::instance()->thread()); set->moveToThread(QApplication::instance()->thread());
...@@ -344,23 +333,52 @@ QGCCacheWorker::_updateSetTotals(QGCCachedTileSet* set) ...@@ -344,23 +333,52 @@ QGCCacheWorker::_updateSetTotals(QGCCachedTileSet* set)
{ {
if(set->defaultSet()) { if(set->defaultSet()) {
_updateTotals(); _updateTotals();
set->setSavedTiles(_totalCount); set->setSavedTileCount(_totalCount);
set->setSavedSize(_totalSize); set->setSavedTileSize(_totalSize);
set->setNumTiles(_defaultCount); set->setTotalTileCount(_defaultCount);
set->setTilesSize(_defaultSize); set->setTotalTileSize(_defaultSize);
return; return;
} }
QSqlQuery subquery(*_db); QSqlQuery subquery(*_db);
QString sq = QString("SELECT COUNT(size), SUM(size) FROM Tiles A INNER JOIN SetTiles B on A.tileID = B.tileID WHERE B.setID = %1").arg(set->id()); QString sq = QString("SELECT COUNT(size), SUM(size) FROM Tiles A INNER JOIN SetTiles B on A.tileID = B.tileID WHERE B.setID = %1").arg(set->id());
qCDebug(QGCTileCacheLog) << "_updateSetTotals(): " << sq;
if(subquery.exec(sq)) { if(subquery.exec(sq)) {
if(subquery.next()) { if(subquery.next()) {
set->setSavedTiles(subquery.value(0).toUInt()); set->setSavedTileCount(subquery.value(0).toUInt());
set->setSavedSize(subquery.value(1).toULongLong()); set->setSavedTileSize(subquery.value(1).toULongLong());
//-- Update estimated size qCDebug(QGCTileCacheLog) << "Set" << set->id() << "Totals:" << set->savedTileCount() << " " << set->savedTileSize() << "Expected: " << set->totalTileCount() << " " << set->totalTilesSize();
if(set->savedTiles() > 10 && set->savedSize()) { //-- Update (estimated) size
quint32 avg = set->savedSize() / set->savedTiles(); quint64 avg = UrlFactory::averageSizeForType(set->type());
set->setTilesSize(avg * set->numTiles()); if(set->totalTileCount() <= set->savedTileCount()) {
//-- We're done so the saved size is the total size
set->setTotalTileSize(set->savedTileSize());
} else {
//-- Otherwise we need to estimate it.
if(set->savedTileCount() > 10 && set->savedTileSize()) {
avg = set->savedTileSize() / set->savedTileCount();
}
set->setTotalTileSize(avg * set->totalTileCount());
}
//-- Now figure out the count for tiles unique to this set
quint32 ucount = 0;
quint64 usize = 0;
sq = QString("SELECT COUNT(size), SUM(size) FROM Tiles WHERE tileID IN (SELECT A.tileID FROM SetTiles A join SetTiles B on A.tileID = B.tileID WHERE B.setID = %1 GROUP by A.tileID HAVING COUNT(A.tileID) = 1)").arg(set->id());
if(subquery.exec(sq)) {
if(subquery.next()) {
//-- This is only accurate when all tiles are downloaded
ucount = subquery.value(0).toUInt();
usize = subquery.value(1).toULongLong();
}
}
//-- If we haven't downloaded it all, estimate size of unique tiles
quint32 expectedUcount = set->totalTileCount() - set->savedTileCount();
if(!ucount) {
usize = expectedUcount * avg;
} else {
expectedUcount = ucount;
} }
set->setUniqueTileCount(expectedUcount);
set->setUniqueTileSize(usize);
} }
} }
} }
...@@ -372,13 +390,15 @@ QGCCacheWorker::_updateTotals() ...@@ -372,13 +390,15 @@ QGCCacheWorker::_updateTotals()
QSqlQuery query(*_db); QSqlQuery query(*_db);
QString s; QString s;
s = QString("SELECT COUNT(size), SUM(size) FROM Tiles"); s = QString("SELECT COUNT(size), SUM(size) FROM Tiles");
qCDebug(QGCTileCacheLog) << "_updateTotals(): " << s;
if(query.exec(s)) { if(query.exec(s)) {
if(query.next()) { if(query.next()) {
_totalCount = query.value(0).toUInt(); _totalCount = query.value(0).toUInt();
_totalSize = query.value(1).toULongLong(); _totalSize = query.value(1).toULongLong();
} }
} }
s = QString("SELECT COUNT(size), SUM(size) FROM Tiles A INNER JOIN SetTiles B on A.tileID = B.tileID WHERE B.setID = %1").arg(_getDefaultTileSet()); s = QString("SELECT COUNT(size), SUM(size) FROM Tiles WHERE tileID IN (SELECT A.tileID FROM SetTiles A join SetTiles B on A.tileID = B.tileID WHERE B.setID = %1 GROUP by A.tileID HAVING COUNT(A.tileID) = 1)").arg(_getDefaultTileSet());
qCDebug(QGCTileCacheLog) << "_updateTotals(): " << s;
if(query.exec(s)) { if(query.exec(s)) {
if(query.next()) { if(query.next()) {
_defaultCount = query.value(0).toUInt(); _defaultCount = query.value(0).toUInt();
...@@ -390,17 +410,17 @@ QGCCacheWorker::_updateTotals() ...@@ -390,17 +410,17 @@ QGCCacheWorker::_updateTotals()
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool quint64 QGCCacheWorker::_findTile(const QString hash)
QGCCacheWorker::_findTile(const QString hash)
{ {
quint64 tileID = 0;
QSqlQuery query(*_db); QSqlQuery query(*_db);
QString s = QString("SELECT type FROM Tiles WHERE hash = \"%1\"").arg(hash); QString s = QString("SELECT tileID FROM Tiles WHERE hash = \"%1\"").arg(hash);
if(query.exec(s)) { if(query.exec(s)) {
if(query.next()) { if(query.next()) {
return true; tileID = query.value(0).toULongLong();
} }
} }
return false; return tileID;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -412,15 +432,10 @@ QGCCacheWorker::_createTileSet(QGCMapTask *mtask) ...@@ -412,15 +432,10 @@ QGCCacheWorker::_createTileSet(QGCMapTask *mtask)
quint32 actual_count = 0; quint32 actual_count = 0;
QGCCreateTileSetTask* task = static_cast<QGCCreateTileSetTask*>(mtask); QGCCreateTileSetTask* task = static_cast<QGCCreateTileSetTask*>(mtask);
QSqlQuery query(*_db); QSqlQuery query(*_db);
QString desc = task->tileSet()->description();
//-- Original database had description as NOT NULL
if(desc.isEmpty())
desc = " ";
query.prepare("INSERT INTO TileSets(" query.prepare("INSERT INTO TileSets("
"name, description, typeStr, topleftLat, topleftLon, bottomRightLat, bottomRightLon, minZoom, maxZoom, type, numTiles, tilesSize, thumbNail, thumbW, thumbH, date" "name, typeStr, topleftLat, topleftLon, bottomRightLat, bottomRightLon, minZoom, maxZoom, type, numTiles, date"
") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); ") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
query.addBindValue(task->tileSet()->name()); query.addBindValue(task->tileSet()->name());
query.addBindValue(desc);
query.addBindValue(task->tileSet()->mapTypeStr()); query.addBindValue(task->tileSet()->mapTypeStr());
query.addBindValue(task->tileSet()->topleftLat()); query.addBindValue(task->tileSet()->topleftLat());
query.addBindValue(task->tileSet()->topleftLon()); query.addBindValue(task->tileSet()->topleftLon());
...@@ -429,35 +444,28 @@ QGCCacheWorker::_createTileSet(QGCMapTask *mtask) ...@@ -429,35 +444,28 @@ QGCCacheWorker::_createTileSet(QGCMapTask *mtask)
query.addBindValue(task->tileSet()->minZoom()); query.addBindValue(task->tileSet()->minZoom());
query.addBindValue(task->tileSet()->maxZoom()); query.addBindValue(task->tileSet()->maxZoom());
query.addBindValue(task->tileSet()->type()); query.addBindValue(task->tileSet()->type());
query.addBindValue(task->tileSet()->numTiles()); query.addBindValue(task->tileSet()->totalTileCount());
query.addBindValue(task->tileSet()->tilesSize());
if(task->tileSet()->thumbNail().isNull()) {
query.addBindValue(QByteArray(1,'\0'));
query.addBindValue(0);
query.addBindValue(0);
} else {
query.addBindValue(QByteArray((const char *)(void*)task->tileSet()->thumbNail().convertToFormat(QImage::Format_RGB32).bits(), task->tileSet()->thumbNail().byteCount()));
query.addBindValue(task->tileSet()->thumbNail().width());
query.addBindValue(task->tileSet()->thumbNail().height());
}
query.addBindValue(QDateTime::currentDateTime().toTime_t()); query.addBindValue(QDateTime::currentDateTime().toTime_t());
if(!query.exec()) { if(!query.exec()) {
qWarning() << "Map Cache SQL error (add tileSet into TileSets):" << query.lastError().text(); qWarning() << "Map Cache SQL error (add tileSet into TileSets):" << query.lastError().text();
} else { } else {
//-- Get just creted (auto-incremented) setID //-- Get just created (auto-incremented) setID
quint64 setID = query.lastInsertId().toULongLong(); quint64 setID = query.lastInsertId().toULongLong();
task->tileSet()->setId(setID); task->tileSet()->setId(setID);
//-- Prepare Download List //-- Prepare Download List
quint64 tileCount = 0;
for(int z = task->tileSet()->minZoom(); z <= task->tileSet()->maxZoom(); z++) { for(int z = task->tileSet()->minZoom(); z <= task->tileSet()->maxZoom(); z++) {
QGCTileSet set = QGCMapEngine::getTileCount(z, QGCTileSet set = QGCMapEngine::getTileCount(z,
task->tileSet()->topleftLon(), task->tileSet()->topleftLat(), task->tileSet()->topleftLon(), task->tileSet()->topleftLat(),
task->tileSet()->bottomRightLon(), task->tileSet()->bottomRightLat(), task->tileSet()->type()); task->tileSet()->bottomRightLon(), task->tileSet()->bottomRightLat(), task->tileSet()->type());
tileCount += set.tileCount;
UrlFactory::MapType type = task->tileSet()->type(); UrlFactory::MapType type = task->tileSet()->type();
for(int x = set.tileX0; x <= set.tileX1; x++) { for(int x = set.tileX0; x <= set.tileX1; x++) {
for(int y = set.tileY0; y <= set.tileY1; y++) { for(int y = set.tileY0; y <= set.tileY1; y++) {
//-- See if tile is already downloaded //-- See if tile is already downloaded
QString hash = QGCMapEngine::getTileHash(type, x, y, z); QString hash = QGCMapEngine::getTileHash(type, x, y, z);
if(!_findTile(hash)) { quint64 tileID = _findTile(hash);
if(!tileID) {
//-- Set to download //-- Set to download
query.prepare("INSERT OR IGNORE INTO TilesDownload(setID, hash, type, x, y, z, state) VALUES(?, ?, ?, ?, ? ,? ,?)"); query.prepare("INSERT OR IGNORE INTO TilesDownload(setID, hash, type, x, y, z, state) VALUES(?, ?, ?, ?, ? ,? ,?)");
query.addBindValue(setID); query.addBindValue(setID);
...@@ -473,16 +481,18 @@ QGCCacheWorker::_createTileSet(QGCMapTask *mtask) ...@@ -473,16 +481,18 @@ QGCCacheWorker::_createTileSet(QGCMapTask *mtask)
return; return;
} else } else
actual_count++; actual_count++;
} else {
//-- Tile already in the database. No need to dowload.
QString s = QString("INSERT OR IGNORE INTO SetTiles(tileID, setID) VALUES(%1, %2)").arg(tileID).arg(setID);
query.prepare(s);
if(!query.exec()) {
qWarning() << "Map Cache SQL error (add tile into SetTiles):" << query.lastError().text();
}
qCDebug(QGCTileCacheLog) << "_createTileSet() Already Cached HASH:" << hash;
} }
} }
} }
} }
//-- Now update how many tiles we actually have to download
quint64 actual_size = actual_count * UrlFactory::averageSizeForType(task->tileSet()->type());
QString s = QString("UPDATE TileSets SET numTiles = %1, tilesSize = %2 WHERE setID = %3").arg(actual_count).arg(actual_size).arg(task->tileSet()->setID());
if(!query.exec(s)) {
qWarning() << "Map Cache SQL error (set TilesDownload state):" << query.lastError().text();
}
//-- Done //-- Done
_updateSetTotals(task->tileSet()); _updateSetTotals(task->tileSet());
task->setTileSetSaved(); task->setTileSetSaved();
...@@ -560,7 +570,8 @@ QGCCacheWorker::_pruneCache(QGCMapTask* mtask) ...@@ -560,7 +570,8 @@ QGCCacheWorker::_pruneCache(QGCMapTask* mtask)
QGCPruneCacheTask* task = static_cast<QGCPruneCacheTask*>(mtask); QGCPruneCacheTask* task = static_cast<QGCPruneCacheTask*>(mtask);
QSqlQuery query(*_db); QSqlQuery query(*_db);
QString s; QString s;
s = QString("SELECT tileID, size, hash FROM Tiles WHERE tileID IN (SELECT tileID FROM SetTiles WHERE setID = %1) ORDER BY DATE ASC LIMIT 128").arg(_getDefaultTileSet()); //-- Select tiles in default set only, sorted by oldest.
s = QString("SELECT tileID, size, hash FROM Tiles WHERE tileID IN (SELECT A.tileID FROM SetTiles A join SetTiles B on A.tileID = B.tileID WHERE B.setID = %1 GROUP by A.tileID HAVING COUNT(A.tileID) = 1) ORDER BY DATE ASC LIMIT 128").arg(_getDefaultTileSet());
qint64 amount = (qint64)task->amount(); qint64 amount = (qint64)task->amount();
QList<quint64> tlist; QList<quint64> tlist;
if(query.exec(s)) { if(query.exec(s)) {
...@@ -590,7 +601,8 @@ QGCCacheWorker::_deleteTileSet(QGCMapTask* mtask) ...@@ -590,7 +601,8 @@ QGCCacheWorker::_deleteTileSet(QGCMapTask* mtask)
QGCDeleteTileSetTask* task = static_cast<QGCDeleteTileSetTask*>(mtask); QGCDeleteTileSetTask* task = static_cast<QGCDeleteTileSetTask*>(mtask);
QSqlQuery query(*_db); QSqlQuery query(*_db);
QString s; QString s;
s = QString("DELETE FROM Tiles WHERE tileID IN (SELECT tileID FROM SetTiles WHERE setID = %1)").arg(task->setID()); //-- Only delete tiles unique to this set
s = QString("DELETE FROM Tiles WHERE tileID IN (SELECT A.tileID FROM SetTiles A JOIN SetTiles B ON A.tileID = B.tileID WHERE B.setID = %1 GROUP BY A.tileID HAVING COUNT(A.tileID) = 1)").arg(task->setID());
query.exec(s); query.exec(s);
s = QString("DELETE FROM TilesDownload WHERE setID = %1").arg(task->setID()); s = QString("DELETE FROM TilesDownload WHERE setID = %1").arg(task->setID());
query.exec(s); query.exec(s);
...@@ -672,7 +684,6 @@ QGCCacheWorker::_createDB() ...@@ -672,7 +684,6 @@ QGCCacheWorker::_createDB()
"CREATE TABLE IF NOT EXISTS TileSets (" "CREATE TABLE IF NOT EXISTS TileSets ("
"setID INTEGER PRIMARY KEY NOT NULL, " "setID INTEGER PRIMARY KEY NOT NULL, "
"name TEXT NOT NULL UNIQUE, " "name TEXT NOT NULL UNIQUE, "
"description TEXT, "
"typeStr TEXT, " "typeStr TEXT, "
"topleftLat REAL DEFAULT 0.0, " "topleftLat REAL DEFAULT 0.0, "
"topleftLon REAL DEFAULT 0.0, " "topleftLon REAL DEFAULT 0.0, "
...@@ -682,11 +693,7 @@ QGCCacheWorker::_createDB() ...@@ -682,11 +693,7 @@ QGCCacheWorker::_createDB()
"maxZoom INTEGER DEFAULT 3, " "maxZoom INTEGER DEFAULT 3, "
"type INTEGER DEFAULT -1, " "type INTEGER DEFAULT -1, "
"numTiles INTEGER DEFAULT 0, " "numTiles INTEGER DEFAULT 0, "
"tilesSize INTEGER DEFAULT 0, "
"defaultSet INTEGER DEFAULT 0, " "defaultSet INTEGER DEFAULT 0, "
"thumbNail BLOB NULL, "
"thumbW INTEGER DEFAULT 0, "
"thumbH INTEGER DEFAULT 0, "
"date INTEGER DEFAULT 0)")) "date INTEGER DEFAULT 0)"))
{ {
qWarning() << "Map Cache SQL error (create TileSets db):" << query.lastError().text(); qWarning() << "Map Cache SQL error (create TileSets db):" << query.lastError().text();
...@@ -721,9 +728,8 @@ QGCCacheWorker::_createDB() ...@@ -721,9 +728,8 @@ QGCCacheWorker::_createDB()
QString s = QString("SELECT name FROM TileSets WHERE name = \"%1\"").arg(kDefaultSet); QString s = QString("SELECT name FROM TileSets WHERE name = \"%1\"").arg(kDefaultSet);
if(query.exec(s)) { if(query.exec(s)) {
if(!query.next()) { if(!query.next()) {
query.prepare("INSERT INTO TileSets(name, description, defaultSet, date) VALUES(?, ?, ?, ?)"); query.prepare("INSERT INTO TileSets(name, defaultSet, date) VALUES(?, ?, ?)");
query.addBindValue(kDefaultSet); query.addBindValue(kDefaultSet);
query.addBindValue("System wide tile cache");
query.addBindValue(1); query.addBindValue(1);
query.addBindValue(QDateTime::currentDateTime().toTime_t()); query.addBindValue(QDateTime::currentDateTime().toTime_t());
if(!query.exec()) { if(!query.exec()) {
......
...@@ -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 ();
......
...@@ -37,16 +37,17 @@ QGCView { ...@@ -37,16 +37,17 @@ QGCView {
property real savedZoom: 3 property real savedZoom: 3
property string savedMapType: "" property string savedMapType: ""
property bool _showPreview: true property bool _showPreview: true
property bool _defaultSet: offlineMapView && offlineMapView._currentSelection && offlineMapView._currentSelection.defaultSet
property bool _saveRealEstate: ScreenTools.isTinyScreen || ScreenTools.isShortScreen property bool _saveRealEstate: ScreenTools.isTinyScreen || ScreenTools.isShortScreen
property real _adjustableFontPointSize: _saveRealEstate ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize property real _adjustableFontPointSize: _saveRealEstate ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize
property var _mapAdjustedColor: _map.isSatelliteMap ? "white" : "black" property var _mapAdjustedColor: _map.isSatelliteMap ? "white" : "black"
readonly property real minZoomLevel: 3 readonly property real minZoomLevel: 3
readonly property real maxZoomLevel: 20 readonly property real maxZoomLevel: 20
readonly property int _maxTilesForDownload: 60000 readonly property int _maxTilesForDownload: 100000
QGCPalette { id: qgcPal } QGCPalette { id: qgcPal }
...@@ -98,7 +99,6 @@ QGCView { ...@@ -98,7 +99,6 @@ QGCView {
_map.visible = true _map.visible = true
_tileSetList.visible = false _tileSetList.visible = false
infoView.visible = false infoView.visible = false
defaultInfoView.visible = false
addNewSetView.visible = true addNewSetView.visible = true
} }
...@@ -107,7 +107,6 @@ QGCView { ...@@ -107,7 +107,6 @@ QGCView {
_map.visible = false _map.visible = false
_tileSetList.visible = true _tileSetList.visible = true
infoView.visible = false infoView.visible = false
defaultInfoView.visible = false
addNewSetView.visible = false addNewSetView.visible = false
} }
...@@ -140,13 +139,12 @@ QGCView { ...@@ -140,13 +139,12 @@ QGCView {
} }
function enterInfoView() { function enterInfoView() {
var isDefaultSet = offlineMapView._currentSelection.defaultSet
_map.visible = true _map.visible = true
isMapInteractive = false isMapInteractive = false
savedCenter = _map.toCoordinate(Qt.point(_map.width / 2, _map.height / 2)) savedCenter = _map.toCoordinate(Qt.point(_map.width / 2, _map.height / 2))
savedZoom = _map.zoomLevel savedZoom = _map.zoomLevel
savedMapType = mapType savedMapType = mapType
if(!isDefaultSet) { if(!offlineMapView._currentSelection.defaultSet) {
mapType = offlineMapView._currentSelection.mapTypeStr mapType = offlineMapView._currentSelection.mapTypeStr
_map.center = midPoint(offlineMapView._currentSelection.topleftLat, offlineMapView._currentSelection.bottomRightLat, offlineMapView._currentSelection.topleftLon, offlineMapView._currentSelection.bottomRightLon) _map.center = midPoint(offlineMapView._currentSelection.topleftLat, offlineMapView._currentSelection.bottomRightLat, offlineMapView._currentSelection.topleftLon, offlineMapView._currentSelection.bottomRightLon)
//-- Delineate Set Region //-- Delineate Set Region
...@@ -157,15 +155,14 @@ QGCView { ...@@ -157,15 +155,14 @@ QGCView {
mapBoundary.topLeft = QtPositioning.coordinate(y0, x0) mapBoundary.topLeft = QtPositioning.coordinate(y0, x0)
mapBoundary.bottomRight = QtPositioning.coordinate(y1, x1) mapBoundary.bottomRight = QtPositioning.coordinate(y1, x1)
mapBoundary.visible = true mapBoundary.visible = true
// Some times, for whatever reason, the bounding box is correct (around ETH for instance), but the rectangle is drawn across the planet.
// When that happens, the "_map.fitViewportToMapItems()" below makes the map to zoom to the entire earth.
//console.log("Map boundary: " + mapBoundary.topLeft + " " + mapBoundary.bottomRight)
_map.fitViewportToMapItems() _map.fitViewportToMapItems()
} }
_tileSetList.visible = false _tileSetList.visible = false
addNewSetView.visible = false addNewSetView.visible = false
if(isDefaultSet) { infoView.visible = true
defaultInfoView.visible = true
} else {
infoView.visible = true
}
} }
function leaveInfoView() { function leaveInfoView() {
...@@ -277,30 +274,17 @@ QGCView { ...@@ -277,30 +274,17 @@ QGCView {
Component { Component {
id: deleteConfirmationDialogComponent id: deleteConfirmationDialogComponent
QGCViewMessage { QGCViewMessage {
id: deleteConfirmationDialog id: deleteConfirmationDialog
message: qsTr("Delete %1 and all its tiles.\n\nIs this really what you want?").arg(offlineMapView._currentSelection.name) message: {
if(offlineMapView._currentSelection.defaultSet)
function accept() { return qsTr("This will delete all tiles INCLUDING the tile sets you have created yourself.\n\nIs this really what you want?");
QGroundControl.mapEngineManager.deleteTileSet(offlineMapView._currentSelection) else
deleteConfirmationDialog.hideDialog() return qsTr("Delete %1 and all its tiles.\n\nIs this really what you want?").arg(offlineMapView._currentSelection.name);
leaveInfoView()
showList()
} }
}
}
Component {
id: deleteSystemSetConfirmationDialogComponent
QGCViewMessage {
id: deleteSystemSetConfirmationDialog
message: qsTr("This will delete all tiles INCLUDING the tile sets you have created yourself.\n\nIs this really what you want?")
function accept() { function accept() {
QGroundControl.mapEngineManager.deleteTileSet(offlineMapView._currentSelection) QGroundControl.mapEngineManager.deleteTileSet(offlineMapView._currentSelection)
deleteSystemSetConfirmationDialog.hideDialog() deleteConfirmationDialog.hideDialog()
leaveInfoView() leaveInfoView()
showList() showList()
} }
...@@ -351,35 +335,26 @@ QGCView { ...@@ -351,35 +335,26 @@ QGCView {
mapControl: _map mapControl: _map
} }
//-----------------------------------------------------------------
//-- Show Set Info //-- Show Set Info
Rectangle { Rectangle {
id: infoView id: infoView
anchors.margins: ScreenTools.defaultFontPixelWidth anchors.margins: ScreenTools.defaultFontPixelHeight
y: Math.max(anchors.margins, (parent.height - (anchors.margins * 2) - height) / 2)
anchors.right: parent.right anchors.right: parent.right
width: Math.max(ScreenTools.defaultFontPixelWidth * 20, controlInfoFlickable.width + (infoView._margins * 2)) anchors.verticalCenter: parent.verticalCenter
height: Math.min(parent.height - (anchors.margins * 2), controlInfoFlickable.y + controlInfoColumn.height + ScreenTools.defaultFontPixelHeight) width: tileInfoColumn.width + (ScreenTools.defaultFontPixelWidth * 2)
color: qgcPal.window height: tileInfoColumn.height + (ScreenTools.defaultFontPixelHeight * 2)
opacity: 0.85 color: Qt.rgba(qgcPal.window.r, qgcPal.window.g, qgcPal.window.b, 0.85)
radius: ScreenTools.defaultFontPixelWidth * 0.5 radius: ScreenTools.defaultFontPixelWidth * 0.5
visible: false visible: false
property bool _extraButton: !_defaultSet && ((!offlineMapView._currentSelection.complete && !offlineMapView._currentSelection.downloading) || (!offlineMapView._currentSelection.complete && offlineMapView._currentSelection.downloading))
readonly property real _margins: ScreenTools.defaultFontPixelHeight / 2 property real _labelWidth: ScreenTools.defaultFontPixelWidth * 10
property real _valueWidth: ScreenTools.defaultFontPixelWidth * 14
QGCLabel {
anchors.margins: ScreenTools.defaultFontPixelHeight / 4
anchors.top: parent.top
anchors.right: parent.right
text: "X"
}
Column { Column {
id: titleColumn id: tileInfoColumn
anchors.margins: infoView._margins anchors.margins: ScreenTools.defaultFontPixelHeight * 0.5
anchors.top: parent.top spacing: ScreenTools.defaultFontPixelHeight * 0.5
anchors.left: parent.left anchors.centerIn: parent
anchors.right: parent.right
QGCLabel { QGCLabel {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
...@@ -388,222 +363,113 @@ QGCView { ...@@ -388,222 +363,113 @@ QGCView {
font.pointSize: _saveRealEstate ? ScreenTools.defaultFontPointSize : ScreenTools.mediumFontPointSize font.pointSize: _saveRealEstate ? ScreenTools.defaultFontPointSize : ScreenTools.mediumFontPointSize
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
} }
QGCLabel { QGCLabel {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
text: offlineMapView._currentSelection ? offlineMapView._currentSelection.description : "" text: {
visible: text !== qsTr("Description") if(offlineMapView._currentSelection) {
if(offlineMapView._currentSelection.defaultSet)
return qsTr("System Wide Tile Cache");
else
return "(" + offlineMapView._currentSelection.mapTypeStr + ")"
} else
return "";
}
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
} }
//-- Tile Sets
QGCLabel { Row {
anchors.left: parent.left spacing: ScreenTools.defaultFontPixelWidth
anchors.right: parent.right anchors.horizontalCenter: parent.horizontalCenter
wrapMode: Text.WordWrap visible: !_defaultSet
text: offlineMapView._currentSelection ? "(" + offlineMapView._currentSelection.mapTypeStr + ")" : "" QGCLabel { text: qsTr("Zoom Levels:"); width: infoView._labelWidth; }
horizontalAlignment: Text.AlignHCenter QGCLabel { text: offlineMapView._currentSelection ? (offlineMapView._currentSelection.minZoom + " - " + offlineMapView._currentSelection.maxZoom) : ""; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
} }
Row {
} spacing: ScreenTools.defaultFontPixelWidth
anchors.horizontalCenter: parent.horizontalCenter
MouseArea { visible: !_defaultSet
anchors.fill: titleColumn QGCLabel { text: qsTr("Total:"); width: infoView._labelWidth; }
preventStealing: true QGCLabel { text: (offlineMapView._currentSelection ? offlineMapView._currentSelection.totalTileCountStr : "") + " (" + (offlineMapView._currentSelection ? offlineMapView._currentSelection.totalTilesSizeStr : "") + ")"; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
}
onClicked: { Row {
leaveInfoView() spacing: ScreenTools.defaultFontPixelWidth
showList() anchors.horizontalCenter: parent.horizontalCenter
visible: offlineMapView && offlineMapView._currentSelection && !_defaultSet && offlineMapView._currentSelection.uniqueTileCount > 0
QGCLabel { text: qsTr("Unique:"); width: infoView._labelWidth; }
QGCLabel { text: (offlineMapView._currentSelection ? offlineMapView._currentSelection.uniqueTileCountStr : "") + " (" + (offlineMapView._currentSelection ? offlineMapView._currentSelection.uniqueTileSizeStr : "") + ")"; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
} }
}
QGCFlickable {
id: controlInfoFlickable
anchors.margins: infoView._margins
anchors.top: titleColumn.bottom
anchors.bottom: parent.bottom
anchors.left: parent.left
width: controlInfoColumn.width
clip: true
contentHeight: controlInfoColumn.height
Column {
id: controlInfoColumn
spacing: ScreenTools.defaultFontPixelHeight
GridLayout {
columns: 2
rowSpacing: 0
QGCLabel { text: qsTr("Min Zoom:") }
QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.minZoom : "" }
QGCLabel { text: qsTr("Max Zoom:") }
QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.maxZoom : "" }
QGCLabel { text: qsTr("Total:") }
QGCLabel { text: (offlineMapView._currentSelection ? offlineMapView._currentSelection.numTilesStr : "") + " (" + (offlineMapView._currentSelection ? offlineMapView._currentSelection.tilesSizeStr : "") + ")" }
QGCLabel {
text: qsTr("Downloaded:")
visible: offlineMapView._currentSelection && !offlineMapView._currentSelection.complete
}
QGCLabel {
text: (offlineMapView._currentSelection ? offlineMapView._currentSelection.savedTilesStr : "") + " (" + (offlineMapView._currentSelection ? offlineMapView._currentSelection.savedSizeStr : "") + ")"
visible: offlineMapView._currentSelection && !offlineMapView._currentSelection.complete
}
QGCLabel {
text: qsTr("Error Count:")
visible: offlineMapView._currentSelection && !offlineMapView._currentSelection.complete
}
QGCLabel {
text: offlineMapView._currentSelection ? offlineMapView._currentSelection.errorCountStr : ""
visible: offlineMapView._currentSelection && !offlineMapView._currentSelection.complete
}
}
Row {
spacing: ScreenTools.defaultFontPixelWidth
anchors.horizontalCenter: parent.horizontalCenter
visible: offlineMapView && offlineMapView._currentSelection && !_defaultSet && !offlineMapView._currentSelection.complete
QGCLabel { text: qsTr("Downloaded:"); width: infoView._labelWidth; }
QGCLabel { text: (offlineMapView._currentSelection ? offlineMapView._currentSelection.savedTileCountStr : "") + " (" + (offlineMapView._currentSelection ? offlineMapView._currentSelection.savedTileSizeStr : "") + ")"; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
}
Row {
spacing: ScreenTools.defaultFontPixelWidth
anchors.horizontalCenter: parent.horizontalCenter
visible: offlineMapView && offlineMapView._currentSelection && !_defaultSet && !offlineMapView._currentSelection.complete && offlineMapView._currentSelection.errorCount > 0
QGCLabel { text: qsTr("Error Count:"); width: infoView._labelWidth; }
QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.errorCountStr : ""; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
}
//-- Default Tile Set
Row {
spacing: ScreenTools.defaultFontPixelWidth
anchors.horizontalCenter: parent.horizontalCenter
visible: _defaultSet
QGCLabel { text: qsTr("Size:"); width: infoView._labelWidth; }
QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.savedTileSizeStr : ""; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
}
Row {
spacing: ScreenTools.defaultFontPixelWidth
anchors.horizontalCenter: parent.horizontalCenter
visible: _defaultSet
QGCLabel { text: qsTr("Tile Count:"); width: infoView._labelWidth; }
QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.savedTileCountStr : ""; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
}
Row {
spacing: ScreenTools.defaultFontPixelWidth
anchors.horizontalCenter: parent.horizontalCenter
QGCButton { QGCButton {
text: qsTr("Resume Download") text: qsTr("Resume Download")
visible: offlineMapView._currentSelection && (!offlineMapView._currentSelection.complete && !offlineMapView._currentSelection.downloading) visible: offlineMapView._currentSelection && offlineMapView._currentSelection && !_defaultSet && (!offlineMapView._currentSelection.complete && !offlineMapView._currentSelection.downloading)
width: ScreenTools.defaultFontPixelWidth * 16
onClicked: { onClicked: {
if(offlineMapView._currentSelection) if(offlineMapView._currentSelection)
offlineMapView._currentSelection.resumeDownloadTask() offlineMapView._currentSelection.resumeDownloadTask()
} }
} }
QGCButton { QGCButton {
text: qsTr("Cancel Download") text: qsTr("Cancel Download")
visible: offlineMapView._currentSelection && (!offlineMapView._currentSelection.complete && offlineMapView._currentSelection.downloading) visible: offlineMapView._currentSelection && offlineMapView._currentSelection && !_defaultSet && (!offlineMapView._currentSelection.complete && offlineMapView._currentSelection.downloading)
width: ScreenTools.defaultFontPixelWidth * 16
onClicked: { onClicked: {
if(offlineMapView._currentSelection) if(offlineMapView._currentSelection)
offlineMapView._currentSelection.cancelDownloadTask() offlineMapView._currentSelection.cancelDownloadTask()
} }
} }
QGCButton { QGCButton {
text: qsTr("Delete") text: qsTr("Delete")
width: ScreenTools.defaultFontPixelWidth * (infoView._extraButton ? 6 : 10)
onClicked: showDialog(deleteConfirmationDialogComponent, qsTr("Confirm Delete"), qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No) onClicked: showDialog(deleteConfirmationDialogComponent, qsTr("Confirm Delete"), qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
} }
} // Column
} // QGCFlickable
} // Rectangle - infoView
//-- Show Default Set Info
Rectangle {
id: defaultInfoView
anchors.margins: ScreenTools.defaultFontPixelWidth
y: Math.max(anchors.margins, (parent.height - (anchors.margins * 2) - height) / 2)
anchors.right: parent.right
width: ScreenTools.defaultFontPixelWidth * 20
height: Math.min(parent.height - (anchors.margins * 2), defaultControlInfoFlickable.y + defaultControlInfoColumn.height + ScreenTools.defaultFontPixelHeight)
color: qgcPal.window
opacity: 0.85
radius: ScreenTools.defaultFontPixelWidth * 0.5
visible: false
QGCLabel {
anchors.margins: ScreenTools.defaultFontPixelHeight / 4
anchors.top: parent.top
anchors.right: parent.right
text: "X"
}
Column {
id: defaultTitleColumn
anchors.margins: ScreenTools.defaultFontPixelHeight / 2
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
QGCLabel {
anchors.left: parent.left
anchors.right: parent.right
wrapMode: Text.WordWrap
text: offlineMapView._currentSelection ? offlineMapView._currentSelection.name : ""
font.pointSize: _saveRealEstate ? ScreenTools.defaultFontPointSize : ScreenTools.mediumFontPointSize
horizontalAlignment: Text.AlignHCenter
}
QGCLabel {
anchors.left: parent.left
anchors.right: parent.right
wrapMode: Text.WordWrap
text: qsTr("System Wide Tile Cache")
horizontalAlignment: Text.AlignHCenter
}
}
MouseArea {
anchors.fill: defaultTitleColumn
preventStealing: true
onClicked: {
leaveInfoView()
showList()
}
}
QGCFlickable {
id: defaultControlInfoFlickable
anchors.margins: ScreenTools.defaultFontPixelHeight
anchors.top: defaultTitleColumn.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
clip: true
contentHeight: defaultControlInfoColumn.height
Column {
id: defaultControlInfoColumn
anchors.left: parent.left
anchors.right: parent.right
spacing: ScreenTools.defaultFontPixelHeight
GridLayout {
columns: 2
rowSpacing: 0
QGCLabel {
Layout.columnSpan: 2
text: qsTr("System Cache")
}
QGCLabel { text: qsTr("Size:") }
QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.tilesSizeStr : "" }
QGCLabel { text: qsTr("Tile Count:") }
QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.numTilesStr : "" }
Item {
width: 1
height: ScreenTools.defaultFontPixelHeight
Layout.columnSpan: 2
}
QGCLabel {
Layout.columnSpan: 2
text: qsTr("All Sets")
}
QGCLabel { text: qsTr("Size:") }
QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.savedSizeStr : "" }
QGCLabel { text: qsTr("Tile Count:") }
QGCLabel { text: offlineMapView._currentSelection ? offlineMapView._currentSelection.savedTilesStr : ""}
}
QGCButton { QGCButton {
text: qsTr("Delete All") text: qsTr("Close")
onClicked: showDialog(deleteSystemSetConfirmationDialogComponent, qsTr("Confirm Delete All"), qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No) width: ScreenTools.defaultFontPixelWidth * (infoView._extraButton ? 6 : 10)
onClicked: {
leaveInfoView()
showList()
}
} }
} // Column }
} // QGCFlickable }
} // Rectangle - defaultInfoView } // Rectangle - infoView
//-----------------------------------------------------------------
//-- Add new set
Item { Item {
id: addNewSetView id: addNewSetView
anchors.fill: parent anchors.fill: parent
...@@ -667,13 +533,14 @@ QGCView { ...@@ -667,13 +533,14 @@ QGCView {
border.color: _mapAdjustedColor border.color: _mapAdjustedColor
color: "transparent" color: "transparent"
visible: _showPreview visible: _showPreview
QGCLabel { QGCLabel {
anchors.fill: parent anchors.centerIn: parent
horizontalAlignment: Text.AlignHCenter color: _mapAdjustedColor
verticalAlignment: Text.AlignVCenter text: qsTr("Min Zoom: %1").arg(sliderMinZoom.value)
color: _mapAdjustedColor }
text: qsTr("Min Zoom: %1").arg(sliderMinZoom.value) MouseArea {
anchors.fill: parent
onClicked: _showPreview = false
} }
} }
...@@ -682,26 +549,15 @@ QGCView { ...@@ -682,26 +549,15 @@ QGCView {
border.color: _mapAdjustedColor border.color: _mapAdjustedColor
color: "transparent" color: "transparent"
visible: _showPreview visible: _showPreview
QGCLabel { QGCLabel {
anchors.fill: parent anchors.centerIn: parent
horizontalAlignment: Text.AlignHCenter color: _mapAdjustedColor
verticalAlignment: Text.AlignVCenter text: qsTr("Max Zoom: %1").arg(sliderMaxZoom.value)
color: _mapAdjustedColor }
text: qsTr("Max Zoom: %1").arg(sliderMaxZoom.value) MouseArea {
anchors.fill: parent
onClicked: _showPreview = false
} }
}
MouseArea {
anchors.fill: minZoomPreview
visible: _showPreview
onClicked: _showPreview = false
}
MouseArea {
anchors.fill: maxZoomPreview
visible: _showPreview
onClicked: _showPreview = false
} }
QGCButton { QGCButton {
...@@ -715,21 +571,13 @@ QGCView { ...@@ -715,21 +571,13 @@ QGCView {
//-- Add new set dialog //-- Add new set dialog
Rectangle { Rectangle {
anchors.margins: ScreenTools.defaultFontPixelWidth anchors.margins: ScreenTools.defaultFontPixelWidth
y: Math.max(anchors.margins, (parent.height - (anchors.margins * 2) - height) / 2) anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right anchors.right: parent.right
width: ScreenTools.defaultFontPixelWidth * 20 width: ScreenTools.defaultFontPixelWidth * 24
height: Math.min(parent.height - (anchors.margins * 2), addNewSetFlickable.y + addNewSetColumn.height + ScreenTools.defaultFontPixelHeight) height: Math.min(parent.height - (anchors.margins * 2), addNewSetFlickable.y + addNewSetColumn.height + ScreenTools.defaultFontPixelHeight)
color: qgcPal.window color: Qt.rgba(qgcPal.window.r, qgcPal.window.g, qgcPal.window.b, 0.85)
opacity: 0.85
radius: ScreenTools.defaultFontPixelWidth * 0.5 radius: ScreenTools.defaultFontPixelWidth * 0.5
QGCLabel {
anchors.margins: ScreenTools.defaultFontPixelHeight / 4
anchors.top: parent.top
anchors.right: parent.right
text: "X"
}
QGCLabel { QGCLabel {
id: addNewSetLabel id: addNewSetLabel
anchors.margins: ScreenTools.defaultFontPixelHeight / 2 anchors.margins: ScreenTools.defaultFontPixelHeight / 2
...@@ -742,12 +590,6 @@ QGCView { ...@@ -742,12 +590,6 @@ QGCView {
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
} }
MouseArea {
anchors.fill: addNewSetLabel
preventStealing: true
onClicked: showList()
}
QGCFlickable { QGCFlickable {
id: addNewSetFlickable id: addNewSetFlickable
anchors.leftMargin: ScreenTools.defaultFontPixelWidth anchors.leftMargin: ScreenTools.defaultFontPixelWidth
...@@ -770,9 +612,7 @@ QGCView { ...@@ -770,9 +612,7 @@ QGCView {
Column { Column {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
QGCLabel { text: qsTr("Name:") } QGCLabel { text: qsTr("Name:") }
QGCTextField { QGCTextField {
id: setName id: setName
anchors.left: parent.left anchors.left: parent.left
...@@ -783,25 +623,21 @@ QGCView { ...@@ -783,25 +623,21 @@ QGCView {
Column { Column {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
QGCLabel { QGCLabel {
text: qsTr("Map type:") text: qsTr("Map type:")
visible: !_saveRealEstate visible: !_saveRealEstate
} }
QGCComboBox { QGCComboBox {
id: mapCombo id: mapCombo
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
model: QGroundControl.mapEngineManager.mapList model: QGroundControl.mapEngineManager.mapList
onActivated: { onActivated: {
mapType = textAt(index) mapType = textAt(index)
if(_dropButtonsExclusiveGroup.current) if(_dropButtonsExclusiveGroup.current)
_dropButtonsExclusiveGroup.current.checked = false _dropButtonsExclusiveGroup.current.checked = false
_dropButtonsExclusiveGroup.current = null _dropButtonsExclusiveGroup.current = null
} }
Component.onCompleted: { Component.onCompleted: {
var index = mapCombo.find(mapType) var index = mapCombo.find(mapType)
if (index === -1) { if (index === -1) {
...@@ -823,7 +659,7 @@ QGCView { ...@@ -823,7 +659,7 @@ QGCView {
Column { Column {
id: zoomColumn id: zoomColumn
anchors.margins: ScreenTools.defaultFontPixelHeight / 4 anchors.margins: ScreenTools.defaultFontPixelHeight * 0.25
anchors.top: parent.top anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
...@@ -842,11 +678,8 @@ QGCView { ...@@ -842,11 +678,8 @@ QGCView {
maximumValue: maxZoomLevel maximumValue: maxZoomLevel
stepSize: 1 stepSize: 1
updateValueWhileDragging: true updateValueWhileDragging: true
property real _savedZoom property real _savedZoom
Component.onCompleted: Math.max(sliderMinZoom.value = _map.zoomLevel - 4, 2)
Component.onCompleted: sliderMinZoom.value = _map.zoomLevel - 2
onValueChanged: { onValueChanged: {
if(sliderMinZoom.value > sliderMaxZoom.value) { if(sliderMinZoom.value > sliderMaxZoom.value) {
sliderMaxZoom.value = sliderMinZoom.value sliderMaxZoom.value = sliderMinZoom.value
...@@ -856,8 +689,8 @@ QGCView { ...@@ -856,8 +689,8 @@ QGCView {
} // Slider - min zoom } // Slider - min zoom
QGCLabel { QGCLabel {
text: qsTr("Max Zoom: %1").arg(sliderMaxZoom.value) text: qsTr("Max Zoom: %1").arg(sliderMaxZoom.value)
font.pointSize: _adjustableFontPointSize font.pointSize: _adjustableFontPointSize
} }
Slider { Slider {
...@@ -869,11 +702,8 @@ QGCView { ...@@ -869,11 +702,8 @@ QGCView {
maximumValue: maxZoomLevel maximumValue: maxZoomLevel
stepSize: 1 stepSize: 1
updateValueWhileDragging: true updateValueWhileDragging: true
property real _savedZoom property real _savedZoom
Component.onCompleted: Math.min(sliderMaxZoom.value = _map.zoomLevel + 2, 20)
Component.onCompleted: sliderMaxZoom.value = _map.zoomLevel + 2
onValueChanged: { onValueChanged: {
if(sliderMaxZoom.value < sliderMinZoom.value) { if(sliderMaxZoom.value < sliderMinZoom.value) {
sliderMinZoom.value = sliderMaxZoom.value sliderMinZoom.value = sliderMaxZoom.value
...@@ -885,18 +715,17 @@ QGCView { ...@@ -885,18 +715,17 @@ QGCView {
GridLayout { GridLayout {
columns: 2 columns: 2
rowSpacing: 0 rowSpacing: 0
QGCLabel { QGCLabel {
text: qsTr("Tile Count") text: qsTr("Count:")
font.pointSize: _adjustableFontPointSize font.pointSize: _adjustableFontPointSize
} }
QGCLabel { QGCLabel {
text: QGroundControl.mapEngineManager.tileCountStr text: QGroundControl.mapEngineManager.tileCountStr
font.pointSize: _adjustableFontPointSize font.pointSize: _adjustableFontPointSize
} }
QGCLabel { QGCLabel {
text: qsTr("Set Size (Est)") text: qsTr("Est Size:")
font.pointSize: _adjustableFontPointSize font.pointSize: _adjustableFontPointSize
} }
QGCLabel { QGCLabel {
...@@ -907,27 +736,30 @@ QGCView { ...@@ -907,27 +736,30 @@ QGCView {
} // Column - Zoom info } // Column - Zoom info
} // Rectangle - Zoom info } // Rectangle - Zoom info
QGCButton { Row {
text: _tooManyTiles ? qsTr("Too many tiles") : qsTr("Download") spacing: ScreenTools.defaultFontPixelWidth
enabled: !_tooManyTiles && setName.text.length > 0
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
QGCButton {
property bool _tooManyTiles: QGroundControl.mapEngineManager.tileCount > _maxTilesForDownload text: _tooManyTiles ? qsTr("Too many tiles") : qsTr("Download")
enabled: !_tooManyTiles && setName.text.length > 0
onClicked: { property bool _tooManyTiles: QGroundControl.mapEngineManager.tileCount > _maxTilesForDownload
if(QGroundControl.mapEngineManager.findName(setName.text)) { onClicked: {
duplicateName.visible = true if(QGroundControl.mapEngineManager.findName(setName.text)) {
} else { duplicateName.visible = true
/* This does not work if hosted by QQuickWidget. Waiting until we're 100% QtQuick } else {
var mapImage QGroundControl.mapEngineManager.startDownload(setName.text, mapType);
_map.grabToImage(function(result) { mapImage = result; }) showList()
QGroundControl.mapEngineManager.startDownload(setName.text, "Description", mapType, mapImage); }
*/ }
QGroundControl.mapEngineManager.startDownload(setName.text, "Description" /* Description */, mapType); }
QGCButton {
text: qsTr("Cancel")
onClicked: {
showList() showList()
} }
} }
} }
} // Column } // Column
} // QGCFlickable } // QGCFlickable
} // Rectangle - Add new set dialog } // Rectangle - Add new set dialog
...@@ -965,6 +797,7 @@ QGCView { ...@@ -965,6 +797,7 @@ QGCView {
delegate: OfflineMapButton { delegate: OfflineMapButton {
text: object.name text: object.name
size: object.downloadStatus size: object.downloadStatus
tiles: object.totalTileCount
complete: object.complete complete: object.complete
width: firstButton.width width: firstButton.width
height: ScreenTools.defaultFontPixelHeight * 2 height: ScreenTools.defaultFontPixelHeight * 2
......
...@@ -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