add set variables dialog

This commit is contained in:
Axel Kohlmeyer
2023-08-12 00:09:30 -04:00
parent 45b9801941
commit 9110c23fcb
5 changed files with 104 additions and 0 deletions

View File

@ -81,6 +81,8 @@ set(PROJECT_SOURCES
logwindow.h
preferences.cpp
preferences.h
setvariables.cpp
setvariables.h
stdcapture.cpp
${PLUGIN_LOADER_SRC}
)

View File

@ -19,6 +19,7 @@
#include "lammpsrunner.h"
#include "logwindow.h"
#include "preferences.h"
#include "setvariables.h"
#include "stdcapture.h"
#include "ui_lammpsgui.h"
@ -150,6 +151,7 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
connect(ui->actionRedo, &QAction::triggered, this, &LammpsGui::redo);
connect(ui->actionRun_Buffer, &QAction::triggered, this, &LammpsGui::run_buffer);
connect(ui->actionStop_LAMMPS, &QAction::triggered, this, &LammpsGui::stop_run);
connect(ui->actionSet_Variables, &QAction::triggered, this, &LammpsGui::edit_variables);
connect(ui->actionImage, &QAction::triggered, this, &LammpsGui::render_image);
connect(ui->actionAbout_LAMMPS_GUI, &QAction::triggered, this, &LammpsGui::about);
connect(ui->action_Help, &QAction::triggered, this, &LammpsGui::help);
@ -892,6 +894,13 @@ void LammpsGui::defaults()
settings.sync();
}
void LammpsGui::edit_variables()
{
QList<QPair<QString, QString>> newvars = variables;
SetVariables vars(newvars);
if (vars.exec() == QDialog::Accepted) variables = newvars;
}
void LammpsGui::preferences()
{
QSettings settings;

View File

@ -77,6 +77,7 @@ private slots:
void clear();
void run_buffer();
void stop_run();
void edit_variables();
void render_image();
void view_image();
void view_chart();

View File

@ -0,0 +1,55 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
LAMMPS development team: developers@lammps.org
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "setvariables.h"
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QSizePolicy>
SetVariables::SetVariables(QList<QPair<QString, QString>> &vars, QWidget *parent) : QDialog(parent)
{
auto *layout = new QGridLayout;
auto *top = new QLabel("Set Variables:");
layout->addWidget(top, 0, 0, 1, 2, Qt::AlignHCenter);
auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &SetVariables::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
int i = 1;
for (const auto &v : vars) {
auto *name = new QLineEdit(v.first);
auto *val = new QLineEdit(v.second);
name->setObjectName("varname");
val->setObjectName("varval");
layout->addWidget(name, i, 0);
layout->addWidget(val, i, 1);
++i;
}
layout->addItem(new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Expanding), i, 0);
layout->addWidget(buttonBox, i + 1, 0, 1, 2);
setLayout(layout);
setWindowTitle("LAMMPS-GUI - Set Variables");
resize(500, 400);
}
void SetVariables::accept()
{
// store all data in settings class
// and then confirm accepting
QDialog::accept();
}

View File

@ -0,0 +1,37 @@
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
LAMMPS development team: developers@lammps.org
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifndef SET_VARIABLES_H
#define SET_VARIABLES_H
#include <QDialog>
#include <QList>
#include <QPair>
#include <QString>
class SetVariables : public QDialog {
Q_OBJECT
public:
explicit SetVariables(QList<QPair<QString, QString>> &vars, QWidget *parent = nullptr);
~SetVariables() = default;
private slots:
void accept() override;
};
#endif
// Local Variables:
// c-basic-offset: 4
// End: