-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoney.h
67 lines (60 loc) · 1.72 KB
/
Money.h
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
#ifndef MONEY_H
#define MONEY_H
#include "complication.h"
class MoneyComp: public Complication {
public:
MoneyComp(): Complication() { }
MoneyComp(const MoneyComp& d)
: Complication()
, v(d.v) { }
MoneyComp(MoneyComp&& d)
: Complication()
, v(d.v) { }
MoneyComp(const QJsonObject& json)
: Complication()
, v { json["amount"].toInt(0) } { }
~MoneyComp() override { }
MoneyComp& operator=(const MoneyComp& d) {
if (this != &d) {
v = d.v;
}
return *this;
}
MoneyComp& operator=(MoneyComp&& d) {
v = d.v;
return *this;
}
QString description() override {
static QList<QString> amount { "Destitute ($3,000 or less)",
"Poor ($10,000 or less)" };
if (v._amount < 0) return "<incomplete>";
return amount[v._amount];
}
void form(QWidget* parent, QVBoxLayout* layout) override {
amount = createComboBox(parent, layout, "How Poor is the PC?", { "Destitute ($3,000 or less)", "Poor ($10,000 or less)" });
}
Points points(bool noStore = false) override {
if (!noStore) store();
return (v._amount < 0) ? 0_cp : ((2 - v._amount) * 5_cp); // NOLINT
}
void restore() override {
vars s = v;
amount->setCurrentIndex(s._amount);
v = s;
}
void store() override {
v._amount = amount->currentIndex();
}
QJsonObject toJson() override {
QJsonObject obj;
obj["name"] = "Money";
obj["amount"] = v._amount;
return obj;
}
private:
struct vars {
int _amount = -1;
} v;
gsl::owner<QComboBox*> amount = nullptr;
};
#endif // MONEY_H