diff --git a/.clang-tidy b/.clang-tidy index 645c9c05..26230c78 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -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' diff --git a/scwx-qt/source/scwx/qt/settings/hotkey_settings.cpp b/scwx-qt/source/scwx/qt/settings/hotkey_settings.cpp index ba5b4e3e..39f21379 100644 --- a/scwx-qt/source/scwx/qt/settings/hotkey_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/hotkey_settings.cpp @@ -25,6 +25,12 @@ static const std::unordered_map 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, diff --git a/scwx-qt/source/scwx/qt/types/hotkey_types.cpp b/scwx-qt/source/scwx/qt/types/hotkey_types.cpp index 72c77f63..7a121079 100644 --- a/scwx-qt/source/scwx/qt/types/hotkey_types.cpp +++ b/scwx-qt/source/scwx/qt/types/hotkey_types.cpp @@ -25,6 +25,8 @@ static const std::unordered_map 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 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"}, diff --git a/scwx-qt/source/scwx/qt/types/hotkey_types.hpp b/scwx-qt/source/scwx/qt/types/hotkey_types.hpp index 2107a009..6e770b67 100644 --- a/scwx-qt/source/scwx/qt/types/hotkey_types.hpp +++ b/scwx-qt/source/scwx/qt/types/hotkey_types.hpp @@ -25,6 +25,8 @@ enum class Hotkey MapRotateCounterclockwise, MapZoomIn, MapZoomOut, + ProductCategoryPrevious, + ProductCategoryNext, ProductTiltDecrease, ProductTiltIncrease, SelectLevel2Ref, diff --git a/scwx-qt/source/scwx/qt/ui/level3_products_widget.cpp b/scwx-qt/source/scwx/qt/ui/level3_products_widget.cpp index e6de32b2..5c993b66 100644 --- a/scwx-qt/source/scwx/qt/ui/level3_products_widget.cpp +++ b/scwx-qt/source/scwx/qt/ui/level3_products_widget.cpp @@ -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); diff --git a/test/data b/test/data index 6115c159..c68bee74 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit 6115c15987fd75dd019db995e6bdc07a05b83dcc +Subproject commit c68bee74549963e9a02e0fa998efad0f10f8256b