Use new alert palette settings in parent palette settings

This commit is contained in:
Dan Paulat 2024-09-21 08:30:17 -05:00
parent efee1653e1
commit 47b7d475c8
2 changed files with 17 additions and 60 deletions

View file

@ -76,32 +76,6 @@ static const awips::Phenomenon kDefaultPhenomenon_ {awips::Phenomenon::Marine};
class PaletteSettings::Impl class PaletteSettings::Impl
{ {
public: public:
struct AlertData
{
AlertData(awips::Phenomenon phenomenon) : phenomenon_ {phenomenon}
{
auto& info = awips::ibw::GetImpactBasedWarningInfo(phenomenon);
for (auto& threatCategory : info.threatCategories_)
{
std::string threatCategoryName =
awips::ibw::GetThreatCategoryName(threatCategory);
boost::algorithm::to_lower(threatCategoryName);
threatCategoryMap_.emplace(threatCategory, threatCategoryName);
}
}
void RegisterVariables(SettingsCategory& settings);
awips::Phenomenon phenomenon_;
std::map<awips::ibw::ThreatCategory, SettingsVariable<std::string>>
threatCategoryMap_ {};
SettingsVariable<std::string> observed_ {"observed"};
SettingsVariable<std::string> tornadoPossible_ {"tornado_possible"};
SettingsVariable<std::string> inactive_ {"inactive"};
};
explicit Impl(PaletteSettings* self) : self_ {self} explicit Impl(PaletteSettings* self) : self_ {self}
{ {
InitializeColorTables(); InitializeColorTables();
@ -124,9 +98,8 @@ public:
inactiveAlertColor_ {}; inactiveAlertColor_ {};
std::vector<SettingsVariableBase*> variables_ {}; std::vector<SettingsVariableBase*> variables_ {};
std::unordered_map<awips::Phenomenon, AlertData> alertDataMap_ {}; std::unordered_map<awips::Phenomenon, AlertPaletteSettings>
alertPaletteMap_ {};
std::vector<SettingsCategory> alertSettings_ {};
}; };
PaletteSettings::PaletteSettings() : PaletteSettings::PaletteSettings() :
@ -197,43 +170,19 @@ void PaletteSettings::Impl::InitializeLegacyAlerts()
void PaletteSettings::Impl::InitializeAlerts() void PaletteSettings::Impl::InitializeAlerts()
{ {
std::vector<SettingsCategory*> alertSettings {};
for (auto phenomenon : PaletteSettings::alert_phenomena()) for (auto phenomenon : PaletteSettings::alert_phenomena())
{ {
auto pair = alertDataMap_.emplace( auto result = alertPaletteMap_.emplace(phenomenon, phenomenon);
std::make_pair(phenomenon, AlertData {phenomenon})); auto& it = result.first;
auto& alertData = pair.first->second; AlertPaletteSettings& alertPaletteSettings = it->second;
// Variable registration // Variable registration
auto& settings = alertSettings_.emplace_back( alertSettings.push_back(&alertPaletteSettings);
SettingsCategory {awips::GetPhenomenonCode(phenomenon)});
alertData.RegisterVariables(settings);
} }
self_->RegisterSubcategoryArray("alerts", alertSettings_); self_->RegisterSubcategoryArray("alerts", alertSettings);
}
void PaletteSettings::Impl::AlertData::RegisterVariables(
SettingsCategory& settings)
{
auto& info = awips::ibw::GetImpactBasedWarningInfo(phenomenon_);
for (auto& threatCategory : threatCategoryMap_)
{
settings.RegisterVariables({&threatCategory.second});
}
if (info.hasObservedTag_)
{
settings.RegisterVariables({&observed_});
}
if (info.hasTornadoPossibleTag_)
{
settings.RegisterVariables({&tornadoPossible_});
}
settings.RegisterVariables({&inactive_});
} }
SettingsVariable<std::string>& SettingsVariable<std::string>&
@ -272,6 +221,12 @@ PaletteSettings::alert_color(awips::Phenomenon phenomenon, bool active) const
} }
} }
AlertPaletteSettings&
PaletteSettings::alert_palette(awips::Phenomenon phenomenon)
{
return p->alertPaletteMap_.at(phenomenon);
}
const std::vector<awips::Phenomenon>& PaletteSettings::alert_phenomena() const std::vector<awips::Phenomenon>& PaletteSettings::alert_phenomena()
{ {
static const std::vector<awips::Phenomenon> kAlertPhenomena_ { static const std::vector<awips::Phenomenon> kAlertPhenomena_ {

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <scwx/qt/settings/alert_palette_settings.hpp>
#include <scwx/qt/settings/settings_category.hpp> #include <scwx/qt/settings/settings_category.hpp>
#include <scwx/qt/settings/settings_variable.hpp> #include <scwx/qt/settings/settings_variable.hpp>
#include <scwx/awips/impact_based_warnings.hpp> #include <scwx/awips/impact_based_warnings.hpp>
@ -30,6 +31,7 @@ public:
SettingsVariable<std::string>& palette(const std::string& name) const; SettingsVariable<std::string>& palette(const std::string& name) const;
SettingsVariable<std::string>& alert_color(awips::Phenomenon phenomenon, SettingsVariable<std::string>& alert_color(awips::Phenomenon phenomenon,
bool active) const; bool active) const;
AlertPaletteSettings& alert_palette(awips::Phenomenon);
static const std::vector<awips::Phenomenon>& alert_phenomena(); static const std::vector<awips::Phenomenon>& alert_phenomena();