From 1d031d285bd8e3294fc24b474b61b960269eb821 Mon Sep 17 00:00:00 2001 From: Patrick Roncagliolo Date: Mon, 26 Aug 2024 19:44:09 +0200 Subject: [PATCH] Fully handle `Tool::processKeyEvent` return value (#1270) --- rviz_common/include/rviz_common/tool_manager.hpp | 2 +- rviz_common/src/rviz_common/tool_manager.cpp | 8 +++----- rviz_common/src/rviz_common/visualization_manager.cpp | 11 ++++++++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/rviz_common/include/rviz_common/tool_manager.hpp b/rviz_common/include/rviz_common/tool_manager.hpp index 23c8f8118..bdb37871d 100644 --- a/rviz_common/include/rviz_common/tool_manager.hpp +++ b/rviz_common/include/rviz_common/tool_manager.hpp @@ -138,7 +138,7 @@ class ToolManager : public QObject QStringList getToolClasses(); /// Function to handle a key event. - void handleChar(QKeyEvent * event, RenderPanel * panel); + [[nodiscard]] int handleChar(QKeyEvent * event, RenderPanel * panel); PluginlibFactory * getFactory(); diff --git a/rviz_common/src/rviz_common/tool_manager.cpp b/rviz_common/src/rviz_common/tool_manager.cpp index eb29a4c5a..2ebb8f466 100644 --- a/rviz_common/src/rviz_common/tool_manager.cpp +++ b/rviz_common/src/rviz_common/tool_manager.cpp @@ -144,12 +144,12 @@ bool ToolManager::toKey(QString const & str, uint & key) } } -void ToolManager::handleChar(QKeyEvent * event, RenderPanel * panel) +int ToolManager::handleChar(QKeyEvent * event, RenderPanel * panel) { // if the incoming key is ESC fallback to the default tool if (event->key() == Qt::Key_Escape) { setCurrentTool(getDefaultTool()); - return; + return 0; } // check if the incoming key triggers the activation of another tool @@ -180,9 +180,7 @@ void ToolManager::handleChar(QKeyEvent * event, RenderPanel * panel) flags = current_tool_->processKeyEvent(event, panel); } - if (flags & Tool::Finished) { - setCurrentTool(getDefaultTool()); - } + return flags; } void ToolManager::setCurrentTool(Tool * tool) diff --git a/rviz_common/src/rviz_common/visualization_manager.cpp b/rviz_common/src/rviz_common/visualization_manager.cpp index 500acdc6b..260de3e51 100644 --- a/rviz_common/src/rviz_common/visualization_manager.cpp +++ b/rviz_common/src/rviz_common/visualization_manager.cpp @@ -641,7 +641,16 @@ void VisualizationManager::handleChar(QKeyEvent * event, RenderPanel * panel) if (event->key() == Qt::Key_Escape) { Q_EMIT escapePressed(); } - tool_manager_->handleChar(event, panel); + + int flags = tool_manager_->handleChar(event, panel); + + if (flags & Tool::Render) { + queueRender(); + } + + if (flags & Tool::Finished) { + tool_manager_->setCurrentTool(tool_manager_->getDefaultTool()); + } } void VisualizationManager::notifyConfigChanged()