-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccidentalChange.h
95 lines (88 loc) · 3.44 KB
/
AccidentalChange.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
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
#ifndef ACCIDENTALCHANGE_H
#define ACCIDENTALCHANGE_H
#include "complication.h"
#ifndef ISHSC
#include "sheet.h"
#endif
class AccidentalChange: public Complication
{
public:
AccidentalChange(): Complication() { }
AccidentalChange(const AccidentalChange& ac)
: Complication()
, v(ac.v) { }
AccidentalChange(AccidentalChange&& ac)
: Complication()
, v(ac.v) { }
AccidentalChange(const QJsonObject& json)
: Complication()
, v { json["circumstance"].toInt(0), json["frequency"].toInt(0), json["what"].toString("") } { }
~AccidentalChange() override { }
AccidentalChange& operator=(const AccidentalChange& ac) {
if (this != &ac) v = ac.v;
return *this;
}
AccidentalChange& operator=(AccidentalChange&& ac) {
v = ac.v;
return *this;
}
QString description() override {
static QList<QString> circ { "Uncommon", "Common", "Very Common" };
static QList<QString> freq { "Infrequently (8-)", "Frequently (11-)", "Very Frequently (14-)", "Always" };
static QList<QString> freqSans { "Infrequently", "Frequently", "Very Frequently", "Always" };
if (v._frequency < 0 || v._circumstance < 0 || v._what.isEmpty()) return "<incomplete>";
#ifndef ISHSC
if (Sheet::ref().getOption().showFrequencyRolls())
#endif
return QString("Accidental Change: %1 (%2; %3)").arg(v._what, circ[v._circumstance], freq[v._frequency]);
#ifndef ISHSC
else return QString("Accidental Change: %1 (%2; %3)").arg(v._what, circ[v._circumstance], freqSans[v._frequency]);
#endif
}
void form(QWidget* parent, QVBoxLayout* layout) override {
what = createLineEdit(parent, layout, "What sets off the change?");
circumstance = createComboBox(parent, layout, "How common is the change", { "Uncommmon", "Common", "Very Common" });
#ifndef ISHSC
if (Sheet::ref().getOption().showFrequencyRolls())
#endif
frequency = createComboBox(parent, layout, "How often do you change", { "Infrequently (8-)", "Frequently (11-)", "Very Frequently (14-)", "Always" });
#ifndef ISHSC
else
frequency = createComboBox(parent, layout, "How often do you change", { "Infrequently", "Frequently", "Very Frequently", "Always" });
#endif
}
Points points(bool noStore = false) override {
if (!noStore) store();
return (v._circumstance > -1 && v._frequency > -1) ? (v._circumstance - 1) * 5_cp + v._frequency * 5_cp : 0_cp; // NOLINT
}
void restore() override {
vars s = v;
what->setText(s._what);
circumstance->setCurrentIndex(s._circumstance);
frequency->setCurrentIndex(s._frequency);
v = s;
}
void store() override {
v._what = what->text();
v._circumstance = circumstance->currentIndex();
v._frequency = frequency->currentIndex();
}
QJsonObject toJson() override {
QJsonObject obj;
obj["name"] = "Accidental Change";
obj["circumstance"] = v._circumstance;
obj["frequency"] = v._frequency;
obj["what"] = v._what;
return obj;
}
private:
struct vars {
int _circumstance = -1;
int _frequency = -1;
QString _what = "";
} v;
gsl::owner<QComboBox*> circumstance = nullptr;
gsl::owner<QComboBox*> frequency = nullptr;
gsl::owner<QLineEdit*> what = nullptr;
};
#endif // ACCIDENTALCHANGE_H