From 49ba9b905b29063082ec4b4c894355f3b42b4377 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Tue, 18 Jun 2024 00:33:22 -0500 Subject: [PATCH] Add threat category to alert dock widget --- scwx-qt/source/scwx/qt/model/alert_model.cpp | 41 +++++++++++++++++++ scwx-qt/source/scwx/qt/model/alert_model.hpp | 19 +++++---- .../scwx/awips/impact_based_warnings.hpp | 12 +++--- 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/scwx-qt/source/scwx/qt/model/alert_model.cpp b/scwx-qt/source/scwx/qt/model/alert_model.cpp index 4cadff42..18ff2055 100644 --- a/scwx-qt/source/scwx/qt/model/alert_model.cpp +++ b/scwx-qt/source/scwx/qt/model/alert_model.cpp @@ -34,6 +34,8 @@ public: explicit AlertModelImpl(); ~AlertModelImpl() = default; + awips::ThreatCategory GetThreatCategory(const types::TextEventKey& key); + static std::string GetCounties(const types::TextEventKey& key); static std::string GetState(const types::TextEventKey& key); static std::chrono::system_clock::time_point @@ -49,6 +51,10 @@ public: const GeographicLib::Geodesic& geodesic_; + std::unordered_map> + threatCategoryMap_; std::unordered_map> @@ -125,6 +131,17 @@ QVariant AlertModel::data(const QModelIndex& index, int role) const return QString::fromStdString( awips::GetSignificanceText(textEventKey.significance_)); + case static_cast(Column::ThreatCategory): + if (role == Qt::DisplayRole) + { + return QString::fromStdString(awips::GetThreatCategoryName( + p->GetThreatCategory(textEventKey))); + } + else + { + return static_cast(p->GetThreatCategory(textEventKey)); + } + case static_cast(Column::State): return QString::fromStdString(AlertModelImpl::GetState(textEventKey)); @@ -204,6 +221,9 @@ AlertModel::headerData(int section, Qt::Orientation orientation, int role) const case static_cast(Column::Significance): return tr("Significance"); + case static_cast(Column::ThreatCategory): + return tr("Category"); + case static_cast(Column::State): return tr("State"); @@ -240,6 +260,10 @@ AlertModel::headerData(int section, Qt::Orientation orientation, int role) const contentsSize = fontMetrics.size(0, QString(10, 'W')); break; + case static_cast(Column::ThreatCategory): + contentsSize = fontMetrics.size(0, QString(6, 'W')); + break; + case static_cast(Column::State): contentsSize = fontMetrics.size(0, "WW, WW"); break; @@ -285,6 +309,9 @@ void AlertModel::HandleAlert(const types::TextEventKey& alertKey, std::shared_ptr alertSegment = alertMessages[messageIndex]->segments().back(); + p->threatCategoryMap_.insert_or_assign(alertKey, + alertSegment->threatCategory_); + if (alertSegment->codedLocation_.has_value()) { // Update centroid and distance @@ -365,6 +392,20 @@ AlertModelImpl::AlertModelImpl() : { } +awips::ThreatCategory +AlertModelImpl::GetThreatCategory(const types::TextEventKey& key) +{ + awips::ThreatCategory threatCategory = awips::ThreatCategory::Base; + + auto it = threatCategoryMap_.find(key); + if (it != threatCategoryMap_.cend()) + { + threatCategory = it->second; + } + + return threatCategory; +} + std::string AlertModelImpl::GetCounties(const types::TextEventKey& key) { auto messageList = manager::TextEventManager::Instance()->message_list(key); diff --git a/scwx-qt/source/scwx/qt/model/alert_model.hpp b/scwx-qt/source/scwx/qt/model/alert_model.hpp index 76bddf9d..71fb0dfb 100644 --- a/scwx-qt/source/scwx/qt/model/alert_model.hpp +++ b/scwx-qt/source/scwx/qt/model/alert_model.hpp @@ -21,15 +21,16 @@ class AlertModel : public QAbstractTableModel public: enum class Column : int { - Etn = 0, - OfficeId = 1, - Phenomenon = 2, - Significance = 3, - State = 4, - Counties = 5, - StartTime = 6, - EndTime = 7, - Distance = 8 + Etn = 0, + OfficeId = 1, + Phenomenon = 2, + Significance = 3, + ThreatCategory = 4, + State = 5, + Counties = 6, + StartTime = 7, + EndTime = 8, + Distance = 9 }; explicit AlertModel(QObject* parent = nullptr); diff --git a/wxdata/include/scwx/awips/impact_based_warnings.hpp b/wxdata/include/scwx/awips/impact_based_warnings.hpp index ff64bb99..a7b22288 100644 --- a/wxdata/include/scwx/awips/impact_based_warnings.hpp +++ b/wxdata/include/scwx/awips/impact_based_warnings.hpp @@ -7,13 +7,13 @@ namespace scwx namespace awips { -enum class ThreatCategory +enum class ThreatCategory : int { - Base, - Significant, - Considerable, - Destructive, - Catastrophic, + Base = 0, + Significant = 1, + Considerable = 2, + Destructive = 3, + Catastrophic = 4, Unknown };