From ff4e3e63cff92ab44c7b5b1bc15823fc91e7bbee Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Tue, 2 May 2023 22:24:51 -0500 Subject: [PATCH] Add default alert action to settings --- .../scwx/qt/settings/general_settings.cpp | 40 ++++++++++++++++++- .../scwx/qt/settings/general_settings.hpp | 1 + 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/scwx-qt/source/scwx/qt/settings/general_settings.cpp b/scwx-qt/source/scwx/qt/settings/general_settings.cpp index 19c97f8a..0375ecc4 100644 --- a/scwx-qt/source/scwx/qt/settings/general_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/general_settings.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include @@ -20,12 +21,21 @@ class GeneralSettingsImpl public: explicit GeneralSettingsImpl() { + std::string defaultDefaultAlertActionValue = + types::GetAlertActionName(types::AlertAction::Go); + std::string defaultMapProviderValue = + map::GetMapProviderName(map::MapProvider::MapTiler); + + boost::to_lower(defaultDefaultAlertActionValue); + boost::to_lower(defaultMapProviderValue); + debugEnabled_.SetDefault(false); + defaultAlertAction_.SetDefault(defaultDefaultAlertActionValue); defaultRadarSite_.SetDefault("KLSX"); fontSizes_.SetDefault({16}); gridWidth_.SetDefault(1); gridHeight_.SetDefault(1); - mapProvider_.SetDefault("maptiler"); + mapProvider_.SetDefault(defaultMapProviderValue); mapboxApiKey_.SetDefault("?"); maptilerApiKey_.SetDefault("?"); updateNotificationsEnabled_.SetDefault(true); @@ -38,6 +48,26 @@ public: gridWidth_.SetMaximum(2); gridHeight_.SetMinimum(1); gridHeight_.SetMaximum(2); + + defaultAlertAction_.SetValidator( + [](const std::string& value) + { + for (types::AlertAction alertAction : types::AlertActionIterator()) + { + // If the value is equal to a lower case alert action name + std::string alertActionName = + types::GetAlertActionName(alertAction); + boost::to_lower(alertActionName); + if (value == alertActionName) + { + // Regard as a match, valid + return true; + } + } + + // No match found, invalid + return false; + }); mapProvider_.SetValidator( [](const std::string& value) { @@ -66,6 +96,7 @@ public: ~GeneralSettingsImpl() {} SettingsVariable debugEnabled_ {"debug_enabled"}; + SettingsVariable defaultAlertAction_ {"default_alert_action"}; SettingsVariable defaultRadarSite_ {"default_radar_site"}; SettingsContainer> fontSizes_ {"font_sizes"}; SettingsVariable gridWidth_ {"grid_width"}; @@ -80,6 +111,7 @@ GeneralSettings::GeneralSettings() : SettingsCategory("general"), p(std::make_unique()) { RegisterVariables({&p->debugEnabled_, + &p->defaultAlertAction_, &p->defaultRadarSite_, &p->fontSizes_, &p->gridWidth_, @@ -101,6 +133,11 @@ SettingsVariable& GeneralSettings::debug_enabled() const return p->debugEnabled_; } +SettingsVariable& GeneralSettings::default_alert_action() const +{ + return p->defaultAlertAction_; +} + SettingsVariable& GeneralSettings::default_radar_site() const { return p->defaultRadarSite_; @@ -145,6 +182,7 @@ SettingsVariable& GeneralSettings::update_notifications_enabled() const bool operator==(const GeneralSettings& lhs, const GeneralSettings& rhs) { return (lhs.p->debugEnabled_ == rhs.p->debugEnabled_ && + lhs.p->defaultAlertAction_ == rhs.p->defaultAlertAction_ && lhs.p->defaultRadarSite_ == rhs.p->defaultRadarSite_ && lhs.p->fontSizes_ == rhs.p->fontSizes_ && lhs.p->gridWidth_ == rhs.p->gridWidth_ && diff --git a/scwx-qt/source/scwx/qt/settings/general_settings.hpp b/scwx-qt/source/scwx/qt/settings/general_settings.hpp index a565f09e..4d54074d 100644 --- a/scwx-qt/source/scwx/qt/settings/general_settings.hpp +++ b/scwx-qt/source/scwx/qt/settings/general_settings.hpp @@ -28,6 +28,7 @@ public: GeneralSettings& operator=(GeneralSettings&&) noexcept; SettingsVariable& debug_enabled() const; + SettingsVariable& default_alert_action() const; SettingsVariable& default_radar_site() const; SettingsContainer>& font_sizes() const; SettingsVariable& grid_height() const;