Refactor clock format to wxdata

This commit is contained in:
Dan Paulat 2024-03-29 00:26:52 -05:00
parent bb287dad9c
commit a7cb459e20
6 changed files with 42 additions and 33 deletions

View file

@ -5,6 +5,7 @@
#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 <scwx/qt/types/time_types.hpp>
#include <scwx/util/time.hpp>
#include <array> #include <array>
@ -25,7 +26,7 @@ public:
explicit Impl() explicit Impl()
{ {
std::string defaultClockFormatValue = std::string defaultClockFormatValue =
types::GetClockFormatName(types::ClockFormat::_24Hour); scwx::util::GetClockFormatName(scwx::util::ClockFormat::_24Hour);
std::string defaultDefaultAlertActionValue = std::string defaultDefaultAlertActionValue =
types::GetAlertActionName(types::AlertAction::Go); types::GetAlertActionName(types::AlertAction::Go);
std::string defaultDefaultTimeZoneValue = std::string defaultDefaultTimeZoneValue =
@ -78,9 +79,9 @@ public:
loopTime_.SetMaximum(1440); loopTime_.SetMaximum(1440);
clockFormat_.SetValidator( clockFormat_.SetValidator(
SCWX_SETTINGS_ENUM_VALIDATOR(types::ClockFormat, SCWX_SETTINGS_ENUM_VALIDATOR(scwx::util::ClockFormat,
types::ClockFormatIterator(), scwx::util::ClockFormatIterator(),
types::GetClockFormatName)); scwx::util::GetClockFormatName));
defaultAlertAction_.SetValidator( defaultAlertAction_.SetValidator(
SCWX_SETTINGS_ENUM_VALIDATOR(types::AlertAction, SCWX_SETTINGS_ENUM_VALIDATOR(types::AlertAction,
types::AlertActionIterator(), types::AlertActionIterator(),

View file

@ -12,24 +12,12 @@ namespace qt
namespace types 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> static const std::unordered_map<DefaultTimeZone, std::string>
defaultTimeZoneName_ {{DefaultTimeZone::Local, "Local"}, defaultTimeZoneName_ {{DefaultTimeZone::Local, "Local"},
{DefaultTimeZone::Radar, "Radar"}, {DefaultTimeZone::Radar, "Radar"},
{DefaultTimeZone::UTC, "UTC"}, {DefaultTimeZone::UTC, "UTC"},
{DefaultTimeZone::Unknown, "?"}}; {DefaultTimeZone::Unknown, "?"}};
SCWX_GET_ENUM(ClockFormat, GetClockFormat, clockFormatName_)
const std::string& GetClockFormatName(ClockFormat clockFormat)
{
return clockFormatName_.at(clockFormat);
}
SCWX_GET_ENUM(DefaultTimeZone, GetDefaultTimeZone, defaultTimeZoneName_) SCWX_GET_ENUM(DefaultTimeZone, GetDefaultTimeZone, defaultTimeZoneName_)
const std::string& GetDefaultTimeZoneName(DefaultTimeZone timeZone) const std::string& GetDefaultTimeZoneName(DefaultTimeZone timeZone)

View file

@ -11,16 +11,6 @@ namespace qt
namespace types namespace types
{ {
enum class ClockFormat
{
_12Hour,
_24Hour,
Unknown
};
typedef scwx::util::
Iterator<ClockFormat, ClockFormat::_12Hour, ClockFormat::_24Hour>
ClockFormatIterator;
enum class DefaultTimeZone enum class DefaultTimeZone
{ {
Local, Local,
@ -32,8 +22,6 @@ typedef scwx::util::
Iterator<DefaultTimeZone, DefaultTimeZone::Local, DefaultTimeZone::UTC> Iterator<DefaultTimeZone, DefaultTimeZone::Local, DefaultTimeZone::UTC>
DefaultTimeZoneIterator; DefaultTimeZoneIterator;
ClockFormat GetClockFormat(const std::string& name);
const std::string& GetClockFormatName(ClockFormat clockFormat);
DefaultTimeZone GetDefaultTimeZone(const std::string& name); DefaultTimeZone GetDefaultTimeZone(const std::string& name);
const std::string& GetDefaultTimeZoneName(DefaultTimeZone timeZone); const std::string& GetDefaultTimeZoneName(DefaultTimeZone timeZone);

View file

@ -608,17 +608,17 @@ void SettingsDialogImpl::SetupGeneralTab()
defaultAlertAction_.SetEditWidget(self_->ui->defaultAlertActionComboBox); defaultAlertAction_.SetEditWidget(self_->ui->defaultAlertActionComboBox);
defaultAlertAction_.SetResetButton(self_->ui->resetDefaultAlertActionButton); defaultAlertAction_.SetResetButton(self_->ui->resetDefaultAlertActionButton);
for (const auto& clockFormat : types::ClockFormatIterator()) for (const auto& clockFormat : scwx::util::ClockFormatIterator())
{ {
self_->ui->clockFormatComboBox->addItem( self_->ui->clockFormatComboBox->addItem(
QString::fromStdString(types::GetClockFormatName(clockFormat))); QString::fromStdString(scwx::util::GetClockFormatName(clockFormat)));
} }
clockFormat_.SetSettingsVariable(generalSettings.clock_format()); clockFormat_.SetSettingsVariable(generalSettings.clock_format());
clockFormat_.SetMapFromValueFunction( clockFormat_.SetMapFromValueFunction(
SCWX_ENUM_MAP_FROM_VALUE(types::ClockFormat, SCWX_ENUM_MAP_FROM_VALUE(scwx::util::ClockFormat,
types::ClockFormatIterator(), scwx::util::ClockFormatIterator(),
types::GetClockFormatName)); scwx::util::GetClockFormatName));
clockFormat_.SetMapToValueFunction( clockFormat_.SetMapToValueFunction(
[](std::string text) -> std::string [](std::string text) -> std::string
{ {

View file

@ -1,7 +1,10 @@
#pragma once #pragma once
#include <scwx/util/iterator.hpp>
#include <chrono> #include <chrono>
#include <optional> #include <optional>
#include <string>
#if !defined(_MSC_VER) #if !defined(_MSC_VER)
# include <date/tz.h> # include <date/tz.h>
@ -18,6 +21,19 @@ typedef std::chrono::time_zone time_zone;
typedef date::time_zone time_zone; typedef date::time_zone time_zone;
#endif #endif
enum class ClockFormat
{
_12Hour,
_24Hour,
Unknown
};
typedef scwx::util::
Iterator<ClockFormat, ClockFormat::_12Hour, ClockFormat::_24Hour>
ClockFormatIterator;
ClockFormat GetClockFormat(const std::string& name);
const std::string& GetClockFormatName(ClockFormat clockFormat);
std::chrono::system_clock::time_point TimePoint(uint32_t modifiedJulianDate, std::chrono::system_clock::time_point TimePoint(uint32_t modifiedJulianDate,
uint32_t milliseconds); uint32_t milliseconds);

View file

@ -9,8 +9,12 @@
#endif #endif
#include <scwx/util/time.hpp> #include <scwx/util/time.hpp>
#include <scwx/util/enum.hpp>
#include <sstream> #include <sstream>
#include <unordered_map>
#include <boost/algorithm/string.hpp>
#if !defined(_MSC_VER) #if !defined(_MSC_VER)
# include <date/date.h> # include <date/date.h>
@ -21,6 +25,18 @@ namespace scwx
namespace util namespace util
{ {
static const std::unordered_map<ClockFormat, std::string> clockFormatName_ {
{ClockFormat::_12Hour, "12-hour"},
{ClockFormat::_24Hour, "24-hour"},
{ClockFormat::Unknown, "?"}};
SCWX_GET_ENUM(ClockFormat, GetClockFormat, clockFormatName_)
const std::string& GetClockFormatName(ClockFormat clockFormat)
{
return clockFormatName_.at(clockFormat);
}
std::chrono::system_clock::time_point TimePoint(uint32_t modifiedJulianDate, std::chrono::system_clock::time_point TimePoint(uint32_t modifiedJulianDate,
uint32_t milliseconds) uint32_t milliseconds)
{ {