Add threat category to alert dock widget

This commit is contained in:
Dan Paulat 2024-06-18 00:33:22 -05:00
parent 9437b0bfce
commit 49ba9b905b
3 changed files with 57 additions and 15 deletions

View file

@ -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<types::TextEventKey,
awips::ThreatCategory,
types::TextEventHash<types::TextEventKey>>
threatCategoryMap_;
std::unordered_map<types::TextEventKey,
common::Coordinate,
types::TextEventHash<types::TextEventKey>>
@ -125,6 +131,17 @@ QVariant AlertModel::data(const QModelIndex& index, int role) const
return QString::fromStdString(
awips::GetSignificanceText(textEventKey.significance_));
case static_cast<int>(Column::ThreatCategory):
if (role == Qt::DisplayRole)
{
return QString::fromStdString(awips::GetThreatCategoryName(
p->GetThreatCategory(textEventKey)));
}
else
{
return static_cast<int>(p->GetThreatCategory(textEventKey));
}
case static_cast<int>(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<int>(Column::Significance):
return tr("Significance");
case static_cast<int>(Column::ThreatCategory):
return tr("Category");
case static_cast<int>(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<int>(Column::ThreatCategory):
contentsSize = fontMetrics.size(0, QString(6, 'W'));
break;
case static_cast<int>(Column::State):
contentsSize = fontMetrics.size(0, "WW, WW");
break;
@ -285,6 +309,9 @@ void AlertModel::HandleAlert(const types::TextEventKey& alertKey,
std::shared_ptr<const awips::Segment> 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);

View file

@ -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);

View file

@ -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
};