From a7cb459e2035dca4999cf9f9fb361de0674d105f Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Fri, 29 Mar 2024 00:26:52 -0500 Subject: [PATCH] Refactor clock format to wxdata --- .../source/scwx/qt/settings/general_settings.cpp | 9 +++++---- scwx-qt/source/scwx/qt/types/time_types.cpp | 12 ------------ scwx-qt/source/scwx/qt/types/time_types.hpp | 12 ------------ scwx-qt/source/scwx/qt/ui/settings_dialog.cpp | 10 +++++----- wxdata/include/scwx/util/time.hpp | 16 ++++++++++++++++ wxdata/source/scwx/util/time.cpp | 16 ++++++++++++++++ 6 files changed, 42 insertions(+), 33 deletions(-) diff --git a/scwx-qt/source/scwx/qt/settings/general_settings.cpp b/scwx-qt/source/scwx/qt/settings/general_settings.cpp index b865e5f9..86544a1e 100644 --- a/scwx-qt/source/scwx/qt/settings/general_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/general_settings.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -25,7 +26,7 @@ public: explicit Impl() { std::string defaultClockFormatValue = - types::GetClockFormatName(types::ClockFormat::_24Hour); + scwx::util::GetClockFormatName(scwx::util::ClockFormat::_24Hour); std::string defaultDefaultAlertActionValue = types::GetAlertActionName(types::AlertAction::Go); std::string defaultDefaultTimeZoneValue = @@ -78,9 +79,9 @@ public: loopTime_.SetMaximum(1440); clockFormat_.SetValidator( - SCWX_SETTINGS_ENUM_VALIDATOR(types::ClockFormat, - types::ClockFormatIterator(), - types::GetClockFormatName)); + SCWX_SETTINGS_ENUM_VALIDATOR(scwx::util::ClockFormat, + scwx::util::ClockFormatIterator(), + scwx::util::GetClockFormatName)); defaultAlertAction_.SetValidator( SCWX_SETTINGS_ENUM_VALIDATOR(types::AlertAction, types::AlertActionIterator(), diff --git a/scwx-qt/source/scwx/qt/types/time_types.cpp b/scwx-qt/source/scwx/qt/types/time_types.cpp index 7978f207..01c53fed 100644 --- a/scwx-qt/source/scwx/qt/types/time_types.cpp +++ b/scwx-qt/source/scwx/qt/types/time_types.cpp @@ -12,24 +12,12 @@ 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) diff --git a/scwx-qt/source/scwx/qt/types/time_types.hpp b/scwx-qt/source/scwx/qt/types/time_types.hpp index 3764d56a..2d4fa2b1 100644 --- a/scwx-qt/source/scwx/qt/types/time_types.hpp +++ b/scwx-qt/source/scwx/qt/types/time_types.hpp @@ -11,16 +11,6 @@ namespace qt namespace types { -enum class ClockFormat -{ - _12Hour, - _24Hour, - Unknown -}; -typedef scwx::util:: - Iterator - ClockFormatIterator; - enum class DefaultTimeZone { Local, @@ -32,8 +22,6 @@ 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); diff --git a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp index 2a87e5c2..635324cc 100644 --- a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp +++ b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp @@ -608,17 +608,17 @@ void SettingsDialogImpl::SetupGeneralTab() defaultAlertAction_.SetEditWidget(self_->ui->defaultAlertActionComboBox); defaultAlertAction_.SetResetButton(self_->ui->resetDefaultAlertActionButton); - for (const auto& clockFormat : types::ClockFormatIterator()) + for (const auto& clockFormat : scwx::util::ClockFormatIterator()) { self_->ui->clockFormatComboBox->addItem( - QString::fromStdString(types::GetClockFormatName(clockFormat))); + QString::fromStdString(scwx::util::GetClockFormatName(clockFormat))); } clockFormat_.SetSettingsVariable(generalSettings.clock_format()); clockFormat_.SetMapFromValueFunction( - SCWX_ENUM_MAP_FROM_VALUE(types::ClockFormat, - types::ClockFormatIterator(), - types::GetClockFormatName)); + SCWX_ENUM_MAP_FROM_VALUE(scwx::util::ClockFormat, + scwx::util::ClockFormatIterator(), + scwx::util::GetClockFormatName)); clockFormat_.SetMapToValueFunction( [](std::string text) -> std::string { diff --git a/wxdata/include/scwx/util/time.hpp b/wxdata/include/scwx/util/time.hpp index 04cc1d39..b5ef06df 100644 --- a/wxdata/include/scwx/util/time.hpp +++ b/wxdata/include/scwx/util/time.hpp @@ -1,7 +1,10 @@ #pragma once +#include + #include #include +#include #if !defined(_MSC_VER) # include @@ -18,6 +21,19 @@ typedef std::chrono::time_zone time_zone; typedef date::time_zone time_zone; #endif +enum class ClockFormat +{ + _12Hour, + _24Hour, + Unknown +}; +typedef scwx::util:: + Iterator + ClockFormatIterator; + +ClockFormat GetClockFormat(const std::string& name); +const std::string& GetClockFormatName(ClockFormat clockFormat); + std::chrono::system_clock::time_point TimePoint(uint32_t modifiedJulianDate, uint32_t milliseconds); diff --git a/wxdata/source/scwx/util/time.cpp b/wxdata/source/scwx/util/time.cpp index 9fdd9a3e..a46c28a3 100644 --- a/wxdata/source/scwx/util/time.cpp +++ b/wxdata/source/scwx/util/time.cpp @@ -9,8 +9,12 @@ #endif #include +#include #include +#include + +#include #if !defined(_MSC_VER) # include @@ -21,6 +25,18 @@ namespace scwx namespace util { +static const std::unordered_map 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, uint32_t milliseconds) {