From 34ec35caf0e7d8b984312d3956db4390243a095b Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 31 May 2025 00:24:17 -0500 Subject: [PATCH] Update color table immediately on palette change --- scwx-qt/source/scwx/qt/map/map_widget.cpp | 100 ++++++++++++---------- 1 file changed, 57 insertions(+), 43 deletions(-) diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index 78362a28..e219bfb6 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -135,6 +135,9 @@ public: ~MapWidgetImpl() { + // Disconnect signals + colorPaletteConnection_.disconnect(); + DeinitializeCustomStyles(); // Set ImGui Context @@ -182,6 +185,7 @@ public: std::optional type); void SetRadarSite(const std::string& radarSite, bool checkProductAvailability = false); + void UpdateColorTable(const std::string& colorPalette); void UpdateLoadedStyle(); bool UpdateStoredMapParameters(); void CheckLevel3Availability(); @@ -214,6 +218,8 @@ public: boost::uuids::uuid customStyleUrlChangedCallbackId_ {}; boost::uuids::uuid customStyleDrawBelowChangedCallbackId_ {}; + boost::signals2::scoped_connection colorPaletteConnection_ {}; + ImGuiContext* imGuiContext_; std::string imGuiContextName_; bool imGuiRendererInitialized_; @@ -901,6 +907,13 @@ void MapWidget::SelectRadarProduct(common::RadarProductGroup group, (group == common::RadarProductGroup::Level2) ? common::GetLevel2Palette(common::GetLevel2Product(productName)) : common::GetLevel3Palette(productCode); + + auto& paletteSetting = + settings::PaletteSettings::Instance().palette(palette); + + p->colorPaletteConnection_ = paletteSetting.changed_signal().connect( + [this, palette]() { p->UpdateColorTable(palette); }); + p->InitializeNewRadarProductView(palette); } else if (update) @@ -1953,49 +1966,19 @@ void MapWidgetImpl::RadarProductManagerDisconnect() void MapWidgetImpl::InitializeNewRadarProductView( const std::string& colorPalette) { - boost::asio::post( - threadPool_, - [colorPalette, this]() - { - try - { - auto radarProductView = context_->radar_product_view(); - - auto& paletteSetting = - settings::PaletteSettings::Instance().palette(colorPalette); - - std::string colorTableFile = paletteSetting.GetValue(); - if (colorTableFile.empty()) - { - colorTableFile = paletteSetting.GetDefault(); - } - - std::unique_ptr colorTableStream = - util::OpenFile(colorTableFile); - if (colorTableStream->fail()) - { - logger_->warn("Could not open color table {}", colorTableFile); - colorTableStream = util::OpenFile(paletteSetting.GetDefault()); - } - - std::shared_ptr colorTable = - common::ColorTable::Load(*colorTableStream); - if (!colorTable->IsValid()) - { - logger_->warn("Could not load color table {}", colorTableFile); - colorTableStream = util::OpenFile(paletteSetting.GetDefault()); - colorTable = common::ColorTable::Load(*colorTableStream); - } - - radarProductView->LoadColorTable(colorTable); - - radarProductView->Initialize(); - } - catch (const std::exception& ex) - { - logger_->error(ex.what()); - } - }); + boost::asio::post(threadPool_, + [colorPalette, this]() + { + try + { + UpdateColorTable(colorPalette); + context_->radar_product_view()->Initialize(); + } + catch (const std::exception& ex) + { + logger_->error(ex.what()); + } + }); if (map_ != nullptr) { @@ -2116,6 +2099,37 @@ void MapWidgetImpl::Update() } } +void MapWidgetImpl::UpdateColorTable(const std::string& colorPalette) +{ + auto& paletteSetting = + settings::PaletteSettings::Instance().palette(colorPalette); + + std::string colorTableFile = paletteSetting.GetValue(); + if (colorTableFile.empty()) + { + colorTableFile = paletteSetting.GetDefault(); + } + + std::unique_ptr colorTableStream = + util::OpenFile(colorTableFile); + if (colorTableStream->fail()) + { + logger_->warn("Could not open color table {}", colorTableFile); + colorTableStream = util::OpenFile(paletteSetting.GetDefault()); + } + + std::shared_ptr colorTable = + common::ColorTable::Load(*colorTableStream); + if (!colorTable->IsValid()) + { + logger_->warn("Could not load color table {}", colorTableFile); + colorTableStream = util::OpenFile(paletteSetting.GetDefault()); + colorTable = common::ColorTable::Load(*colorTableStream); + } + + context_->radar_product_view()->LoadColorTable(colorTable); +} + bool MapWidgetImpl::UpdateStoredMapParameters() { bool changed = false;