move redundant code to find pointer to main widget to helper function

This commit is contained in:
Axel Kohlmeyer
2025-06-14 19:04:43 -04:00
parent 90df96b16f
commit c5c1f47c20
10 changed files with 31 additions and 37 deletions

View File

@ -13,6 +13,7 @@
#include "chartviewer.h"
#include "helpers.h"
#include "lammpsgui.h"
#include <QAction>
@ -221,9 +222,7 @@ void ChartWindow::add_data(int step, double data, int index)
void ChartWindow::quit()
{
LammpsGui *main = nullptr;
for (QWidget *widget : QApplication::topLevelWidgets())
if (widget->objectName() == "LammpsGui") main = dynamic_cast<LammpsGui *>(widget);
auto *main = dynamic_cast<LammpsGui *>(get_main_widget());
if (main) main->quit();
}
@ -238,9 +237,7 @@ void ChartWindow::reset_zoom()
void ChartWindow::stop_run()
{
LammpsGui *main = nullptr;
for (QWidget *widget : QApplication::topLevelWidgets())
if (widget->objectName() == "LammpsGui") main = dynamic_cast<LammpsGui *>(widget);
auto *main = dynamic_cast<LammpsGui *>(get_main_widget());
if (main) main->stop_run();
}