-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
176 lines (146 loc) · 5.16 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QLabel"
#include "QTreeWidget"
#include "Core/CalcThread.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
//setMinimumWidth(ui->menu->minimumWidth() + layout()->margin());
createMenu();
stackedWidgetSetup();
isLoading = false;
selectFirstFrame();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::createMenu()
{
itemWidgetMapping = new QMap<QTreeWidgetItem *, QWidget *>();
const int integralItemsCount = 3;
TMember integralItems[integralItemsCount] =
{
{"Постоянный шаг", new IntegralConstStepFrame},
{"Переменный шаг", new IntegralFloatingStepFrame},
{"Кратное интегрирование", new IntegralMultipleFrame}
};
const int differentialEquationsItemsCount = 2;
TMember differentialEquationsItems[differentialEquationsItemsCount] =
{
{"Метод Эйлера", new DiffEqEulerMethodFrame(this, ModeDiffEuler)},
{"Метод Рунге-Кутты", new DiffEqEulerMethodFrame(this, ModeDiffRunge)}
};
const int nolinearItemsCount = 3;
TMember nolinearItems[nolinearItemsCount] =
{
{"Метод Дихотомии", new NonlinearEquationsFrame(this, ModeEqHalfDiv)},
{"Метод Хорд", new NonlinearEquationsFrame(this, ModeEqChord)},
{"Метод Ньютона", new NonlinearEquationsFrame(this, ModeEqNewton)}
};
const int simpleFunctionsItemsCount = 1;
TMember simpleFunctionsItems[simpleFunctionsItemsCount] =
{
{"Метод Маклорена", new SinCosFrame(this, MaclaurinMode)}
};
const int equationsSystemsItemsCount = 4;
TMember equationsSystemsItems[equationsSystemsItemsCount] =
{
{"Метод Гаусса", new EquationsSystemsFrame(this, ModeEqSysGauss)},
{"Метод оптимальных исключений", new EquationsSystemsFrame(this, ModeEqSysGaussOptimal)},
{"Метод Гаусса-Жордана", new EquationsSystemsFrame(this, ModeEqSysGaussJordan)},
{"Метод наименьших квадратов", new EquationsSystemsFrame(this, ModeEqSysSquare)},
};
const int menuItemsCount = 5;
THeader menu[menuItemsCount] =
{
{
"Интегрирование",
integralItems,
integralItemsCount
},
{
"Дифференциальные уравнения",
differentialEquationsItems,
differentialEquationsItemsCount
},
{
"Нелинейные уравнения",
nolinearItems,
nolinearItemsCount
},
{
"Элементарные функции",
simpleFunctionsItems,
simpleFunctionsItemsCount
},
{
"Решение СЛАУ",
equationsSystemsItems,
equationsSystemsItemsCount
}
};
for(int i = 0; i < menuItemsCount; ++i)
{
QTreeWidgetItem *header = new QTreeWidgetItem(ui->menu);
header->setText(0, menu[i].name);
header->setFlags(header->flags() & ~Qt::ItemIsSelectable);
PMember members = menu[i].members;
for(int j = 0; j < menu[i].membersCount; ++j)
{
QTreeWidgetItem *member = new QTreeWidgetItem(header);
member->setText(0, members[j].name);
itemWidgetMapping->insert(member, members[j].widget);
}
}
ui->menu->expandAll();
}
void MainWindow::stackedWidgetSetup()
{
QMap<QTreeWidgetItem *, QWidget *>::iterator iter = itemWidgetMapping->begin();
while(iter != itemWidgetMapping->end())
{
ui->stackedWidget->addWidget(iter.value());
++iter;
}
ui->stackedWidget->setFocus();
}
void MainWindow::selectFirstFrame()
{
QTreeWidgetItem *item = ui->menu->topLevelItem(0)->child(0);
ui->menu->setCurrentItem(item);
}
void MainWindow::on_menu_expanded(const QModelIndex &index)
{
ui->menu->resizeColumnToContents(index.column());
}
void MainWindow::on_menu_collapsed(const QModelIndex &index)
{
ui->menu->resizeColumnToContents(index.column());
}
void MainWindow::on_helpButton_clicked()
{
createHelpDialog();
helpDialogFrame->show();
helpDialogFrame->setFocus();
}
void MainWindow::createHelpDialog()
{
if(helpDialogFrame == nullptr)
helpDialogFrame = new HelpDialogFrame;
}
void MainWindow::on_menu_itemSelectionChanged()
{
if(isLoading)
return;
QTreeWidgetItem *item = ui->menu->currentItem();
QMap<QTreeWidgetItem *, QWidget *>::iterator currentWidgetIterator = itemWidgetMapping->find(item);
if(currentWidgetIterator != itemWidgetMapping->end())
{
ui->stackedWidget->setCurrentWidget(currentWidgetIterator.value());
ui->frameName->setText(item->parent()->text(0) + ": " + item->text(0));
if(dynamic_cast<FrameThreadHelper*>(currentWidgetIterator.value()))
static_cast<FrameThreadHelper*>(currentWidgetIterator.value())->change();
}
}