complete implementation of variable setting dialog
This commit is contained in:
@ -271,35 +271,35 @@ void LammpsGui::update_recents(const QString &filename)
|
||||
ui->action_1->setVisible(false);
|
||||
if ((recent.size() > 0) && !recent[0].isEmpty()) {
|
||||
QFileInfo fi(recent[0]);
|
||||
ui->action_1->setText(QString("1. ") + fi.fileName());
|
||||
ui->action_1->setText(QString("&1. ") + fi.fileName());
|
||||
ui->action_1->setData(recent[0]);
|
||||
ui->action_1->setVisible(true);
|
||||
}
|
||||
ui->action_2->setVisible(false);
|
||||
if ((recent.size() > 1) && !recent[1].isEmpty()) {
|
||||
QFileInfo fi(recent[1]);
|
||||
ui->action_2->setText(QString("2. ") + fi.fileName());
|
||||
ui->action_2->setText(QString("&2. ") + fi.fileName());
|
||||
ui->action_2->setData(recent[1]);
|
||||
ui->action_2->setVisible(true);
|
||||
}
|
||||
ui->action_3->setVisible(false);
|
||||
if ((recent.size() > 2) && !recent[2].isEmpty()) {
|
||||
QFileInfo fi(recent[2]);
|
||||
ui->action_3->setText(QString("3. ") + fi.fileName());
|
||||
ui->action_3->setText(QString("&3. ") + fi.fileName());
|
||||
ui->action_3->setData(recent[2]);
|
||||
ui->action_3->setVisible(true);
|
||||
}
|
||||
ui->action_4->setVisible(false);
|
||||
if ((recent.size() > 3) && !recent[3].isEmpty()) {
|
||||
QFileInfo fi(recent[3]);
|
||||
ui->action_4->setText(QString("4. ") + fi.fileName());
|
||||
ui->action_4->setText(QString("&4. ") + fi.fileName());
|
||||
ui->action_4->setData(recent[3]);
|
||||
ui->action_4->setVisible(true);
|
||||
}
|
||||
ui->action_5->setVisible(false);
|
||||
if ((recent.size() > 4) && !recent[4].isEmpty()) {
|
||||
QFileInfo fi(recent[4]);
|
||||
ui->action_5->setText(QString("5. ") + fi.fileName());
|
||||
ui->action_5->setText(QString("&5. ") + fi.fileName());
|
||||
ui->action_5->setData(recent[4]);
|
||||
ui->action_5->setVisible(true);
|
||||
}
|
||||
@ -898,7 +898,10 @@ void LammpsGui::edit_variables()
|
||||
{
|
||||
QList<QPair<QString, QString>> newvars = variables;
|
||||
SetVariables vars(newvars);
|
||||
if (vars.exec() == QDialog::Accepted) variables = newvars;
|
||||
if (vars.exec() == QDialog::Accepted) {
|
||||
variables = newvars;
|
||||
lammps.close();
|
||||
}
|
||||
}
|
||||
|
||||
void LammpsGui::preferences()
|
||||
@ -968,6 +971,18 @@ void LammpsGui::start_lammps()
|
||||
lammps_args.push_back(mystrdup("screen"));
|
||||
}
|
||||
|
||||
// add variables, if defined
|
||||
for (auto &var : variables) {
|
||||
QString name = var.first;
|
||||
QString value = var.second;
|
||||
if (!name.isEmpty() && !value.isEmpty()) {
|
||||
lammps_args.push_back(mystrdup("-var"));
|
||||
lammps_args.push_back(mystrdup(name.toStdString()));
|
||||
for (const auto &v : value.split(' '))
|
||||
lammps_args.push_back(mystrdup(v.toStdString()));
|
||||
}
|
||||
}
|
||||
|
||||
char **args = lammps_args.data();
|
||||
int narg = lammps_args.size();
|
||||
lammps.open(narg, args);
|
||||
|
||||
@ -11,6 +11,9 @@
|
||||
<qresource>
|
||||
<file>gtk-zoom-fit.png</file>
|
||||
</qresource>
|
||||
<qresource>
|
||||
<file>edit-delete.png</file>
|
||||
</qresource>
|
||||
<qresource>
|
||||
<file>object-rotate-right.png</file>
|
||||
</qresource>
|
||||
|
||||
@ -418,11 +418,15 @@
|
||||
</action>
|
||||
<action name="actionSet_Variables">
|
||||
<property name="icon">
|
||||
<iconset theme="preferences-desktop-personal"/>
|
||||
<iconset theme="preferences-desktop-personal">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Set &Variables</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Shift+V</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
||||
@ -15,32 +15,45 @@
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QIcon>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QSizePolicy>
|
||||
|
||||
SetVariables::SetVariables(QList<QPair<QString, QString>> &vars, QWidget *parent) : QDialog(parent)
|
||||
SetVariables::SetVariables(QList<QPair<QString, QString>> &_vars, QWidget *parent) :
|
||||
QDialog(parent), vars(_vars), layout(new QVBoxLayout)
|
||||
{
|
||||
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);
|
||||
auto *top = new QLabel("Set Variables:");
|
||||
layout->addWidget(top, 0, Qt::AlignHCenter);
|
||||
|
||||
int i = 1;
|
||||
for (const auto &v : vars) {
|
||||
auto *row = new QHBoxLayout;
|
||||
auto *name = new QLineEdit(v.first);
|
||||
auto *val = new QLineEdit(v.second);
|
||||
auto *del = new QPushButton(QIcon(":/edit-delete.png"), "");
|
||||
name->setObjectName("varname");
|
||||
val->setObjectName("varval");
|
||||
layout->addWidget(name, i, 0);
|
||||
layout->addWidget(val, i, 1);
|
||||
del->setObjectName(QString::number(i));
|
||||
connect(del, &QPushButton::released, this, &SetVariables::del_row);
|
||||
row->addWidget(name);
|
||||
row->addWidget(val);
|
||||
row->addWidget(del);
|
||||
layout->addLayout(row);
|
||||
++i;
|
||||
}
|
||||
layout->addItem(new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Expanding), i, 0);
|
||||
layout->addWidget(buttonBox, i + 1, 0, 1, 2);
|
||||
layout->addSpacerItem(new QSpacerItem(10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
||||
|
||||
auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
auto *add = new QPushButton("&Add Row");
|
||||
add->setObjectName("add_row");
|
||||
buttonBox->addButton(add, QDialogButtonBox::ActionRole);
|
||||
connect(add, &QPushButton::released, this, &SetVariables::add_row);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &SetVariables::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
|
||||
layout->addWidget(buttonBox);
|
||||
setLayout(layout);
|
||||
setWindowTitle("LAMMPS-GUI - Set Variables");
|
||||
resize(500, 400);
|
||||
@ -48,8 +61,64 @@ SetVariables::SetVariables(QList<QPair<QString, QString>> &vars, QWidget *parent
|
||||
|
||||
void SetVariables::accept()
|
||||
{
|
||||
// store all data in settings class
|
||||
// and then confirm accepting
|
||||
// store all data in variables class and then confirm accepting
|
||||
vars.clear();
|
||||
int nrows = layout->count() - 2;
|
||||
for (int i = 1; i < nrows; ++i) {
|
||||
auto *row = layout->itemAt(i)->layout();
|
||||
auto *var = dynamic_cast<QLineEdit *>(row->itemAt(0)->widget());
|
||||
auto *val = dynamic_cast<QLineEdit *>(row->itemAt(1)->widget());
|
||||
if (var && val) vars.append(qMakePair(var->text(), val->text()));
|
||||
}
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void SetVariables::add_row()
|
||||
{
|
||||
int nrows = layout->count();
|
||||
auto *row = new QHBoxLayout;
|
||||
auto *name = new QLineEdit(QString());
|
||||
auto *val = new QLineEdit(QString());
|
||||
auto *del = new QPushButton(QIcon(":/edit-delete.png"), "");
|
||||
name->setObjectName("varname");
|
||||
val->setObjectName("varval");
|
||||
del->setObjectName(QString::number(nrows - 2));
|
||||
connect(del, &QPushButton::released, this, &SetVariables::del_row);
|
||||
row->addWidget(name);
|
||||
row->addWidget(val);
|
||||
row->addWidget(del);
|
||||
layout->insertLayout(nrows - 2, row);
|
||||
}
|
||||
|
||||
void SetVariables::del_row()
|
||||
{
|
||||
int nrows = layout->count();
|
||||
auto *who = sender();
|
||||
if (who) {
|
||||
// figure out which row was deleted and delete its layout and widgets
|
||||
int delrow = who->objectName().toInt();
|
||||
auto *row = layout->takeAt(delrow);
|
||||
while (row->layout()->count() > 0) {
|
||||
auto *item = row->layout()->takeAt(0);
|
||||
row->layout()->removeItem(item);
|
||||
if (item) {
|
||||
delete item->widget();
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
layout->removeItem(row);
|
||||
delete row->layout();
|
||||
|
||||
// renumber the delete pushbutton names
|
||||
for (int i = delrow; i < nrows - 3; ++i) {
|
||||
auto *row = layout->itemAt(i)->layout();
|
||||
auto *widget = row->itemAt(2)->widget();
|
||||
widget->setObjectName(QString::number(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
// c-basic-offset: 4
|
||||
// End:
|
||||
|
||||
@ -28,6 +28,12 @@ public:
|
||||
|
||||
private slots:
|
||||
void accept() override;
|
||||
void add_row();
|
||||
void del_row();
|
||||
|
||||
private:
|
||||
QList<QPair<QString, QString>> &vars;
|
||||
class QVBoxLayout *layout;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user