1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-27 03:29:16 +02:00

Added support for downloading DEM tiles

This commit is contained in:
2021-08-30 20:31:33 +02:00
parent 94a0158243
commit 2232b011a1
24 changed files with 437 additions and 87 deletions

View File

@ -0,0 +1,14 @@
#include <QFormLayout>
#include "authenticationwidget.h"
AuthenticationWidget::AuthenticationWidget(QWidget *parent) : QWidget(parent)
{
_username = new QLineEdit();
_password = new QLineEdit();
QFormLayout *layout = new QFormLayout();
layout->addRow(tr("Username:"), _username);
layout->addRow(tr("Password:"), _password);
setLayout(layout);
}

View File

@ -0,0 +1,24 @@
#ifndef AUTHENTICATIONWIDGET_H
#define AUTHENTICATIONWIDGET_H
#include <QWidget>
#include <QLineEdit>
class AuthenticationWidget : public QWidget
{
Q_OBJECT
public:
AuthenticationWidget(QWidget *parent = 0);
QString username() const {return _username->text();}
QString password() const {return _password->text();}
void setUsername(const QString &username) {_username->setText(username);}
void setPassword(const QString &password) {_password->setText(password);}
private:
QLineEdit *_username, *_password;
};
#endif // AUTHENTICATIONWIDGET_H

View File

@ -29,6 +29,7 @@
#include "common/downloader.h"
#include "data/data.h"
#include "data/poi.h"
#include "data/demloader.h"
#include "map/maplist.h"
#include "map/emptymap.h"
#include "map/crs.h"
@ -62,6 +63,8 @@ GUI::GUI()
TreeNode<POIAction*> poiActions;
_poi = new POI(this);
_dem = new DEMLoader(ProgramPaths::demDir(true), this);
connect(_dem, &DEMLoader::finished, this, &GUI::demLoaded);
createMapView();
createGraphTabs();
@ -402,6 +405,12 @@ void GUI::createActions(TreeNode<MapAction*> &mapActions,
_showMarkerCoordinatesAction->setCheckable(true);
_showMarkerCoordinatesAction->setActionGroup(markerInfoGroup);
// DEM actions
_downloadDEMAction = new QAction(tr("Download DEM data"), this);
_downloadDEMAction->setMenuRole(QAction::NoRole);
_downloadDEMAction->setEnabled(false);
connect(_downloadDEMAction, &QAction::triggered, this, &GUI::downloadDEM);
// Graph actions
_showGraphsAction = new QAction(QIcon(SHOW_GRAPHS_ICON), tr("Show graphs"),
this);
@ -585,18 +594,6 @@ void GUI::createMenus(const TreeNode<MapAction*> &mapActions,
graphMenu->addSeparator();
graphMenu->addAction(_showGraphsAction);
_poiMenu = menuBar()->addMenu(tr("&POI"));
createPOINodeMenu(poiActions, _poiMenu);
_poisEnd = _poiMenu->addSeparator();
_poiMenu->addAction(_openPOIAction);
_poiMenu->addAction(_selectAllPOIAction);
_poiMenu->addAction(_unselectAllPOIAction);
_poiMenu->addSeparator();
_poiMenu->addAction(_showPOILabelsAction);
_poiMenu->addAction(_overlapPOIAction);
_poiMenu->addSeparator();
_poiMenu->addAction(_showPOIAction);
QMenu *dataMenu = menuBar()->addMenu(tr("&Data"));
dataMenu->addAction(_showWaypointLabelsAction);
dataMenu->addAction(_showRouteWaypointsAction);
@ -612,6 +609,22 @@ void GUI::createMenus(const TreeNode<MapAction*> &mapActions,
dataMenu->addAction(_showAreasAction);
dataMenu->addAction(_showWaypointsAction);
_poiMenu = menuBar()->addMenu(tr("&POI"));
createPOINodeMenu(poiActions, _poiMenu);
_poisEnd = _poiMenu->addSeparator();
_poiMenu->addAction(_openPOIAction);
_poiMenu->addAction(_selectAllPOIAction);
_poiMenu->addAction(_unselectAllPOIAction);
_poiMenu->addSeparator();
_poiMenu->addAction(_showPOILabelsAction);
_poiMenu->addAction(_overlapPOIAction);
_poiMenu->addSeparator();
_poiMenu->addAction(_showPOIAction);
QMenu *demMenu = menuBar()->addMenu(tr("DEM"));
demMenu->addSeparator();
demMenu->addAction(_downloadDEMAction);
QMenu *settingsMenu = menuBar()->addMenu(tr("&Settings"));
QMenu *timeMenu = settingsMenu->addMenu(tr("Time"));
timeMenu->addAction(_totalTimeAction);
@ -1052,6 +1065,16 @@ void GUI::openOptions()
if (options.poiRadius != _options.poiRadius)
_poi->setRadius(options.poiRadius);
if (options.demURL != _options.demURL)
_dem->setUrl(options.demURL);
if (options.demAuthorization != _options.demAuthorization
|| options.demUsername != _options.demUsername
|| options.demPassword != _options.demPassword)
_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);
@ -1688,6 +1711,26 @@ void GUI::clearMapCache()
_mapView->clearMapCache();
}
void GUI::downloadDEM()
{
_demRect = _mapView->boundingRect();
if (_dem->loadTiles(_demRect))
_downloadDEMAction->setEnabled(false);
else
demLoaded();
}
void GUI::demLoaded()
{
if (!_dem->checkTiles(_demRect))
QMessageBox::warning(this, APP_NAME,
tr("Could not download all required DEM files."));
reloadFiles();
_downloadDEMAction->setEnabled(!_options.demURL.isEmpty());
}
void GUI::updateStatusBarInfo()
{
if (_files.count() == 0)
@ -2236,6 +2279,14 @@ void GUI::writeSettings()
settings.setValue(USE_SEGMENTS_SETTING, _options.useSegments);
if (_options.poiRadius != POI_RADIUS_DEFAULT)
settings.setValue(POI_RADIUS_SETTING, _options.poiRadius);
if (_options.demURL != DEM_URL_DEFAULT)
settings.setValue(DEM_URL_SETTING, _options.demURL);
if (_options.demAuthorization != DEM_AUTH_DEFAULT)
settings.setValue(DEM_AUTH_SETTING, _options.demAuthorization);
if (_options.demUsername != DEM_USERNAME_DEFAULT)
settings.setValue(DEM_USERNAME_SETTING, _options.demUsername);
if (_options.demPassword != DEM_PASSWORD_DEFAULT)
settings.setValue(DEM_PASSWORD_SETTING, _options.demPassword);
if (_options.useOpenGL != USE_OPENGL_DEFAULT)
settings.setValue(USE_OPENGL_SETTING, _options.useOpenGL);
if (_options.enableHTTP2 != ENABLE_HTTP2_DEFAULT)
@ -2547,6 +2598,13 @@ void GUI::readSettings()
PAUSE_INTERVAL_DEFAULT).toInt();
_options.poiRadius = settings.value(POI_RADIUS_SETTING, POI_RADIUS_DEFAULT)
.toInt();
_options.demURL = settings.value(DEM_URL_SETTING, DEM_URL_DEFAULT).toString();
_options.demAuthorization = settings.value(DEM_AUTH_SETTING,
DEM_AUTH_DEFAULT).toBool();
_options.demUsername = settings.value(DEM_USERNAME_SETTING,
DEM_USERNAME_DEFAULT).toString();
_options.demPassword = settings.value(DEM_PASSWORD_SETTING,
DEM_PASSWORD_DEFAULT).toString();
_options.useOpenGL = settings.value(USE_OPENGL_SETTING, USE_OPENGL_DEFAULT)
.toBool();
_options.enableHTTP2 = settings.value(ENABLE_HTTP2_SETTING,
@ -2641,6 +2699,13 @@ void GUI::readSettings()
_poi->setRadius(_options.poiRadius);
_dem->setUrl(_options.demURL);
if (_options.demAuthorization)
_dem->setAuthorization(Authorization(_options.demUsername,
_options.demPassword));
if (!_options.demURL.isEmpty())
_downloadDEMAction->setEnabled(true);
QPixmapCache::setCacheLimit(_options.pixmapCache * 1024);
settings.endGroup();

View File

@ -7,6 +7,7 @@
#include <QDate>
#include <QPrinter>
#include "common/treenode.h"
#include "common/rectc.h"
#include "data/graph.h"
#include "units.h"
#include "timetype.h"
@ -32,6 +33,7 @@ class QScreen;
class MapAction;
class POIAction;
class Data;
class DEMLoader;
class GUI : public QMainWindow
{
@ -71,6 +73,7 @@ private slots:
void prevMap();
void openOptions();
void clearMapCache();
void downloadDEM();
void mapChanged(QAction *action);
void graphChanged(int);
@ -102,6 +105,8 @@ private slots:
void mapLoadedDir();
void mapInitialized();
void demLoaded();
private:
typedef QPair<QDateTime, QDateTime> DateTimeRange;
@ -224,6 +229,7 @@ private:
QAction *_showTicksAction;
QAction *_showCoordinatesAction;
QAction *_openOptionsAction;
QAction *_downloadDEMAction;
QAction *_mapsEnd;
QAction *_poisEnd;
@ -239,6 +245,7 @@ private:
POI *_poi;
Map *_map;
DEMLoader *_dem;
FileBrowser *_browser;
QList<QString> _files;
@ -260,6 +267,8 @@ private:
QString _dataDir, _mapDir, _poiDir;
Units _units;
RectC _demRect;
};
#endif // GUI_H

View File

@ -26,5 +26,6 @@
#define PRINT_EXPORT_ICON ":/document-print_32.png"
#define DATA_ICON ":/view-filter.png"
#define MAPS_ICON ":/applications-internet_32.png"
#define DEM_ICON ":/view-grid.png"
#endif /* ICONS_H */

10
src/GUI/infolabel.cpp Normal file
View File

@ -0,0 +1,10 @@
#include "infolabel.h"
InfoLabel::InfoLabel(const QString &text, QWidget *parent)
: QLabel(text, parent)
{
QFont f(font());
f.setPointSize(f.pointSize() - 1);
setWordWrap(true);
setFont(f);
}

12
src/GUI/infolabel.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef INFOLABEL_H
#define INFOLABEL_H
#include <QLabel>
class InfoLabel : public QLabel
{
public:
InfoLabel(const QString &text, QWidget *parent = 0);
};
#endif // INFOLABEL_H

View File

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

View File

@ -14,12 +14,14 @@
#include <QSysInfo>
#include <QButtonGroup>
#include "icons.h"
#include "infolabel.h"
#include "colorbox.h"
#include "stylecombobox.h"
#include "oddspinbox.h"
#include "percentslider.h"
#include "projectioncombobox.h"
#include "dirselectwidget.h"
#include "authenticationwidget.h"
#include "optionsdialog.h"
@ -53,17 +55,11 @@ QWidget *OptionsDialog::createMapPage()
_inputProjection->setCurrentIndex(_inputProjection->findData(
_options.inputProjection));
QLabel *inInfo = new QLabel(tr("Select the proper projection of maps"
InfoLabel *inInfo = new InfoLabel(tr("Select the proper projection of maps"
" without a projection definition (JNX, KMZ and world file maps)."));
QLabel *outInfo = new QLabel(tr("Select the desired projection of vector"
" maps (IMG and Mapsforge maps). The projection must be valid for"
InfoLabel *outInfo = new InfoLabel(tr("Select the desired projection of"
" vector maps (IMG and Mapsforge maps). The projection must be valid for"
" the whole map area."));
QFont f = inInfo->font();
f.setPointSize(f.pointSize() - 1);
inInfo->setWordWrap(true);
outInfo->setWordWrap(true);
inInfo->setFont(f);
outInfo->setFont(f);
_hidpi = new QRadioButton(tr("High-resolution"));
_lodpi = new QRadioButton(tr("Standard"));
@ -71,14 +67,10 @@ QWidget *OptionsDialog::createMapPage()
_hidpi->setChecked(true);
else
_lodpi->setChecked(true);
QLabel *lhi = new QLabel(tr("Non-HiDPI maps are loaded as HiDPI maps. "
InfoLabel *lhi = new InfoLabel(tr("Non-HiDPI maps are loaded as HiDPI maps. "
"The map is sharp but map objects are small/hard to read."));
QLabel *llo = new QLabel(tr("Non-HiDPI maps are loaded such as they are. "
InfoLabel *llo = new InfoLabel(tr("Non-HiDPI maps are loaded such as they are. "
"Map objects have the expected size but the map is blurry."));
lhi->setWordWrap(true);
llo->setWordWrap(true);
lhi->setFont(f);
llo->setFont(f);
QVBoxLayout *inLayout = new QVBoxLayout();
inLayout->addWidget(_inputProjection);
@ -576,6 +568,42 @@ QWidget *OptionsDialog::createPOIPage()
return poiPage;
}
QWidget *OptionsDialog::createDEMPage()
{
_demURL = new QLineEdit();
_demURL->setText(_options.demURL);
_demAuth = new AuthenticationWidget();
_demAuth->setUsername(_options.demUsername);
_demAuth->setPassword(_options.demPassword);
_demAuth->setEnabled(_options.demAuthorization);
QCheckBox *useAuth = new QCheckBox(tr("Use HTTP authentication"));
useAuth->setChecked(_demAuth->isEnabled());
connect(useAuth, &QRadioButton::toggled, _demAuth,
&AuthenticationWidget::setEnabled);
InfoLabel *info = new InfoLabel(tr("Use $lat and $lon for NYY/SYY and EXXX/WXXX in the URL."));
QFormLayout *urlLayout = new QFormLayout();
urlLayout->addRow(tr("URL:"), _demURL);
urlLayout->addRow(info);
QVBoxLayout *sourceLayout = new QVBoxLayout();
sourceLayout->addLayout(urlLayout);
sourceLayout->addSpacing(10);
sourceLayout->addWidget(useAuth);
sourceLayout->addWidget(_demAuth);
sourceLayout->addStretch();
QWidget *sourceTab = new QWidget();
sourceTab->setLayout(sourceLayout);
QTabWidget *demPage = new QTabWidget();
demPage->addTab(sourceTab, tr("Source"));
return demPage;
}
QWidget *OptionsDialog::createExportPage()
{
_wysiwyg = new QRadioButton(tr("WYSIWYG"));
@ -584,17 +612,11 @@ QWidget *OptionsDialog::createExportPage()
_hires->setChecked(true);
else
_wysiwyg->setChecked(true);
QLabel *lw = new QLabel(tr("The printed area is approximately the display"
" area. The map zoom level does not change."));
QLabel *lh = new QLabel(tr("The zoom level will be changed so that"
InfoLabel *lw = new InfoLabel(tr("The printed area is approximately the "
"display area. The map zoom level does not change."));
InfoLabel *lh = new InfoLabel(tr("The zoom level will be changed so that"
" the whole content (tracks/waypoints) fits to the printed area and"
" the map resolution is as close as possible to the print resolution."));
QFont f = lw->font();
f.setPointSize(f.pointSize() - 1);
lw->setWordWrap(true);
lh->setWordWrap(true);
lw->setFont(f);
lh->setFont(f);
QVBoxLayout *modeTabLayout = new QVBoxLayout();
modeTabLayout->addWidget(_wysiwyg);
@ -691,12 +713,8 @@ QWidget *OptionsDialog::createSystemPage()
_poiPath = new DirSelectWidget();
_poiPath->setDir(_options.poiPath);
QLabel *info = new QLabel(tr("Select the initial paths of the file open"
" dialogues. Leave the field empty for the system default."));
QFont f = info->font();
f.setPointSize(f.pointSize() - 1);
info->setFont(f);
info->setWordWrap(true);
InfoLabel *info = new InfoLabel(tr("Select the initial paths of the file"
" open dialogues. Leave the field empty for the system default."));
QFormLayout *pathsFormLayout = new QFormLayout();
pathsFormLayout->addRow(tr("Data:"), _dataPath);
@ -705,8 +723,8 @@ QWidget *OptionsDialog::createSystemPage()
QWidget *pathsTab = new QWidget();
QVBoxLayout *pathsTabLayout = new QVBoxLayout();
pathsTabLayout->addWidget(info);
pathsTabLayout->addLayout(pathsFormLayout);
pathsTabLayout->addWidget(info);
pathsTabLayout->addStretch();
pathsTab->setLayout(pathsTabLayout);
@ -725,6 +743,7 @@ OptionsDialog::OptionsDialog(Options &options, Units units, QWidget *parent)
pages->addWidget(createMapPage());
pages->addWidget(createDataPage());
pages->addWidget(createPOIPage());
pages->addWidget(createDEMPage());
pages->addWidget(createExportPage());
pages->addWidget(createSystemPage());
@ -735,6 +754,7 @@ OptionsDialog::OptionsDialog(Options &options, Units units, QWidget *parent)
new QListWidgetItem(QIcon(MAPS_ICON), tr("Maps"), menu);
new QListWidgetItem(QIcon(DATA_ICON), tr("Data"), menu);
new QListWidgetItem(QIcon(POI_ICON), tr("POI"), menu);
new QListWidgetItem(QIcon(DEM_ICON), tr("DEM"), menu);
new QListWidgetItem(QIcon(PRINT_EXPORT_ICON), tr("Print & Export"),
menu);
new QListWidgetItem(QIcon(SYSTEM_ICON), tr("System"), menu);
@ -831,6 +851,11 @@ void OptionsDialog::accept()
if (qAbs(poiRadius - _options.poiRadius) > 0.01)
_options.poiRadius = poiRadius;
_options.demURL = _demURL->text();
_options.demAuthorization = _demAuth->isEnabled();
_options.demUsername = _demAuth->username();
_options.demPassword = _demAuth->password();
_options.useOpenGL = _useOpenGL->isChecked();
_options.enableHTTP2 = _enableHTTP2->isChecked();
_options.pixmapCache = _pixmapCache->value();

View File

@ -6,18 +6,19 @@
#include "units.h"
#include "timezoneinfo.h"
class ColorBox;
class StyleComboBox;
class OddSpinBox;
class QSpinBox;
class QDoubleSpinBox;
class QComboBox;
class QCheckBox;
class QRadioButton;
class QLineEdit;
class ColorBox;
class StyleComboBox;
class OddSpinBox;
class PercentSlider;
class ProjectionComboBox;
class DirSelectWidget;
class AuthenticationWidget;
struct Options {
// Appearance
@ -61,6 +62,11 @@ struct Options {
bool useSegments;
// POI
int poiRadius;
// DEM
QString demURL;
QString demUsername;
QString demPassword;
bool demAuthorization;
// System
bool useOpenGL;
bool enableHTTP2;
@ -100,6 +106,7 @@ private:
QWidget *createPOIPage();
QWidget *createSystemPage();
QWidget *createExportPage();
QWidget *createDEMPage();
Options &_options;
@ -153,6 +160,9 @@ private:
QCheckBox *_useSegments;
// POI
QDoubleSpinBox *_poiRadius;
// DEM
QLineEdit *_demURL;
AuthenticationWidget *_demAuth;
// System
QSpinBox *_pixmapCache;
QSpinBox *_connectionTimeout;

View File

@ -173,6 +173,14 @@
#define USE_SEGMENTS_DEFAULT true
#define POI_RADIUS_SETTING "poiRadius"
#define POI_RADIUS_DEFAULT (int)(IMPERIAL_UNITS() ? MIINM : KMINM)
#define DEM_URL_SETTING "demURL"
#define DEM_URL_DEFAULT ""
#define DEM_AUTH_SETTING "demAuthentication"
#define DEM_AUTH_DEFAULT false
#define DEM_USERNAME_SETTING "demUsername"
#define DEM_USERNAME_DEFAULT ""
#define DEM_PASSWORD_SETTING "demPassword"
#define DEM_PASSWORD_DEFAULT ""
#define USE_OPENGL_SETTING "useOpenGL"
#define USE_OPENGL_DEFAULT false
#define ENABLE_HTTP2_SETTING "enableHTTP2"