mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 17:20:04 +00:00
Add hotkeys for switching between products in a category
This commit is contained in:
parent
4306bb09ae
commit
36b2e77ecf
6 changed files with 80 additions and 3 deletions
|
|
@ -8,6 +8,7 @@ Checks:
|
||||||
- 'performance-*'
|
- 'performance-*'
|
||||||
- '-bugprone-easily-swappable-parameters'
|
- '-bugprone-easily-swappable-parameters'
|
||||||
- '-cppcoreguidelines-pro-type-reinterpret-cast'
|
- '-cppcoreguidelines-pro-type-reinterpret-cast'
|
||||||
|
- '-cppcoreguidelines-avoid-do-while'
|
||||||
- '-misc-include-cleaner'
|
- '-misc-include-cleaner'
|
||||||
- '-misc-non-private-member-variables-in-classes'
|
- '-misc-non-private-member-variables-in-classes'
|
||||||
- '-misc-use-anonymous-namespace'
|
- '-misc-use-anonymous-namespace'
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,12 @@ static const std::unordered_map<types::Hotkey, QKeySequence> kDefaultHotkeys_ {
|
||||||
{types::Hotkey::MapRotateCounterclockwise, QKeySequence {Qt::Key::Key_Q}},
|
{types::Hotkey::MapRotateCounterclockwise, QKeySequence {Qt::Key::Key_Q}},
|
||||||
{types::Hotkey::MapZoomIn, QKeySequence {Qt::Key::Key_Equal}},
|
{types::Hotkey::MapZoomIn, QKeySequence {Qt::Key::Key_Equal}},
|
||||||
{types::Hotkey::MapZoomOut, QKeySequence {Qt::Key::Key_Minus}},
|
{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,
|
{types::Hotkey::ProductTiltDecrease,
|
||||||
QKeySequence {Qt::Key::Key_BracketLeft}},
|
QKeySequence {Qt::Key::Key_BracketLeft}},
|
||||||
{types::Hotkey::ProductTiltIncrease,
|
{types::Hotkey::ProductTiltIncrease,
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ static const std::unordered_map<Hotkey, std::string> hotkeyShortName_ {
|
||||||
{Hotkey::MapRotateCounterclockwise, "map_rotate_counterclockwise"},
|
{Hotkey::MapRotateCounterclockwise, "map_rotate_counterclockwise"},
|
||||||
{Hotkey::MapZoomIn, "map_zoom_in"},
|
{Hotkey::MapZoomIn, "map_zoom_in"},
|
||||||
{Hotkey::MapZoomOut, "map_zoom_out"},
|
{Hotkey::MapZoomOut, "map_zoom_out"},
|
||||||
|
{Hotkey::ProductCategoryNext, "product_category_next"},
|
||||||
|
{Hotkey::ProductCategoryPrevious, "product_category_last"},
|
||||||
{Hotkey::ProductTiltDecrease, "product_tilt_decrease"},
|
{Hotkey::ProductTiltDecrease, "product_tilt_decrease"},
|
||||||
{Hotkey::ProductTiltIncrease, "product_tilt_increase"},
|
{Hotkey::ProductTiltIncrease, "product_tilt_increase"},
|
||||||
{Hotkey::SelectLevel2Ref, "select_l2_ref"},
|
{Hotkey::SelectLevel2Ref, "select_l2_ref"},
|
||||||
|
|
@ -65,6 +67,8 @@ static const std::unordered_map<Hotkey, std::string> hotkeyLongName_ {
|
||||||
{Hotkey::MapRotateCounterclockwise, "Map Rotate Counterclockwise"},
|
{Hotkey::MapRotateCounterclockwise, "Map Rotate Counterclockwise"},
|
||||||
{Hotkey::MapZoomIn, "Map Zoom In"},
|
{Hotkey::MapZoomIn, "Map Zoom In"},
|
||||||
{Hotkey::MapZoomOut, "Map Zoom Out"},
|
{Hotkey::MapZoomOut, "Map Zoom Out"},
|
||||||
|
{Hotkey::ProductCategoryNext, "Next Product in Category"},
|
||||||
|
{Hotkey::ProductCategoryPrevious, "Previous Product in Category"},
|
||||||
{Hotkey::ProductTiltDecrease, "Product Tilt Decrease"},
|
{Hotkey::ProductTiltDecrease, "Product Tilt Decrease"},
|
||||||
{Hotkey::ProductTiltIncrease, "Product Tilt Increase"},
|
{Hotkey::ProductTiltIncrease, "Product Tilt Increase"},
|
||||||
{Hotkey::SelectLevel2Ref, "Select L2 REF"},
|
{Hotkey::SelectLevel2Ref, "Select L2 REF"},
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ enum class Hotkey
|
||||||
MapRotateCounterclockwise,
|
MapRotateCounterclockwise,
|
||||||
MapZoomIn,
|
MapZoomIn,
|
||||||
MapZoomOut,
|
MapZoomOut,
|
||||||
|
ProductCategoryPrevious,
|
||||||
|
ProductCategoryNext,
|
||||||
ProductTiltDecrease,
|
ProductTiltDecrease,
|
||||||
ProductTiltIncrease,
|
ProductTiltIncrease,
|
||||||
SelectLevel2Ref,
|
SelectLevel2Ref,
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,9 @@ void Level3ProductsWidgetImpl::HandleHotkeyPressed(types::Hotkey hotkey,
|
||||||
|
|
||||||
if (productCategoryIt == kHotkeyProductCategoryMap_.cend() &&
|
if (productCategoryIt == kHotkeyProductCategoryMap_.cend() &&
|
||||||
hotkey != types::Hotkey::ProductTiltDecrease &&
|
hotkey != types::Hotkey::ProductTiltDecrease &&
|
||||||
hotkey != types::Hotkey::ProductTiltIncrease)
|
hotkey != types::Hotkey::ProductTiltIncrease &&
|
||||||
|
hotkey != types::Hotkey::ProductCategoryNext &&
|
||||||
|
hotkey != types::Hotkey::ProductCategoryPrevious)
|
||||||
{
|
{
|
||||||
// Not handling this hotkey
|
// Not handling this hotkey
|
||||||
return;
|
return;
|
||||||
|
|
@ -251,7 +253,69 @@ void Level3ProductsWidgetImpl::HandleHotkeyPressed(types::Hotkey hotkey,
|
||||||
return;
|
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
|
// Find the current product tilt
|
||||||
auto productTiltsIt = productTiltMap_.find(product);
|
auto productTiltsIt = productTiltMap_.find(product);
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6115c15987fd75dd019db995e6bdc07a05b83dcc
|
Subproject commit c68bee74549963e9a02e0fa998efad0f10f8256b
|
||||||
Loading…
Add table
Add a link
Reference in a new issue