mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
Improved DEM downloads handling logic
This commit is contained in:
parent
133aac3bd4
commit
7f6ac2e4c3
@ -363,13 +363,12 @@ void GUI::createActions(TreeNode<MapAction*> &mapActions,
|
|||||||
_showWaypointsAction = new QAction(tr("Show waypoints"), this);
|
_showWaypointsAction = new QAction(tr("Show waypoints"), this);
|
||||||
_showWaypointsAction->setMenuRole(QAction::NoRole);
|
_showWaypointsAction->setMenuRole(QAction::NoRole);
|
||||||
_showWaypointsAction->setCheckable(true);
|
_showWaypointsAction->setCheckable(true);
|
||||||
connect(_showWaypointsAction, &QAction::triggered, _mapView,
|
connect(_showWaypointsAction, &QAction::triggered, this,
|
||||||
&MapView::showWaypoints);
|
&GUI::showWaypoints);
|
||||||
_showAreasAction = new QAction(tr("Show areas"), this);
|
_showAreasAction = new QAction(tr("Show areas"), this);
|
||||||
_showAreasAction->setMenuRole(QAction::NoRole);
|
_showAreasAction->setMenuRole(QAction::NoRole);
|
||||||
_showAreasAction->setCheckable(true);
|
_showAreasAction->setCheckable(true);
|
||||||
connect(_showAreasAction, &QAction::triggered, _mapView,
|
connect(_showAreasAction, &QAction::triggered, this, &GUI::showAreas);
|
||||||
&MapView::showAreas);
|
|
||||||
_showWaypointLabelsAction = new QAction(tr("Waypoint labels"), this);
|
_showWaypointLabelsAction = new QAction(tr("Waypoint labels"), this);
|
||||||
_showWaypointLabelsAction->setMenuRole(QAction::NoRole);
|
_showWaypointLabelsAction->setMenuRole(QAction::NoRole);
|
||||||
_showWaypointLabelsAction->setCheckable(true);
|
_showWaypointLabelsAction->setCheckable(true);
|
||||||
@ -867,6 +866,7 @@ bool GUI::loadFile(const QString &fileName, bool silent)
|
|||||||
updateStatusBarInfo();
|
updateStatusBarInfo();
|
||||||
updateWindowTitle();
|
updateWindowTitle();
|
||||||
updateGraphTabs();
|
updateGraphTabs();
|
||||||
|
updateDEMDownloadAction();
|
||||||
|
|
||||||
QString error = tr("Error loading data file:") + "\n\n"
|
QString error = tr("Error loading data file:") + "\n\n"
|
||||||
+ fileName + "\n\n" + data.errorString();
|
+ fileName + "\n\n" + data.errorString();
|
||||||
@ -932,6 +932,8 @@ void GUI::loadData(const Data &data)
|
|||||||
pi->setMarkerPosition(gt->sliderPosition());
|
pi->setMarkerPosition(gt->sliderPosition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateDEMDownloadAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::openPOIFile()
|
void GUI::openPOIFile()
|
||||||
@ -1073,7 +1075,6 @@ void GUI::openOptions()
|
|||||||
_dem->setAuthorization(options.demAuthorization
|
_dem->setAuthorization(options.demAuthorization
|
||||||
? Authorization(options.demUsername, options.demPassword)
|
? Authorization(options.demUsername, options.demPassword)
|
||||||
: Authorization());
|
: Authorization());
|
||||||
_downloadDEMAction->setEnabled(!options.demURL.isEmpty());
|
|
||||||
|
|
||||||
if (options.pixmapCache != _options.pixmapCache)
|
if (options.pixmapCache != _options.pixmapCache)
|
||||||
QPixmapCache::setCacheLimit(options.pixmapCache * 1024);
|
QPixmapCache::setCacheLimit(options.pixmapCache * 1024);
|
||||||
@ -1094,6 +1095,8 @@ void GUI::openOptions()
|
|||||||
reloadFiles();
|
reloadFiles();
|
||||||
|
|
||||||
_options = options;
|
_options = options;
|
||||||
|
|
||||||
|
updateDEMDownloadAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::printFile()
|
void GUI::printFile()
|
||||||
@ -1387,6 +1390,7 @@ void GUI::reloadFiles()
|
|||||||
_fileActionGroup->setEnabled(false);
|
_fileActionGroup->setEnabled(false);
|
||||||
else
|
else
|
||||||
_browser->setCurrent(_files.last());
|
_browser->setCurrent(_files.last());
|
||||||
|
updateDEMDownloadAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::closeFiles()
|
void GUI::closeFiles()
|
||||||
@ -1419,6 +1423,7 @@ void GUI::closeAll()
|
|||||||
updateStatusBarInfo();
|
updateStatusBarInfo();
|
||||||
updateWindowTitle();
|
updateWindowTitle();
|
||||||
updateGraphTabs();
|
updateGraphTabs();
|
||||||
|
updateDEMDownloadAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::showGraphs(bool show)
|
void GUI::showGraphs(bool show)
|
||||||
@ -1478,6 +1483,7 @@ void GUI::showTracks(bool show)
|
|||||||
|
|
||||||
updateStatusBarInfo();
|
updateStatusBarInfo();
|
||||||
updateGraphTabs();
|
updateGraphTabs();
|
||||||
|
updateDEMDownloadAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::showRoutes(bool show)
|
void GUI::showRoutes(bool show)
|
||||||
@ -1489,6 +1495,19 @@ void GUI::showRoutes(bool show)
|
|||||||
|
|
||||||
updateStatusBarInfo();
|
updateStatusBarInfo();
|
||||||
updateGraphTabs();
|
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)
|
void GUI::showGraphGrids(bool show)
|
||||||
@ -1713,22 +1732,26 @@ void GUI::clearMapCache()
|
|||||||
|
|
||||||
void GUI::downloadDEM()
|
void GUI::downloadDEM()
|
||||||
{
|
{
|
||||||
_demRect = _mapView->boundingRect();
|
RectC br(_mapView->boundingRect());
|
||||||
|
_demRects.append(br);
|
||||||
|
|
||||||
if (_dem->loadTiles(_demRect))
|
if (!_dem->loadTiles(br) && _demRects.size() == 1)
|
||||||
_downloadDEMAction->setEnabled(false);
|
|
||||||
else
|
|
||||||
demLoaded();
|
demLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::demLoaded()
|
void GUI::demLoaded()
|
||||||
{
|
{
|
||||||
if (!_dem->checkTiles(_demRect))
|
for (int i = 0; i < _demRects.size(); i++) {
|
||||||
QMessageBox::warning(this, APP_NAME,
|
if (!_dem->checkTiles(_demRects.at(i))) {
|
||||||
tr("Could not download all required DEM files."));
|
QMessageBox::warning(this, APP_NAME,
|
||||||
|
tr("Could not download all required DEM files."));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DEM::clearCache();
|
||||||
|
_demRects.clear();
|
||||||
reloadFiles();
|
reloadFiles();
|
||||||
_downloadDEMAction->setEnabled(!_options.demURL.isEmpty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::updateStatusBarInfo()
|
void GUI::updateStatusBarInfo()
|
||||||
@ -1886,6 +1909,12 @@ bool GUI::updateGraphTabs()
|
|||||||
return (hidden != _graphTabWidget->isHidden());
|
return (hidden != _graphTabWidget->isHidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GUI::updateDEMDownloadAction()
|
||||||
|
{
|
||||||
|
_downloadDEMAction->setEnabled(!_options.demURL.isEmpty()
|
||||||
|
&& !_dem->checkTiles(_mapView->boundingRect()));
|
||||||
|
}
|
||||||
|
|
||||||
void GUI::setTimeType(TimeType type)
|
void GUI::setTimeType(TimeType type)
|
||||||
{
|
{
|
||||||
for (int i = 0; i <_tabs.count(); i++)
|
for (int i = 0; i <_tabs.count(); i++)
|
||||||
@ -2703,8 +2732,6 @@ void GUI::readSettings()
|
|||||||
if (_options.demAuthorization)
|
if (_options.demAuthorization)
|
||||||
_dem->setAuthorization(Authorization(_options.demUsername,
|
_dem->setAuthorization(Authorization(_options.demUsername,
|
||||||
_options.demPassword));
|
_options.demPassword));
|
||||||
if (!_options.demURL.isEmpty())
|
|
||||||
_downloadDEMAction->setEnabled(true);
|
|
||||||
|
|
||||||
QPixmapCache::setCacheLimit(_options.pixmapCache * 1024);
|
QPixmapCache::setCacheLimit(_options.pixmapCache * 1024);
|
||||||
|
|
||||||
|
@ -67,6 +67,8 @@ private slots:
|
|||||||
void showFullscreen(bool show);
|
void showFullscreen(bool show);
|
||||||
void showTracks(bool show);
|
void showTracks(bool show);
|
||||||
void showRoutes(bool show);
|
void showRoutes(bool show);
|
||||||
|
void showAreas(bool show);
|
||||||
|
void showWaypoints(bool show);
|
||||||
void loadMap();
|
void loadMap();
|
||||||
void loadMapDir();
|
void loadMapDir();
|
||||||
void nextMap();
|
void nextMap();
|
||||||
@ -143,6 +145,7 @@ private:
|
|||||||
void updateStatusBarInfo();
|
void updateStatusBarInfo();
|
||||||
void updateWindowTitle();
|
void updateWindowTitle();
|
||||||
bool updateGraphTabs();
|
bool updateGraphTabs();
|
||||||
|
void updateDEMDownloadAction();
|
||||||
|
|
||||||
TimeType timeType() const;
|
TimeType timeType() const;
|
||||||
Units units() const;
|
Units units() const;
|
||||||
@ -268,7 +271,7 @@ private:
|
|||||||
|
|
||||||
Units _units;
|
Units _units;
|
||||||
|
|
||||||
RectC _demRect;
|
QList<RectC> _demRects;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GUI_H
|
#endif // GUI_H
|
||||||
|
@ -1147,3 +1147,19 @@ void MapView::fitContentToSize()
|
|||||||
|
|
||||||
centerOn(contentCenter());
|
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;
|
||||||
|
}
|
||||||
|
@ -88,7 +88,7 @@ public:
|
|||||||
void clearMapCache();
|
void clearMapCache();
|
||||||
void fitContentToSize();
|
void fitContentToSize();
|
||||||
|
|
||||||
RectC boundingRect() const {return _tr | _rr | _wr | _ar;}
|
RectC boundingRect() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void showMap(bool show);
|
void showMap(bool show);
|
||||||
|
@ -559,6 +559,7 @@ QWidget *OptionsDialog::createDEMPage()
|
|||||||
|
|
||||||
InfoLabel *info = new InfoLabel(
|
InfoLabel *info = new InfoLabel(
|
||||||
tr("Use $lat and $lon for NYY/SYY and EXXX/WXXX in the URL."));
|
tr("Use $lat and $lon for NYY/SYY and EXXX/WXXX in the URL."));
|
||||||
|
info->setMinimumWidth(_demURL->minimumWidth());
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
QFormLayout *sourceLayout = new QFormLayout();
|
QFormLayout *sourceLayout = new QFormLayout();
|
||||||
|
@ -94,6 +94,10 @@ QString DEM::fileName(const QString &baseName)
|
|||||||
void DEM::setDir(const QString &path)
|
void DEM::setDir(const QString &path)
|
||||||
{
|
{
|
||||||
_dir = path;
|
_dir = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DEM::clearCache()
|
||||||
|
{
|
||||||
_data.clear();
|
_data.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void setDir(const QString &path);
|
static void setDir(const QString &path);
|
||||||
|
static void clearCache();
|
||||||
static qreal elevation(const Coordinates &c);
|
static qreal elevation(const Coordinates &c);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <QDir>
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include "common/rectc.h"
|
#include "common/rectc.h"
|
||||||
#include "demloader.h"
|
#include "demloader.h"
|
||||||
|
|
||||||
|
|
||||||
#define DOWNLOAD_LIMIT 32
|
#define DOWNLOAD_LIMIT 16
|
||||||
|
|
||||||
static QList<DEM::Tile> tiles(const RectC &rect)
|
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
|
/* Create the user DEM dir only when a download is requested as it will
|
||||||
override the global DEM dir. */
|
override the global DEM dir. */
|
||||||
if (!QDir().mkpath(_dir)) {
|
if (!_dir.mkpath(_dir.absolutePath())) {
|
||||||
qWarning("%s: %s", qPrintable(_dir), "Error creating DEM directory");
|
qWarning("%s: %s", qPrintable(_dir.canonicalPath()),
|
||||||
|
"Error creating DEM directory");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/* This also clears the DEM data cache which is necessary to use the data
|
DEM::setDir(_dir.path());
|
||||||
from the downloaded DEM tiles. */
|
|
||||||
DEM::setDir(_dir);
|
|
||||||
|
|
||||||
for (int i = 0; i < tl.size(); i++) {
|
for (int i = 0; i < tl.size(); i++) {
|
||||||
const DEM::Tile &t = tl.at(i);
|
const DEM::Tile &t = tl.at(i);
|
||||||
@ -62,8 +60,8 @@ bool DEMLoader::loadTiles(const RectC &rect)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dl.size() > DOWNLOAD_LIMIT) {
|
if (dl.size() > DOWNLOAD_LIMIT) {
|
||||||
qWarning("DEM download limit exceeded. Limit/requested: %u/%u.",
|
qWarning("Requested DEM area is too large (%u tiles)",
|
||||||
DOWNLOAD_LIMIT, (unsigned)dl.size());
|
(unsigned)dl.size());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,5 +96,5 @@ QUrl DEMLoader::tileUrl(const DEM::Tile &tile) const
|
|||||||
|
|
||||||
QString DEMLoader::tileFile(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
|
#define DEMLOADER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QDir>
|
||||||
#include "common/downloader.h"
|
#include "common/downloader.h"
|
||||||
#include "dem.h"
|
#include "dem.h"
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ private:
|
|||||||
|
|
||||||
Downloader *_downloader;
|
Downloader *_downloader;
|
||||||
QString _url;
|
QString _url;
|
||||||
QString _dir;
|
QDir _dir;
|
||||||
Authorization _authorization;
|
Authorization _authorization;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user