port LAMMPS GUI to Qt6 while still supporting Qt5

This commit is contained in:
Axel Kohlmeyer
2023-10-12 23:24:11 -04:00
parent 1a9dac83d7
commit 6ad5c0eced
5 changed files with 71 additions and 24 deletions

View File

@ -35,6 +35,7 @@
#include <QLabel>
#include <QLocale>
#include <QMessageBox>
#include <QMetaType>
#include <QPlainTextEdit>
#include <QProcess>
#include <QProgressBar>
@ -69,8 +70,10 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
// enforce using the plain ASCII C locale within the GUI.
QLocale::setDefault(QLocale("C"));
// register QList<QString>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// register QList<QString> only needed for Qt5
qRegisterMetaTypeStreamOperators<QList<QString>>("QList<QString>");
#endif
ui->setupUi(this);
this->setCentralWidget(ui->textEdit);
@ -588,7 +591,8 @@ void LammpsGui::open_file(const QString &fileName)
if (!file.open(QIODevice::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, "Warning",
"Cannot open file " + path.absoluteFilePath() + ": " +
file.errorString() + ".\nWill create new file on saving editor buffer.");
file.errorString() +
".\nWill create new file on saving editor buffer.");
ui->textEdit->document()->setPlainText(QString());
} else {
QTextStream in(&file);
@ -1039,9 +1043,9 @@ void LammpsGui::do_run(bool use_buffer)
logwindow->document()->setDefaultFont(text_font);
logwindow->setLineWrapMode(LogWindow::NoWrap);
logwindow->setMinimumSize(400, 300);
QShortcut *shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), logwindow);
QShortcut *shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_W), logwindow);
QObject::connect(shortcut, &QShortcut::activated, logwindow, &LogWindow::close);
shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Slash), logwindow);
shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Slash), logwindow);
QObject::connect(shortcut, &QShortcut::activated, this, &LammpsGui::stop_run);
if (settings.value("viewlog", true).toBool())
logwindow->show();
@ -1058,9 +1062,9 @@ void LammpsGui::do_run(bool use_buffer)
.arg(run_counter));
chartwindow->setWindowIcon(QIcon(":/icons/lammps-icon-128x128.png"));
chartwindow->setMinimumSize(400, 300);
shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), chartwindow);
shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_W), chartwindow);
QObject::connect(shortcut, &QShortcut::activated, chartwindow, &ChartWindow::close);
shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Slash), chartwindow);
shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Slash), chartwindow);
QObject::connect(shortcut, &QShortcut::activated, this, &LammpsGui::stop_run);
if (settings.value("viewchart", true).toBool())
chartwindow->show();