Skip to content

Commit 1d031d2

Browse files
authored
Fully handle Tool::processKeyEvent return value (#1270)
1 parent db7e7f8 commit 1d031d2

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

rviz_common/include/rviz_common/tool_manager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class ToolManager : public QObject
138138
QStringList getToolClasses();
139139

140140
/// Function to handle a key event.
141-
void handleChar(QKeyEvent * event, RenderPanel * panel);
141+
[[nodiscard]] int handleChar(QKeyEvent * event, RenderPanel * panel);
142142

143143
PluginlibFactory<Tool> * getFactory();
144144

rviz_common/src/rviz_common/tool_manager.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ bool ToolManager::toKey(QString const & str, uint & key)
144144
}
145145
}
146146

147-
void ToolManager::handleChar(QKeyEvent * event, RenderPanel * panel)
147+
int ToolManager::handleChar(QKeyEvent * event, RenderPanel * panel)
148148
{
149149
// if the incoming key is ESC fallback to the default tool
150150
if (event->key() == Qt::Key_Escape) {
151151
setCurrentTool(getDefaultTool());
152-
return;
152+
return 0;
153153
}
154154

155155
// check if the incoming key triggers the activation of another tool
@@ -180,9 +180,7 @@ void ToolManager::handleChar(QKeyEvent * event, RenderPanel * panel)
180180
flags = current_tool_->processKeyEvent(event, panel);
181181
}
182182

183-
if (flags & Tool::Finished) {
184-
setCurrentTool(getDefaultTool());
185-
}
183+
return flags;
186184
}
187185

188186
void ToolManager::setCurrentTool(Tool * tool)

rviz_common/src/rviz_common/visualization_manager.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,16 @@ void VisualizationManager::handleChar(QKeyEvent * event, RenderPanel * panel)
641641
if (event->key() == Qt::Key_Escape) {
642642
Q_EMIT escapePressed();
643643
}
644-
tool_manager_->handleChar(event, panel);
644+
645+
int flags = tool_manager_->handleChar(event, panel);
646+
647+
if (flags & Tool::Render) {
648+
queueRender();
649+
}
650+
651+
if (flags & Tool::Finished) {
652+
tool_manager_->setCurrentTool(tool_manager_->getDefaultTool());
653+
}
645654
}
646655

647656
void VisualizationManager::notifyConfigChanged()

0 commit comments

Comments
 (0)