From aec52f940da6836a021d1f049fd2a156864c51e3 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sun, 4 Aug 2024 23:05:02 -0500 Subject: [PATCH] Open alert dialog when an alert is selected on the map --- scwx-qt/source/scwx/qt/main/main_window.cpp | 4 ++++ scwx-qt/source/scwx/qt/map/alert_layer.cpp | 12 +++++++++--- scwx-qt/source/scwx/qt/map/alert_layer.hpp | 5 +++++ scwx-qt/source/scwx/qt/map/map_widget.cpp | 8 +++++++- scwx-qt/source/scwx/qt/map/map_widget.hpp | 2 ++ scwx-qt/source/scwx/qt/ui/alert_dock_widget.cpp | 7 +++++++ scwx-qt/source/scwx/qt/ui/alert_dock_widget.hpp | 3 +++ 7 files changed, 37 insertions(+), 4 deletions(-) diff --git a/scwx-qt/source/scwx/qt/main/main_window.cpp b/scwx-qt/source/scwx/qt/main/main_window.cpp index 718f0e3a..4046e3bd 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.cpp +++ b/scwx-qt/source/scwx/qt/main/main_window.cpp @@ -830,6 +830,10 @@ void MainWindowImpl::ConnectMapSignals() { for (const auto& mapWidget : maps_) { + connect(mapWidget, + &map::MapWidget::AlertSelected, + alertDockWidget_, + &ui::AlertDockWidget::SelectAlert); connect(mapWidget, &map::MapWidget::MapParametersChanged, this, diff --git a/scwx-qt/source/scwx/qt/map/alert_layer.cpp b/scwx-qt/source/scwx/qt/map/alert_layer.cpp index 77273afa..85429f5e 100644 --- a/scwx-qt/source/scwx/qt/map/alert_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/alert_layer.cpp @@ -109,8 +109,10 @@ signals: class AlertLayer::Impl { public: - explicit Impl(std::shared_ptr context, + explicit Impl(AlertLayer* self, + std::shared_ptr context, awips::Phenomenon phenomenon) : + self_ {self}, phenomenon_ {phenomenon}, geoLines_ {{false, std::make_shared(context)}, {true, std::make_shared(context)}} @@ -165,6 +167,8 @@ public: boost::container::stable_vector< std::shared_ptr>& drawItems); + AlertLayer* self_; + const awips::Phenomenon phenomenon_; std::unique_ptr receiver_ {std::make_unique()}; @@ -190,7 +194,7 @@ public: AlertLayer::AlertLayer(std::shared_ptr context, awips::Phenomenon phenomenon) : - DrawLayer(context), p(std::make_unique(context, phenomenon)) + DrawLayer(context), p(std::make_unique(this, context, phenomenon)) { for (auto alertActive : {false, true}) { @@ -536,7 +540,9 @@ void AlertLayer::Impl::HandleGeoLinesEvent( auto it = segmentsByLine_.find(di); if (it != segmentsByLine_.cend()) { - logger_->info("Selected alert: {}", it->second->key_.ToString()); + // Display alert dialog + logger_->debug("Selected alert: {}", it->second->key_.ToString()); + Q_EMIT self_->AlertSelected(it->second->key_); } break; } diff --git a/scwx-qt/source/scwx/qt/map/alert_layer.hpp b/scwx-qt/source/scwx/qt/map/alert_layer.hpp index 1bcf91c9..abc3f8f2 100644 --- a/scwx-qt/source/scwx/qt/map/alert_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/alert_layer.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -16,6 +17,7 @@ namespace map class AlertLayer : public DrawLayer { + Q_OBJECT Q_DISABLE_COPY_MOVE(AlertLayer) public: @@ -27,6 +29,9 @@ public: void Render(const QMapLibre::CustomLayerRenderParameters&) override final; void Deinitialize() override final; +signals: + void AlertSelected(const types::TextEventKey& key); + private: class Impl; std::unique_ptr p; diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index 7a7f37bc..85e1a0a6 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -1180,9 +1180,15 @@ void MapWidgetImpl::AddLayer(types::LayerType type, { auto phenomenon = std::get(description); + std::shared_ptr alertLayer = + std::make_shared(context_, phenomenon); AddLayer(fmt::format("alert.{}", awips::GetPhenomenonCode(phenomenon)), - std::make_shared(context_, phenomenon), + alertLayer, before); + connect(alertLayer.get(), + &AlertLayer::AlertSelected, + widget_, + &MapWidget::AlertSelected); } else if (type == types::LayerType::Placefile) { diff --git a/scwx-qt/source/scwx/qt/map/map_widget.hpp b/scwx-qt/source/scwx/qt/map/map_widget.hpp index d47c55ab..40f7df77 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.hpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -150,6 +151,7 @@ private slots: void mapChanged(QMapLibre::Map::MapChange); signals: + void AlertSelected(const types::TextEventKey& key); void Level3ProductsChanged(); void MapParametersChanged(double latitude, double longitude, diff --git a/scwx-qt/source/scwx/qt/ui/alert_dock_widget.cpp b/scwx-qt/source/scwx/qt/ui/alert_dock_widget.cpp index e827469c..61fd160a 100644 --- a/scwx-qt/source/scwx/qt/ui/alert_dock_widget.cpp +++ b/scwx-qt/source/scwx/qt/ui/alert_dock_widget.cpp @@ -114,6 +114,13 @@ void AlertDockWidget::HandleMapUpdate(double latitude, double longitude) } } +void AlertDockWidget::SelectAlert(const types::TextEventKey& key) +{ + // View alert + p->alertDialog_->SelectAlert(key); + p->alertDialog_->show(); +} + void AlertDockWidgetImpl::ConnectSignals() { connect(self_->ui->alertFilter, diff --git a/scwx-qt/source/scwx/qt/ui/alert_dock_widget.hpp b/scwx-qt/source/scwx/qt/ui/alert_dock_widget.hpp index 6ccdd5f4..237bed27 100644 --- a/scwx-qt/source/scwx/qt/ui/alert_dock_widget.hpp +++ b/scwx-qt/source/scwx/qt/ui/alert_dock_widget.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include namespace Ui @@ -32,6 +34,7 @@ signals: public slots: void HandleMapUpdate(double latitude, double longitude); + void SelectAlert(const types::TextEventKey& key); private: friend class AlertDockWidgetImpl;