Add level 2 and level 3 product selections to hotkeys

Closes #215
This commit is contained in:
Dan Paulat 2024-05-24 02:02:46 -05:00
parent 8f4325f61a
commit f33d8c0aba
6 changed files with 151 additions and 2 deletions

View file

@ -1,5 +1,6 @@
#include <scwx/qt/ui/level2_products_widget.hpp>
#include <scwx/qt/ui/flow_layout.hpp>
#include <scwx/qt/manager/hotkey_manager.hpp>
#include <scwx/util/logger.hpp>
#include <execution>
@ -16,6 +17,20 @@ namespace ui
static const std::string logPrefix_ = "scwx::qt::ui::level2_products_widget";
static const auto logger_ = util::Logger::Create(logPrefix_);
static const std::unordered_map<types::Hotkey, common::Level2Product>
kHotkeyProductMap_ {
{types::Hotkey::SelectLevel2Ref, common::Level2Product::Reflectivity},
{types::Hotkey::SelectLevel2Vel, common::Level2Product::Velocity},
{types::Hotkey::SelectLevel2SW, common::Level2Product::SpectrumWidth},
{types::Hotkey::SelectLevel2ZDR,
common::Level2Product::DifferentialReflectivity},
{types::Hotkey::SelectLevel2Phi,
common::Level2Product::DifferentialPhase},
{types::Hotkey::SelectLevel2Rho,
common::Level2Product::CorrelationCoefficient},
{types::Hotkey::SelectLevel2CFP,
common::Level2Product::ClutterFilterPowerRemoved}};
class Level2ProductsWidgetImpl : public QObject
{
Q_OBJECT
@ -40,10 +55,16 @@ public:
&QToolButton::clicked,
this,
[=, this]() { SelectProduct(product); });
QObject::connect(hotkeyManager_.get(),
&manager::HotkeyManager::HotkeyPressed,
this,
&Level2ProductsWidgetImpl::HandleHotkeyPressed);
}
}
~Level2ProductsWidgetImpl() = default;
void HandleHotkeyPressed(types::Hotkey hotkey, bool isAutoRepeat);
void NormalizeProductButtons();
void SelectProduct(common::Level2Product product);
void UpdateProductSelection(common::Level2Product product);
@ -51,6 +72,9 @@ public:
Level2ProductsWidget* self_;
QLayout* layout_;
std::list<QToolButton*> productButtons_;
std::shared_ptr<manager::HotkeyManager> hotkeyManager_ {
manager::HotkeyManager::Instance()};
};
Level2ProductsWidget::Level2ProductsWidget(QWidget* parent) :
@ -67,6 +91,25 @@ void Level2ProductsWidget::showEvent(QShowEvent* event)
p->NormalizeProductButtons();
}
void Level2ProductsWidgetImpl::HandleHotkeyPressed(types::Hotkey hotkey,
bool isAutoRepeat)
{
auto productIt = kHotkeyProductMap_.find(hotkey);
if (productIt == kHotkeyProductMap_.cend())
{
// Not handling this hotkey
return;
}
logger_->trace("Handling hotkey: {}, repeat: {}",
types::GetHotkeyShortName(hotkey),
isAutoRepeat);
// Select product category hotkey
SelectProduct(productIt->second);
}
void Level2ProductsWidgetImpl::NormalizeProductButtons()
{
int level2MaxWidth = 0;

View file

@ -7,6 +7,7 @@
#include <execution>
#include <shared_mutex>
#include <unordered_map>
#include <QCheckBox>
#include <QMenu>
@ -23,6 +24,29 @@ namespace ui
static const std::string logPrefix_ = "scwx::qt::ui::level3_products_widget";
static const auto logger_ = util::Logger::Create(logPrefix_);
static const std::unordered_map<types::Hotkey, common::Level3ProductCategory>
kHotkeyProductCategoryMap_ {
{types::Hotkey::SelectLevel3Ref,
common::Level3ProductCategory::Reflectivity},
{types::Hotkey::SelectLevel3Vel, common::Level3ProductCategory::Velocity},
{types::Hotkey::SelectLevel3SRM,
common::Level3ProductCategory::StormRelativeVelocity},
{types::Hotkey::SelectLevel3SW,
common::Level3ProductCategory::SpectrumWidth},
{types::Hotkey::SelectLevel3ZDR,
common::Level3ProductCategory::DifferentialReflectivity},
{types::Hotkey::SelectLevel3KDP,
common::Level3ProductCategory::SpecificDifferentialPhase},
{types::Hotkey::SelectLevel3CC,
common::Level3ProductCategory::CorrelationCoefficient},
{types::Hotkey::SelectLevel3VIL,
common::Level3ProductCategory::VerticallyIntegratedLiquid},
{types::Hotkey::SelectLevel3ET, common::Level3ProductCategory::EchoTops},
{types::Hotkey::SelectLevel3HC,
common::Level3ProductCategory::HydrometeorClassification},
{types::Hotkey::SelectLevel3Acc,
common::Level3ProductCategory::PrecipitationAccumulation}};
class Level3ProductsWidgetImpl : public QObject
{
Q_OBJECT
@ -183,7 +207,10 @@ void Level3ProductsWidget::showEvent(QShowEvent* event)
void Level3ProductsWidgetImpl::HandleHotkeyPressed(types::Hotkey hotkey,
bool isAutoRepeat)
{
if (hotkey != types::Hotkey::ProductTiltDecrease &&
auto productCategoryIt = kHotkeyProductCategoryMap_.find(hotkey);
if (productCategoryIt == kHotkeyProductCategoryMap_.cend() &&
hotkey != types::Hotkey::ProductTiltDecrease &&
hotkey != types::Hotkey::ProductTiltIncrease)
{
// Not handling this hotkey
@ -194,6 +221,13 @@ void Level3ProductsWidgetImpl::HandleHotkeyPressed(types::Hotkey hotkey,
types::GetHotkeyShortName(hotkey),
isAutoRepeat);
if (productCategoryIt != kHotkeyProductCategoryMap_.cend())
{
// Select product category hotkey
SelectProductCategory(productCategoryIt->second);
return;
}
std::string currentAwipsId = currentAwipsId_;
QAction* currentProductTiltAction = currentProductTiltAction_;