-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterpreterwindow.cpp
More file actions
99 lines (76 loc) · 2.51 KB
/
interpreterwindow.cpp
File metadata and controls
99 lines (76 loc) · 2.51 KB
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
#include "interpreterwindow.h"
#include "ui_interpreterwindow.h"
#include <cstdlib>
#include <ctime>
InterpreterWindow::InterpreterWindow(const Project &proj, QWidget *parent) :
QWidget(parent),
ui(new Ui::InterpreterWindow),
proj(proj),
interp(proj.getVarNames(), proj.getRules()),
varNameMaxLength(0)
{
ui->setupUi(this);
initialize();
}
InterpreterWindow::~InterpreterWindow()
{
delete ui;
}
void InterpreterWindow::initialize()
{
std::srand(unsigned(std::time(0)));
QStringList inputVars = interp.getRequiredInputVarList();
ui->varComboBox->addItems(inputVars);
for (auto str : inputVars)
{
varNameMaxLength = ((str.length() > varNameMaxLength) ? str.length() : varNameMaxLength);
}
// Converting StringList to Map
for (int i = 0; i < inputVars.length(); i++)
{
QStringList temp = *proj.getVarValues(inputVars.at(i));
inputVarsMap[inputVars.at(i)] = temp.at(std::rand() % temp.length());
}
refreshVarsAndValuesList();
ui->errorsEdit->setText(Error(ErrorCode::NoErrors).text());
}
void InterpreterWindow::refreshVarsAndValuesList()
{
ui->varsAndValuesList->clear();
foreach (auto key, inputVarsMap.keys())
{
ui->varsAndValuesList->addItem(Pair(key, inputVarsMap[key]).stringify(false, (varNameMaxLength - key.length()), false));
}
ui->errorsEdit->setText(Error(ErrorCode::NoErrors).text());
}
void InterpreterWindow::on_varComboBox_currentIndexChanged(const QString &arg1)
{
if (arg1.isEmpty()) return;
auto result = proj.getVarValues(arg1);
if (!result) return;
ui->valueComboBox->clear();
ui->valueComboBox->addItems(*result);
ui->errorsEdit->setText(Error(ErrorCode::NoErrors).text());
}
void InterpreterWindow::on_enterButton_clicked()
{
if (ui->varComboBox->currentText().isEmpty()) return;
if (ui->valueComboBox->currentText().isEmpty()) return;
inputVarsMap[ui->varComboBox->currentText()] = ui->valueComboBox->currentText();
refreshVarsAndValuesList();
}
void InterpreterWindow::on_interpretButton_clicked()
{
for (auto value : inputVarsMap)
{
if (value.isEmpty())
{
ui->errorsEdit->setText("You should enter value for all Variables.");
return;
}
}
ui->errorsEdit->setText(Error(ErrorCode::NoErrors).text());
QMap<QString, QString> result = interp.interpret(inputVarsMap);
resWindow = new ResultWindow(result);
resWindow->show();
}