Add hotkeys for switching between products in a category

This commit is contained in:
AdenKoperczak 2025-06-08 09:46:17 -04:00
parent 4306bb09ae
commit 36b2e77ecf
No known key found for this signature in database
GPG key ID: 9843017036F62EE7
6 changed files with 80 additions and 3 deletions

View file

@ -8,6 +8,7 @@ Checks:
- 'performance-*'
- '-bugprone-easily-swappable-parameters'
- '-cppcoreguidelines-pro-type-reinterpret-cast'
- '-cppcoreguidelines-avoid-do-while'
- '-misc-include-cleaner'
- '-misc-non-private-member-variables-in-classes'
- '-misc-use-anonymous-namespace'

View file

@ -25,6 +25,12 @@ static const std::unordered_map<types::Hotkey, QKeySequence> kDefaultHotkeys_ {
{types::Hotkey::MapRotateCounterclockwise, QKeySequence {Qt::Key::Key_Q}},
{types::Hotkey::MapZoomIn, QKeySequence {Qt::Key::Key_Equal}},
{types::Hotkey::MapZoomOut, QKeySequence {Qt::Key::Key_Minus}},
{types::Hotkey::ProductCategoryNext,
QKeySequence {QKeyCombination {Qt::KeyboardModifier::ControlModifier,
Qt::Key::Key_BracketRight}}},
{types::Hotkey::ProductCategoryPrevious,
QKeySequence {QKeyCombination {Qt::KeyboardModifier::ControlModifier,
Qt::Key::Key_BracketLeft}}},
{types::Hotkey::ProductTiltDecrease,
QKeySequence {Qt::Key::Key_BracketLeft}},
{types::Hotkey::ProductTiltIncrease,

View file

@ -25,6 +25,8 @@ static const std::unordered_map<Hotkey, std::string> hotkeyShortName_ {
{Hotkey::MapRotateCounterclockwise, "map_rotate_counterclockwise"},
{Hotkey::MapZoomIn, "map_zoom_in"},
{Hotkey::MapZoomOut, "map_zoom_out"},
{Hotkey::ProductCategoryNext, "product_category_next"},
{Hotkey::ProductCategoryPrevious, "product_category_last"},
{Hotkey::ProductTiltDecrease, "product_tilt_decrease"},
{Hotkey::ProductTiltIncrease, "product_tilt_increase"},
{Hotkey::SelectLevel2Ref, "select_l2_ref"},
@ -65,6 +67,8 @@ static const std::unordered_map<Hotkey, std::string> hotkeyLongName_ {
{Hotkey::MapRotateCounterclockwise, "Map Rotate Counterclockwise"},
{Hotkey::MapZoomIn, "Map Zoom In"},
{Hotkey::MapZoomOut, "Map Zoom Out"},
{Hotkey::ProductCategoryNext, "Next Product in Category"},
{Hotkey::ProductCategoryPrevious, "Previous Product in Category"},
{Hotkey::ProductTiltDecrease, "Product Tilt Decrease"},
{Hotkey::ProductTiltIncrease, "Product Tilt Increase"},
{Hotkey::SelectLevel2Ref, "Select L2 REF"},

View file

@ -25,6 +25,8 @@ enum class Hotkey
MapRotateCounterclockwise,
MapZoomIn,
MapZoomOut,
ProductCategoryPrevious,
ProductCategoryNext,
ProductTiltDecrease,
ProductTiltIncrease,
SelectLevel2Ref,

View file

@ -216,7 +216,9 @@ void Level3ProductsWidgetImpl::HandleHotkeyPressed(types::Hotkey hotkey,
if (productCategoryIt == kHotkeyProductCategoryMap_.cend() &&
hotkey != types::Hotkey::ProductTiltDecrease &&
hotkey != types::Hotkey::ProductTiltIncrease)
hotkey != types::Hotkey::ProductTiltIncrease &&
hotkey != types::Hotkey::ProductCategoryNext &&
hotkey != types::Hotkey::ProductCategoryPrevious)
{
// Not handling this hotkey
return;
@ -251,7 +253,69 @@ void Level3ProductsWidgetImpl::HandleHotkeyPressed(types::Hotkey hotkey,
return;
}
std::shared_lock lock {awipsProductMutex_};
if (hotkey == types::Hotkey::ProductCategoryNext ||
hotkey == types::Hotkey::ProductCategoryPrevious)
{
const std::shared_lock lock1 {categoryMapMutex_};
const std::shared_lock lock2 {awipsProductMutex_};
const common::Level3ProductCategory category =
common::GetLevel3CategoryByProduct(product);
auto productsIt = categoryMap_.find(category);
if (productsIt == categoryMap_.cend())
{
logger_->error("Could not find the current category in category map");
return;
}
auto availableProducts = productsIt->second;
const auto& products = common::GetLevel3ProductsByCategory(category);
auto productIt = std::find(products.begin(), products.end(), product);
if (productIt == products.end())
{
logger_->error("Could not find product in category");
return;
}
if (hotkey == types::Hotkey::ProductCategoryNext)
{
do
{
productIt = std::next(productIt);
if (productIt == products.cend())
{
logger_->info("Cannot go past the last product");
return;
}
} while (!availableProducts.contains(*productIt));
}
else
{
do
{
if (productIt == products.begin())
{
logger_->info("Cannot go past the first product");
return;
}
productIt = std::prev(productIt);
} while (!availableProducts.contains(*productIt));
}
auto productTiltsIt = productTiltMap_.find(*productIt);
if (productTiltsIt == productTiltMap_.cend())
{
logger_->error("Could not find product tilt map: {}",
common::GetLevel3ProductDescription(product));
return;
}
// Select the new tilt
productTiltsIt->second.at(0)->trigger();
return;
}
const std::shared_lock lock {awipsProductMutex_};
// Find the current product tilt
auto productTiltsIt = productTiltMap_.find(product);

@ -1 +1 @@
Subproject commit 6115c15987fd75dd019db995e6bdc07a05b83dcc
Subproject commit c68bee74549963e9a02e0fa998efad0f10f8256b