diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index eb94efd3..179c7bc9 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -201,7 +201,8 @@ set(HDR_TYPES source/scwx/qt/types/alert_types.hpp source/scwx/qt/types/radar_product_record.hpp source/scwx/qt/types/text_event_key.hpp source/scwx/qt/types/text_types.hpp - source/scwx/qt/types/texture_types.hpp) + source/scwx/qt/types/texture_types.hpp + source/scwx/qt/types/time_types.hpp) set(SRC_TYPES source/scwx/qt/types/alert_types.cpp source/scwx/qt/types/github_types.cpp source/scwx/qt/types/icon_types.cpp @@ -214,7 +215,8 @@ set(SRC_TYPES source/scwx/qt/types/alert_types.cpp source/scwx/qt/types/radar_product_record.cpp source/scwx/qt/types/text_event_key.cpp source/scwx/qt/types/text_types.cpp - source/scwx/qt/types/texture_types.cpp) + source/scwx/qt/types/texture_types.cpp + source/scwx/qt/types/time_types.cpp) set(HDR_UI source/scwx/qt/ui/about_dialog.hpp source/scwx/qt/ui/alert_dialog.hpp source/scwx/qt/ui/alert_dock_widget.hpp diff --git a/scwx-qt/source/scwx/qt/settings/general_settings.cpp b/scwx-qt/source/scwx/qt/settings/general_settings.cpp index b2f597a3..b865e5f9 100644 --- a/scwx-qt/source/scwx/qt/settings/general_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/general_settings.cpp @@ -1,8 +1,10 @@ #include #include +#include #include #include #include +#include #include @@ -22,21 +24,29 @@ class GeneralSettings::Impl public: explicit Impl() { + std::string defaultClockFormatValue = + types::GetClockFormatName(types::ClockFormat::_24Hour); std::string defaultDefaultAlertActionValue = types::GetAlertActionName(types::AlertAction::Go); + std::string defaultDefaultTimeZoneValue = + types::GetDefaultTimeZoneName(types::DefaultTimeZone::Radar); std::string defaultMapProviderValue = map::GetMapProviderName(map::MapProvider::MapTiler); std::string defaultThemeValue = types::GetUiStyleName(types::UiStyle::Default); + boost::to_lower(defaultClockFormatValue); boost::to_lower(defaultDefaultAlertActionValue); + boost::to_lower(defaultDefaultTimeZoneValue); boost::to_lower(defaultMapProviderValue); boost::to_lower(defaultThemeValue); antiAliasingEnabled_.SetDefault(true); + clockFormat_.SetDefault(defaultClockFormatValue); debugEnabled_.SetDefault(false); defaultAlertAction_.SetDefault(defaultDefaultAlertActionValue); defaultRadarSite_.SetDefault("KLSX"); + defaultTimeZone_.SetDefault(defaultDefaultTimeZoneValue); fontSizes_.SetDefault({16}); loopDelay_.SetDefault(2500); loopSpeed_.SetDefault(5.0); @@ -67,74 +77,40 @@ public: loopTime_.SetMinimum(1); loopTime_.SetMaximum(1440); + clockFormat_.SetValidator( + SCWX_SETTINGS_ENUM_VALIDATOR(types::ClockFormat, + types::ClockFormatIterator(), + types::GetClockFormatName)); 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; - }); + SCWX_SETTINGS_ENUM_VALIDATOR(types::AlertAction, + types::AlertActionIterator(), + types::GetAlertActionName)); + defaultTimeZone_.SetValidator( + SCWX_SETTINGS_ENUM_VALIDATOR(types::DefaultTimeZone, + types::DefaultTimeZoneIterator(), + types::GetDefaultTimeZoneName)); mapProvider_.SetValidator( - [](const std::string& value) - { - for (map::MapProvider mapProvider : map::MapProviderIterator()) - { - // If the value is equal to a lower case map provider name - std::string mapProviderName = - map::GetMapProviderName(mapProvider); - boost::to_lower(mapProviderName); - if (value == mapProviderName) - { - // Regard as a match, valid - return true; - } - } - - // No match found, invalid - return false; - }); + SCWX_SETTINGS_ENUM_VALIDATOR(map::MapProvider, + map::MapProviderIterator(), + map::GetMapProviderName)); mapboxApiKey_.SetValidator([](const std::string& value) { return !value.empty(); }); maptilerApiKey_.SetValidator([](const std::string& value) { return !value.empty(); }); - theme_.SetValidator( - [](const std::string& value) - { - for (types::UiStyle uiStyle : types::UiStyleIterator()) - { - // If the value is equal to a lower case UI style name - std::string uiStyleName = types::GetUiStyleName(uiStyle); - boost::to_lower(uiStyleName); - if (value == uiStyleName) - { - // Regard as a match, valid - return true; - } - } - - // No match found, invalid - return false; - }); + theme_.SetValidator( // + SCWX_SETTINGS_ENUM_VALIDATOR(types::UiStyle, // + types::UiStyleIterator(), + types::GetUiStyleName)); } ~Impl() {} SettingsVariable antiAliasingEnabled_ {"anti_aliasing_enabled"}; + SettingsVariable clockFormat_ {"clock_format"}; SettingsVariable debugEnabled_ {"debug_enabled"}; SettingsVariable defaultAlertAction_ {"default_alert_action"}; SettingsVariable defaultRadarSite_ {"default_radar_site"}; + SettingsVariable defaultTimeZone_ {"default_time_zone"}; SettingsContainer> fontSizes_ {"font_sizes"}; SettingsVariable gridWidth_ {"grid_width"}; SettingsVariable gridHeight_ {"grid_height"}; @@ -154,10 +130,12 @@ public: GeneralSettings::GeneralSettings() : SettingsCategory("general"), p(std::make_unique()) { - RegisterVariables({&p->antiAliasingEnabled_, + RegisterVariables({&p->antiAliasingEnabled_, // + &p->clockFormat_, &p->debugEnabled_, &p->defaultAlertAction_, &p->defaultRadarSite_, + &p->defaultTimeZone_, &p->fontSizes_, &p->gridWidth_, &p->gridHeight_, @@ -185,6 +163,11 @@ SettingsVariable& GeneralSettings::anti_aliasing_enabled() const return p->antiAliasingEnabled_; } +SettingsVariable& GeneralSettings::clock_format() const +{ + return p->clockFormat_; +} + SettingsVariable& GeneralSettings::debug_enabled() const { return p->debugEnabled_; @@ -200,6 +183,11 @@ SettingsVariable& GeneralSettings::default_radar_site() const return p->defaultRadarSite_; } +SettingsVariable& GeneralSettings::default_time_zone() const +{ + return p->defaultTimeZone_; +} + SettingsContainer>& GeneralSettings::font_sizes() const { @@ -293,9 +281,11 @@ GeneralSettings& GeneralSettings::Instance() bool operator==(const GeneralSettings& lhs, const GeneralSettings& rhs) { return (lhs.p->antiAliasingEnabled_ == rhs.p->antiAliasingEnabled_ && + lhs.p->clockFormat_ == rhs.p->clockFormat_ && lhs.p->debugEnabled_ == rhs.p->debugEnabled_ && lhs.p->defaultAlertAction_ == rhs.p->defaultAlertAction_ && lhs.p->defaultRadarSite_ == rhs.p->defaultRadarSite_ && + lhs.p->defaultTimeZone_ == rhs.p->defaultTimeZone_ && lhs.p->fontSizes_ == rhs.p->fontSizes_ && lhs.p->gridWidth_ == rhs.p->gridWidth_ && lhs.p->gridHeight_ == rhs.p->gridHeight_ && diff --git a/scwx-qt/source/scwx/qt/settings/general_settings.hpp b/scwx-qt/source/scwx/qt/settings/general_settings.hpp index 984fa995..e11597c7 100644 --- a/scwx-qt/source/scwx/qt/settings/general_settings.hpp +++ b/scwx-qt/source/scwx/qt/settings/general_settings.hpp @@ -26,9 +26,11 @@ public: GeneralSettings& operator=(GeneralSettings&&) noexcept; SettingsVariable& anti_aliasing_enabled() const; + SettingsVariable& clock_format() const; SettingsVariable& debug_enabled() const; SettingsVariable& default_alert_action() const; SettingsVariable& default_radar_site() const; + SettingsVariable& default_time_zone() const; SettingsContainer>& font_sizes() const; SettingsVariable& grid_height() const; SettingsVariable& grid_width() const; diff --git a/scwx-qt/source/scwx/qt/types/time_types.cpp b/scwx-qt/source/scwx/qt/types/time_types.cpp new file mode 100644 index 00000000..7978f207 --- /dev/null +++ b/scwx-qt/source/scwx/qt/types/time_types.cpp @@ -0,0 +1,42 @@ +#include +#include + +#include + +#include + +namespace scwx +{ +namespace qt +{ +namespace types +{ + +static const std::unordered_map clockFormatName_ { + {ClockFormat::_12Hour, "12-hour"}, + {ClockFormat::_24Hour, "24-hour"}, + {ClockFormat::Unknown, "?"}}; + +static const std::unordered_map + defaultTimeZoneName_ {{DefaultTimeZone::Local, "Local"}, + {DefaultTimeZone::Radar, "Radar"}, + {DefaultTimeZone::UTC, "UTC"}, + {DefaultTimeZone::Unknown, "?"}}; + +SCWX_GET_ENUM(ClockFormat, GetClockFormat, clockFormatName_) + +const std::string& GetClockFormatName(ClockFormat clockFormat) +{ + return clockFormatName_.at(clockFormat); +} + +SCWX_GET_ENUM(DefaultTimeZone, GetDefaultTimeZone, defaultTimeZoneName_) + +const std::string& GetDefaultTimeZoneName(DefaultTimeZone timeZone) +{ + return defaultTimeZoneName_.at(timeZone); +} + +} // namespace types +} // namespace qt +} // namespace scwx diff --git a/scwx-qt/source/scwx/qt/types/time_types.hpp b/scwx-qt/source/scwx/qt/types/time_types.hpp new file mode 100644 index 00000000..3764d56a --- /dev/null +++ b/scwx-qt/source/scwx/qt/types/time_types.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include + +#include + +namespace scwx +{ +namespace qt +{ +namespace types +{ + +enum class ClockFormat +{ + _12Hour, + _24Hour, + Unknown +}; +typedef scwx::util:: + Iterator + ClockFormatIterator; + +enum class DefaultTimeZone +{ + Local, + Radar, + UTC, + Unknown +}; +typedef scwx::util:: + Iterator + DefaultTimeZoneIterator; + +ClockFormat GetClockFormat(const std::string& name); +const std::string& GetClockFormatName(ClockFormat clockFormat); +DefaultTimeZone GetDefaultTimeZone(const std::string& name); +const std::string& GetDefaultTimeZoneName(DefaultTimeZone timeZone); + +} // namespace types +} // namespace qt +} // namespace scwx diff --git a/test/data b/test/data index 9cef3730..2ba87405 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit 9cef3730c84d22803ea433fba8111826327dd82f +Subproject commit 2ba8740516bbdc58c848bf71755b2f285aa47938