From 1c5e0d51b7df180713dfe38c31be9f81d40d2012 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 15 Oct 2022 17:41:46 -0500 Subject: [PATCH] Update alert signal to include message index, so messages aren't missed --- .../scwx/qt/manager/text_event_manager.cpp | 17 ++++++++++------- .../scwx/qt/manager/text_event_manager.hpp | 4 ++-- scwx-qt/source/scwx/qt/model/alert_model.cpp | 5 +++-- scwx-qt/source/scwx/qt/model/alert_model.hpp | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp b/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp index 232e2edb..1c743702 100644 --- a/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp @@ -40,17 +40,17 @@ public: TextEventManager::TextEventManager() : p(std::make_unique(this)) {} TextEventManager::~TextEventManager() = default; -std::list> +std::vector> TextEventManager::message_list(const types::TextEventKey& key) const { - std::list> messageList {}; + std::vector> messageList {}; std::shared_lock lock(p->textEventMutex_); auto it = p->textEventMap_.find(key); if (it != p->textEventMap_.cend()) { - messageList = it->second; + messageList.assign(it->second.begin(), it->second.end()); } return messageList; @@ -109,14 +109,16 @@ void TextEventManager::Impl::HandleMessage( // Find a matching event in the event map auto& vtecString = segments[0]->header_->vtecString_; types::TextEventKey key {vtecString[0].pVtec_}; - auto it = textEventMap_.find(key); - bool updated = false; + size_t messageIndex = 0; + auto it = textEventMap_.find(key); + bool updated = false; if (it == textEventMap_.cend()) { // If there was no matching event, add the message to a new event textEventMap_.emplace(key, std::list {message}); - updated = true; + messageIndex = 0; + updated = true; } else if (std::find_if(it->second.cbegin(), it->second.cend(), @@ -128,6 +130,7 @@ void TextEventManager::Impl::HandleMessage( // If there was a matching event, and this message has not been stored // (WMO header equivalence check), add the updated message to the existing // event + messageIndex = it->second.size(); it->second.push_back(message); updated = true; }; @@ -136,7 +139,7 @@ void TextEventManager::Impl::HandleMessage( if (updated) { - emit self_->AlertUpdated(key); + emit self_->AlertUpdated(key, messageIndex); } } diff --git a/scwx-qt/source/scwx/qt/manager/text_event_manager.hpp b/scwx-qt/source/scwx/qt/manager/text_event_manager.hpp index b29a8ebb..97f313cb 100644 --- a/scwx-qt/source/scwx/qt/manager/text_event_manager.hpp +++ b/scwx-qt/source/scwx/qt/manager/text_event_manager.hpp @@ -23,7 +23,7 @@ public: explicit TextEventManager(); ~TextEventManager(); - std::list> + std::vector> message_list(const types::TextEventKey& key) const; void LoadFile(const std::string& filename); @@ -31,7 +31,7 @@ public: static TextEventManager& Instance(); signals: - void AlertUpdated(const types::TextEventKey& key); + void AlertUpdated(const types::TextEventKey& key, size_t messageIndex); private: class Impl; diff --git a/scwx-qt/source/scwx/qt/model/alert_model.cpp b/scwx-qt/source/scwx/qt/model/alert_model.cpp index 23b83af8..5df7c76b 100644 --- a/scwx-qt/source/scwx/qt/model/alert_model.cpp +++ b/scwx-qt/source/scwx/qt/model/alert_model.cpp @@ -171,7 +171,8 @@ AlertModel::headerData(int section, Qt::Orientation orientation, int role) const return QVariant(); } -void AlertModel::HandleAlert(const types::TextEventKey& alertKey) +void AlertModel::HandleAlert(const types::TextEventKey& alertKey, + size_t messageIndex) { logger_->trace("Handle alert: {}", alertKey.ToString()); @@ -181,7 +182,7 @@ void AlertModel::HandleAlert(const types::TextEventKey& alertKey) auto alertMessages = manager::TextEventManager::Instance().message_list(alertKey); std::shared_ptr alertSegment = - alertMessages.back()->segments().back(); + alertMessages[messageIndex]->segments().back(); if (alertSegment->codedLocation_.has_value()) { diff --git a/scwx-qt/source/scwx/qt/model/alert_model.hpp b/scwx-qt/source/scwx/qt/model/alert_model.hpp index 3859b0f6..d10aa7e3 100644 --- a/scwx-qt/source/scwx/qt/model/alert_model.hpp +++ b/scwx-qt/source/scwx/qt/model/alert_model.hpp @@ -31,7 +31,7 @@ public: int role = Qt::DisplayRole) const override; public slots: - void HandleAlert(const types::TextEventKey& alertKey); + void HandleAlert(const types::TextEventKey& alertKey, size_t messageIndex); void HandleMapUpdate(double latitude, double longitude); private: