From abaaa4a078849400d2fa5d269db25e18cfae8050 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Fri, 29 Jul 2022 05:33:32 +0200 Subject: [PATCH 1/2] Improve code readability --- src/rviz/visualization_frame.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/rviz/visualization_frame.cpp b/src/rviz/visualization_frame.cpp index 94112219a6..09a8111d83 100644 --- a/src/rviz/visualization_frame.cpp +++ b/src/rviz/visualization_frame.cpp @@ -1348,10 +1348,8 @@ void VisualizationFrame::onDeletePanel() custom_panels_.removeAt(i); setDisplayConfigModified(); action->deleteLater(); - if (delete_view_menu_->actions().size() == 1 && delete_view_menu_->actions().first() == action) - { - delete_view_menu_->setEnabled(false); - } + delete_view_menu_->removeAction(action); + delete_view_menu_->setDisabled(delete_view_menu_->actions().isEmpty()); return; } } From 737ed5632abaf86dcab4ee0905da17eb176bbf68 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Fri, 29 Jul 2022 05:58:50 +0200 Subject: [PATCH 2/2] Gracefully handle destruction of PanelDockWidget --- src/rviz/visualization_frame.cpp | 23 ++++++++++++++++++----- src/rviz/visualization_frame.h | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/rviz/visualization_frame.cpp b/src/rviz/visualization_frame.cpp index 09a8111d83..85e0e8fcd8 100644 --- a/src/rviz/visualization_frame.cpp +++ b/src/rviz/visualization_frame.cpp @@ -1331,6 +1331,23 @@ QWidget* VisualizationFrame::getParentWindow() return this; } +void VisualizationFrame::onPanelDeleted(QObject* dock) +{ + for (int i = 0; i < custom_panels_.size(); ++i) + { + if (custom_panels_[i].dock == dock) + { + auto& record = custom_panels_[i]; + record.delete_action->deleteLater(); + delete_view_menu_->removeAction(record.delete_action); + delete_view_menu_->setDisabled(delete_view_menu_->actions().isEmpty()); + custom_panels_.removeAt(i); + setDisplayConfigModified(); + return; + } + } +} + void VisualizationFrame::onDeletePanel() { // This should only be called as a SLOT from a QAction in the @@ -1345,11 +1362,6 @@ void VisualizationFrame::onDeletePanel() if (custom_panels_[i].delete_action == action) { delete custom_panels_[i].dock; - custom_panels_.removeAt(i); - setDisplayConfigModified(); - action->deleteLater(); - delete_view_menu_->removeAction(action); - delete_view_menu_->setDisabled(delete_view_menu_->actions().isEmpty()); return; } } @@ -1402,6 +1414,7 @@ QDockWidget* VisualizationFrame::addPanelByName(const QString& name, record.panel = panel; record.name = name; record.delete_action = delete_view_menu_->addAction(name, this, SLOT(onDeletePanel())); + connect(record.dock, &QObject::destroyed, this, &VisualizationFrame::onPanelDeleted); custom_panels_.append(record); delete_view_menu_->setEnabled(true); diff --git a/src/rviz/visualization_frame.h b/src/rviz/visualization_frame.h index f4d3cd94c2..80c956475f 100644 --- a/src/rviz/visualization_frame.h +++ b/src/rviz/visualization_frame.h @@ -267,6 +267,7 @@ protected Q_SLOTS: void reset(); + void onPanelDeleted(QObject* dock); void onHelpDestroyed(); void hideLeftDock(bool hide);