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 f0fbaa6c..d76212fd 100644 --- a/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp @@ -245,7 +245,7 @@ void TextEventManager::Impl::HandleMessage( if (updated) { - Q_EMIT self_->AlertUpdated(key, messageIndex); + Q_EMIT self_->AlertUpdated(key, messageIndex, message->uuid()); } } 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 f97ca223..30748781 100644 --- a/scwx-qt/source/scwx/qt/manager/text_event_manager.hpp +++ b/scwx-qt/source/scwx/qt/manager/text_event_manager.hpp @@ -6,6 +6,7 @@ #include #include +#include #include namespace scwx @@ -32,7 +33,9 @@ public: static std::shared_ptr Instance(); signals: - void AlertUpdated(const types::TextEventKey& key, size_t messageIndex); + void AlertUpdated(const types::TextEventKey& key, + std::size_t messageIndex, + boost::uuids::uuid uuid); private: class Impl; diff --git a/scwx-qt/source/scwx/qt/map/alert_layer.cpp b/scwx-qt/source/scwx/qt/map/alert_layer.cpp index 7c5c9db2..77a2332f 100644 --- a/scwx-qt/source/scwx/qt/map/alert_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/alert_layer.cpp @@ -73,8 +73,10 @@ public: connect(textEventManager_.get(), &manager::TextEventManager::AlertUpdated, this, - [this](const types::TextEventKey& key, std::size_t messageIndex) - { HandleAlert(key, messageIndex); }); + [this](const types::TextEventKey& key, + std::size_t messageIndex, + boost::uuids::uuid uuid) + { HandleAlert(key, messageIndex, uuid); }); } ~AlertLayerHandler() { @@ -95,7 +97,9 @@ public: types::TextEventHash> segmentsByKey_ {}; - void HandleAlert(const types::TextEventKey& key, size_t messageIndex); + void HandleAlert(const types::TextEventKey& key, + size_t messageIndex, + boost::uuids::uuid uuid); static AlertLayerHandler& Instance(); @@ -322,7 +326,8 @@ bool IsAlertActive(const std::shared_ptr& segment) } void AlertLayerHandler::HandleAlert(const types::TextEventKey& key, - size_t messageIndex) + size_t messageIndex, + boost::uuids::uuid uuid) { logger_->trace("HandleAlert: {}", key.ToString()); @@ -330,7 +335,27 @@ void AlertLayerHandler::HandleAlert(const types::TextEventKey& key, AlertTypeHash>> alertsUpdated {}; - auto message = textEventManager_->message_list(key).at(messageIndex); + const auto& messageList = textEventManager_->message_list(key); + auto message = messageList.at(messageIndex); + + if (message->uuid() != uuid) + { + // 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 it = std::find_if(messageList.cbegin(), + messageList.cend(), + [&uuid](const auto& message) + { return uuid == message->uuid(); }); + + if (it == messageList.cend()) + { + logger_->warn( + "Could not find alert uuid: {} ({})", key.ToString(), messageIndex); + return; + } + + message = *it; + } // Determine start time for first segment std::chrono::system_clock::time_point segmentBegin {}; diff --git a/wxdata/include/scwx/awips/text_product_message.hpp b/wxdata/include/scwx/awips/text_product_message.hpp index b043494f..6830f91a 100644 --- a/wxdata/include/scwx/awips/text_product_message.hpp +++ b/wxdata/include/scwx/awips/text_product_message.hpp @@ -13,6 +13,8 @@ #include #include +#include + namespace scwx { namespace awips @@ -94,6 +96,7 @@ public: TextProductMessage(TextProductMessage&&) noexcept; TextProductMessage& operator=(TextProductMessage&&) noexcept; + boost::uuids::uuid uuid() const; std::string message_content() const; std::shared_ptr wmo_header() const; std::vector mnd_header() const; diff --git a/wxdata/source/scwx/awips/text_product_message.cpp b/wxdata/source/scwx/awips/text_product_message.cpp index 9674b325..f8716b2b 100644 --- a/wxdata/source/scwx/awips/text_product_message.cpp +++ b/wxdata/source/scwx/awips/text_product_message.cpp @@ -9,6 +9,7 @@ #include #include +#include #include namespace scwx::awips @@ -53,6 +54,8 @@ public: TextProductMessageImpl(const TextProductMessageImpl&&) = delete; TextProductMessageImpl& operator=(const TextProductMessageImpl&&) = delete; + boost::uuids::uuid uuid_ {boost::uuids::random_generator()()}; + std::string messageContent_; std::shared_ptr wmoHeader_; std::vector mndHeader_; @@ -70,6 +73,11 @@ TextProductMessage::TextProductMessage(TextProductMessage&&) noexcept = default; TextProductMessage& TextProductMessage::operator=(TextProductMessage&&) noexcept = default; +boost::uuids::uuid TextProductMessage::uuid() const +{ + return p->uuid_; +} + std::string TextProductMessage::message_content() const { return p->messageContent_;