From 97be6fe7c0261c89b247c81c23369eadb5dc07b4 Mon Sep 17 00:00:00 2001 From: ygerlach <100762533+ygerlach@users.noreply.github.com> Date: Fri, 28 Oct 2022 15:15:11 +0200 Subject: [PATCH 1/3] use static QCoreApplication::processEvents() function without a QApplication instance. This removes the need for the setApp() call. --- src/rviz/main.cpp | 1 - src/rviz/visualization_frame.cpp | 36 ++++++++++++-------------------- src/rviz/visualization_frame.h | 3 +-- src/rviz/visualizer_app.cpp | 5 ++--- src/rviz/visualizer_app.h | 4 ++-- 5 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/rviz/main.cpp b/src/rviz/main.cpp index c7f841d363..5e4fd9c0ad 100644 --- a/src/rviz/main.cpp +++ b/src/rviz/main.cpp @@ -36,7 +36,6 @@ int main(int argc, char** argv) QApplication qapp(argc, argv); rviz::VisualizerApp vapp; - vapp.setApp(&qapp); if (vapp.init(argc, argv)) { return qapp.exec(); diff --git a/src/rviz/visualization_frame.cpp b/src/rviz/visualization_frame.cpp index cd5c3a405b..b1b0268ee0 100644 --- a/src/rviz/visualization_frame.cpp +++ b/src/rviz/visualization_frame.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -103,7 +104,6 @@ namespace rviz { VisualizationFrame::VisualizationFrame(QWidget* parent) : QMainWindow(parent) - , app_(nullptr) , render_panel_(nullptr) , show_help_action_(nullptr) , preferences_(new Preferences()) @@ -166,7 +166,7 @@ VisualizationFrame::~VisualizationFrame() void VisualizationFrame::setApp(QApplication* app) { - app_ = app; + Q_UNUSED(app); } void VisualizationFrame::setStatus(const QString& message) @@ -258,8 +258,7 @@ void VisualizationFrame::initialize(const QString& display_config_file) // Periodically process events for the splash screen. // See: http://doc.qt.io/qt-5/qsplashscreen.html#details - if (app_) - app_->processEvents(); + QCoreApplication::processEvents(); if (!ros::isInitialized()) { @@ -268,8 +267,7 @@ void VisualizationFrame::initialize(const QString& display_config_file) } // Periodically process events for the splash screen. - if (app_) - app_->processEvents(); + QCoreApplication::processEvents(); QWidget* central_widget = new QWidget(this); QHBoxLayout* central_layout = new QHBoxLayout; @@ -305,40 +303,34 @@ void VisualizationFrame::initialize(const QString& display_config_file) central_widget->setLayout(central_layout); // Periodically process events for the splash screen. - if (app_) - app_->processEvents(); + QCoreApplication::processEvents(); initMenus(); // Periodically process events for the splash screen. - if (app_) - app_->processEvents(); + QCoreApplication::processEvents(); initToolbars(); // Periodically process events for the splash screen. - if (app_) - app_->processEvents(); + QCoreApplication::processEvents(); setCentralWidget(central_widget); // Periodically process events for the splash screen. - if (app_) - app_->processEvents(); + QCoreApplication::processEvents(); manager_ = new VisualizationManager(render_panel_, this); manager_->setHelpPath(help_path_); connect(manager_, SIGNAL(escapePressed()), this, SLOT(exitFullScreen())); // Periodically process events for the splash screen. - if (app_) - app_->processEvents(); + QCoreApplication::processEvents(); render_panel_->initialize(manager_->getSceneManager(), manager_); // Periodically process events for the splash screen. - if (app_) - app_->processEvents(); + QCoreApplication::processEvents(); ToolManager* tool_man = manager_->getToolManager(); @@ -351,8 +343,7 @@ void VisualizationFrame::initialize(const QString& display_config_file) manager_->initialize(); // Periodically process events for the splash screen. - if (app_) - app_->processEvents(); + QCoreApplication::processEvents(); if (display_config_file != "") { @@ -364,8 +355,7 @@ void VisualizationFrame::initialize(const QString& display_config_file) } // Periodically process events for the splash screen. - if (app_) - app_->processEvents(); + QCoreApplication::processEvents(); delete splash_; splash_ = nullptr; @@ -759,7 +749,7 @@ bool VisualizationFrame::loadDisplayConfigHelper(const std::string& full_path, c dialog.reset(new LoadingDialog(this)); dialog->show(); connect(this, SIGNAL(statusUpdate(const QString&)), dialog.get(), SLOT(showMessage(const QString&))); - app_->processEvents(); // make the window correctly appear although running a long-term function + QCoreApplication::processEvents(); // make the window correctly appear although running a long-term function } YamlConfigReader reader; diff --git a/src/rviz/visualization_frame.h b/src/rviz/visualization_frame.h index e63d29a511..d0c9f305c8 100644 --- a/src/rviz/visualization_frame.h +++ b/src/rviz/visualization_frame.h @@ -78,6 +78,7 @@ class RVIZ_EXPORT VisualizationFrame : public QMainWindow, public WindowManagerI VisualizationFrame(QWidget* parent = nullptr); ~VisualizationFrame() override; + // now deprecated void setApp(QApplication* app); /** @brief Call this @e before initialize() to have it take effect. */ @@ -328,8 +329,6 @@ protected Q_SLOTS: void hideDockImpl(Qt::DockWidgetArea area, bool hide); - QApplication* app_; - RenderPanel* render_panel_; QAction* show_help_action_; diff --git a/src/rviz/visualizer_app.cpp b/src/rviz/visualizer_app.cpp index e29add3b3d..bab6f3aef0 100644 --- a/src/rviz/visualizer_app.cpp +++ b/src/rviz/visualizer_app.cpp @@ -100,13 +100,13 @@ bool reloadShaders(std_srvs::Empty::Request& /*unused*/, std_srvs::Empty::Respon return true; } -VisualizerApp::VisualizerApp() : app_(nullptr), continue_timer_(nullptr), frame_(nullptr) +VisualizerApp::VisualizerApp() : continue_timer_(nullptr), frame_(nullptr) { } void VisualizerApp::setApp(QApplication* app) { - app_ = app; + Q_UNUSED(app); } bool VisualizerApp::init(int argc, char** argv) @@ -202,7 +202,6 @@ bool VisualizerApp::init(int argc, char** argv) RenderSystem::forceNoStereo(); frame_ = new VisualizationFrame(); - frame_->setApp(this->app_); if (!help_path.empty()) { frame_->setHelpPath(QString::fromStdString(help_path)); diff --git a/src/rviz/visualizer_app.h b/src/rviz/visualizer_app.h index 3700435630..af880a45e3 100644 --- a/src/rviz/visualizer_app.h +++ b/src/rviz/visualizer_app.h @@ -29,7 +29,6 @@ #ifndef RVIZ_VISUALIZER_APP_H #define RVIZ_VISUALIZER_APP_H -#include #include #ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829 @@ -38,6 +37,7 @@ #include #endif +class QApplication; class QTimer; namespace rviz @@ -51,6 +51,7 @@ class RVIZ_EXPORT VisualizerApp : public QObject VisualizerApp(); ~VisualizerApp() override; + // now deprecated void setApp(QApplication* app); /** Start everything. Pass in command line arguments. @@ -67,7 +68,6 @@ private Q_SLOTS: bool loadConfigDiscardingCallback(rviz::SendFilePathRequest& req, rviz::SendFilePathResponse& res); bool saveConfigCallback(rviz::SendFilePathRequest& req, rviz::SendFilePathResponse& res); - QApplication* app_; QTimer* continue_timer_; VisualizationFrame* frame_; ros::NodeHandlePtr nh_; From ef75ebc27629cd43a8dc46ebf62f6f41acbfc743 Mon Sep 17 00:00:00 2001 From: Yannis Gerlach <100762533+ygerlach@users.noreply.github.com> Date: Fri, 28 Oct 2022 15:53:07 +0200 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Robert Haschke --- src/rviz/visualization_frame.h | 2 +- src/rviz/visualizer_app.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rviz/visualization_frame.h b/src/rviz/visualization_frame.h index d0c9f305c8..dfc45270c9 100644 --- a/src/rviz/visualization_frame.h +++ b/src/rviz/visualization_frame.h @@ -78,7 +78,7 @@ class RVIZ_EXPORT VisualizationFrame : public QMainWindow, public WindowManagerI VisualizationFrame(QWidget* parent = nullptr); ~VisualizationFrame() override; - // now deprecated + [[deprecated("setApp() not needed anymore")]] void setApp(QApplication* app); /** @brief Call this @e before initialize() to have it take effect. */ diff --git a/src/rviz/visualizer_app.h b/src/rviz/visualizer_app.h index af880a45e3..27a5dd18f8 100644 --- a/src/rviz/visualizer_app.h +++ b/src/rviz/visualizer_app.h @@ -51,7 +51,7 @@ class RVIZ_EXPORT VisualizerApp : public QObject VisualizerApp(); ~VisualizerApp() override; - // now deprecated + [[deprecated("setApp() not needed anymore")]] void setApp(QApplication* app); /** Start everything. Pass in command line arguments. From 9fe8e28d2a4483f291d5796541113ae19422052f Mon Sep 17 00:00:00 2001 From: ygerlach <100762533+ygerlach@users.noreply.github.com> Date: Wed, 2 Nov 2022 08:09:29 +0100 Subject: [PATCH 3/3] apply changes suggested by clang-format --- src/rviz/visualization_frame.cpp | 4 +++- src/rviz/visualization_frame.h | 3 +-- src/rviz/visualizer_app.h | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rviz/visualization_frame.cpp b/src/rviz/visualization_frame.cpp index b1b0268ee0..2323872689 100644 --- a/src/rviz/visualization_frame.cpp +++ b/src/rviz/visualization_frame.cpp @@ -749,7 +749,9 @@ bool VisualizationFrame::loadDisplayConfigHelper(const std::string& full_path, c dialog.reset(new LoadingDialog(this)); dialog->show(); connect(this, SIGNAL(statusUpdate(const QString&)), dialog.get(), SLOT(showMessage(const QString&))); - QCoreApplication::processEvents(); // make the window correctly appear although running a long-term function + + // make the window correctly appear although running a long-term function + QCoreApplication::processEvents(); } YamlConfigReader reader; diff --git a/src/rviz/visualization_frame.h b/src/rviz/visualization_frame.h index dfc45270c9..988b6dc62e 100644 --- a/src/rviz/visualization_frame.h +++ b/src/rviz/visualization_frame.h @@ -78,8 +78,7 @@ class RVIZ_EXPORT VisualizationFrame : public QMainWindow, public WindowManagerI VisualizationFrame(QWidget* parent = nullptr); ~VisualizationFrame() override; - [[deprecated("setApp() not needed anymore")]] - void setApp(QApplication* app); + [[deprecated("setApp() not needed anymore")]] void setApp(QApplication* app); /** @brief Call this @e before initialize() to have it take effect. */ void setShowChooseNewMaster(bool show); diff --git a/src/rviz/visualizer_app.h b/src/rviz/visualizer_app.h index 27a5dd18f8..4beae97184 100644 --- a/src/rviz/visualizer_app.h +++ b/src/rviz/visualizer_app.h @@ -51,8 +51,7 @@ class RVIZ_EXPORT VisualizerApp : public QObject VisualizerApp(); ~VisualizerApp() override; - [[deprecated("setApp() not needed anymore")]] - void setApp(QApplication* app); + [[deprecated("setApp() not needed anymore")]] void setApp(QApplication* app); /** Start everything. Pass in command line arguments. * @return false on failure, true on success. */