Skip to content

Commit

Permalink
Use static QCoreApplication::processEvents() w/o QApplication instance (
Browse files Browse the repository at this point in the history
#1772)

Drop QApplication instance from VisualizationFrame
  • Loading branch information
ygerlach authored Mar 20, 2023
1 parent d122ab1 commit 15e148d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/rviz/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
38 changes: 15 additions & 23 deletions src/rviz/visualization_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QAction>
#include <QShortcut>
#include <QApplication>
#include <QCoreApplication>
#include <QCloseEvent>
#include <QDesktopServices>
#include <QDockWidget>
Expand Down Expand Up @@ -103,7 +104,6 @@ namespace rviz
{
VisualizationFrame::VisualizationFrame(QWidget* parent)
: QMainWindow(parent)
, app_(nullptr)
, render_panel_(nullptr)
, show_help_action_(nullptr)
, preferences_(new Preferences())
Expand Down Expand Up @@ -166,7 +166,7 @@ VisualizationFrame::~VisualizationFrame()

void VisualizationFrame::setApp(QApplication* app)
{
app_ = app;
Q_UNUSED(app);
}

void VisualizationFrame::setStatus(const QString& message)
Expand Down Expand Up @@ -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())
{
Expand All @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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 != "")
{
Expand All @@ -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;
Expand Down Expand Up @@ -759,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&)));
app_->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;
Expand Down
4 changes: 1 addition & 3 deletions src/rviz/visualization_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class RVIZ_EXPORT VisualizationFrame : public QMainWindow, public WindowManagerI
VisualizationFrame(QWidget* parent = nullptr);
~VisualizationFrame() override;

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);
Expand Down Expand Up @@ -328,8 +328,6 @@ protected Q_SLOTS:

void hideDockImpl(Qt::DockWidgetArea area, bool hide);

QApplication* app_;

RenderPanel* render_panel_;

QAction* show_help_action_;
Expand Down
5 changes: 2 additions & 3 deletions src/rviz/visualizer_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand Down
5 changes: 2 additions & 3 deletions src/rviz/visualizer_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#ifndef RVIZ_VISUALIZER_APP_H
#define RVIZ_VISUALIZER_APP_H

#include <QApplication>
#include <QObject>

#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829
Expand All @@ -38,6 +37,7 @@
#include <rviz/SendFilePath.h>
#endif

class QApplication;
class QTimer;

namespace rviz
Expand All @@ -51,7 +51,7 @@ class RVIZ_EXPORT VisualizerApp : public QObject
VisualizerApp();
~VisualizerApp() override;

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. */
Expand All @@ -67,7 +67,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_;
Expand Down

0 comments on commit 15e148d

Please sign in to comment.