diff --git a/src/GUI/gui.cpp b/src/GUI/gui.cpp index e85e794a..f3e3176a 100644 --- a/src/GUI/gui.cpp +++ b/src/GUI/gui.cpp @@ -384,6 +384,9 @@ void GUI::createActions() _downloadDEMAction->setEnabled(false); _downloadDEMAction->setShortcut(DOWNLOAD_DEM_SHORTCUT); connect(_downloadDEMAction, &QAction::triggered, this, &GUI::downloadDEM); + _showDEMTilesAction = new QAction(tr("Show local DEM tiles")); + _showDEMTilesAction->setMenuRole(QAction::NoRole); + connect(_showDEMTilesAction, &QAction::triggered, this, &GUI::showDEMTiles); // Graph actions _showGraphsAction = new QAction(QIcon(SHOW_GRAPHS_ICON), tr("Show graphs"), @@ -595,7 +598,7 @@ void GUI::createMenus() _poiMenu->addAction(_showPOIAction); QMenu *demMenu = menuBar()->addMenu(tr("DEM")); - demMenu->addSeparator(); + demMenu->addAction(_showDEMTilesAction); demMenu->addAction(_downloadDEMAction); QMenu *settingsMenu = menuBar()->addMenu(tr("&Settings")); @@ -1730,6 +1733,14 @@ void GUI::demLoaded() reloadFiles(); } +void GUI::showDEMTiles() +{ + _mapView->loadDEMs(DEM::tiles()); + + _fileActionGroup->setEnabled(true); + _reloadFileAction->setEnabled(false); +} + void GUI::updateStatusBarInfo() { if (_files.count() == 0) diff --git a/src/GUI/gui.h b/src/GUI/gui.h index 87124ee6..3e8e5001 100644 --- a/src/GUI/gui.h +++ b/src/GUI/gui.h @@ -76,6 +76,7 @@ private slots: void openOptions(); void clearMapCache(); void downloadDEM(); + void showDEMTiles(); void mapChanged(QAction *action); void graphChanged(int); @@ -234,6 +235,7 @@ private: QAction *_showCoordinatesAction; QAction *_openOptionsAction; QAction *_downloadDEMAction; + QAction *_showDEMTilesAction; QAction *_mapsEnd; QAction *_poisEnd; diff --git a/src/GUI/mapview.cpp b/src/GUI/mapview.cpp index 7c68a568..36404da9 100644 --- a/src/GUI/mapview.cpp +++ b/src/GUI/mapview.cpp @@ -293,6 +293,23 @@ void MapView::loadMaps(const QList &maps) centerOn(contentCenter()); } +void MapView::loadDEMs(const QList &dems) +{ + int zoom = _map->zoom(); + + for (int i = 0; i < dems.size(); i++) + addArea(dems.at(i)); + + if (fitMapZoom() != zoom) + rescale(); + else + updatePOIVisibility(); + + updateZValues(_areas); + + centerOn(contentCenter()); +} + int MapView::fitMapZoom() const { RectC br = _tr | _rr | _wr | _ar; diff --git a/src/GUI/mapview.h b/src/GUI/mapview.h index 7c5c2918..455140ba 100644 --- a/src/GUI/mapview.h +++ b/src/GUI/mapview.h @@ -52,6 +52,7 @@ public: QList loadData(const Data &data); void loadMaps(const QList &maps); + void loadDEMs(const QList &dems); void setPalette(const Palette &palette); void setPOI(POI *poi); diff --git a/src/data/dem.cpp b/src/data/dem.cpp index 4214ce81..020062b5 100644 --- a/src/data/dem.cpp +++ b/src/data/dem.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "common/rectc.h" #include "dem.h" @@ -138,6 +139,36 @@ qreal DEM::elevation(const Coordinates &c) return height(c, ba); } +QList DEM::tiles() +{ + QDir dir(_dir); + QFileInfoList files(dir.entryInfoList(QDir::Files | QDir::Readable)); + QRegularExpression re("([NS])([0-9]{2})([EW])([0-9]{3})"); + QList list; + + for (int i = 0; i < files.size(); i++) { + QString basename(files.at(i).baseName()); + QRegularExpressionMatch match(re.match(basename)); + if (!match.hasMatch()) + continue; + + int lat = match.captured(2).toInt(); + int lon = match.captured(4).toInt(); + if (match.captured(1) == "S") + lat = -lat; + if (match.captured(3) == "W") + lon = -lon; + + Area area(RectC(Coordinates(lon, lat + 1), Coordinates(lon + 1, lat))); + area.setName(basename); + area.setDescription(files.at(i).canonicalFilePath()); + + list.append(area); + } + + return list; +} + #ifndef QT_NO_DEBUG QDebug operator<<(QDebug dbg, const DEM::Tile &tile) { diff --git a/src/data/dem.h b/src/data/dem.h index cf78a726..de1e0fb3 100644 --- a/src/data/dem.h +++ b/src/data/dem.h @@ -5,6 +5,7 @@ #include #include #include "common/config.h" +#include "area.h" class QString; class Coordinates; @@ -37,6 +38,8 @@ public: static void clearCache(); static qreal elevation(const Coordinates &c); + static QList tiles(); + private: static QString fileName(const QString &baseName);