mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 03:50:05 +00:00 
			
		
		
		
	Add clock format and default time zone to settings
This commit is contained in:
		
							parent
							
								
									f719fcbc06
								
							
						
					
					
						commit
						2a0ab9ad93
					
				
					 6 changed files with 136 additions and 58 deletions
				
			
		|  | @ -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/radar_product_record.hpp | ||||||
|               source/scwx/qt/types/text_event_key.hpp |               source/scwx/qt/types/text_event_key.hpp | ||||||
|               source/scwx/qt/types/text_types.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 | set(SRC_TYPES source/scwx/qt/types/alert_types.cpp | ||||||
|               source/scwx/qt/types/github_types.cpp |               source/scwx/qt/types/github_types.cpp | ||||||
|               source/scwx/qt/types/icon_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/radar_product_record.cpp | ||||||
|               source/scwx/qt/types/text_event_key.cpp |               source/scwx/qt/types/text_event_key.cpp | ||||||
|               source/scwx/qt/types/text_types.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 | set(HDR_UI source/scwx/qt/ui/about_dialog.hpp | ||||||
|            source/scwx/qt/ui/alert_dialog.hpp |            source/scwx/qt/ui/alert_dialog.hpp | ||||||
|            source/scwx/qt/ui/alert_dock_widget.hpp |            source/scwx/qt/ui/alert_dock_widget.hpp | ||||||
|  |  | ||||||
|  | @ -1,8 +1,10 @@ | ||||||
| #include <scwx/qt/settings/general_settings.hpp> | #include <scwx/qt/settings/general_settings.hpp> | ||||||
| #include <scwx/qt/settings/settings_container.hpp> | #include <scwx/qt/settings/settings_container.hpp> | ||||||
|  | #include <scwx/qt/settings/settings_definitions.hpp> | ||||||
| #include <scwx/qt/map/map_provider.hpp> | #include <scwx/qt/map/map_provider.hpp> | ||||||
| #include <scwx/qt/types/alert_types.hpp> | #include <scwx/qt/types/alert_types.hpp> | ||||||
| #include <scwx/qt/types/qt_types.hpp> | #include <scwx/qt/types/qt_types.hpp> | ||||||
|  | #include <scwx/qt/types/time_types.hpp> | ||||||
| 
 | 
 | ||||||
| #include <array> | #include <array> | ||||||
| 
 | 
 | ||||||
|  | @ -22,21 +24,29 @@ class GeneralSettings::Impl | ||||||
| public: | public: | ||||||
|    explicit Impl() |    explicit Impl() | ||||||
|    { |    { | ||||||
|  |       std::string defaultClockFormatValue = | ||||||
|  |          types::GetClockFormatName(types::ClockFormat::_24Hour); | ||||||
|       std::string defaultDefaultAlertActionValue = |       std::string defaultDefaultAlertActionValue = | ||||||
|          types::GetAlertActionName(types::AlertAction::Go); |          types::GetAlertActionName(types::AlertAction::Go); | ||||||
|  |       std::string defaultDefaultTimeZoneValue = | ||||||
|  |          types::GetDefaultTimeZoneName(types::DefaultTimeZone::Radar); | ||||||
|       std::string defaultMapProviderValue = |       std::string defaultMapProviderValue = | ||||||
|          map::GetMapProviderName(map::MapProvider::MapTiler); |          map::GetMapProviderName(map::MapProvider::MapTiler); | ||||||
|       std::string defaultThemeValue = |       std::string defaultThemeValue = | ||||||
|          types::GetUiStyleName(types::UiStyle::Default); |          types::GetUiStyleName(types::UiStyle::Default); | ||||||
| 
 | 
 | ||||||
|  |       boost::to_lower(defaultClockFormatValue); | ||||||
|       boost::to_lower(defaultDefaultAlertActionValue); |       boost::to_lower(defaultDefaultAlertActionValue); | ||||||
|  |       boost::to_lower(defaultDefaultTimeZoneValue); | ||||||
|       boost::to_lower(defaultMapProviderValue); |       boost::to_lower(defaultMapProviderValue); | ||||||
|       boost::to_lower(defaultThemeValue); |       boost::to_lower(defaultThemeValue); | ||||||
| 
 | 
 | ||||||
|       antiAliasingEnabled_.SetDefault(true); |       antiAliasingEnabled_.SetDefault(true); | ||||||
|  |       clockFormat_.SetDefault(defaultClockFormatValue); | ||||||
|       debugEnabled_.SetDefault(false); |       debugEnabled_.SetDefault(false); | ||||||
|       defaultAlertAction_.SetDefault(defaultDefaultAlertActionValue); |       defaultAlertAction_.SetDefault(defaultDefaultAlertActionValue); | ||||||
|       defaultRadarSite_.SetDefault("KLSX"); |       defaultRadarSite_.SetDefault("KLSX"); | ||||||
|  |       defaultTimeZone_.SetDefault(defaultDefaultTimeZoneValue); | ||||||
|       fontSizes_.SetDefault({16}); |       fontSizes_.SetDefault({16}); | ||||||
|       loopDelay_.SetDefault(2500); |       loopDelay_.SetDefault(2500); | ||||||
|       loopSpeed_.SetDefault(5.0); |       loopSpeed_.SetDefault(5.0); | ||||||
|  | @ -67,74 +77,40 @@ public: | ||||||
|       loopTime_.SetMinimum(1); |       loopTime_.SetMinimum(1); | ||||||
|       loopTime_.SetMaximum(1440); |       loopTime_.SetMaximum(1440); | ||||||
| 
 | 
 | ||||||
|  |       clockFormat_.SetValidator( | ||||||
|  |          SCWX_SETTINGS_ENUM_VALIDATOR(types::ClockFormat, | ||||||
|  |                                       types::ClockFormatIterator(), | ||||||
|  |                                       types::GetClockFormatName)); | ||||||
|       defaultAlertAction_.SetValidator( |       defaultAlertAction_.SetValidator( | ||||||
|          [](const std::string& value) |          SCWX_SETTINGS_ENUM_VALIDATOR(types::AlertAction, | ||||||
|          { |                                       types::AlertActionIterator(), | ||||||
|             for (types::AlertAction alertAction : types::AlertActionIterator()) |                                       types::GetAlertActionName)); | ||||||
|             { |       defaultTimeZone_.SetValidator( | ||||||
|                // If the value is equal to a lower case alert action name
 |          SCWX_SETTINGS_ENUM_VALIDATOR(types::DefaultTimeZone, | ||||||
|                std::string alertActionName = |                                       types::DefaultTimeZoneIterator(), | ||||||
|                   types::GetAlertActionName(alertAction); |                                       types::GetDefaultTimeZoneName)); | ||||||
|                boost::to_lower(alertActionName); |  | ||||||
|                if (value == alertActionName) |  | ||||||
|                { |  | ||||||
|                   // Regard as a match, valid
 |  | ||||||
|                   return true; |  | ||||||
|                } |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             // No match found, invalid
 |  | ||||||
|             return false; |  | ||||||
|          }); |  | ||||||
|       mapProvider_.SetValidator( |       mapProvider_.SetValidator( | ||||||
|          [](const std::string& value) |          SCWX_SETTINGS_ENUM_VALIDATOR(map::MapProvider, | ||||||
|          { |                                       map::MapProviderIterator(), | ||||||
|             for (map::MapProvider mapProvider : map::MapProviderIterator()) |                                       map::GetMapProviderName)); | ||||||
|             { |  | ||||||
|                // 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; |  | ||||||
|          }); |  | ||||||
|       mapboxApiKey_.SetValidator([](const std::string& value) |       mapboxApiKey_.SetValidator([](const std::string& value) | ||||||
|                                  { return !value.empty(); }); |                                  { return !value.empty(); }); | ||||||
|       maptilerApiKey_.SetValidator([](const std::string& value) |       maptilerApiKey_.SetValidator([](const std::string& value) | ||||||
|                                    { return !value.empty(); }); |                                    { return !value.empty(); }); | ||||||
|       theme_.SetValidator( |       theme_.SetValidator(                            //
 | ||||||
|          [](const std::string& value) |          SCWX_SETTINGS_ENUM_VALIDATOR(types::UiStyle, //
 | ||||||
|          { |                                       types::UiStyleIterator(), | ||||||
|             for (types::UiStyle uiStyle : types::UiStyleIterator()) |                                       types::GetUiStyleName)); | ||||||
|             { |  | ||||||
|                // 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; |  | ||||||
|          }); |  | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    ~Impl() {} |    ~Impl() {} | ||||||
| 
 | 
 | ||||||
|    SettingsVariable<bool>        antiAliasingEnabled_ {"anti_aliasing_enabled"}; |    SettingsVariable<bool>        antiAliasingEnabled_ {"anti_aliasing_enabled"}; | ||||||
|  |    SettingsVariable<std::string> clockFormat_ {"clock_format"}; | ||||||
|    SettingsVariable<bool>        debugEnabled_ {"debug_enabled"}; |    SettingsVariable<bool>        debugEnabled_ {"debug_enabled"}; | ||||||
|    SettingsVariable<std::string> defaultAlertAction_ {"default_alert_action"}; |    SettingsVariable<std::string> defaultAlertAction_ {"default_alert_action"}; | ||||||
|    SettingsVariable<std::string> defaultRadarSite_ {"default_radar_site"}; |    SettingsVariable<std::string> defaultRadarSite_ {"default_radar_site"}; | ||||||
|  |    SettingsVariable<std::string> defaultTimeZone_ {"default_time_zone"}; | ||||||
|    SettingsContainer<std::vector<std::int64_t>> fontSizes_ {"font_sizes"}; |    SettingsContainer<std::vector<std::int64_t>> fontSizes_ {"font_sizes"}; | ||||||
|    SettingsVariable<std::int64_t>               gridWidth_ {"grid_width"}; |    SettingsVariable<std::int64_t>               gridWidth_ {"grid_width"}; | ||||||
|    SettingsVariable<std::int64_t>               gridHeight_ {"grid_height"}; |    SettingsVariable<std::int64_t>               gridHeight_ {"grid_height"}; | ||||||
|  | @ -154,10 +130,12 @@ public: | ||||||
| GeneralSettings::GeneralSettings() : | GeneralSettings::GeneralSettings() : | ||||||
|     SettingsCategory("general"), p(std::make_unique<Impl>()) |     SettingsCategory("general"), p(std::make_unique<Impl>()) | ||||||
| { | { | ||||||
|    RegisterVariables({&p->antiAliasingEnabled_, |    RegisterVariables({&p->antiAliasingEnabled_, //
 | ||||||
|  |                       &p->clockFormat_, | ||||||
|                       &p->debugEnabled_, |                       &p->debugEnabled_, | ||||||
|                       &p->defaultAlertAction_, |                       &p->defaultAlertAction_, | ||||||
|                       &p->defaultRadarSite_, |                       &p->defaultRadarSite_, | ||||||
|  |                       &p->defaultTimeZone_, | ||||||
|                       &p->fontSizes_, |                       &p->fontSizes_, | ||||||
|                       &p->gridWidth_, |                       &p->gridWidth_, | ||||||
|                       &p->gridHeight_, |                       &p->gridHeight_, | ||||||
|  | @ -185,6 +163,11 @@ SettingsVariable<bool>& GeneralSettings::anti_aliasing_enabled() const | ||||||
|    return p->antiAliasingEnabled_; |    return p->antiAliasingEnabled_; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | SettingsVariable<std::string>& GeneralSettings::clock_format() const | ||||||
|  | { | ||||||
|  |    return p->clockFormat_; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| SettingsVariable<bool>& GeneralSettings::debug_enabled() const | SettingsVariable<bool>& GeneralSettings::debug_enabled() const | ||||||
| { | { | ||||||
|    return p->debugEnabled_; |    return p->debugEnabled_; | ||||||
|  | @ -200,6 +183,11 @@ SettingsVariable<std::string>& GeneralSettings::default_radar_site() const | ||||||
|    return p->defaultRadarSite_; |    return p->defaultRadarSite_; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | SettingsVariable<std::string>& GeneralSettings::default_time_zone() const | ||||||
|  | { | ||||||
|  |    return p->defaultTimeZone_; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| SettingsContainer<std::vector<std::int64_t>>& | SettingsContainer<std::vector<std::int64_t>>& | ||||||
| GeneralSettings::font_sizes() const | GeneralSettings::font_sizes() const | ||||||
| { | { | ||||||
|  | @ -293,9 +281,11 @@ GeneralSettings& GeneralSettings::Instance() | ||||||
| bool operator==(const GeneralSettings& lhs, const GeneralSettings& rhs) | bool operator==(const GeneralSettings& lhs, const GeneralSettings& rhs) | ||||||
| { | { | ||||||
|    return (lhs.p->antiAliasingEnabled_ == rhs.p->antiAliasingEnabled_ && |    return (lhs.p->antiAliasingEnabled_ == rhs.p->antiAliasingEnabled_ && | ||||||
|  |            lhs.p->clockFormat_ == rhs.p->clockFormat_ && | ||||||
|            lhs.p->debugEnabled_ == rhs.p->debugEnabled_ && |            lhs.p->debugEnabled_ == rhs.p->debugEnabled_ && | ||||||
|            lhs.p->defaultAlertAction_ == rhs.p->defaultAlertAction_ && |            lhs.p->defaultAlertAction_ == rhs.p->defaultAlertAction_ && | ||||||
|            lhs.p->defaultRadarSite_ == rhs.p->defaultRadarSite_ && |            lhs.p->defaultRadarSite_ == rhs.p->defaultRadarSite_ && | ||||||
|  |            lhs.p->defaultTimeZone_ == rhs.p->defaultTimeZone_ && | ||||||
|            lhs.p->fontSizes_ == rhs.p->fontSizes_ && |            lhs.p->fontSizes_ == rhs.p->fontSizes_ && | ||||||
|            lhs.p->gridWidth_ == rhs.p->gridWidth_ && |            lhs.p->gridWidth_ == rhs.p->gridWidth_ && | ||||||
|            lhs.p->gridHeight_ == rhs.p->gridHeight_ && |            lhs.p->gridHeight_ == rhs.p->gridHeight_ && | ||||||
|  |  | ||||||
|  | @ -26,9 +26,11 @@ public: | ||||||
|    GeneralSettings& operator=(GeneralSettings&&) noexcept; |    GeneralSettings& operator=(GeneralSettings&&) noexcept; | ||||||
| 
 | 
 | ||||||
|    SettingsVariable<bool>&                       anti_aliasing_enabled() const; |    SettingsVariable<bool>&                       anti_aliasing_enabled() const; | ||||||
|  |    SettingsVariable<std::string>&                clock_format() const; | ||||||
|    SettingsVariable<bool>&                       debug_enabled() const; |    SettingsVariable<bool>&                       debug_enabled() const; | ||||||
|    SettingsVariable<std::string>&                default_alert_action() const; |    SettingsVariable<std::string>&                default_alert_action() const; | ||||||
|    SettingsVariable<std::string>&                default_radar_site() const; |    SettingsVariable<std::string>&                default_radar_site() const; | ||||||
|  |    SettingsVariable<std::string>&                default_time_zone() const; | ||||||
|    SettingsContainer<std::vector<std::int64_t>>& font_sizes() const; |    SettingsContainer<std::vector<std::int64_t>>& font_sizes() const; | ||||||
|    SettingsVariable<std::int64_t>&               grid_height() const; |    SettingsVariable<std::int64_t>&               grid_height() const; | ||||||
|    SettingsVariable<std::int64_t>&               grid_width() const; |    SettingsVariable<std::int64_t>&               grid_width() const; | ||||||
|  |  | ||||||
							
								
								
									
										42
									
								
								scwx-qt/source/scwx/qt/types/time_types.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								scwx-qt/source/scwx/qt/types/time_types.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,42 @@ | ||||||
|  | #include <scwx/qt/types/time_types.hpp> | ||||||
|  | #include <scwx/util/enum.hpp> | ||||||
|  | 
 | ||||||
|  | #include <unordered_map> | ||||||
|  | 
 | ||||||
|  | #include <boost/algorithm/string.hpp> | ||||||
|  | 
 | ||||||
|  | namespace scwx | ||||||
|  | { | ||||||
|  | namespace qt | ||||||
|  | { | ||||||
|  | namespace types | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | static const std::unordered_map<ClockFormat, std::string> clockFormatName_ { | ||||||
|  |    {ClockFormat::_12Hour, "12-hour"}, | ||||||
|  |    {ClockFormat::_24Hour, "24-hour"}, | ||||||
|  |    {ClockFormat::Unknown, "?"}}; | ||||||
|  | 
 | ||||||
|  | static const std::unordered_map<DefaultTimeZone, std::string> | ||||||
|  |    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
 | ||||||
							
								
								
									
										42
									
								
								scwx-qt/source/scwx/qt/types/time_types.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								scwx-qt/source/scwx/qt/types/time_types.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,42 @@ | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include <scwx/util/iterator.hpp> | ||||||
|  | 
 | ||||||
|  | #include <string> | ||||||
|  | 
 | ||||||
|  | namespace scwx | ||||||
|  | { | ||||||
|  | namespace qt | ||||||
|  | { | ||||||
|  | namespace types | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | enum class ClockFormat | ||||||
|  | { | ||||||
|  |    _12Hour, | ||||||
|  |    _24Hour, | ||||||
|  |    Unknown | ||||||
|  | }; | ||||||
|  | typedef scwx::util:: | ||||||
|  |    Iterator<ClockFormat, ClockFormat::_12Hour, ClockFormat::_24Hour> | ||||||
|  |       ClockFormatIterator; | ||||||
|  | 
 | ||||||
|  | enum class DefaultTimeZone | ||||||
|  | { | ||||||
|  |    Local, | ||||||
|  |    Radar, | ||||||
|  |    UTC, | ||||||
|  |    Unknown | ||||||
|  | }; | ||||||
|  | typedef scwx::util:: | ||||||
|  |    Iterator<DefaultTimeZone, DefaultTimeZone::Local, DefaultTimeZone::UTC> | ||||||
|  |       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
 | ||||||
|  | @ -1 +1 @@ | ||||||
| Subproject commit 9cef3730c84d22803ea433fba8111826327dd82f | Subproject commit 2ba8740516bbdc58c848bf71755b2f285aa47938 | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat