mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 20:50:06 +00:00
Refactor clock format to wxdata
This commit is contained in:
parent
bb287dad9c
commit
a7cb459e20
6 changed files with 42 additions and 33 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include <scwx/qt/types/alert_types.hpp>
|
||||
#include <scwx/qt/types/qt_types.hpp>
|
||||
#include <scwx/qt/types/time_types.hpp>
|
||||
#include <scwx/util/time.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -12,24 +12,12 @@ 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)
|
||||
|
|
|
|||
|
|
@ -11,16 +11,6 @@ namespace qt
|
|||
namespace types
|
||||
{
|
||||
|
||||
enum class ClockFormat
|
||||
{
|
||||
_12Hour,
|
||||
_24Hour,
|
||||
Unknown
|
||||
};
|
||||
typedef scwx::util::
|
||||
Iterator<ClockFormat, ClockFormat::_12Hour, ClockFormat::_24Hour>
|
||||
ClockFormatIterator;
|
||||
|
||||
enum class DefaultTimeZone
|
||||
{
|
||||
Local,
|
||||
|
|
@ -32,8 +22,6 @@ 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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/util/iterator.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#if !defined(_MSC_VER)
|
||||
# include <date/tz.h>
|
||||
|
|
@ -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<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,
|
||||
uint32_t milliseconds);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,12 @@
|
|||
#endif
|
||||
|
||||
#include <scwx/util/time.hpp>
|
||||
#include <scwx/util/enum.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#if !defined(_MSC_VER)
|
||||
# include <date/date.h>
|
||||
|
|
@ -21,6 +25,18 @@ namespace scwx
|
|||
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,
|
||||
uint32_t milliseconds)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue