mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 21:20:06 +00:00
Handle selection of items in the alert view
This commit is contained in:
parent
f8021b00bf
commit
c117078335
5 changed files with 60 additions and 4 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/qt/types/text_event_key.hpp>
|
||||
#include <scwx/common/geographic.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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_);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ namespace types
|
|||
|
||||
struct TextEventKey
|
||||
{
|
||||
TextEventKey() : TextEventKey(awips::PVtec {}) {}
|
||||
TextEventKey(const awips::PVtec& pvtec) :
|
||||
officeId_ {pvtec.office_id()},
|
||||
phenomenon_ {pvtec.phenomenon()},
|
||||
|
|
|
|||
|
|
@ -27,7 +27,9 @@ public:
|
|||
alertModel_ {std::make_unique<model::AlertModel>()},
|
||||
proxyModel_ {std::make_unique<QSortFilterProxyModel>()},
|
||||
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue