-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmanager.cpp
More file actions
158 lines (134 loc) · 4.34 KB
/
Copy pathmanager.cpp
File metadata and controls
158 lines (134 loc) · 4.34 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
#include "manager.h"
Q_GLOBAL_STATIC(Manager, GlobalManager)
void Manager::addVariable(const VariableData& var)
{
variables.append(var);
}
void Manager::recalculationMeasurementCount() {
measurement_count = 0;
for (int i = 0; i < this->getVariableCount(); ++i)
if (variables.at(i).measurements.size() > measurement_count)
measurement_count = variables.at(i).measurements.size();
for (int i = 0; i < this->getCalculatedCount(); ++i)
if (calculated.at(i).measurements.size() > measurement_count)
measurement_count = calculated.at(i).measurements.size();
}
int Manager::getCalculatedCount() const { return calculated.size(); }
void Manager::deleteVariable(int index)
{
if (index < 0 || index > variables.count())
throw std::out_of_range("There isn't a column with this index");
variables.removeAt(index);
}
void Manager::addMeasurementRow(QList<double>& meas)
{
if (meas.count() != variables.count())
throw std::out_of_range("Too few or too many measurement");
for (int i = 0; i < meas.count(); ++i)
variables[i].measurements.append(meas[i]);
}
void Manager::addMeasurementRowWithZeros()
{
for (int i = 0; i < getVariableAndCalculatedCount(); ++i)
{
getVariableOrCalculated(i)->measurements.append(0.);
}
}
void Manager::removeMeasurementRow(int num_row)
{
if (num_row < 0 || num_row >= measurement_count)
throw std::out_of_range("Can't remove row");
for (int i = 0; i < variables.count(); ++i)
if (variables[i].measurements.count() > num_row)
variables[i].measurements.removeAt(num_row);
for (int i = 0; i < calculated.count(); ++i)
if (calculated[i].measurements.count() > num_row)
calculated[i].measurements.removeAt(num_row);
recalculationMeasurementCount();
}
void Manager::addCalculated(const VariableData& var)
{
calculated.append(var);
}
void Manager::clearCalculated()
{
calculated.clear();
}
Manager *Manager::instance()
{
return GlobalManager;
}
int Manager::getVariableCount() const { return variables.size(); }
int Manager::getMeasurementCount() const {
Manager::instance()->recalculationMeasurementCount();
return measurement_count;
}
VariableData* Manager::getVariable(const QString& name)
{
for (auto& v: variables)
{
if (v.shortNaming == name || v.fullNaming == name)
return &v;
}
return nullptr;
}
VariableData* Manager::getVariable(int index)
{
if (index >= variables.size()) throw std::runtime_error("No such index (in getVariable(int index))");
return &variables[index];
}
VariableData* Manager::getCalculated(const QString& name)
{
for (auto& v: calculated)
{
if (v.shortNaming == name || v.fullNaming == name)
return &v;
}
throw std::runtime_error("No such index (in getCalculated(const QString& name))");
}
VariableData* Manager::getCalculated(int index)
{
if (index >= calculated.size()) throw std::runtime_error("No such index (in getCalculated(int index))");
return &calculated[index];
}
int Manager::getVariableAndCalculatedCount() const {
return this->getCalculatedCount() + this->getVariableCount();
}
VariableData* Manager::getVariableOrCalculated(int index)
{
if (index >= getVariableAndCalculatedCount()) throw std::runtime_error("No such index (in getVarOrCalc(int index))");
if (index < getVariableCount()) return getVariable(index);
else return getCalculated(index - getVariableCount());
}
VariableData* Manager::getVariableOrCalculated(const QString& name)
{
for (auto& v: variables)
{
if (v.shortNaming == name || v.fullNaming == name)
return &v;
}
for (auto& v: calculated)
{
if (v.shortNaming == name || v.fullNaming == name)
return &v;
}
return nullptr;
}
void Manager::clear() {
variables.clear();
calculated.clear();
measurement_count = 0;
}
bool Manager::isInManager(QString name) {
for (auto var : variables)
if (var.shortNaming == name) return true;
for (auto var : calculated)
if (var.shortNaming == name) return true;
return false;
}
void Manager::deleteCalculated(int index)
{
if (index < 0 || index >= calculated.count())
throw std::out_of_range("There isn't a column with this index (from deleteCalculated)");
calculated.removeAt(index);
}