-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWeightCurve.h
156 lines (117 loc) · 4.88 KB
/
WeightCurve.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
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
#pragma once
#include <QObject>
#include <QSqlDatabase>
#include <QUrl>
#include <QVector>
#include <QDate>
#include <QTimer>
#include <QPoint>
#include <QColor>
#include <QAbstractListModel>
// TODO Save windows settings (size, position,...)
class Curve : public QObject
{
Q_OBJECT
public:
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(QVariantList points READ points NOTIFY pointsChanged)
Q_PROPERTY(QStringList comments READ comments WRITE setComments NOTIFY commentsChanged)
Q_PROPERTY(float min READ min WRITE setMin NOTIFY minChanged)
Q_PROPERTY(float max READ max WRITE setMax NOTIFY maxChanged)
Curve();
void setName(const QString& name) {mName = name; emit nameChanged(mName);}
QString name() const {return mName;}
void setColor(const QColor& color) {mColor = color; emit colorChanged(mColor);}
QColor color() const {return mColor;}
void setPoints(const QVariantList& points) {mPoints = points; emit pointsChanged(mPoints);}
QVariantList points() const {return mPoints;}
void setComments(const QStringList& comments) {mComments = comments; emit commentsChanged(mComments);}
QStringList comments() const {return mComments;}
void setMin(float min) {mMin = min; emit minChanged(mMin);}
float min() const {return mMin;}
void setMax(float max) {mMax = max; emit maxChanged(mMax);}
float max() const {return mMax;}
signals:
void nameChanged(const QString&);
void colorChanged(const QColor&);
void pointsChanged(const QVariantList&);
void commentsChanged(const QStringList&);
void minChanged(float);
void maxChanged(float);
private:
QString mName;
QColor mColor;
QVariantList mPoints;
QStringList mComments;
float mMin;
float mMax;
};
class WeightCurve : public QObject
{
Q_OBJECT
static QString dbFileName;
static WeightCurve* instance;
public:
static WeightCurve* singleton();
static void destroy();
void initialize();
Q_PROPERTY(QDate inputDate READ inputDate WRITE setInputDate NOTIFY inputDateChanged)
Q_PROPERTY(float morningWeight READ morningWeight WRITE setMorningWeight NOTIFY morningWeightChanged)
Q_PROPERTY(float noonWeight READ noonWeight WRITE setNoonWeight NOTIFY noonWeightChanged)
Q_PROPERTY(float eveningWeight READ eveningWeight WRITE setEveningWeight NOTIFY eveningWeightChanged)
Q_PROPERTY(QString comment READ comment WRITE setComment NOTIFY commentChanged)
Q_PROPERTY(QObject* morningCurve READ morningCurve NOTIFY morningCurveChanged)
Q_PROPERTY(QObject* noonCurve READ noonCurve NOTIFY noonCurveChanged)
Q_PROPERTY(QObject* eveningCurve READ eveningCurve NOTIFY eveningCurveChanged)
Q_PROPERTY(QDate startDate READ startDate WRITE setStartDate NOTIFY startDateChanged)
Q_PROPERTY(QDate endDate READ endDate WRITE setEndDate NOTIFY endDateChanged)
Q_INVOKABLE bool importFromCSVFile(const QUrl& sourceFilePath);
Q_INVOKABLE bool exportToCSVFile(const QUrl& destinationFilePath);
void setInputDate(const QDate& date);
QDate inputDate() const;
void setMorningWeight(float weight);
float morningWeight() const;
void setNoonWeight(float weight);
float noonWeight() const;
void setEveningWeight(float weight);
float eveningWeight() const;
void setComment(const QString& comment);
QString comment() const;
Curve* morningCurve();
Curve* noonCurve();
Curve* eveningCurve();
void setStartDate(const QDate&);
QDate startDate() const;
void setEndDate(const QDate&);
QDate endDate() const;
signals:
void dateChanged(); /// Called when current day changed
void inputDateChanged(const QDate& date);
void morningWeightChanged(float weight);
void noonWeightChanged(float weight);
void eveningWeightChanged(float weight);
void commentChanged(const QString& comment);
void morningCurveChanged(Curve*);
void noonCurveChanged(Curve*);
void eveningCurveChanged(Curve*);
void startDateChanged(const QDate& date);
void endDateChanged(const QDate& date);
private slots:
void onTimerUpdated();
void onDateChanged();
private:
WeightCurve();
~WeightCurve();
void updateCurves(); // startDate and enDate must be valid
void updateCurve(const QString& columnName, Curve& curve);
QDate mInputDate;
QString mDBFilePath;
QSqlDatabase mDB;
QTimer mTimer;
Curve mMorningCurve;
Curve mNoonCurve;
Curve mEveningCurve;
QDate mStartDate;
QDate mEndDate;
};