mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 03:29:16 +02:00
Improved DEM downloads handling logic
This commit is contained in:
@ -94,6 +94,10 @@ QString DEM::fileName(const QString &baseName)
|
||||
void DEM::setDir(const QString &path)
|
||||
{
|
||||
_dir = path;
|
||||
}
|
||||
|
||||
void DEM::clearCache()
|
||||
{
|
||||
_data.clear();
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
};
|
||||
|
||||
static void setDir(const QString &path);
|
||||
static void clearCache();
|
||||
static qreal elevation(const Coordinates &c);
|
||||
|
||||
private:
|
||||
|
@ -1,11 +1,10 @@
|
||||
#include <QtMath>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include "common/rectc.h"
|
||||
#include "demloader.h"
|
||||
|
||||
|
||||
#define DOWNLOAD_LIMIT 32
|
||||
#define DOWNLOAD_LIMIT 16
|
||||
|
||||
static QList<DEM::Tile> tiles(const RectC &rect)
|
||||
{
|
||||
@ -42,13 +41,12 @@ bool DEMLoader::loadTiles(const RectC &rect)
|
||||
|
||||
/* Create the user DEM dir only when a download is requested as it will
|
||||
override the global DEM dir. */
|
||||
if (!QDir().mkpath(_dir)) {
|
||||
qWarning("%s: %s", qPrintable(_dir), "Error creating DEM directory");
|
||||
if (!_dir.mkpath(_dir.absolutePath())) {
|
||||
qWarning("%s: %s", qPrintable(_dir.canonicalPath()),
|
||||
"Error creating DEM directory");
|
||||
return false;
|
||||
}
|
||||
/* This also clears the DEM data cache which is necessary to use the data
|
||||
from the downloaded DEM tiles. */
|
||||
DEM::setDir(_dir);
|
||||
DEM::setDir(_dir.path());
|
||||
|
||||
for (int i = 0; i < tl.size(); i++) {
|
||||
const DEM::Tile &t = tl.at(i);
|
||||
@ -62,8 +60,8 @@ bool DEMLoader::loadTiles(const RectC &rect)
|
||||
}
|
||||
|
||||
if (dl.size() > DOWNLOAD_LIMIT) {
|
||||
qWarning("DEM download limit exceeded. Limit/requested: %u/%u.",
|
||||
DOWNLOAD_LIMIT, (unsigned)dl.size());
|
||||
qWarning("Requested DEM area is too large (%u tiles)",
|
||||
(unsigned)dl.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -98,5 +96,5 @@ QUrl DEMLoader::tileUrl(const DEM::Tile &tile) const
|
||||
|
||||
QString DEMLoader::tileFile(const DEM::Tile &tile) const
|
||||
{
|
||||
return _dir + QLatin1Char('/') + tile.baseName();
|
||||
return _dir.absoluteFilePath(tile.baseName());
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define DEMLOADER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDir>
|
||||
#include "common/downloader.h"
|
||||
#include "dem.h"
|
||||
|
||||
@ -30,7 +31,7 @@ private:
|
||||
|
||||
Downloader *_downloader;
|
||||
QString _url;
|
||||
QString _dir;
|
||||
QDir _dir;
|
||||
Authorization _authorization;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user