Skip to content

Commit

Permalink
Merge pull request #178 from dpaulat/feature/time-customization
Browse files Browse the repository at this point in the history
Time Customization
  • Loading branch information
dpaulat authored Mar 30, 2024
2 parents 1e19f63 + d3375de commit 0fabe1e
Show file tree
Hide file tree
Showing 18 changed files with 664 additions and 394 deletions.
412 changes: 206 additions & 206 deletions scwx-qt/res/config/radar_sites.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions scwx-qt/scwx-qt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
61 changes: 43 additions & 18 deletions scwx-qt/source/scwx/qt/config/radar_site.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
#include <scwx/common/sites.hpp>
#include <scwx/util/logger.hpp>

#include <chrono>
#include <shared_mutex>
#include <unordered_map>

#include <boost/json.hpp>

#if !defined(_MSC_VER)
# include <date/date.h>
#endif

namespace scwx
{
namespace qt
Expand All @@ -35,26 +40,19 @@ static bool ValidateJsonEntry(const boost::json::object& o);
class RadarSiteImpl
{
public:
explicit RadarSiteImpl() :
type_ {},
id_ {},
latitude_ {0.0},
longitude_ {0.0},
country_ {},
state_ {},
place_ {}
{
}

explicit RadarSiteImpl() {}
~RadarSiteImpl() {}

std::string type_;
std::string id_;
double latitude_;
double longitude_;
std::string country_;
std::string state_;
std::string place_;
std::string type_ {};
std::string id_ {};
double latitude_ {0.0};
double longitude_ {0.0};
std::string country_ {};
std::string state_ {};
std::string place_ {};
std::string tzName_ {};

const scwx::util::time_zone* timeZone_ {nullptr};
};

RadarSite::RadarSite() : p(std::make_unique<RadarSiteImpl>()) {}
Expand Down Expand Up @@ -134,6 +132,16 @@ std::string RadarSite::location_name() const
return locationName;
}

std::string RadarSite::tz_name() const
{
return p->tzName_;
}

const scwx::util::time_zone* RadarSite::time_zone() const
{
return p->timeZone_;
}

std::shared_ptr<RadarSite> RadarSite::Get(const std::string& id)
{
std::shared_lock lock(siteMutex_);
Expand Down Expand Up @@ -259,6 +267,23 @@ size_t RadarSite::ReadConfig(const std::string& path)
boost::json::value_to<std::string>(o.at("country"));
site->p->state_ = boost::json::value_to<std::string>(o.at("state"));
site->p->place_ = boost::json::value_to<std::string>(o.at("place"));
site->p->tzName_ = boost::json::value_to<std::string>(o.at("tz"));

try
{
#if defined(_MSC_VER)
using namespace std::chrono;
#else
using namespace date;
#endif

site->p->timeZone_ = get_tzdb().locate_zone(site->p->tzName_);
}
catch (const std::runtime_error&)
{
logger_->warn(
"{} unknown time zone: {}", site->p->id_, site->p->tzName_);
}

if (!radarSiteMap_.contains(site->p->id_))
{
Expand Down
5 changes: 5 additions & 0 deletions scwx-qt/source/scwx/qt/config/radar_site.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <scwx/util/time.hpp>

#include <memory>
#include <optional>
#include <string>
Expand Down Expand Up @@ -35,6 +37,9 @@ class RadarSite
std::string state() const;
std::string place() const;
std::string location_name() const;
std::string tz_name() const;

const scwx::util::time_zone* time_zone() const;

static std::shared_ptr<RadarSite> Get(const std::string& id);
static std::vector<std::shared_ptr<RadarSite>> GetAll();
Expand Down
31 changes: 30 additions & 1 deletion scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include <scwx/qt/manager/radar_product_manager.hpp>
#include <scwx/qt/manager/radar_product_manager_notifier.hpp>
#include <scwx/qt/settings/general_settings.hpp>
#include <scwx/qt/types/time_types.hpp>
#include <scwx/qt/util/geographic_lib.hpp>
#include <scwx/common/constants.hpp>
#include <scwx/provider/nexrad_data_provider_factory.hpp>
#include <scwx/util/logger.hpp>
#include <scwx/util/map.hpp>
#include <scwx/util/threads.hpp>
#include <scwx/util/time.hpp>
#include <scwx/wsr88d/nexrad_file_factory.hpp>

#include <deque>
Expand Down Expand Up @@ -391,6 +392,34 @@ RadarProductManager::coordinates(common::RadialSize radialSize) const
throw std::invalid_argument("Invalid radial size");
}
}
const scwx::util::time_zone* RadarProductManager::default_time_zone() const
{
types::DefaultTimeZone defaultTimeZone = types::GetDefaultTimeZone(
settings::GeneralSettings::Instance().default_time_zone().GetValue());

switch (defaultTimeZone)
{
case types::DefaultTimeZone::Radar:
{
auto radarSite = radar_site();
if (radarSite != nullptr)
{
return radarSite->time_zone();
}
[[fallthrough]];
}

case types::DefaultTimeZone::Local:
#if defined(_MSC_VER)
return std::chrono::current_zone();
#else
return date::current_zone();
#endif

default:
return nullptr;
}
}

float RadarProductManager::gate_size() const
{
Expand Down
6 changes: 4 additions & 2 deletions scwx-qt/source/scwx/qt/manager/radar_product_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <scwx/qt/config/radar_site.hpp>
#include <scwx/qt/request/nexrad_file_request.hpp>
#include <scwx/qt/types/radar_product_record.hpp>
#include <scwx/util/time.hpp>
#include <scwx/wsr88d/ar2v_file.hpp>
#include <scwx/wsr88d/level3_file.hpp>

Expand Down Expand Up @@ -41,8 +42,9 @@ class RadarProductManager : public QObject
static void DumpRecords();

const std::vector<float>& coordinates(common::RadialSize radialSize) const;
float gate_size() const;
std::string radar_id() const;
const scwx::util::time_zone* default_time_zone() const;
float gate_size() const;
std::string radar_id() const;
std::shared_ptr<config::RadarSite> radar_site() const;

void Initialize();
Expand Down
38 changes: 30 additions & 8 deletions scwx-qt/source/scwx/qt/map/overlay_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ class OverlayLayerImpl
{
auto& generalSettings = settings::GeneralSettings::Instance();

clockFormatCallbackUuid_ =
generalSettings.clock_format().RegisterValueChangedCallback(
[this](const std::string&)
{
sweepTimeNeedsUpdate_ = true;
Q_EMIT self_->NeedsRendering();
});
defaultTimeZoneCallbackUuid_ =
generalSettings.default_time_zone().RegisterValueChangedCallback(
[this](const std::string&)
{
sweepTimeNeedsUpdate_ = true;
Q_EMIT self_->NeedsRendering();
});
showMapAttributionCallbackUuid_ =
generalSettings.show_map_attribution().RegisterValueChangedCallback(
[this](const bool&) { Q_EMIT self_->NeedsRendering(); });
Expand All @@ -64,6 +78,10 @@ class OverlayLayerImpl
{
auto& generalSettings = settings::GeneralSettings::Instance();

generalSettings.clock_format().UnregisterValueChangedCallback(
clockFormatCallbackUuid_);
generalSettings.default_time_zone().UnregisterValueChangedCallback(
defaultTimeZoneCallbackUuid_);
generalSettings.show_map_attribution().UnregisterValueChangedCallback(
showMapAttributionCallbackUuid_);
generalSettings.show_map_logo().UnregisterValueChangedCallback(
Expand All @@ -72,6 +90,8 @@ class OverlayLayerImpl

OverlayLayer* self_;

boost::uuids::uuid clockFormatCallbackUuid_;
boost::uuids::uuid defaultTimeZoneCallbackUuid_;
boost::uuids::uuid showMapAttributionCallbackUuid_;
boost::uuids::uuid showMapLogoCallbackUuid_;

Expand Down Expand Up @@ -263,18 +283,20 @@ void OverlayLayer::Render(const QMapLibre::CustomLayerRenderParameters& params)

p->sweepTimePicked_ = false;

if (p->sweepTimeNeedsUpdate_ && radarProductView != nullptr)
if (radarProductView != nullptr)
{
const scwx::util::time_zone* currentZone;
scwx::util::ClockFormat clockFormat = scwx::util::GetClockFormat(
settings::GeneralSettings::Instance().clock_format().GetValue());

#if defined(_MSC_VER)
currentZone = std::chrono::current_zone();
#else
currentZone = date::current_zone();
#endif
auto radarProductManager = radarProductView->radar_product_manager();

const scwx::util::time_zone* currentZone =
(radarProductManager != nullptr) ?
radarProductManager->default_time_zone() :
nullptr;

p->sweepTimeString_ = scwx::util::TimeString(
radarProductView->sweep_time(), currentZone, false);
radarProductView->sweep_time(), clockFormat, currentZone, false);
p->sweepTimeNeedsUpdate_ = false;
}

Expand Down
Loading

0 comments on commit 0fabe1e

Please sign in to comment.