Skip to content

Commit

Permalink
Fully handle Tool::processKeyEvent return value (#1270)
Browse files Browse the repository at this point in the history
  • Loading branch information
roncapat authored Aug 26, 2024
1 parent db7e7f8 commit 1d031d2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rviz_common/include/rviz_common/tool_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tool> * getFactory();

Expand Down
8 changes: 3 additions & 5 deletions rviz_common/src/rviz_common/tool_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion rviz_common/src/rviz_common/visualization_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1d031d2

Please sign in to comment.