Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tool: Propagate name changes to VisualizationFrame #1570

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/rviz/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ void Tool::setCursor(const QCursor& cursor)

void Tool::setName(const QString& name)
{
// Early return if the name did not change
if (name == name_)
return;

// Change the name and emit a signal to let slots know
name_ = name;
property_container_->setName(name_);
Q_EMIT nameChanged(name_);
}

void Tool::setDescription(const QString& description)
Expand Down
1 change: 1 addition & 0 deletions src/rviz/tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class RVIZ_EXPORT Tool : public QObject

Q_SIGNALS:
void close();
void nameChanged(const QString& name);

protected:
/** Override onInitialize to do any setup needed after the
Expand Down
13 changes: 13 additions & 0 deletions src/rviz/visualization_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,19 @@ void VisualizationFrame::addTool(Tool* tool)
tool_to_action_map_[tool] = action;

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

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

void VisualizationFrame::onToolNameChanged(const QString& name)
{
// Early return if the tool is not present
auto it = tool_to_action_map_.find(qobject_cast<Tool*>(sender()));
if (it == tool_to_action_map_.end())
return;

// Change the name of the action
it->second->setIconText(name);
}

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

/** @brief React to name changes of a tool, updating the name of the associated QAction */
void onToolNameChanged(const QString& name);

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

Expand Down