-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
164 lines (138 loc) · 5.92 KB
/
mainwindow.cpp
File metadata and controls
164 lines (138 loc) · 5.92 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
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
ni = new NumericalIntegration();
runButton = ui->runButton;
resetButton = ui->resetButton;
aboutButton = ui->aboutButton;
theCancelButton = ui->theCancelButton;
inputExpression = ui->expressionInput;
upperLimit = ui->upperLimitInput;
lowerLimit = ui->lowerLimitInput;
resExpression = ui->resExpression;
resFrom = ui->resFrom;
resTo = ui->resTo;
resRectangle = ui->resRectangle;
resTrapezoidal = ui->resTrapezoidal;
resSimspon = ui->resSimpson;
cbExpression = ui->checkExpression;
cbRettangoli = ui->checkRettangoli;
cbTrapezoidi = ui->checkTrapezoidi;
cbSimpson = ui->checkSimpson;
resolution = ui->resInput;
gresolution = ui->gresInput;
connect(runButton, SIGNAL(clicked()), this, SLOT(onRunButtonPressed()));
connect(resetButton, SIGNAL(clicked()), this,SLOT(onResetButtonPressed()));
connect(aboutButton, SIGNAL(clicked()), this,SLOT(onAboutButtonPressed()));
connect(theCancelButton, SIGNAL(clicked()), this,SLOT(onTheCancelButtonPressed()));
chartView = ui->chartView;
chartView->setRenderHint(QPainter::Antialiasing);
chartView->setRubberBand(QChartView::RectangleRubberBand);
setWindowTitle(QCoreApplication::applicationName());
}// MainWindow
MainWindow::~MainWindow() {
delete ui;
}
void MainWindow::setNi(NumericalIntegration* input){
ni = input;
}// ~MainWindow
void MainWindow::onRunButtonPressed() {
// checking user input
if(!isUserInputCorrect()){
QMessageBox msgBox;
msgBox.setText("The inputted data is not correct.");
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setIcon(QMessageBox::Warning);
msgBox.exec();
} else {
chartView->chart()->removeAllSeries(); // remove old chart
QString expression;
expression = inputExpression->text();
std::string stdstring = expression.toUtf8().constData();
ni->setExpression(stdstring);
ni->setInterval(lowerLimit->value(), upperLimit->value());
ni->setResolution(resolution->value());
ni->setGResolution(gresolution->value());
ni->buildExpression();
ni->computeGraphs(cbExpression->isChecked(), cbRettangoli->isChecked(), cbTrapezoidi->isChecked(), cbSimpson->isChecked());
chartView->setChart(ni->getChart()); // add new chart
chartView->update();
buildResult();
}
}// onRunButtonPressed
void MainWindow::onResetButtonPressed() {
QMessageBox msgBox;
msgBox.setText("Do you want to reset?");
msgBox.setIcon(QMessageBox::Question);
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);
int ret = msgBox.exec();
if(ret == QMessageBox::Yes){
inputExpression->clear();
upperLimit->clear();
lowerLimit->clear();
resExpression->clear();
resFrom->clear();
resTo->clear();
resRectangle->clear();
resTrapezoidal->clear();
resSimspon->clear();
chartView->chart()->removeAllSeries();
chartView->update();
}
}// onResetButtonPressed
void MainWindow::onAboutButtonPressed(){
QMessageBox msgBox;
msgBox.setTextFormat(Qt::RichText);
msgBox.setText("Authors:<br>"
"<a href=https://github.com/annicc>Luca Annicchiarico</a><br>"
"<a href=https://github.com/marc0777>Marco Fincato</a><br>"
"<br>"
"<a href=https://github.com/marc0777/NumericalIntegration>Github</a><br>"
"©Copyright 2019");
msgBox.setTextInteractionFlags(Qt::NoTextInteraction);
msgBox.addButton(tr("Nice"), QMessageBox::AcceptRole);
msgBox.exec();
}// onAboutButtonPressed
void MainWindow::onTheCancelButtonPressed(){
QMessageBox msgBox;
msgBox.setText("Are you sure you want to C̵̤̭̭̙̪̟͕͓̱̮͝ ̶̢̬̞̬͓͓̪̲̹̫͗̎̿͝ ̶̡̟̘͚͈̐͘ͅȂ̷̛̩̣̬̫̣͈̥̖͂͋̊̊̀̈̀̌ ̶͔͎̥͚̱̘̫̮͙̅̿̑̀̚͝ ̸̥͔̮̘̦͕̟̥̙̈́̒̊͂̽͜N̵͔͉͂̏ ̴̝̝͙̌̀̽̌̒͝ ̵̹̒̇̀̓̓̄͒̇̉̾C̸̢̾̈́̈́̽͆ ̴̱̘͇̮͆̈́̃͌͆͐̇͠ ̶̞̖̉̈͒͂͗̃͒̾̿͝E̵̡͚͍̗͌͊̈͘̚ ̷̪̘̤͚̇̉̐̽͋͊̐͋ ̸̲͕̮͔̤̮̪̥͌̐̚̕͘͜͝L̵̼̣̬̟͎͈̥͚̹̋̚͝ͅ ?");
msgBox.setIcon(QMessageBox::Warning);
msgBox.setStandardButtons(QMessageBox::Cancel | QMessageBox::No);
msgBox.addButton(tr("please have mercy"), QMessageBox::DestructiveRole);
msgBox.setDefaultButton(QMessageBox::No);
int ret = msgBox.exec();
QMessageBox msgCancel;
QMessageBox msgPlease;
switch (ret) {
case QMessageBox::Cancel:
msgCancel.setText("You have successfully cancelled");
msgCancel.setStandardButtons(QMessageBox::Ok);
msgCancel.exec();
break;
case QMessageBox::No:
onTheCancelButtonPressed();
break;
default:
msgPlease.setText("I will 🆂 🅿 🅰 🆁 🅴 you");
msgPlease.addButton(tr("thank you master"), QMessageBox::AcceptRole);
msgPlease.exec();
break;
}
}// onTheCancelButtonPressed
bool MainWindow::isUserInputCorrect(){
return
!inputExpression->text().isEmpty() || // doesn't work on second run
!lowerLimit->text().isEmpty() ||
!upperLimit->text().isEmpty();
}// isUserInputCorrect
void MainWindow::buildResult(){
resExpression->setText(QString::fromStdString(ni->getExpression()));
resFrom->setText(QString::number(ni->getFrom()));
resTo->setText(QString::number(ni->getTo()));
resRectangle->setText(QString::number(ni->getRectangleOut()));
resTrapezoidal->setText(QString::number(ni->getTrapezoidalOut()));
resSimspon->setText(QString::number(ni->getSimpsonOut()));
}// resultBuilder