From c1170783353d6e8aa777ea12f4dc71162cda859e Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sun, 16 Oct 2022 00:49:00 -0500 Subject: [PATCH] Handle selection of items in the alert view --- scwx-qt/source/scwx/qt/model/alert_model.cpp | 19 +++++++++++ scwx-qt/source/scwx/qt/model/alert_model.hpp | 4 +++ .../source/scwx/qt/types/text_event_key.cpp | 6 ++-- .../source/scwx/qt/types/text_event_key.hpp | 1 + .../source/scwx/qt/ui/alert_dock_widget.cpp | 34 ++++++++++++++++++- 5 files changed, 60 insertions(+), 4 deletions(-) diff --git a/scwx-qt/source/scwx/qt/model/alert_model.cpp b/scwx-qt/source/scwx/qt/model/alert_model.cpp index 5df7c76b..c14ce460 100644 --- a/scwx-qt/source/scwx/qt/model/alert_model.cpp +++ b/scwx-qt/source/scwx/qt/model/alert_model.cpp @@ -66,6 +66,25 @@ AlertModel::AlertModel(QObject* parent) : } AlertModel::~AlertModel() = default; +types::TextEventKey AlertModel::key(const QModelIndex& index) const +{ + return index.isValid() ? p->textEventKeys_[index.row()] : + types::TextEventKey {}; +} + +common::Coordinate AlertModel::centroid(const types::TextEventKey& key) const +{ + common::Coordinate centroid {}; + + const auto& it = p->centroidMap_.find(key); + if (it != p->centroidMap_.cend()) + { + centroid = it->second; + } + + return centroid; +} + int AlertModel::rowCount(const QModelIndex& parent) const { return parent.isValid() ? 0 : p->textEventKeys_.size(); diff --git a/scwx-qt/source/scwx/qt/model/alert_model.hpp b/scwx-qt/source/scwx/qt/model/alert_model.hpp index d10aa7e3..d15de462 100644 --- a/scwx-qt/source/scwx/qt/model/alert_model.hpp +++ b/scwx-qt/source/scwx/qt/model/alert_model.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include @@ -21,6 +22,9 @@ public: explicit AlertModel(QObject* parent = nullptr); ~AlertModel(); + types::TextEventKey key(const QModelIndex& index) const; + common::Coordinate centroid(const types::TextEventKey& key) const; + int rowCount(const QModelIndex& parent = QModelIndex()) const override; int columnCount(const QModelIndex& parent = QModelIndex()) const override; diff --git a/scwx-qt/source/scwx/qt/types/text_event_key.cpp b/scwx-qt/source/scwx/qt/types/text_event_key.cpp index 0e5b189f..cbf29baf 100644 --- a/scwx-qt/source/scwx/qt/types/text_event_key.cpp +++ b/scwx-qt/source/scwx/qt/types/text_event_key.cpp @@ -15,10 +15,10 @@ static const std::string logPrefix_ = "scwx::qt::types::text_event_key"; std::string TextEventKey::ToString() const { - return std::format("{}, {}, {}, {}", + return std::format("{}.{}.{}.{}", officeId_, - awips::GetPhenomenonText(phenomenon_), - awips::GetSignificanceText(significance_), + awips::GetPhenomenonCode(phenomenon_), + awips::GetSignificanceCode(significance_), etn_); } diff --git a/scwx-qt/source/scwx/qt/types/text_event_key.hpp b/scwx-qt/source/scwx/qt/types/text_event_key.hpp index 1925b5ee..8fd187eb 100644 --- a/scwx-qt/source/scwx/qt/types/text_event_key.hpp +++ b/scwx-qt/source/scwx/qt/types/text_event_key.hpp @@ -11,6 +11,7 @@ namespace types struct TextEventKey { + TextEventKey() : TextEventKey(awips::PVtec {}) {} TextEventKey(const awips::PVtec& pvtec) : officeId_ {pvtec.office_id()}, phenomenon_ {pvtec.phenomenon()}, 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 21c35098..39cc9220 100644 --- a/scwx-qt/source/scwx/qt/ui/alert_dock_widget.cpp +++ b/scwx-qt/source/scwx/qt/ui/alert_dock_widget.cpp @@ -27,7 +27,9 @@ public: alertModel_ {std::make_unique()}, proxyModel_ {std::make_unique()}, mapPosition_ {}, - mapUpdateDeferred_ {false} + mapUpdateDeferred_ {false}, + selectedAlertKey_ {}, + selectedAlertCentroid_ {} { proxyModel_->setSourceModel(alertModel_.get()); proxyModel_->setSortRole(types::SortRole); @@ -44,6 +46,9 @@ public: scwx::common::Coordinate mapPosition_; bool mapUpdateDeferred_; + + types::TextEventKey selectedAlertKey_; + common::Coordinate selectedAlertCentroid_; }; AlertDockWidget::AlertDockWidget(QWidget* parent) : @@ -57,6 +62,9 @@ AlertDockWidget::AlertDockWidget(QWidget* parent) : ui->alertSettings->addAction(ui->actionActiveAlerts); + ui->alertViewButton->setEnabled(false); + ui->alertGoButton->setEnabled(false); + p->ConnectSignals(); } @@ -115,6 +123,30 @@ void AlertDockWidgetImpl::ConnectSignals() // the indices of selected items change. return; } + + bool itemSelected = selected.size() > 0; + bool itemHasCoordinates = false; + + if (itemSelected) + { + QModelIndex selectedIndex = + proxyModel_->mapToSource(selected[0].indexes()[0]); + selectedAlertKey_ = alertModel_->key(selectedIndex); + selectedAlertCentroid_ = + alertModel_->centroid(selectedAlertKey_); + itemHasCoordinates = + selectedAlertCentroid_ != common::Coordinate {}; + } + else + { + selectedAlertKey_ = {}; + selectedAlertCentroid_ = {}; + } + + self_->ui->alertViewButton->setEnabled(itemSelected); + self_->ui->alertGoButton->setEnabled(itemHasCoordinates); + + logger_->debug("Selected: {}", selectedAlertKey_.ToString()); }); connect(self_->ui->alertViewButton, &QPushButton::clicked,