-
Notifications
You must be signed in to change notification settings - Fork 1
/
mpostdialog.cpp
103 lines (85 loc) · 3.19 KB
/
mpostdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*!
* \file mpostdialog.cpp
* \author Simon Coakley
* \date 2012
* \copyright Copyright (c) 2012 University of Sheffield
* \brief Implementation of mpost dialog
*/
#include <QtGui>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include "./mpostdialog.h"
MpostDialog::MpostDialog(MemoryModel * m, QWidget *parent)
: QDialog(parent) {
// qDebug() << "MpreDialog";
memory = m;
lhsGroup = new QGroupBox(tr("LHS"));
rhsGroup = new QGroupBox(tr("RHS"));
opGroup = new QGroupBox(tr("OP"));
myEnabled = new QCheckBox(tr("Enabled"));
connect(myEnabled, SIGNAL(clicked(bool)), lhsGroup, SLOT(setEnabled(bool)));
connect(myEnabled, SIGNAL(clicked(bool)), rhsGroup, SLOT(setEnabled(bool)));
connect(myEnabled, SIGNAL(clicked(bool)), opGroup, SLOT(setEnabled(bool)));
variable = new QComboBox();
variable2 = new QComboBox();
value = new QSpinBox();
op = new QComboBox();
value2 = new QSpinBox();
operators << "=" << "+=" << "-=" << "*=" << "/=";
op->addItems(operators);
variable->addItems(memory->getNames());
variable2->addItems(memory->getNames());
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
connect(this, SIGNAL(setVariableComboBox(int)),
variable, SLOT(setCurrentIndex(int)));
connect(this, SIGNAL(setVariable2ComboBox(int)),
variable2, SLOT(setCurrentIndex(int)));
connect(this, SIGNAL(setOpComboBox(int)), op, SLOT(setCurrentIndex(int)));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QVBoxLayout *lhsLayout = new QVBoxLayout;
lhsLayout->addWidget(variable);
lhsGroup->setLayout(lhsLayout);
QVBoxLayout *rhsLayout = new QVBoxLayout;
// rhsLayout->addWidget(value);
rhsLayout->addWidget(variable2);
rhsGroup->setLayout(rhsLayout);
QHBoxLayout *opLayout = new QHBoxLayout;
opLayout->addWidget(op);
opGroup->setLayout(opLayout);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(myEnabled);
mainLayout->addWidget(lhsGroup);
mainLayout->addWidget(opGroup);
mainLayout->addWidget(rhsGroup);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Mpost Editor"));
}
void MpostDialog::setMpost(Mpost m) {
mpost = m;
myEnabled->setChecked(mpost.enabled());
lhsGroup->setEnabled(mpost.enabled());
opGroup->setEnabled(mpost.enabled());
rhsGroup->setEnabled(mpost.enabled());
value->setValue(mpost.value());
// value2->setValue(mpost.value2());
int index = memory->getNames().indexOf(mpost.name());
if (index == -1) index = 0;
emit(setVariableComboBox(index));
index = operators.indexOf(mpost.op());
if (index == -1) index = 0;
emit(setOpComboBox(index));
index = memory->getNames().indexOf(mpost.name2());
if (index == -1) index = 0;
emit(setVariable2ComboBox(index));
}
Mpost MpostDialog::getMpost() {
mpost.setEnabled(myEnabled->isChecked());
mpost.setValue(value->value());
mpost.setName(variable->currentText());
mpost.setOp(op->currentText());
// mpost.setValue2(value2->value());
mpost.setName2(variable2->currentText());
return mpost;
}