From 9b90189566d320a7250bbd7ce3d2c43dabb00661 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sun, 13 Feb 2022 11:43:31 -0600 Subject: [PATCH] Open NEXRAD Product stub --- scwx-qt/source/scwx/qt/main/main_window.cpp | 66 +++++++++++++++++++++ scwx-qt/source/scwx/qt/main/main_window.hpp | 1 + scwx-qt/source/scwx/qt/main/main_window.ui | 20 +++++-- scwx-qt/ts/scwx_en_US.ts | 48 ++++++++++----- 4 files changed, 115 insertions(+), 20 deletions(-) diff --git a/scwx-qt/source/scwx/qt/main/main_window.cpp b/scwx-qt/source/scwx/qt/main/main_window.cpp index cd7eecf3..3f5e2dd1 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.cpp +++ b/scwx-qt/source/scwx/qt/main/main_window.cpp @@ -1,6 +1,9 @@ +#define NOMINMAX + #include "main_window.hpp" #include "./ui_main_window.h" +#include #include #include #include @@ -8,6 +11,8 @@ #include #include +#include +#include #include #include @@ -33,6 +38,7 @@ public: activeMap_ {nullptr}, maps_ {}, elevationCuts_ {}, + elevationButtonsChanged_ {false}, resizeElevationButtons_ {false} { settings_.setCacheDatabasePath("/tmp/mbgl-cache.db"); @@ -191,6 +197,66 @@ void MainWindow::showEvent(QShowEvent* event) resizeDocks({ui->radarToolboxDock}, {150}, Qt::Horizontal); } +void MainWindow::on_actionOpen_triggered() +{ + static const std::string nexradFilter = "NEXRAD Products (*)"; + + QFileDialog* dialog = new QFileDialog(this); + + dialog->setFileMode(QFileDialog::ExistingFile); + dialog->setNameFilter(tr(nexradFilter.c_str())); + dialog->setAttribute(Qt::WA_DeleteOnClose); + + // Make sure the parent window properly repaints on close + connect( + dialog, + &QFileDialog::finished, + this, + [=]() { update(); }, + Qt::QueuedConnection); + + connect( + dialog, + &QFileDialog::fileSelected, + this, + [=](const QString& file) + { + BOOST_LOG_TRIVIAL(info) << "Selected: " << file.toStdString(); + + manager::RadarProductManager::LoadFile( + file.toStdString(), + [=](std::shared_ptr nexradFile) + { + std::shared_ptr level2File = + std::dynamic_pointer_cast(nexradFile); + std::shared_ptr level3File = + std::dynamic_pointer_cast(nexradFile); + + if (level2File != nullptr) + { + // TODO: Handle + } + else if (level3File != nullptr) + { + // TODO: Handle + } + else + { + QMessageBox* messageBox = new QMessageBox(this); + messageBox->setIcon(QMessageBox::Warning); + messageBox->setText( + QString("%1\n%2").arg(tr("Unrecognized NEXRAD Product:"), + QDir::toNativeSeparators(file))); + messageBox->setAttribute(Qt::WA_DeleteOnClose); + messageBox->open(); + } + }, + this); + }); + + dialog->open(); +} + void MainWindow::on_actionExit_triggered() { close(); diff --git a/scwx-qt/source/scwx/qt/main/main_window.hpp b/scwx-qt/source/scwx/qt/main/main_window.hpp index cb55c835..782c974c 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.hpp +++ b/scwx-qt/source/scwx/qt/main/main_window.hpp @@ -30,6 +30,7 @@ public: void showEvent(QShowEvent* event) override; private slots: + void on_actionOpen_triggered(); void on_actionExit_triggered(); private: diff --git a/scwx-qt/source/scwx/qt/main/main_window.ui b/scwx-qt/source/scwx/qt/main/main_window.ui index bd6429d0..f32827dd 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.ui +++ b/scwx-qt/source/scwx/qt/main/main_window.ui @@ -35,23 +35,25 @@ 0 0 1024 - 21 + 22 - + &File + + - + &Help - - + + @@ -247,6 +249,14 @@ About &Supercell Wx... + + + &Open... + + + Ctrl+O + + diff --git a/scwx-qt/ts/scwx_en_US.ts b/scwx-qt/ts/scwx_en_US.ts index a97dba2c..d10a47b8 100644 --- a/scwx-qt/ts/scwx_en_US.ts +++ b/scwx-qt/ts/scwx_en_US.ts @@ -4,32 +4,32 @@ MainWindow - + Toolbox - + ... - + Level 3 - + Settings - + Declutter - + Radar Site @@ -44,49 +44,67 @@ - + &Help - + Volume Coverage Pattern - + VCP - + Clear Air Mode - + Radar Products - + Level 2 - + Elevation - + E&xit - + About &Supercell Wx... + + + &Open... + + + + + Ctrl+O + + + + + scwx::qt::main::MainWindow + + + Unrecognized NEXRAD Product: + +