port LAMMPS GUI to Qt6 while still supporting Qt5
This commit is contained in:
@ -11,6 +11,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
option(LAMMPS_GUI_USE_PLUGIN "Load LAMMPS library dynamically at runtime" OFF)
|
||||
mark_as_advanced(LAMMPS_GUI_USE_PLUGIN)
|
||||
option(LAMMPS_GUI_USE_QT5 "Prefer using Qt5 over Qt6" OFF)
|
||||
|
||||
# checks
|
||||
# when this file is included as subdirectory in the LAMMPS build, many settings are directly imported
|
||||
@ -73,7 +74,15 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
endif()
|
||||
|
||||
# we require Qt 5 and at least version 5.12 at that.
|
||||
if(NOT LAMMPS_GUI_USE_QT5)
|
||||
find_package(Qt6 6.2 COMPONENTS Widgets Charts)
|
||||
endif()
|
||||
if(NOT Qt6_FOUND)
|
||||
find_package(Qt5 5.12 REQUIRED COMPONENTS Widgets Charts)
|
||||
set(QT_VERSION_MAJOR "5")
|
||||
else()
|
||||
set(QT_VERSION_MAJOR "6")
|
||||
endif()
|
||||
|
||||
set(PROJECT_SOURCES
|
||||
main.cpp
|
||||
@ -105,7 +114,11 @@ set(PROJECT_SOURCES
|
||||
${PLUGIN_LOADER_SRC}
|
||||
${ICON_RC_FILE}
|
||||
)
|
||||
if(QT_VERSION_MAJOR EQUAL 6)
|
||||
qt6_add_resources(PROJECT_SOURCES lammpsgui.qrc)
|
||||
else()
|
||||
qt5_add_resources(PROJECT_SOURCES lammpsgui.qrc)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
set(MACOSX_ICON_FILE ${LAMMPS_DIR}/cmake/packaging/lammps.icns)
|
||||
@ -113,10 +126,22 @@ if(APPLE)
|
||||
set(MACOSX_BACKGROUND_FILE ${LAMMPS_DIR}/cmake/packaging/LAMMPS_DMG_Background.png)
|
||||
endif()
|
||||
|
||||
if(QT_VERSION_MAJOR EQUAL 6)
|
||||
qt_add_executable(lammps-gui
|
||||
MANUAL_FINALIZATION
|
||||
${MACOSX_ICON_FILE}
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
else()
|
||||
add_executable(lammps-gui
|
||||
${MACOSX_ICON_FILE}
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
endif()
|
||||
|
||||
if(QT_VERSION_MAJOR EQUAL 6)
|
||||
qt_finalize_executable(lammps-gui)
|
||||
endif()
|
||||
|
||||
# compilation settings
|
||||
if(LAMMPS_GUI_USE_PLUGIN)
|
||||
@ -128,7 +153,7 @@ else()
|
||||
endif()
|
||||
target_include_directories(lammps-gui PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_compile_definitions(lammps-gui PRIVATE LAMMPS_GUI_VERSION="${PROJECT_VERSION}")
|
||||
target_link_libraries(lammps-gui PRIVATE Qt5::Widgets Qt5::Charts)
|
||||
target_link_libraries(lammps-gui PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${VERSION_MAJOR}::Charts)
|
||||
if(BUILD_OMP)
|
||||
find_package(OpenMP COMPONENTS CXX REQUIRED)
|
||||
target_link_libraries(lammps-gui PRIVATE OpenMP::OpenMP_CXX)
|
||||
@ -209,7 +234,7 @@ elseif((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND CMAKE_CROSSCOMPILING)
|
||||
COMMENT "Create zip file with windows binaries"
|
||||
BYPRODUCT LAMMPS-Win10-amd64.zip
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
elseif((CMAKE_SYSTEM_NAME STREQUAL "Linux") AND NOT LAMMPS_GUI_USE_PLUGIN)
|
||||
install(TARGETS lammps-gui DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lammps-gui.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications/)
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lammps-input.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/mime/packages/)
|
||||
|
||||
@ -15,11 +15,19 @@
|
||||
|
||||
#include "lammpsgui.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QFileDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
#include <QLineSeries>
|
||||
#include <QMenu>
|
||||
#include <QMenuBar>
|
||||
#include <QPushButton>
|
||||
#include <QSettings>
|
||||
#include <QSpacerItem>
|
||||
#include <QTextStream>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
using namespace QtCharts;
|
||||
@ -288,7 +296,7 @@ void ChartViewer::add_data(int step, double data)
|
||||
if (last_step < step) {
|
||||
last_step = step;
|
||||
series->append(step, data);
|
||||
auto points = series->pointsVector();
|
||||
auto points = series->points();
|
||||
|
||||
qreal xmin = 1.0e100;
|
||||
qreal xmax = -1.0e100;
|
||||
@ -309,7 +317,7 @@ void ChartViewer::add_data(int step, double data)
|
||||
|
||||
void ChartViewer::reset_zoom()
|
||||
{
|
||||
auto points = series->pointsVector();
|
||||
auto points = series->points();
|
||||
|
||||
qreal xmin = 1.0e100;
|
||||
qreal xmax = -1.0e100;
|
||||
|
||||
@ -14,16 +14,17 @@
|
||||
#ifndef CHARTVIEWER_H
|
||||
#define CHARTVIEWER_H
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
#include <QtCharts>
|
||||
|
||||
class QAction;
|
||||
class QMenuBar;
|
||||
class QMenu;
|
||||
class QComboBox;
|
||||
namespace QtCharts {
|
||||
class ChartViewer;
|
||||
}
|
||||
|
||||
class ChartWindow : public QWidget {
|
||||
Q_OBJECT
|
||||
@ -64,12 +65,18 @@ private:
|
||||
QAction *closeAct, *stopAct, *quitAct;
|
||||
|
||||
QString filename;
|
||||
QList<ChartViewer *> charts;
|
||||
QList<QtCharts::ChartViewer *> charts;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
class ChartViewer : public QtCharts::QChartView {
|
||||
#include <QChart>
|
||||
#include <QChartView>
|
||||
#include <QLineSeries>
|
||||
#include <QValueAxis>
|
||||
|
||||
namespace QtCharts {
|
||||
class ChartViewer : public QChartView {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
@ -86,11 +93,12 @@ public:
|
||||
|
||||
private:
|
||||
int last_step, index;
|
||||
QtCharts::QChart *chart;
|
||||
QtCharts::QLineSeries *series;
|
||||
QtCharts::QValueAxis *xaxis;
|
||||
QtCharts::QValueAxis *yaxis;
|
||||
QChart *chart;
|
||||
QLineSeries *series;
|
||||
QValueAxis *xaxis;
|
||||
QValueAxis *yaxis;
|
||||
};
|
||||
} // namespace QtCharts
|
||||
#endif
|
||||
|
||||
// Local Variables:
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -16,8 +16,10 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QList>
|
||||
#include <QPair>
|
||||
#include <QSpacerItem>
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user