mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 13:20:04 +00:00
AlertModel::HandleAlert should find the alert index from the UUID
This commit is contained in:
parent
dc074b0262
commit
4532327f50
2 changed files with 39 additions and 14 deletions
|
|
@ -323,23 +323,45 @@ AlertModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlertModel::HandleAlert(const types::TextEventKey& alertKey,
|
void AlertModel::HandleAlert(const types::TextEventKey& alertKey,
|
||||||
size_t messageIndex)
|
std::size_t messageIndex,
|
||||||
|
boost::uuids::uuid uuid)
|
||||||
{
|
{
|
||||||
logger_->trace("Handle alert: {}", alertKey.ToString());
|
logger_->trace("Handle alert: {}", alertKey.ToString());
|
||||||
|
|
||||||
double distanceInMeters;
|
double distanceInMeters;
|
||||||
|
|
||||||
auto alertMessages = p->textEventManager_->message_list(alertKey);
|
const auto& alertMessages = p->textEventManager_->message_list(alertKey);
|
||||||
|
|
||||||
|
// Find message by UUID instead of index, as the message index could have
|
||||||
|
// changed between the signal being emitted and the handler being called
|
||||||
|
auto messageIt = std::find_if(alertMessages.cbegin(),
|
||||||
|
alertMessages.cend(),
|
||||||
|
[&uuid](const auto& message)
|
||||||
|
{ return uuid == message->uuid(); });
|
||||||
|
|
||||||
|
if (messageIt == alertMessages.cend())
|
||||||
|
{
|
||||||
|
logger_->warn("Could not find alert uuid: {} ({})",
|
||||||
|
alertKey.ToString(),
|
||||||
|
messageIndex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& message = *messageIt;
|
||||||
|
|
||||||
|
// Store the current message index
|
||||||
|
messageIndex = static_cast<std::size_t>(
|
||||||
|
std::distance(alertMessages.cbegin(), messageIt));
|
||||||
|
|
||||||
// Skip alert if this is not the most recent message
|
// Skip alert if this is not the most recent message
|
||||||
if (alertMessages.empty() || messageIndex + 1 < alertMessages.size())
|
if (messageIndex + 1 < alertMessages.size())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the most recent segment for the event
|
// Get the most recent segment for the event
|
||||||
std::shared_ptr<const awips::Segment> alertSegment =
|
const std::shared_ptr<const awips::Segment> alertSegment =
|
||||||
alertMessages[messageIndex]->segments().back();
|
message->segments().back();
|
||||||
|
|
||||||
p->observedMap_.insert_or_assign(alertKey, alertSegment->observed_);
|
p->observedMap_.insert_or_assign(alertKey, alertSegment->observed_);
|
||||||
p->threatCategoryMap_.insert_or_assign(alertKey,
|
p->threatCategoryMap_.insert_or_assign(alertKey,
|
||||||
|
|
@ -519,8 +541,8 @@ std::string AlertModelImpl::GetCounties(const types::TextEventKey& key)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger_->warn("GetCounties(): No message associated with key: {}",
|
logger_->trace("GetCounties(): No message associated with key: {}",
|
||||||
key.ToString());
|
key.ToString());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -538,8 +560,8 @@ std::string AlertModelImpl::GetState(const types::TextEventKey& key)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger_->warn("GetState(): No message associated with key: {}",
|
logger_->trace("GetState(): No message associated with key: {}",
|
||||||
key.ToString());
|
key.ToString());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -556,8 +578,8 @@ AlertModelImpl::GetStartTime(const types::TextEventKey& key)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger_->warn("GetStartTime(): No message associated with key: {}",
|
logger_->trace("GetStartTime(): No message associated with key: {}",
|
||||||
key.ToString());
|
key.ToString());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -581,8 +603,8 @@ AlertModelImpl::GetEndTime(const types::TextEventKey& key)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger_->warn("GetEndTime(): No message associated with key: {}",
|
logger_->trace("GetEndTime(): No message associated with key: {}",
|
||||||
key.ToString());
|
key.ToString());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
|
#include <boost/uuid/uuid.hpp>
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
|
|
@ -51,7 +52,9 @@ public:
|
||||||
int role = Qt::DisplayRole) const override;
|
int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void HandleAlert(const types::TextEventKey& alertKey, size_t messageIndex);
|
void HandleAlert(const types::TextEventKey& alertKey,
|
||||||
|
std::size_t messageIndex,
|
||||||
|
boost::uuids::uuid uuid);
|
||||||
void HandleAlertsRemoved(
|
void HandleAlertsRemoved(
|
||||||
const std::unordered_set<types::TextEventKey,
|
const std::unordered_set<types::TextEventKey,
|
||||||
types::TextEventHash<types::TextEventKey>>&
|
types::TextEventHash<types::TextEventKey>>&
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue