Skip to content

Commit

Permalink
[tool] update the toolbar when nameChanged is emitted
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmonteiro authored and João Carlos Espiúca Monteiro committed Dec 17, 2020
1 parent be15e7f commit c4f109e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/rviz/visualization_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,17 @@ void VisualizationFrame::addTool(Tool* tool)
tool_to_action_map_[tool] = action;

remove_tool_menu_->addAction(tool->getName());

QObject::connect(tool, &Tool::nameChanged, this, &VisualizationFrame::updateTool);
}

void VisualizationFrame::updateTool(Tool* tool)
{
// Early return if the tool is not present
if (tool_to_action_map_.find(tool) == tool_to_action_map_.end())
return;
QAction* action = tool_to_action_map_[tool];
action->setIconText(tool->getName());
}

void VisualizationFrame::onToolbarActionTriggered(QAction* action)
Expand Down
6 changes: 6 additions & 0 deletions src/rviz/visualization_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ protected Q_SLOTS:
* the shortcut key, onToolbarActionTriggered() is called. */
void addTool(Tool* tool);

/** @brief Update the given tool to this frame's toolbar.
*
* This updates the QAction associated with the passed Tool instance.
* @sa addTool(Tool) */
void updateTool(Tool* tool);

/** @brief Remove the given tool from the frame's toolbar. */
void removeTool(Tool* tool);

Expand Down

0 comments on commit c4f109e

Please sign in to comment.