diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index 2c21cbf6..651f454e 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -97,9 +97,11 @@ set(SRC_SETTINGS source/scwx/qt/settings/general_settings.cpp set(HDR_TYPES source/scwx/qt/types/radar_product_record.hpp) set(SRC_TYPES source/scwx/qt/types/radar_product_record.cpp) set(HDR_UI source/scwx/qt/ui/flow_layout.hpp - source/scwx/qt/ui/level2_products_widget.hpp) + source/scwx/qt/ui/level2_products_widget.hpp + source/scwx/qt/ui/level2_settings_widget.hpp) set(SRC_UI source/scwx/qt/ui/flow_layout.cpp - source/scwx/qt/ui/level2_products_widget.cpp) + source/scwx/qt/ui/level2_products_widget.cpp + source/scwx/qt/ui/level2_settings_widget.cpp) set(HDR_UTIL source/scwx/qt/util/font.hpp source/scwx/qt/util/font_buffer.hpp source/scwx/qt/util/json.hpp) diff --git a/scwx-qt/source/scwx/qt/main/main_window.cpp b/scwx-qt/source/scwx/qt/main/main_window.cpp index 95179c68..7c4347ce 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.cpp +++ b/scwx-qt/source/scwx/qt/main/main_window.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,7 @@ public: settings_ {}, activeMap_ {nullptr}, level2ProductsWidget_ {nullptr}, + level2SettingsWidget_ {nullptr}, maps_ {}, elevationCuts_ {}, elevationButtonsChanged_ {false}, @@ -71,7 +73,6 @@ public: void ConfigureMapLayout(); void HandleFocusChange(QWidget* focused); - void NormalizeElevationButtons(); void SelectElevation(map::MapWidget* mapWidget, float elevation); void SelectRadarProduct(map::MapWidget* mapWidget, common::RadarProductGroup group, @@ -90,6 +91,7 @@ public: map::MapWidget* activeMap_; ui::Level2ProductsWidget* level2ProductsWidget_; + ui::Level2SettingsWidget* level2SettingsWidget_; std::vector maps_; std::vector elevationCuts_; @@ -125,11 +127,10 @@ MainWindow::MainWindow(QWidget* parent) : delete ui->level2ProductFrame; ui->level2ProductFrame = p->level2ProductsWidget_; - QLayout* elevationLayout = new ui::FlowLayout(); - ui->elevationGroupBox->setLayout(elevationLayout); - - ui->settingsGroupBox->setVisible(false); - ui->declutterCheckbox->setVisible(false); + // Add Level 2 Settings + p->level2SettingsWidget_ = new ui::Level2SettingsWidget(ui->settingsFrame); + ui->settingsFrame->layout()->addWidget(p->level2SettingsWidget_); + p->level2SettingsWidget_->setVisible(false); p->SelectRadarProduct( p->maps_.at(0), @@ -168,6 +169,11 @@ MainWindow::MainWindow(QWidget* parent) : p->SelectRadarProduct( p->activeMap_, group, productName, productCode); }); + connect(p->level2SettingsWidget_, + &ui::Level2SettingsWidget::ElevationSelected, + this, + [&](float elevation) + { p->SelectElevation(p->activeMap_, elevation); }); p->HandleFocusChange(p->activeMap_); } @@ -177,57 +183,13 @@ MainWindow::~MainWindow() delete ui; } -bool MainWindow::event(QEvent* event) -{ - if (event->type() == QEvent::Type::Paint) - { - if (p->elevationButtonsChanged_) - { - p->elevationButtonsChanged_ = false; - } - else if (p->resizeElevationButtons_) - { - p->NormalizeElevationButtons(); - } - } - - return QMainWindow::event(event); -} - void MainWindow::showEvent(QShowEvent* event) { QMainWindow::showEvent(event); - p->NormalizeElevationButtons(); - resizeDocks({ui->radarToolboxDock}, {150}, Qt::Horizontal); } -void MainWindowImpl::NormalizeElevationButtons() -{ - // Set each elevation cut's tool button to the same size - int elevationCutMaxWidth = 0; - for (QToolButton* widget : - mainWindow_->ui->elevationGroupBox->findChildren()) - { - if (widget->isVisible()) - { - elevationCutMaxWidth = std::max(elevationCutMaxWidth, widget->width()); - } - } - - if (elevationCutMaxWidth > 0) - { - for (QToolButton* widget : - mainWindow_->ui->elevationGroupBox->findChildren()) - { - widget->setMinimumWidth(elevationCutMaxWidth); - } - - resizeElevationButtons_ = false; - } -} - void MainWindow::on_actionOpen_triggered() { static const std::string nexradFilter = "NEXRAD Products (*)"; @@ -388,12 +350,12 @@ void MainWindowImpl::HandleFocusChange(QWidget* focused) void MainWindowImpl::SelectElevation(map::MapWidget* mapWidget, float elevation) { - mapWidget->SelectElevation(elevation); - if (mapWidget == activeMap_) { UpdateElevationSelection(elevation); } + + mapWidget->SelectElevation(elevation); } void MainWindowImpl::SelectRadarProduct(map::MapWidget* mapWidget, @@ -401,7 +363,6 @@ void MainWindowImpl::SelectRadarProduct(map::MapWidget* mapWidget, const std::string& productName, int16_t productCode) { - logger_->debug("Selecting radar product: {}, {}", common::GetRadarProductGroupName(group), productName); @@ -432,23 +393,7 @@ void MainWindowImpl::SetActiveMap(map::MapWidget* mapWidget) void MainWindowImpl::UpdateElevationSelection(float elevation) { - QString buttonText {QString::number(elevation, 'f', 1) + - common::Characters::DEGREE}; - - for (QToolButton* toolButton : - mainWindow_->ui->elevationGroupBox->findChildren()) - { - if (toolButton->text() == buttonText) - { - toolButton->setCheckable(true); - toolButton->setChecked(true); - } - else - { - toolButton->setChecked(false); - toolButton->setCheckable(false); - } - } + level2SettingsWidget_->UpdateElevationSelection(elevation); } void MainWindowImpl::UpdateMapParameters( @@ -468,39 +413,15 @@ void MainWindowImpl::UpdateRadarProductSelection( void MainWindowImpl::UpdateRadarProductSettings() { - float currentElevation = activeMap_->GetElevation(); - std::vector elevationCuts = activeMap_->GetElevationCuts(); - - if (elevationCuts_ != elevationCuts) + if (activeMap_->GetRadarProductGroup() == common::RadarProductGroup::Level2) { - for (QToolButton* toolButton : - mainWindow_->ui->elevationGroupBox->findChildren()) - { - delete toolButton; - } - - QLayout* layout = mainWindow_->ui->elevationGroupBox->layout(); - - // Create elevation cut tool buttons - for (float elevationCut : elevationCuts) - { - QToolButton* toolButton = new QToolButton(); - toolButton->setText(QString::number(elevationCut, 'f', 1) + - common::Characters::DEGREE); - layout->addWidget(toolButton); - - connect(toolButton, - &QToolButton::clicked, - this, - [=]() { SelectElevation(activeMap_, elevationCut); }); - } - - elevationCuts_ = elevationCuts; - elevationButtonsChanged_ = true; - resizeElevationButtons_ = true; + level2SettingsWidget_->UpdateSettings(activeMap_); + level2SettingsWidget_->setVisible(true); + } + else + { + level2SettingsWidget_->setVisible(false); } - - UpdateElevationSelection(currentElevation); } void MainWindowImpl::UpdateRadarSite() diff --git a/scwx-qt/source/scwx/qt/main/main_window.hpp b/scwx-qt/source/scwx/qt/main/main_window.hpp index 782c974c..c885bb77 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.hpp +++ b/scwx-qt/source/scwx/qt/main/main_window.hpp @@ -26,7 +26,6 @@ public: MainWindow(QWidget* parent = nullptr); ~MainWindow(); - bool event(QEvent* event) override; void showEvent(QShowEvent* event) override; private slots: diff --git a/scwx-qt/source/scwx/qt/main/main_window.ui b/scwx-qt/source/scwx/qt/main/main_window.ui index 31615fe3..6359edc9 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.ui +++ b/scwx-qt/source/scwx/qt/main/main_window.ui @@ -191,25 +191,20 @@ - - - Elevation - - - - - - - Settings - - - - - - Declutter - - - + + + + 0 + + + 0 + + + 0 + + + 0 + diff --git a/scwx-qt/source/scwx/qt/ui/level2_settings_widget.cpp b/scwx-qt/source/scwx/qt/ui/level2_settings_widget.cpp new file mode 100644 index 00000000..f19a7fb8 --- /dev/null +++ b/scwx-qt/source/scwx/qt/ui/level2_settings_widget.cpp @@ -0,0 +1,199 @@ +#include +#include +#include + +#include + +#include +#include +#include +#include + +namespace scwx +{ +namespace qt +{ +namespace ui +{ + +class Level2SettingsWidgetImpl : public QObject +{ + Q_OBJECT + +public: + explicit Level2SettingsWidgetImpl(Level2SettingsWidget* self) : + self_ {self}, + layout_ {new QVBoxLayout(self)}, + elevationGroupBox_ {}, + elevationButtons_ {}, + elevationCuts_ {}, + elevationButtonsChanged_ {false}, + resizeElevationButtons_ {false}, + settingsGroupBox_ {}, + declutterCheckBox_ {} + { + layout_->setContentsMargins(0, 0, 0, 0); + + elevationGroupBox_ = new QGroupBox(tr("Elevation"), self); + QLayout* elevationLayout = new ui::FlowLayout(elevationGroupBox_); + layout_->addWidget(elevationGroupBox_); + + settingsGroupBox_ = new QGroupBox(tr("Settings"), self); + QLayout* settingsLayout = new QVBoxLayout(settingsGroupBox_); + layout_->addWidget(settingsGroupBox_); + + declutterCheckBox_ = new QCheckBox(tr("Declutter"), settingsGroupBox_); + settingsLayout->addWidget(declutterCheckBox_); + + settingsGroupBox_->setVisible(false); + } + ~Level2SettingsWidgetImpl() = default; + + void NormalizeElevationButtons(); + void SelectElevation(float elevation); + void UpdateSettings(); + + Level2SettingsWidget* self_; + QLayout* layout_; + + QGroupBox* elevationGroupBox_; + std::list elevationButtons_; + std::vector elevationCuts_; + bool elevationButtonsChanged_; + bool resizeElevationButtons_; + + QGroupBox* settingsGroupBox_; + QCheckBox* declutterCheckBox_; +}; + +Level2SettingsWidget::Level2SettingsWidget(QWidget* parent) : + QWidget(parent), p {std::make_shared(this)} +{ +} + +Level2SettingsWidget::~Level2SettingsWidget() {} + +bool Level2SettingsWidget::event(QEvent* event) +{ + if (event->type() == QEvent::Type::Paint) + { + if (p->elevationButtonsChanged_) + { + p->elevationButtonsChanged_ = false; + } + else if (p->resizeElevationButtons_) + { + p->NormalizeElevationButtons(); + } + } + + return QWidget::event(event); +} + +void Level2SettingsWidget::showEvent(QShowEvent* event) +{ + QWidget::showEvent(event); + + p->NormalizeElevationButtons(); +} + +void Level2SettingsWidgetImpl::NormalizeElevationButtons() +{ + // Set each elevation cut's tool button to the same size + int elevationCutMaxWidth = 0; + std::for_each(elevationButtons_.cbegin(), + elevationButtons_.cend(), + [&](auto& toolButton) + { + if (toolButton->isVisible()) + { + elevationCutMaxWidth = + std::max(elevationCutMaxWidth, toolButton->width()); + } + }); + + if (elevationCutMaxWidth > 0) + { + std::for_each(elevationButtons_.cbegin(), + elevationButtons_.cend(), + [&](auto& toolButton) + { toolButton->setMinimumWidth(elevationCutMaxWidth); }); + + resizeElevationButtons_ = false; + } +} + +void Level2SettingsWidgetImpl::SelectElevation(float elevation) +{ + self_->UpdateElevationSelection(elevation); + + emit self_->ElevationSelected(elevation); +} + +void Level2SettingsWidget::UpdateElevationSelection(float elevation) +{ + QString buttonText {QString::number(elevation, 'f', 1) + + common::Characters::DEGREE}; + + std::for_each(std::execution::par_unseq, + p->elevationButtons_.cbegin(), + p->elevationButtons_.cend(), + [&](auto& toolButton) + { + if (toolButton->text() == buttonText) + { + toolButton->setCheckable(true); + toolButton->setChecked(true); + } + else + { + toolButton->setChecked(false); + toolButton->setCheckable(false); + } + }); +} + +void Level2SettingsWidget::UpdateSettings(map::MapWidget* activeMap) +{ + float currentElevation = activeMap->GetElevation(); + std::vector elevationCuts = activeMap->GetElevationCuts(); + + if (p->elevationCuts_ != elevationCuts) + { + for (auto it = p->elevationButtons_.begin(); + it != p->elevationButtons_.end();) + { + delete *it; + it = p->elevationButtons_.erase(it); + } + + QLayout* layout = p->elevationGroupBox_->layout(); + + // Create elevation cut tool buttons + for (float elevationCut : elevationCuts) + { + QToolButton* toolButton = new QToolButton(); + toolButton->setText(QString::number(elevationCut, 'f', 1) + + common::Characters::DEGREE); + layout->addWidget(toolButton); + p->elevationButtons_.push_back(toolButton); + + connect(toolButton, + &QToolButton::clicked, + this, + [=]() { p->SelectElevation(elevationCut); }); + } + + p->elevationCuts_ = elevationCuts; + p->elevationButtonsChanged_ = true; + p->resizeElevationButtons_ = true; + } + + UpdateElevationSelection(currentElevation); +} + +} // namespace ui +} // namespace qt +} // namespace scwx + +#include "level2_settings_widget.moc" diff --git a/scwx-qt/source/scwx/qt/ui/level2_settings_widget.hpp b/scwx-qt/source/scwx/qt/ui/level2_settings_widget.hpp new file mode 100644 index 00000000..ce2e443f --- /dev/null +++ b/scwx-qt/source/scwx/qt/ui/level2_settings_widget.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include + +namespace scwx +{ +namespace qt +{ +namespace ui +{ + +class Level2SettingsWidgetImpl; + +class Level2SettingsWidget : public QWidget +{ + Q_OBJECT + +public: + explicit Level2SettingsWidget(QWidget* parent = nullptr); + ~Level2SettingsWidget(); + + bool event(QEvent* event) override; + void showEvent(QShowEvent* event) override; + + void UpdateElevationSelection(float elevation); + void UpdateSettings(map::MapWidget* activeMap); + +signals: + void ElevationSelected(float elevation); + +private: + std::shared_ptr p; +}; + +} // namespace ui +} // namespace qt +} // namespace scwx diff --git a/scwx-qt/ts/scwx_en_US.ts b/scwx-qt/ts/scwx_en_US.ts index 0b5df9ab..12fba785 100644 --- a/scwx-qt/ts/scwx_en_US.ts +++ b/scwx-qt/ts/scwx_en_US.ts @@ -18,16 +18,6 @@ Level 3 - - - Settings - - - - - Declutter - - Radar Site @@ -74,27 +64,22 @@ - - Elevation - - - - + E&xit - + About &Supercell Wx... - + &Open... - + Ctrl+O @@ -102,9 +87,27 @@ scwx::qt::main::MainWindow - + Unrecognized NEXRAD Product: + + scwx::qt::ui::Level2SettingsWidgetImpl + + + Elevation + + + + + Settings + + + + + Declutter + + +