From efb1832db802eb904f3e8b00ac96bc399a26e9f9 Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Wed, 17 Aug 2022 09:17:04 +0900 Subject: [PATCH] Map Short Names - add preference setting Adds a preference setting in the "Default" settings tab to toggle whether to display shortened names in the Map. TODO: instead of using the generic "settingsChanged" signal, it would be much more efficient to only update items based on the actual setting which was changed. Signed-off-by: Michael WERLE --- core/pref.h | 1 + core/settings/qPrefDisplay.cpp | 3 +++ core/settings/qPrefDisplay.h | 5 ++++ desktop-widgets/mapwidget.cpp | 1 + .../preferences/preferences_defaults.cpp | 3 +++ .../preferences/preferences_defaults.ui | 27 +++++++++++++++++-- qt-models/maplocationmodel.cpp | 7 ++++- 7 files changed, 44 insertions(+), 3 deletions(-) diff --git a/core/pref.h b/core/pref.h index 71255c605..e0c10cda4 100644 --- a/core/pref.h +++ b/core/pref.h @@ -104,6 +104,7 @@ struct preferences { double mobile_scale; bool show_developer; bool three_m_based_grid; + bool map_short_names; // ********** Equipment tab ******* const char *default_cylinder; diff --git a/core/settings/qPrefDisplay.cpp b/core/settings/qPrefDisplay.cpp index 6e71d0d40..3ac23b97f 100644 --- a/core/settings/qPrefDisplay.cpp +++ b/core/settings/qPrefDisplay.cpp @@ -68,6 +68,7 @@ void qPrefDisplay::loadSync(bool doSync) load_singleColumnPortrait(); } disk_three_m_based_grid(doSync); + disk_map_short_names(doSync); } void qPrefDisplay::set_divelist_font(const QString &value) @@ -151,6 +152,8 @@ HANDLE_PREFERENCE_BOOL(Display, "show_developer", show_developer); HANDLE_PREFERENCE_BOOL(Display, "three_m_based_grid", three_m_based_grid); +HANDLE_PREFERENCE_BOOL(Display, "map_short_names", map_short_names); + void qPrefDisplay::setCorrectFont() { // get the font from the settings or our defaults diff --git a/core/settings/qPrefDisplay.h b/core/settings/qPrefDisplay.h index ffcf4c7cc..a00241386 100644 --- a/core/settings/qPrefDisplay.h +++ b/core/settings/qPrefDisplay.h @@ -26,6 +26,7 @@ class qPrefDisplay : public QObject { Q_PROPERTY(int lastState READ lastState WRITE set_lastState NOTIFY lastStateChanged) Q_PROPERTY(bool singleColumnPortrait READ singleColumnPortrait WRITE set_singleColumnPortrait NOTIFY singleColumnPortraitChanged) Q_PROPERTY(bool three_m_based_grid READ three_m_based_grid WRITE set_three_m_based_grid NOTIFY three_m_based_gridChanged) + Q_PROPERTY(bool map_short_names READ map_short_names WRITE set_map_short_names NOTIFY map_short_namesChanged) public: static qPrefDisplay *instance(); @@ -54,6 +55,7 @@ public: static int lastState() { return st_lastState; } static bool singleColumnPortrait() { return st_singleColumnPortrait; } static bool three_m_based_grid() { return prefs.three_m_based_grid; } + static bool map_short_names() { return prefs.map_short_names; } public slots: static void set_animation_speed(int value); @@ -74,6 +76,7 @@ public slots: static void set_lastState(int value); static void set_singleColumnPortrait(bool value); static void set_three_m_based_grid(bool value); + static void set_map_short_names(bool value); signals: void animation_speedChanged(int value); @@ -94,6 +97,7 @@ signals: void lastStateChanged(int value); void singleColumnPortraitChanged(bool value); void three_m_based_gridChanged(bool value); + void map_short_namesChanged(bool value); private: qPrefDisplay() {} @@ -106,6 +110,7 @@ private: static void disk_display_invalid_dives(bool doSync); static void disk_show_developer(bool doSync); static void disk_three_m_based_grid(bool doSync); + static void disk_map_short_names(bool doSync); // functions to handle class variables static void load_lastDir(); diff --git a/desktop-widgets/mapwidget.cpp b/desktop-widgets/mapwidget.cpp index 9ba77268a..254ffe903 100644 --- a/desktop-widgets/mapwidget.cpp +++ b/desktop-widgets/mapwidget.cpp @@ -29,6 +29,7 @@ MapWidget::MapWidget(QWidget *parent) : QQuickWidget(parent) connect(this, &QQuickWidget::statusChanged, this, &MapWidget::doneLoading); connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &MapWidget::divesChanged); connect(&diveListNotifier, &DiveListNotifier::dataReset, this, &MapWidget::reload); + connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MapWidget::reload); setSource(urlMapWidget); } diff --git a/desktop-widgets/preferences/preferences_defaults.cpp b/desktop-widgets/preferences/preferences_defaults.cpp index b30b25fd1..ab2d37783 100644 --- a/desktop-widgets/preferences/preferences_defaults.cpp +++ b/desktop-widgets/preferences/preferences_defaults.cpp @@ -32,6 +32,8 @@ void PreferencesDefaults::refreshSettings() ui->grid3MBased->setChecked(true); else ui->gridGeneric->setChecked(true); + + ui->checkBox_map_short_names->setChecked(qPrefDisplay::map_short_names()); } void PreferencesDefaults::syncSettings() @@ -40,4 +42,5 @@ void PreferencesDefaults::syncSettings() qPrefDisplay::set_font_size(ui->fontsize->value()); qPrefDisplay::set_animation_speed(ui->velocitySlider->value()); qPrefDisplay::set_three_m_based_grid(ui->grid3MBased->isChecked()); + qPrefDisplay::set_map_short_names(ui->checkBox_map_short_names->isChecked()); } diff --git a/desktop-widgets/preferences/preferences_defaults.ui b/desktop-widgets/preferences/preferences_defaults.ui index 5a32e276c..237c1494d 100644 --- a/desktop-widgets/preferences/preferences_defaults.ui +++ b/desktop-widgets/preferences/preferences_defaults.ui @@ -86,12 +86,12 @@ - + - Speed + Speed @@ -149,6 +149,29 @@ + + + + Map Display Options + + + + + + Short Names: + + + + + + + + + + + + + diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp index 98bb17e9f..ab1764f69 100644 --- a/qt-models/maplocationmodel.cpp +++ b/qt-models/maplocationmodel.cpp @@ -3,6 +3,7 @@ #include "divelocationmodel.h" #include "core/divesite.h" #include "core/divefilter.h" +#include "core/settings/qPrefDisplay.h" #if !defined(SUBSURFACE_MOBILE) && !defined(SUBSURFACE_DOWNLOADER) #include "qt-models/filtermodels.h" #include "desktop-widgets/mapwidget.h" @@ -19,8 +20,12 @@ static QString siteMapDisplayName(const char *sitename) { const char Separator = '/'; QString fullname(sitename); - QString name = fullname.section(Separator, -1).trimmed(); + if (!qPrefDisplay::map_short_names() ) { + return fullname; + } + + QString name = fullname.section(Separator, -1).trimmed(); if (name.isEmpty()) { name = fullname; }