From c77cf70f9f835918ec7a6f52efba8b2f2b02d53d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Wed, 22 Sep 2021 20:29:48 +0200 Subject: [PATCH] Multiple settings handling fixes and enhancements --- gpxsee.pro | 4 +- src/GUI/app.cpp | 9 --- src/GUI/gui.cpp | 152 ++++++++++++++++++++++++++---------------------- src/GUI/gui.h | 19 +++--- 4 files changed, 95 insertions(+), 89 deletions(-) diff --git a/gpxsee.pro b/gpxsee.pro index de2add88..1b676260 100644 --- a/gpxsee.pro +++ b/gpxsee.pro @@ -18,7 +18,6 @@ greaterThan(QT_MAJOR_VERSION, 5) {QT += openglwidgets} CONFIG += object_parallel_to_source INCLUDEPATH += ./src HEADERS += src/common/config.h \ - src/GUI/passwordedit.h \ src/common/garmin.h \ src/common/coordinates.h \ src/common/range.h \ @@ -104,6 +103,7 @@ HEADERS += src/common/config.h \ src/GUI/pdfexportdialog.h \ src/GUI/pngexportdialog.h \ src/GUI/timezoneinfo.h \ + src/GUI/passwordedit.h \ src/map/proj/polyconic.h \ src/map/proj/webmercator.h \ src/map/proj/transversemercator.h \ @@ -235,7 +235,6 @@ HEADERS += src/common/config.h \ src/data/geojsonparser.h SOURCES += src/main.cpp \ - src/GUI/passwordedit.cpp \ src/common/coordinates.cpp \ src/common/rectc.cpp \ src/common/range.cpp \ @@ -302,6 +301,7 @@ SOURCES += src/main.cpp \ src/GUI/pdfexportdialog.cpp \ src/GUI/pngexportdialog.cpp \ src/GUI/projectioncombobox.cpp \ + src/GUI/passwordedit.cpp \ src/map/proj/polyconic.cpp \ src/map/proj/webmercator.cpp \ src/map/proj/transversemercator.cpp \ diff --git a/src/GUI/app.cpp b/src/GUI/app.cpp index bdc23571..1b4fee8d 100644 --- a/src/GUI/app.cpp +++ b/src/GUI/app.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include "common/programpaths.h" #include "common/config.h" @@ -60,14 +59,6 @@ App::App(int &argc, char **argv) : QApplication(argc, argv) loadDatums(); loadPCSs(); - QSettings settings(qApp->applicationName(), qApp->applicationName()); - settings.beginGroup(OPTIONS_SETTINGS_GROUP); - Downloader::enableHTTP2(settings.value(ENABLE_HTTP2_SETTING, - ENABLE_HTTP2_DEFAULT).toBool()); - Downloader::setTimeout(settings.value(CONNECTION_TIMEOUT_SETTING, - CONNECTION_TIMEOUT_DEFAULT).toInt()); - settings.endGroup(); - _gui = new GUI(); } diff --git a/src/GUI/gui.cpp b/src/GUI/gui.cpp index af350a62..e85e794a 100644 --- a/src/GUI/gui.cpp +++ b/src/GUI/gui.cpp @@ -59,8 +59,8 @@ GUI::GUI() { - TreeNode mapActions; - TreeNode poiActions; + QString activeMap; + QStringList disabledPOIs; _poi = new POI(this); _dem = new DEMLoader(ProgramPaths::demDir(true), this); @@ -69,8 +69,8 @@ GUI::GUI() createMapView(); createGraphTabs(); createStatusBar(); - createActions(mapActions, poiActions); - createMenus(mapActions, poiActions); + createActions(); + createMenus(); createToolBars(); createBrowser(); @@ -99,11 +99,10 @@ GUI::GUI() _movingTime = 0; _lastTab = 0; - readSettings(); + readSettings(activeMap, disabledPOIs); - _dataDir = _options.dataPath; - _mapDir = _options.mapsPath; - _poiDir = _options.poiPath; + loadInitialMaps(activeMap); + loadInitialPOIs(disabledPOIs); updateGraphTabs(); updateStatusBarInfo(); @@ -117,21 +116,6 @@ void GUI::createBrowser() &GUI::updateNavigationActions); } -TreeNode GUI::createMapActions() -{ - _mapsActionGroup = new QActionGroup(this); - _mapsActionGroup->setExclusive(true); - connect(_mapsActionGroup, &QActionGroup::triggered, this, &GUI::mapChanged); - - QString mapDir(ProgramPaths::mapDir()); - if (mapDir.isNull()) - return TreeNode(); - - TreeNode maps(MapList::loadMaps(mapDir, - CRS::projection(_options.inputProjection))); - return createMapActionsNode(maps); -} - TreeNode GUI::createMapActionsNode(const TreeNode &node) { TreeNode tree(node.name()); @@ -171,21 +155,6 @@ void GUI::mapInitialized() } } -TreeNode GUI::createPOIActions() -{ - _poisActionGroup = new QActionGroup(this); - _poisActionGroup->setExclusive(false); - connect(_poisActionGroup, &QActionGroup::triggered, this, - &GUI::poiFileChecked); - - TreeNode poiFiles; - QString poiDir(ProgramPaths::poiDir()); - if (!poiDir.isNull()) - poiFiles = _poi->loadDir(poiDir); - - return createPOIActionsNode(poiFiles); -} - TreeNode GUI::createPOIActionsNode(const TreeNode &node) { TreeNode tree(node.name()); @@ -198,8 +167,7 @@ TreeNode GUI::createPOIActionsNode(const TreeNode &node) return tree; } -void GUI::createActions(TreeNode &mapActions, - TreeNode &poiActions) +void GUI::createActions() { QActionGroup *ag; @@ -277,7 +245,10 @@ void GUI::createActions(TreeNode &mapActions, addAction(_statisticsAction); // POI actions - poiActions = createPOIActions(); + _poisActionGroup = new QActionGroup(this); + _poisActionGroup->setExclusive(false); + connect(_poisActionGroup, &QActionGroup::triggered, this, + &GUI::poiFileChecked); _openPOIAction = new QAction(QIcon(OPEN_FILE_ICON), tr("Load POI file..."), this); _openPOIAction->setMenuRole(QAction::NoRole); @@ -285,12 +256,12 @@ void GUI::createActions(TreeNode &mapActions, QOverload<>::of(&GUI::openPOIFile)); _selectAllPOIAction = new QAction(tr("Select all files"), this); _selectAllPOIAction->setMenuRole(QAction::NoRole); - _selectAllPOIAction->setEnabled(!_poisActionGroup->actions().isEmpty()); + _selectAllPOIAction->setEnabled(false); connect(_selectAllPOIAction, &QAction::triggered, this, &GUI::selectAllPOIs); _unselectAllPOIAction = new QAction(tr("Unselect all files"), this); _unselectAllPOIAction->setMenuRole(QAction::NoRole); - _unselectAllPOIAction->setEnabled(_selectAllPOIAction->isEnabled()); + _unselectAllPOIAction->setEnabled(false); connect(_unselectAllPOIAction, &QAction::triggered, this, &GUI::unselectAllPOIs); _overlapPOIAction = new QAction(tr("Overlap POIs"), this); @@ -311,7 +282,9 @@ void GUI::createActions(TreeNode &mapActions, addAction(_showPOIAction); // Map actions - mapActions = createMapActions(); + _mapsActionGroup = new QActionGroup(this); + _mapsActionGroup->setExclusive(true); + connect(_mapsActionGroup, &QActionGroup::triggered, this, &GUI::mapChanged); _showMapAction = new QAction(QIcon(SHOW_MAP_ICON), tr("Show map"), this); _showMapAction->setEnabled(false); @@ -532,7 +505,8 @@ void GUI::createActions(TreeNode &mapActions, connect(_firstAction, &QAction::triggered, this, &GUI::first); } -void GUI::createMapNodeMenu(const TreeNode &node, QMenu *menu) +void GUI::createMapNodeMenu(const TreeNode &node, QMenu *menu, + QAction *action) { for (int i = 0; i < node.childs().size(); i++) { QMenu *cm = new QMenu(node.childs().at(i).name(), menu); @@ -541,10 +515,11 @@ void GUI::createMapNodeMenu(const TreeNode &node, QMenu *menu) } for (int i = 0; i < node.items().size(); i++) - menu->addAction(node.items().at(i)); + menu->insertAction(action, node.items().at(i)); } -void GUI::createPOINodeMenu(const TreeNode &node, QMenu *menu) +void GUI::createPOINodeMenu(const TreeNode &node, QMenu *menu, + QAction *action) { for (int i = 0; i < node.childs().size(); i++) { QMenu *cm = new QMenu(node.childs().at(i).name(), menu); @@ -553,11 +528,10 @@ void GUI::createPOINodeMenu(const TreeNode &node, QMenu *menu) } for (int i = 0; i < node.items().size(); i++) - menu->addAction(node.items().at(i)); + menu->insertAction(action, node.items().at(i)); } -void GUI::createMenus(const TreeNode &mapActions, - const TreeNode &poiActions) +void GUI::createMenus() { QMenu *fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(_openFileAction); @@ -576,7 +550,6 @@ void GUI::createMenus(const TreeNode &mapActions, #endif // Q_OS_MAC _mapMenu = menuBar()->addMenu(tr("&Map")); - createMapNodeMenu(mapActions, _mapMenu); _mapsEnd = _mapMenu->addSeparator(); _mapMenu->addAction(_loadMapAction); _mapMenu->addAction(_loadMapDirAction); @@ -611,7 +584,6 @@ void GUI::createMenus(const TreeNode &mapActions, dataMenu->addAction(_showWaypointsAction); _poiMenu = menuBar()->addMenu(tr("&POI")); - createPOINodeMenu(poiActions, _poiMenu); _poisEnd = _poiMenu->addSeparator(); _poiMenu->addAction(_openPOIAction); _poiMenu->addAction(_selectAllPOIAction); @@ -2363,7 +2335,7 @@ void GUI::writeSettings() settings.endGroup(); } -void GUI::readSettings() +void GUI::readSettings(QString &activeMap, QStringList &disabledPOIs) { int value; QSettings settings(qApp->applicationName(), qApp->applicationName()); @@ -2406,17 +2378,12 @@ void GUI::readSettings() _showMapAction->setChecked(true); else _mapView->showMap(false); - QAction *ma = mapAction(settings.value(CURRENT_MAP_SETTING).toString()); - if (ma) { - ma->trigger(); - _showMapAction->setEnabled(true); - _clearMapCacheAction->setEnabled(true); - } if (settings.value(SHOW_COORDINATES_SETTING, SHOW_COORDINATES_DEFAULT) .toBool()) { _showCoordinatesAction->setChecked(true); _mapView->showCoordinates(true); } + activeMap = settings.value(CURRENT_MAP_SETTING).toString(); settings.endGroup(); settings.beginGroup(GRAPH_SETTINGS_GROUP); @@ -2456,18 +2423,11 @@ void GUI::readSettings() _showPOIAction->setChecked(true); else _mapView->showPOI(false); - QList poiActions(_poisActionGroup->actions()); - for (int i = 0; i < poiActions.count(); i++) - poiActions.at(i)->setChecked(true); + int size = settings.beginReadArray(DISABLED_POI_FILE_SETTINGS_PREFIX); for (int i = 0; i < size; i++) { settings.setArrayIndex(i); - QString file(settings.value(DISABLED_POI_FILE_SETTING).toString()); - if (_poi->enableFile(file, false)) { - for (int j = 0; j < poiActions.size(); j++) - if (poiActions.at(j)->data().toString() == file) - poiActions.at(j)->setChecked(false); - } + disabledPOIs.append(settings.value(DISABLED_POI_FILE_SETTING).toString()); } settings.endArray(); settings.endGroup(); @@ -2730,6 +2690,11 @@ void GUI::readSettings() Waypoint::useDEM(_options.dataUseDEM); Waypoint::showSecondaryElevation(_options.showSecondaryElevation); + Downloader::enableHTTP2(_options.enableHTTP2); + Downloader::setTimeout(_options.connectionTimeout); + + QPixmapCache::setCacheLimit(_options.pixmapCache * 1024); + _poi->setRadius(_options.poiRadius); _dem->setUrl(_options.demURL); @@ -2737,11 +2702,60 @@ void GUI::readSettings() _dem->setAuthorization(Authorization(_options.demUsername, _options.demPassword)); - QPixmapCache::setCacheLimit(_options.pixmapCache * 1024); + _dataDir = _options.dataPath; + _mapDir = _options.mapsPath; + _poiDir = _options.poiPath; settings.endGroup(); } +void GUI::loadInitialMaps(const QString &selected) +{ + // Load the maps + QString mapDir(ProgramPaths::mapDir()); + if (mapDir.isNull()) + return; + + TreeNode maps(MapList::loadMaps(mapDir, + CRS::projection(_options.inputProjection))); + createMapNodeMenu(createMapActionsNode(maps), _mapMenu, _mapsEnd); + + // Select the active map according to the user settings + QAction *ma = mapAction(selected); + if (ma) { + ma->trigger(); + _showMapAction->setEnabled(true); + _clearMapCacheAction->setEnabled(true); + } +} + +void GUI::loadInitialPOIs(const QStringList &disabled) +{ + // Load the POI files + QString poiDir(ProgramPaths::poiDir()); + if (poiDir.isNull()) + return; + + TreeNode poiFiles(_poi->loadDir(poiDir)); + createPOINodeMenu(createPOIActionsNode(poiFiles), _poiMenu, _poisEnd); + + // Enable/disable the files according to the user settings + QList poiActions(_poisActionGroup->actions()); + for (int i = 0; i < poiActions.count(); i++) + poiActions.at(i)->setChecked(true); + for (int i = 0; i < disabled.size(); i++) { + const QString &file = disabled.at(i); + if (_poi->enableFile(file, false)) { + for (int j = 0; j < poiActions.size(); j++) + if (poiActions.at(j)->data().toString() == file) + poiActions.at(j)->setChecked(false); + } + } + + _selectAllPOIAction->setEnabled(!poiActions.isEmpty()); + _unselectAllPOIAction->setEnabled(!poiActions.isEmpty()); +} + QAction *GUI::mapAction(const QString &name) { QList maps(_mapsActionGroup->actions()); diff --git a/src/GUI/gui.h b/src/GUI/gui.h index 9b6b78b6..87124ee6 100644 --- a/src/GUI/gui.h +++ b/src/GUI/gui.h @@ -119,16 +119,14 @@ private: void plotGraphsPage(QPainter *painter, const QRectF &rect, qreal ratio); qreal graphPlotHeight(const QRectF &rect, qreal ratio); - TreeNode createPOIActions(); TreeNode createPOIActionsNode(const TreeNode &node); - TreeNode createMapActions(); TreeNode createMapActionsNode(const TreeNode &node); - void createActions(TreeNode &mapActions, - TreeNode &poiActions); - void createMapNodeMenu(const TreeNode &node, QMenu *menu); - void createPOINodeMenu(const TreeNode &node, QMenu *menu); - void createMenus(const TreeNode &mapActions, - const TreeNode &poiActions); + void createMapNodeMenu(const TreeNode &node, QMenu *menu, + QAction *action = 0); + void createPOINodeMenu(const TreeNode &node, QMenu *menu, + QAction *action = 0); + void createActions(); + void createMenus(); void createToolBars(); void createStatusBar(); void createMapView(); @@ -158,9 +156,12 @@ private: qreal time() const; qreal movingTime() const; QAction *mapAction(const QString &name); - void readSettings(); + void readSettings(QString &activeMap, QStringList &disabledPOIs); void writeSettings(); + void loadInitialMaps(const QString &selected); + void loadInitialPOIs(const QStringList &disabled); + void keyPressEvent(QKeyEvent *event); void closeEvent(QCloseEvent *event); void dragEnterEvent(QDragEnterEvent *event);