-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
161 lines (134 loc) · 3.81 KB
/
mainwindow.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <ogrie.h>
#include <QFileDialog>
OgrieParty rezult;
void MainWindow::reCountRezult(){
OgrieParty rez;
unsigned short N = ui->spinBox->value();
if (ui->CB_struct->currentIndex() == 0){
rez.createByRangedValues(*(new std::stack<int>), *(new Ogrie), 0, N);
}else{
rez.createByRangedValues(*(new std::deque<int>), *(new Ogrie), 0, N);
}
rezult = rez;
}
void MainWindow::reFillComboBoxOfRezults(){
QStringList list;
ui->CB_rezults->clear();
for ( unsigned int i = 0; i < rezult.size(); ++i){
list<<QString::fromStdString(rezult[i].toString());
}
ui->CB_rezults->addItems(list);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_CB_struct_currentIndexChanged(int index)
{
reCountRezult();
reFillComboBoxOfRezults();
if (ui->CB_struct->currentIndex() == 0){
ui->spinBox->setMaximum(8);
}else{
ui->spinBox->setMaximum(5);
}
initalizeForVisualization();
}
void MainWindow::on_spinBox_valueChanged(int arg1)
{
reCountRezult();
reFillComboBoxOfRezults();
initalizeForVisualization();
}
void MainWindow::on_spinBox_editingFinished()
{
reCountRezult();
reFillComboBoxOfRezults();
initalizeForVisualization();
}
unsigned int currentNumber = 0;
unsigned int currentActionIndex = 0;
unsigned int currentSize = 0;
Ogrie currentRezult;
void MainWindow::initalizeForVisualization(){
currentNumber = 0;
currentActionIndex = 0;
currentSize = 0;
currentRezult = rezult[ui->CB_rezults->currentIndex()];
ui->TB_actions->clear();
ui->LW_struct_visual->clear();
}
void MainWindow::on_B_run_visual_clicked()
{
currentRezult = rezult[ui->CB_rezults->currentIndex()];
QString tmp;
switch (currentRezult.getAction(currentActionIndex++)){
case 0:
if (currentSize != 0){
tmp = ui->TB_actions->toPlainText();
tmp.append("pop_front();\n");
ui->TB_actions->setText(tmp);
currentSize--;
ui->LW_struct_visual->takeItem(0);
}
break;
case 1:
currentSize++;
tmp = ui->TB_actions->toPlainText();
tmp.append("push_front(");
tmp.append(QString::number(currentNumber));
tmp.append(");\n");
ui->TB_actions->setText(tmp);
ui->LW_struct_visual->insertItem(0, QString::number(currentNumber++));
break;
case 2:
tmp = ui->TB_actions->toPlainText();
tmp.append("pop_back();\n");
ui->TB_actions->setText(tmp);
ui->LW_struct_visual->takeItem(--currentSize);
break;
case 3:
currentSize++;
tmp = ui->TB_actions->toPlainText();
tmp.append("push_back(");
tmp.append(QString::number(currentNumber));
tmp.append(");\n");
ui->TB_actions->setText(tmp);
ui->LW_struct_visual->addItem(QString::number(currentNumber++));
break;
}
}
void MainWindow::on_actionSave_one_rezult_triggered()
{
QString fileName = QFileDialog::getSaveFileName();
fileName.append(".txt");
QFile file(fileName);
file.open(QIODevice::WriteOnly);
file.write(currentRezult.toString(1).c_str());
file.close();
}
void MainWindow::on_actionSave_all_rezults_triggered()
{
QString fileName = QFileDialog::getSaveFileName();
fileName.append(".txt");
QFile file(fileName);
file.open(QIODevice::WriteOnly);
for (unsigned int i = 0; i < rezult.size(); ++i){
file.write("[");
char number[8];
itoa(i, number, 10);
file.write(number);
file.write("]");
file.write(rezult[i].toString(1).c_str());
file.write("\n\n");
}
file.close();
}