Alert dialog button logic, update dialog on message receipt

This commit is contained in:
Dan Paulat 2022-10-16 23:29:59 -05:00
parent b24acb7642
commit ad7f3674d6
4 changed files with 98 additions and 22 deletions

View file

@ -137,9 +137,10 @@ void TextEventManager::Impl::HandleMessage(
}
else if (std::find_if(it->second.cbegin(),
it->second.cend(),
[=](auto& storedMessage) {
return message->wmo_header() ==
storedMessage->wmo_header();
[=](auto& storedMessage)
{
return *message->wmo_header().get() ==
*storedMessage->wmo_header().get();
}) == it->second.cend())
{
// If there was a matching event, and this message has not been stored

View file

@ -4,6 +4,8 @@
#include <scwx/qt/manager/text_event_manager.hpp>
#include <scwx/util/logger.hpp>
#include <QPushButton>
namespace scwx
{
namespace qt
@ -14,21 +16,28 @@ namespace ui
static const std::string logPrefix_ = "scwx::qt::ui::alert_dialog";
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
class AlertDialogImpl
class AlertDialogImpl : public QObject
{
Q_OBJECT
public:
explicit AlertDialogImpl(AlertDialog* self) :
self_ {self}, key_ {}, coordinate_ {}, currentIndex_ {0u}
self_ {self},
goButton_ {nullptr},
key_ {},
centroid_ {},
currentIndex_ {0u}
{
}
~AlertDialogImpl() = default;
void ConnectSignals();
void SelectIndex(size_t newIndex);
void UpdateAlertInfo();
AlertDialog* self_;
QPushButton* goButton_;
types::TextEventKey key_;
common::Coordinate coordinate_;
common::Coordinate centroid_;
size_t currentIndex_;
};
@ -45,7 +54,7 @@ AlertDialog::AlertDialog(QWidget* parent) :
ui->alertText->setFont(monospaceFont);
// Add Go button to button box
ui->buttonBox->addButton("&Go", QDialogButtonBox::ActionRole);
p->goButton_ = ui->buttonBox->addButton("&Go", QDialogButtonBox::ActionRole);
p->ConnectSignals();
}
@ -55,13 +64,33 @@ AlertDialog::~AlertDialog()
delete ui;
}
void AlertDialogImpl::ConnectSignals() {}
bool AlertDialog::SelectAlert(const types::TextEventKey& key,
const common::Coordinate& coordinate)
void AlertDialogImpl::ConnectSignals()
{
p->key_ = key;
p->coordinate_ = coordinate;
connect(
&manager::TextEventManager::Instance(),
&manager::TextEventManager::AlertUpdated,
this,
[=](const types::TextEventKey& key)
{
if (key == key_)
{
UpdateAlertInfo();
}
},
Qt::QueuedConnection);
connect(goButton_,
&QPushButton::clicked,
this,
[=]()
{
emit self_->MoveMap(centroid_.latitude_, centroid_.longitude_);
self_->close();
});
}
bool AlertDialog::SelectAlert(const types::TextEventKey& key)
{
p->key_ = key;
setWindowTitle(QString::fromStdString(key.ToFullString()));
@ -71,7 +100,7 @@ bool AlertDialog::SelectAlert(const types::TextEventKey& key,
return false;
}
p->SelectIndex(messages.size() - 1);
p->SelectIndex(messages.size() - 1u);
return true;
}
@ -92,19 +121,61 @@ void AlertDialogImpl::SelectIndex(size_t newIndex)
self_->ui->alertText->setText(
QString::fromStdString(messages[currentIndex_]->message_content()));
self_->ui->messageCountLabel->setText(
QObject::tr("%1 of %2").arg(currentIndex_ + 1).arg(messageCount));
bool firstSelected = (currentIndex_ == 0);
bool lastSelected = (currentIndex_ == messages.size() - 1);
UpdateAlertInfo();
}
void AlertDialogImpl::UpdateAlertInfo()
{
auto messages = manager::TextEventManager::Instance().message_list(key_);
size_t messageCount = messages.size();
bool firstSelected = (currentIndex_ == 0u);
bool lastSelected = (currentIndex_ == messageCount - 1u);
self_->ui->firstButton->setEnabled(!firstSelected);
self_->ui->previousButton->setEnabled(!firstSelected);
self_->ui->nextButton->setEnabled(!lastSelected);
self_->ui->lastButton->setEnabled(!lastSelected);
self_->ui->messageCountLabel->setText(
QObject::tr("%1 of %2").arg(currentIndex_ + 1u).arg(messageCount));
// Update centroid
auto alertSegment = messages[currentIndex_]->segments().back();
if (alertSegment->codedLocation_.has_value())
{
centroid_ =
common::GetCentroid(alertSegment->codedLocation_->coordinates());
}
goButton_->setEnabled(centroid_ != common::Coordinate {});
}
void AlertDialog::on_firstButton_clicked()
{
p->SelectIndex(0);
}
void AlertDialog::on_previousButton_clicked()
{
p->SelectIndex(p->currentIndex_ - 1u);
}
void AlertDialog::on_nextButton_clicked()
{
p->SelectIndex(p->currentIndex_ + 1u);
}
void AlertDialog::on_lastButton_clicked()
{
p->SelectIndex(manager::TextEventManager::Instance().message_count(p->key_) -
1u);
}
#include "alert_dialog.moc"
} // namespace ui
} // namespace qt
} // namespace scwx

View file

@ -27,8 +27,13 @@ public:
explicit AlertDialog(QWidget* parent = nullptr);
~AlertDialog();
bool SelectAlert(const types::TextEventKey& key,
const common::Coordinate& coordinate);
bool SelectAlert(const types::TextEventKey& key);
public slots:
void on_firstButton_clicked();
void on_previousButton_clicked();
void on_nextButton_clicked();
void on_lastButton_clicked();
signals:
void MoveMap(double latitude, double longitude);

View file

@ -158,8 +158,7 @@ void AlertDockWidgetImpl::ConnectSignals()
[=]()
{
// View alert
alertDialog_->SelectAlert(selectedAlertKey_,
selectedAlertCentroid_);
alertDialog_->SelectAlert(selectedAlertKey_);
alertDialog_->show();
});
connect(self_->ui->alertGoButton,