1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Improved DEM downloads handling logic

This commit is contained in:
Martin Tůma 2021-09-01 13:08:34 +02:00
parent 133aac3bd4
commit 7f6ac2e4c3
9 changed files with 79 additions and 28 deletions

View File

@ -363,13 +363,12 @@ void GUI::createActions(TreeNode<MapAction*> &mapActions,
_showWaypointsAction = new QAction(tr("Show waypoints"), this);
_showWaypointsAction->setMenuRole(QAction::NoRole);
_showWaypointsAction->setCheckable(true);
connect(_showWaypointsAction, &QAction::triggered, _mapView,
&MapView::showWaypoints);
connect(_showWaypointsAction, &QAction::triggered, this,
&GUI::showWaypoints);
_showAreasAction = new QAction(tr("Show areas"), this);
_showAreasAction->setMenuRole(QAction::NoRole);
_showAreasAction->setCheckable(true);
connect(_showAreasAction, &QAction::triggered, _mapView,
&MapView::showAreas);
connect(_showAreasAction, &QAction::triggered, this, &GUI::showAreas);
_showWaypointLabelsAction = new QAction(tr("Waypoint labels"), this);
_showWaypointLabelsAction->setMenuRole(QAction::NoRole);
_showWaypointLabelsAction->setCheckable(true);
@ -867,6 +866,7 @@ bool GUI::loadFile(const QString &fileName, bool silent)
updateStatusBarInfo();
updateWindowTitle();
updateGraphTabs();
updateDEMDownloadAction();
QString error = tr("Error loading data file:") + "\n\n"
+ fileName + "\n\n" + data.errorString();
@ -932,6 +932,8 @@ void GUI::loadData(const Data &data)
pi->setMarkerPosition(gt->sliderPosition());
}
}
updateDEMDownloadAction();
}
void GUI::openPOIFile()
@ -1073,7 +1075,6 @@ void GUI::openOptions()
_dem->setAuthorization(options.demAuthorization
? Authorization(options.demUsername, options.demPassword)
: Authorization());
_downloadDEMAction->setEnabled(!options.demURL.isEmpty());
if (options.pixmapCache != _options.pixmapCache)
QPixmapCache::setCacheLimit(options.pixmapCache * 1024);
@ -1094,6 +1095,8 @@ void GUI::openOptions()
reloadFiles();
_options = options;
updateDEMDownloadAction();
}
void GUI::printFile()
@ -1387,6 +1390,7 @@ void GUI::reloadFiles()
_fileActionGroup->setEnabled(false);
else
_browser->setCurrent(_files.last());
updateDEMDownloadAction();
}
void GUI::closeFiles()
@ -1419,6 +1423,7 @@ void GUI::closeAll()
updateStatusBarInfo();
updateWindowTitle();
updateGraphTabs();
updateDEMDownloadAction();
}
void GUI::showGraphs(bool show)
@ -1478,6 +1483,7 @@ void GUI::showTracks(bool show)
updateStatusBarInfo();
updateGraphTabs();
updateDEMDownloadAction();
}
void GUI::showRoutes(bool show)
@ -1489,6 +1495,19 @@ void GUI::showRoutes(bool show)
updateStatusBarInfo();
updateGraphTabs();
updateDEMDownloadAction();
}
void GUI::showWaypoints(bool show)
{
_mapView->showWaypoints(show);
updateDEMDownloadAction();
}
void GUI::showAreas(bool show)
{
_mapView->showAreas(show);
updateDEMDownloadAction();
}
void GUI::showGraphGrids(bool show)
@ -1713,22 +1732,26 @@ void GUI::clearMapCache()
void GUI::downloadDEM()
{
_demRect = _mapView->boundingRect();
RectC br(_mapView->boundingRect());
_demRects.append(br);
if (_dem->loadTiles(_demRect))
_downloadDEMAction->setEnabled(false);
else
if (!_dem->loadTiles(br) && _demRects.size() == 1)
demLoaded();
}
void GUI::demLoaded()
{
if (!_dem->checkTiles(_demRect))
QMessageBox::warning(this, APP_NAME,
tr("Could not download all required DEM files."));
for (int i = 0; i < _demRects.size(); i++) {
if (!_dem->checkTiles(_demRects.at(i))) {
QMessageBox::warning(this, APP_NAME,
tr("Could not download all required DEM files."));
break;
}
}
DEM::clearCache();
_demRects.clear();
reloadFiles();
_downloadDEMAction->setEnabled(!_options.demURL.isEmpty());
}
void GUI::updateStatusBarInfo()
@ -1886,6 +1909,12 @@ bool GUI::updateGraphTabs()
return (hidden != _graphTabWidget->isHidden());
}
void GUI::updateDEMDownloadAction()
{
_downloadDEMAction->setEnabled(!_options.demURL.isEmpty()
&& !_dem->checkTiles(_mapView->boundingRect()));
}
void GUI::setTimeType(TimeType type)
{
for (int i = 0; i <_tabs.count(); i++)
@ -2703,8 +2732,6 @@ void GUI::readSettings()
if (_options.demAuthorization)
_dem->setAuthorization(Authorization(_options.demUsername,
_options.demPassword));
if (!_options.demURL.isEmpty())
_downloadDEMAction->setEnabled(true);
QPixmapCache::setCacheLimit(_options.pixmapCache * 1024);

View File

@ -67,6 +67,8 @@ private slots:
void showFullscreen(bool show);
void showTracks(bool show);
void showRoutes(bool show);
void showAreas(bool show);
void showWaypoints(bool show);
void loadMap();
void loadMapDir();
void nextMap();
@ -143,6 +145,7 @@ private:
void updateStatusBarInfo();
void updateWindowTitle();
bool updateGraphTabs();
void updateDEMDownloadAction();
TimeType timeType() const;
Units units() const;
@ -268,7 +271,7 @@ private:
Units _units;
RectC _demRect;
QList<RectC> _demRects;
};
#endif // GUI_H

View File

@ -1147,3 +1147,19 @@ void MapView::fitContentToSize()
centerOn(contentCenter());
}
RectC MapView::boundingRect() const
{
RectC rect;
if (_showTracks)
rect |= _tr;
if (_showRoutes)
rect |= _rr;
if (_showWaypoints)
rect |= _wr;
if (_showAreas)
rect |= _ar;
return rect;
}

View File

@ -88,7 +88,7 @@ public:
void clearMapCache();
void fitContentToSize();
RectC boundingRect() const {return _tr | _rr | _wr | _ar;}
RectC boundingRect() const;
public slots:
void showMap(bool show);

View File

@ -559,6 +559,7 @@ QWidget *OptionsDialog::createDEMPage()
InfoLabel *info = new InfoLabel(
tr("Use $lat and $lon for NYY/SYY and EXXX/WXXX in the URL."));
info->setMinimumWidth(_demURL->minimumWidth());
#ifdef Q_OS_MAC
QFormLayout *sourceLayout = new QFormLayout();

View File

@ -94,6 +94,10 @@ QString DEM::fileName(const QString &baseName)
void DEM::setDir(const QString &path)
{
_dir = path;
}
void DEM::clearCache()
{
_data.clear();
}

View File

@ -34,6 +34,7 @@ public:
};
static void setDir(const QString &path);
static void clearCache();
static qreal elevation(const Coordinates &c);
private:

View File

@ -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());
}

View File

@ -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;
};