From 8be9cc72de5388ce1fc66b0ec8126b6ce577fa30 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Fri, 28 Feb 2025 12:20:12 -0500 Subject: [PATCH 1/2] Fall back to default color palette on failure to load color palette. --- scwx-qt/source/scwx/qt/map/map_widget.cpp | 40 ++++++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index b7e9abee..d2d480de 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -1866,26 +1866,48 @@ void MapWidgetImpl::InitializeNewRadarProductView( const std::string& colorPalette) { boost::asio::post(threadPool_, - [=, this]() + [colorPalette, this]() { try { auto radarProductView = context_->radar_product_view(); + auto& paletteSetting = + settings::PaletteSettings::Instance().palette( + colorPalette); + std::string colorTableFile = - settings::PaletteSettings::Instance() - .palette(colorPalette) - .GetValue(); - if (!colorTableFile.empty()) + paletteSetting.GetValue(); + if (colorTableFile.empty()) + { + colorTableFile = paletteSetting.GetDefault(); + } + + std::unique_ptr colorTableStream = + util::OpenFile(colorTableFile); + if (colorTableStream->fail()) { - std::unique_ptr colorTableStream = - util::OpenFile(colorTableFile); - std::shared_ptr colorTable = + 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->LoadColorTable(colorTable); + radarProductView->Initialize(); } catch (const std::exception& ex) From dc3258d149e3afb14e435c8222e569e714b818fe Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Fri, 28 Feb 2025 15:49:56 -0500 Subject: [PATCH 2/2] Clang tidy/format fixes for color_palette_fallback_warning --- scwx-qt/source/scwx/qt/map/map_widget.cpp | 81 +++++++++++------------ 1 file changed, 37 insertions(+), 44 deletions(-) diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index d2d480de..9096a4b7 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -1865,56 +1865,49 @@ void MapWidgetImpl::RadarProductManagerDisconnect() void MapWidgetImpl::InitializeNewRadarProductView( const std::string& colorPalette) { - boost::asio::post(threadPool_, - [colorPalette, this]() - { - try - { - auto radarProductView = - context_->radar_product_view(); + boost::asio::post( + threadPool_, + [colorPalette, this]() + { + try + { + auto radarProductView = context_->radar_product_view(); - auto& paletteSetting = - settings::PaletteSettings::Instance().palette( - colorPalette); + auto& paletteSetting = + settings::PaletteSettings::Instance().palette(colorPalette); - std::string colorTableFile = - paletteSetting.GetValue(); - if (colorTableFile.empty()) - { - colorTableFile = paletteSetting.GetDefault(); - } + 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::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); - } + 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->LoadColorTable(colorTable); - radarProductView->Initialize(); - } - catch (const std::exception& ex) - { - logger_->error(ex.what()); - } - }); + radarProductView->Initialize(); + } + catch (const std::exception& ex) + { + logger_->error(ex.what()); + } + }); if (map_ != nullptr) {