Add clock format and default time zone to settings

This commit is contained in:
Dan Paulat 2024-03-29 00:01:18 -05:00
parent f719fcbc06
commit 2a0ab9ad93
6 changed files with 136 additions and 58 deletions

View file

@ -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

View file

@ -1,8 +1,10 @@
#include <scwx/qt/settings/general_settings.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/types/alert_types.hpp>
#include <scwx/qt/types/qt_types.hpp>
#include <scwx/qt/types/time_types.hpp>
#include <array>
@ -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<bool> antiAliasingEnabled_ {"anti_aliasing_enabled"};
SettingsVariable<std::string> clockFormat_ {"clock_format"};
SettingsVariable<bool> debugEnabled_ {"debug_enabled"};
SettingsVariable<std::string> defaultAlertAction_ {"default_alert_action"};
SettingsVariable<std::string> defaultRadarSite_ {"default_radar_site"};
SettingsVariable<std::string> defaultTimeZone_ {"default_time_zone"};
SettingsContainer<std::vector<std::int64_t>> fontSizes_ {"font_sizes"};
SettingsVariable<std::int64_t> gridWidth_ {"grid_width"};
SettingsVariable<std::int64_t> gridHeight_ {"grid_height"};
@ -154,10 +130,12 @@ public:
GeneralSettings::GeneralSettings() :
SettingsCategory("general"), p(std::make_unique<Impl>())
{
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<bool>& GeneralSettings::anti_aliasing_enabled() const
return p->antiAliasingEnabled_;
}
SettingsVariable<std::string>& GeneralSettings::clock_format() const
{
return p->clockFormat_;
}
SettingsVariable<bool>& GeneralSettings::debug_enabled() const
{
return p->debugEnabled_;
@ -200,6 +183,11 @@ SettingsVariable<std::string>& GeneralSettings::default_radar_site() const
return p->defaultRadarSite_;
}
SettingsVariable<std::string>& GeneralSettings::default_time_zone() const
{
return p->defaultTimeZone_;
}
SettingsContainer<std::vector<std::int64_t>>&
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_ &&

View file

@ -26,9 +26,11 @@ public:
GeneralSettings& operator=(GeneralSettings&&) noexcept;
SettingsVariable<bool>& anti_aliasing_enabled() const;
SettingsVariable<std::string>& clock_format() const;
SettingsVariable<bool>& debug_enabled() const;
SettingsVariable<std::string>& default_alert_action() const;
SettingsVariable<std::string>& default_radar_site() const;
SettingsVariable<std::string>& default_time_zone() const;
SettingsContainer<std::vector<std::int64_t>>& font_sizes() const;
SettingsVariable<std::int64_t>& grid_height() const;
SettingsVariable<std::int64_t>& grid_width() const;

View 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

View 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