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 "helpers.h"
#include <QApplication>
#include <QBrush>
#include <QColor>
#include <QDir>
@ -21,6 +22,7 @@
#include <QPalette>
#include <QProcess>
#include <QStringList>
#include <QWidget>
// duplicate string, STL version
char *mystrdup(const std::string &text)
@ -42,6 +44,15 @@ char *mystrdup(const QString &text)
return mystrdup(text.toStdString());
}
// get pointer to LAMMPS-GUI main widget
QWidget *get_main_widget()
{
for (QWidget *widget : QApplication::topLevelWidgets())
if (widget->objectName() == "LammpsGui") return widget;
return nullptr;
}
// find if executable is in path
// https://stackoverflow.com/a/51041497