-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwoDimensionalProblem.cpp
76 lines (71 loc) · 2.22 KB
/
TwoDimensionalProblem.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
#include "TwoDimensionalProblem.h"
#include "ui_TwoDimensionalProblem.h"
TwoDimensionalProblem::TwoDimensionalProblem(QWidget *parent) :
QWidget(parent),
ui(new Ui::TwoDimensionalProblem)
{
ui->setupUi(this);
}
TwoDimensionalProblem::~TwoDimensionalProblem()
{
delete ui;
}
void TwoDimensionalProblem::setCondition(double **array, quint8 row)
{
QLabel *label;
QString str;
QLayoutItem *item;
m_row = row;
m_array = array;
//free memory
while((item = ui->functionLayout->takeAt(0)) != 0)
{
delete item->widget();
}
while((item = ui->exprLayout->takeAt(0)) != 0)
{
delete item->widget();
}
m_signs.clear();
//processing array
//function
label = new QLabel();
str += "Z = ";
if(m_array[m_row - 1][0] != 0)
str += QString::number(m_array[m_row - 1][0]) + "X<span style=\" vertical-align:sub;\">1</span>";
if(m_array[m_row - 1][1] < 0)
str += " - " + QString::number(m_array[m_row - 1][1] * -1) + "X<span style=\" vertical-align:sub;\">2</span>";
if(m_array[m_row - 1][1] > 0)
str += " + " + QString::number(m_array[m_row - 1][1]) + "X<span style=\" vertical-align:sub;\">2</span>";
if(m_array[m_row - 1][2] != 0)
str += " + " + QString::number(m_array[m_row - 1][2]);
label->setText(str);
ui->functionLayout->addWidget(label);
//expressions
for(quint8 i = 0; i < m_row - 1; i++)
{
label = new QLabel();
str.clear();
//X1
if(m_array[i][0] != 0)
str += QString::number(m_array[i][0]) + "X<span style=\" vertical-align:sub;\">1</span>";
//X2
if(m_array[i][1] < 0)
str += " - " + QString::number(m_array[i][1] * -1) + "X<span style=\" vertical-align:sub;\">2</span>";
if(m_array[i][1] > 0)
str += " + " + QString::number(m_array[i][1]) + "X<span style=\" vertical-align:sub;\">2</span>";
//C
str += " >= " + QString::number(m_array[i][2] * -1);
label->setText(str);
ui->exprLayout->addWidget(label);
}
}
void TwoDimensionalProblem::on_backButton_clicked()
{
emit back();
}
void TwoDimensionalProblem::on_nextButton_clicked()
{
emit next();
emit result(m_array, m_row);
}