forked from Lucky-spirit/Financial-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevgbasicmodel.cpp
More file actions
137 lines (119 loc) · 3.28 KB
/
Copy pathevgbasicmodel.cpp
File metadata and controls
137 lines (119 loc) · 3.28 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
#include "evgbasicmodel.h"
EvgBasicModel::EvgBasicModel(int coefficientsCount, QWidget *parent, QString source, QString modelName, QString formulaText, bool extended) :
QWidget(parent),
count(coefficientsCount),
result(0.0f),
name(modelName),
textOfFormula("<h2>" + formulaText + "</h2>"),
_state(TypeStateUndefined)
{
pLabelFormula = new QLabel(textOfFormula, this);
pLabelResult = new QLabel(tr("<h2> = ?</h2>"), this);
createRows(extended);
pTextDefinitionModel = new evgTextBrowser(0);
pTextDefinitionModel->setSource(QUrl(source));
}
EvgBasicModel::~EvgBasicModel()
{
delete [] pCoefficientRows;
}
void EvgBasicModel::createRows(bool extended)
{
pCoefficientRows = new EvgRow*[count];
for (int i=0; i < count; i++)
{
if (extended)
pCoefficientRows[i] = new ExtendRow;
else
pCoefficientRows[i] = new EvgRow;
}
// Init all Rows by their type
for (int i = 0; i < count; i++)
{
pCoefficientRows[i]->init();
pCoefficientRows[i]->settingLayout();
pCoefficientRows[i]->setIdText(i + 1);
}
}
float EvgBasicModel::getResult() const
{
return result;
}
void EvgBasicModel::setResultValue()
{
QString strResult;
strResult.setNum(result, 'g', 4);
strResult.insert(0, tr("<h2> = "));
strResult.append(tr("</h2>"));
pLabelResult->setText(strResult);
}
void EvgBasicModel::createTopLayout()
{
topLayout = new QHBoxLayout;
topLayout->addStretch(1);
topLayout->addWidget(pLabelFormula, 0);
topLayout->addWidget(pLabelResult, 0);
topLayout->addStretch(1);
}
void EvgBasicModel::createBottomLayout()
{
bottomLayout = new QHBoxLayout;
bottomLayout->addWidget(pTextDefinitionModel, 1);
}
void EvgBasicModel::createCentralLayout()
{
centralGrid = new QGridLayout;
centralGrid->setSpacing(25);
for (int i = 0; i < count; i++)
{
centralGrid->addWidget(pCoefficientRows[i]->labelId(), i, 0, Qt::AlignLeft | Qt::AlignVCenter);
centralGrid->addWidget(pCoefficientRows[i]->spinBoxRow(), i, 1, Qt::AlignLeft | Qt::AlignVCenter);
centralGrid->addWidget(pCoefficientRows[i]->labelDefinition(), i, 2, Qt::AlignLeft | Qt::AlignVCenter);
}
centralLayout = new QHBoxLayout;
centralLayout->addStretch(1);
centralLayout->addLayout(centralGrid);
centralLayout->addStretch(1);
}
void EvgBasicModel::createMainLayout()
{
mainLayout = new QVBoxLayout;
mainLayout->addLayout(topLayout, 0);
mainLayout->addStretch(1);
mainLayout->addLayout(centralLayout);
mainLayout->addStretch(1);
mainLayout->addLayout(bottomLayout, 0);
this->setLayout(mainLayout);
}
void EvgBasicModel::setEditable(bool yes)
{
for (int i = 0; i < count; i++)
{
pCoefficientRows[i]->setEditable(yes);
}
}
double EvgBasicModel::getValue(int number) const
{
return pCoefficientRows[number]->getValue();
}
QString EvgBasicModel::getName() const
{
return name;
}
TypeState EvgBasicModel::getState() const
{
return _state;
}
void EvgBasicModel::setTypeState(TypeState newState)
{
_state = newState;
}
bool EvgBasicModel::checkForZeros() const
{
for (int i = 0; i < count; i++)
{
if (pCoefficientRows[i]->getValue() == 0.0)
return FALSE;
}
return TRUE;
}