From 92bb5154a4b44cbaf7a00f34d8912c510e458e33 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Mon, 10 Apr 2023 23:17:21 -0500 Subject: [PATCH] Enable loading of product by double clicking in the resource explorer - Doesn't work if radar product manager is expired for the site (time not present in record map) - Need to fix going back to expired (garbage collected) live data --- scwx-qt/source/scwx/qt/main/main_window.cpp | 61 +++++++++++++++++++++ scwx-qt/source/scwx/qt/main/main_window.hpp | 1 + scwx-qt/source/scwx/qt/map/map_widget.cpp | 11 ++-- scwx-qt/source/scwx/qt/map/map_widget.hpp | 15 ++++- 4 files changed, 81 insertions(+), 7 deletions(-) diff --git a/scwx-qt/source/scwx/qt/main/main_window.cpp b/scwx-qt/source/scwx/qt/main/main_window.cpp index f8a4ef90..aea9678d 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.cpp +++ b/scwx-qt/source/scwx/qt/main/main_window.cpp @@ -397,6 +397,67 @@ void MainWindow::on_resourceTreeExpandAllButton_clicked() ui->resourceTreeView->expandAll(); } +void MainWindow::on_resourceTreeView_doubleClicked(const QModelIndex& index) +{ + std::string selectedString {index.data().toString().toStdString()}; + std::chrono::system_clock::time_point time {}; + + logger_->debug("Selecting resource: {}", + index.data().toString().toStdString()); + + static const std::string timeFormat {"%Y-%m-%d %H:%M:%S"}; + + std::istringstream in {selectedString}; + in >> std::chrono::parse(timeFormat, time); + + if (in.fail()) + { + // Not a time string, ignore double-click + return; + } + + QModelIndex parent1 = index.parent(); + QModelIndex parent2 = parent1.parent(); + QModelIndex parent3 = parent2.parent(); + + std::string radarSite {}; + std::string groupName {}; + std::string product {}; + + if (!parent2.isValid()) + { + // A time entry should be at the third or fourth level + logger_->error("Unexpected resource data"); + return; + } + + if (parent3.isValid()) + { + // Level 3 Product + radarSite = parent3.data().toString().toStdString(); + groupName = parent2.data().toString().toStdString(); + product = parent1.data().toString().toStdString(); + } + else + { + // Level 2 Product + radarSite = parent2.data().toString().toStdString(); + groupName = parent1.data().toString().toStdString(); + // No product index + } + + common::RadarProductGroup group = common::GetRadarProductGroup(groupName); + + // Update radar site if different from currently selected + if (p->activeMap_->GetRadarSite()->id() != radarSite) + { + p->activeMap_->SelectRadarSite(radarSite); + } + + // Select the updated radar product + p->activeMap_->SelectRadarProduct(group, product, 0, time); +} + void MainWindowImpl::ConfigureMapLayout() { auto& generalSettings = manager::SettingsManager::general_settings(); diff --git a/scwx-qt/source/scwx/qt/main/main_window.hpp b/scwx-qt/source/scwx/qt/main/main_window.hpp index 8b64a014..f67374fe 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.hpp +++ b/scwx-qt/source/scwx/qt/main/main_window.hpp @@ -45,6 +45,7 @@ private slots: void on_radarSiteSelectButton_clicked(); void on_resourceTreeCollapseAllButton_clicked(); void on_resourceTreeExpandAllButton_clicked(); + void on_resourceTreeView_doubleClicked(const QModelIndex& index); private: 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 273ceb55..0b4d56ba 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -307,7 +307,7 @@ std::shared_ptr MapWidget::GetRadarSite() const return radarSite; } -uint16_t MapWidget::GetVcp() const +std::uint16_t MapWidget::GetVcp() const { auto radarProductView = p->context_->radar_product_view(); @@ -317,7 +317,7 @@ uint16_t MapWidget::GetVcp() const } else { - return 0; + return 0u; } } @@ -334,7 +334,8 @@ void MapWidget::SelectElevation(float elevation) void MapWidget::SelectRadarProduct(common::RadarProductGroup group, const std::string& product, - int16_t productCode) + std::int16_t productCode, + std::chrono::system_clock::time_point time) { bool radarProductViewCreated = false; @@ -384,8 +385,8 @@ void MapWidget::SelectRadarProduct(common::RadarProductGroup group, if (radarProductView != nullptr) { - // Always select the latest product available - radarProductView->SelectTime({}); + // Select the time associated with the request + radarProductView->SelectTime(time); if (radarProductViewCreated) { diff --git a/scwx-qt/source/scwx/qt/map/map_widget.hpp b/scwx-qt/source/scwx/qt/map/map_widget.hpp index 63f51160..104c280f 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.hpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.hpp @@ -41,12 +41,23 @@ public: common::RadarProductGroup GetRadarProductGroup() const; std::string GetRadarProductName() const; std::shared_ptr GetRadarSite() const; - uint16_t GetVcp() const; + std::uint16_t GetVcp() const; void SelectElevation(float elevation); + + /** + * @brief Selects a radar product. + * + * @param [in] group Radar product group + * @param [in] product Radar product name + * @param [in] productCode Radar product code (optional) + * @paran [in] time Product time. Default is the latest available. + */ void SelectRadarProduct(common::RadarProductGroup group, const std::string& product, - int16_t productCode); + std::int16_t productCode = 0, + std::chrono::system_clock::time_point time = {}); + void SelectRadarProduct(std::shared_ptr record); /**