mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 06:50:05 +00:00 
			
		
		
		
	Alert dialog button logic, update dialog on message receipt
This commit is contained in:
		
							parent
							
								
									b24acb7642
								
							
						
					
					
						commit
						ad7f3674d6
					
				
					 4 changed files with 98 additions and 22 deletions
				
			
		|  | @ -137,9 +137,10 @@ void TextEventManager::Impl::HandleMessage( | ||||||
|    } |    } | ||||||
|    else if (std::find_if(it->second.cbegin(), |    else if (std::find_if(it->second.cbegin(), | ||||||
|                          it->second.cend(), |                          it->second.cend(), | ||||||
|                          [=](auto& storedMessage) { |                          [=](auto& storedMessage) | ||||||
|                             return message->wmo_header() == |                          { | ||||||
|                                    storedMessage->wmo_header(); |                             return *message->wmo_header().get() == | ||||||
|  |                                    *storedMessage->wmo_header().get(); | ||||||
|                          }) == it->second.cend()) |                          }) == it->second.cend()) | ||||||
|    { |    { | ||||||
|       // If there was a matching event, and this message has not been stored
 |       // If there was a matching event, and this message has not been stored
 | ||||||
|  |  | ||||||
|  | @ -4,6 +4,8 @@ | ||||||
| #include <scwx/qt/manager/text_event_manager.hpp> | #include <scwx/qt/manager/text_event_manager.hpp> | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
| 
 | 
 | ||||||
|  | #include <QPushButton> | ||||||
|  | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
| namespace qt | namespace qt | ||||||
|  | @ -14,21 +16,28 @@ namespace ui | ||||||
| static const std::string logPrefix_ = "scwx::qt::ui::alert_dialog"; | static const std::string logPrefix_ = "scwx::qt::ui::alert_dialog"; | ||||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||||
| 
 | 
 | ||||||
| class AlertDialogImpl | class AlertDialogImpl : public QObject | ||||||
| { | { | ||||||
|  |    Q_OBJECT | ||||||
| public: | public: | ||||||
|    explicit AlertDialogImpl(AlertDialog* self) : |    explicit AlertDialogImpl(AlertDialog* self) : | ||||||
|        self_ {self}, key_ {}, coordinate_ {}, currentIndex_ {0u} |        self_ {self}, | ||||||
|  |        goButton_ {nullptr}, | ||||||
|  |        key_ {}, | ||||||
|  |        centroid_ {}, | ||||||
|  |        currentIndex_ {0u} | ||||||
|    { |    { | ||||||
|    } |    } | ||||||
|    ~AlertDialogImpl() = default; |    ~AlertDialogImpl() = default; | ||||||
| 
 | 
 | ||||||
|    void ConnectSignals(); |    void ConnectSignals(); | ||||||
|    void SelectIndex(size_t newIndex); |    void SelectIndex(size_t newIndex); | ||||||
|  |    void UpdateAlertInfo(); | ||||||
| 
 | 
 | ||||||
|    AlertDialog*        self_; |    AlertDialog*        self_; | ||||||
|  |    QPushButton*        goButton_; | ||||||
|    types::TextEventKey key_; |    types::TextEventKey key_; | ||||||
|    common::Coordinate  coordinate_; |    common::Coordinate  centroid_; | ||||||
|    size_t              currentIndex_; |    size_t              currentIndex_; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | @ -45,7 +54,7 @@ AlertDialog::AlertDialog(QWidget* parent) : | ||||||
|    ui->alertText->setFont(monospaceFont); |    ui->alertText->setFont(monospaceFont); | ||||||
| 
 | 
 | ||||||
|    // Add Go button to button box
 |    // Add Go button to button box
 | ||||||
|    ui->buttonBox->addButton("&Go", QDialogButtonBox::ActionRole); |    p->goButton_ = ui->buttonBox->addButton("&Go", QDialogButtonBox::ActionRole); | ||||||
| 
 | 
 | ||||||
|    p->ConnectSignals(); |    p->ConnectSignals(); | ||||||
| } | } | ||||||
|  | @ -55,13 +64,33 @@ AlertDialog::~AlertDialog() | ||||||
|    delete ui; |    delete ui; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AlertDialogImpl::ConnectSignals() {} | void AlertDialogImpl::ConnectSignals() | ||||||
| 
 |  | ||||||
| bool AlertDialog::SelectAlert(const types::TextEventKey& key, |  | ||||||
|                               const common::Coordinate&  coordinate) |  | ||||||
| { | { | ||||||
|    p->key_        = key; |    connect( | ||||||
|    p->coordinate_ = coordinate; |       &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())); |    setWindowTitle(QString::fromStdString(key.ToFullString())); | ||||||
| 
 | 
 | ||||||
|  | @ -71,7 +100,7 @@ bool AlertDialog::SelectAlert(const types::TextEventKey& key, | ||||||
|       return false; |       return false; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    p->SelectIndex(messages.size() - 1); |    p->SelectIndex(messages.size() - 1u); | ||||||
| 
 | 
 | ||||||
|    return true; |    return true; | ||||||
| } | } | ||||||
|  | @ -92,19 +121,61 @@ void AlertDialogImpl::SelectIndex(size_t newIndex) | ||||||
| 
 | 
 | ||||||
|    self_->ui->alertText->setText( |    self_->ui->alertText->setText( | ||||||
|       QString::fromStdString(messages[currentIndex_]->message_content())); |       QString::fromStdString(messages[currentIndex_]->message_content())); | ||||||
|    self_->ui->messageCountLabel->setText( |  | ||||||
|       QObject::tr("%1 of %2").arg(currentIndex_ + 1).arg(messageCount)); |  | ||||||
| 
 | 
 | ||||||
|    bool firstSelected = (currentIndex_ == 0); |    UpdateAlertInfo(); | ||||||
|    bool lastSelected  = (currentIndex_ == messages.size() - 1); | } | ||||||
|  | 
 | ||||||
|  | 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->firstButton->setEnabled(!firstSelected); | ||||||
|    self_->ui->previousButton->setEnabled(!firstSelected); |    self_->ui->previousButton->setEnabled(!firstSelected); | ||||||
| 
 | 
 | ||||||
|    self_->ui->nextButton->setEnabled(!lastSelected); |    self_->ui->nextButton->setEnabled(!lastSelected); | ||||||
|    self_->ui->lastButton->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 ui
 | ||||||
| } // namespace qt
 | } // namespace qt
 | ||||||
| } // namespace scwx
 | } // namespace scwx
 | ||||||
|  |  | ||||||
|  | @ -27,8 +27,13 @@ public: | ||||||
|    explicit AlertDialog(QWidget* parent = nullptr); |    explicit AlertDialog(QWidget* parent = nullptr); | ||||||
|    ~AlertDialog(); |    ~AlertDialog(); | ||||||
| 
 | 
 | ||||||
|    bool SelectAlert(const types::TextEventKey& key, |    bool SelectAlert(const types::TextEventKey& key); | ||||||
|                     const common::Coordinate&  coordinate); | 
 | ||||||
|  | public slots: | ||||||
|  |    void on_firstButton_clicked(); | ||||||
|  |    void on_previousButton_clicked(); | ||||||
|  |    void on_nextButton_clicked(); | ||||||
|  |    void on_lastButton_clicked(); | ||||||
| 
 | 
 | ||||||
| signals: | signals: | ||||||
|    void MoveMap(double latitude, double longitude); |    void MoveMap(double latitude, double longitude); | ||||||
|  |  | ||||||
|  | @ -158,8 +158,7 @@ void AlertDockWidgetImpl::ConnectSignals() | ||||||
|            [=]() |            [=]() | ||||||
|            { |            { | ||||||
|               // View alert
 |               // View alert
 | ||||||
|               alertDialog_->SelectAlert(selectedAlertKey_, |               alertDialog_->SelectAlert(selectedAlertKey_); | ||||||
|                                         selectedAlertCentroid_); |  | ||||||
|               alertDialog_->show(); |               alertDialog_->show(); | ||||||
|            }); |            }); | ||||||
|    connect(self_->ui->alertGoButton, |    connect(self_->ui->alertGoButton, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat