forked from zel1b08a/QmlTest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank.cpp
More file actions
55 lines (44 loc) · 1.17 KB
/
bank.cpp
File metadata and controls
55 lines (44 loc) · 1.17 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
#include "bank.h"
bool Coefficient::operator==(const Coefficient& o) const
{
return this->value == o.value;
}
Bank::Bank(QVector<Coefficient> coefficients, QObject* parent)
: QObject(parent)
, _coefficients(coefficients)
{
}
QVector<Coefficient> Bank::coefficients() const
{
return _coefficients;
}
void Bank::setCoefficients(QVector<Coefficient> coefficients)
{
if (_coefficients != coefficients) {
_coefficients.swap(coefficients);
emit coefficientsChanged(_coefficients);
}
}
bool Bank::setCoefficientAt(int id, const Coefficient& coefficient)
{
if (id < 0 || id >= _coefficients.size())
return false;
if (coefficient == _coefficients.at(id))
return false;
_coefficients[id] = coefficient;
return true;
}
void Bank::appendCoefficient()
{
emit preCoefficientAppended();
_coefficients.append(Coefficient {});
emit postCoefficientAppended();
}
void Bank::removeCoefficient(int id)
{
if (id < 0 || id >= _coefficients.size())
return;
emit preCoefficientRemoved(id);
_coefficients.removeAt(id);
emit postCoefficientRemoved();
}