-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchartbuilder.h
114 lines (102 loc) · 3.3 KB
/
chartbuilder.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
/*
* Copyright (C) 2020 brian DOT l DOT miller DOT ttu AT gmail DOT com
* This file is part of QCovidTracker.
*
* This program comes with ABSOLUTELY NO WARRANTY
* QCovidTracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QCovidTracker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QCovidTracker. If not, see <https://www.gnu.org/licenses/.
*/
#ifndef CHARTBUILDER_H
#define CHARTBUILDER_H
#include <QObject>
#include <QSqlDatabase>
#include <QSharedPointer>
#include <QAbstractAxis>
#include <memory>
#include "mainchart.h"
#include "algorithms.h"
#include "customlineseries.h"
struct SeriesData {
//json_mappings_id, value
QHash<int, int> data;
QHash<QPair<int, int>, int> pairedData;
QVariant getData(int key) {
if (data.contains(key)) {
return data[key];
}
return 0;
}
};
struct SeriesInfo {
int stateInfoId;
int jsonMappingId;
int chartType;
int yAxisId{0};
int chartAlignment;
bool showDifferences{false};
int movingAverageDays{0};
QString seriesName;
QString penColor{"#0000FF"};
int penWidth{1};
int penType;
SeriesInfo(int sII, int jMI, int cT, int aI, int cA, QString sN, bool sD, QString pC, int pW, int pT, int mAD) :
stateInfoId(sII),
jsonMappingId(jMI),
chartType(cT),
yAxisId(aI),
chartAlignment(cA),
showDifferences(sD),
movingAverageDays(mAD),
seriesName(sN),
penColor(pC),
penWidth(pW),
penType(pT)
{
}
};
class ChartBuilder : public QObject
{
Q_OBJECT
public:
enum ChartTypes {
BarChart,
LineChart
};
//TODO: remove enum ChartAlignment and just use Qt::AlignLeft/Right
enum ChartAlignment {
left,
right
};
ChartBuilder(QSqlDatabase &p_mdb);
~ChartBuilder();
void addData(int stateInfoId, int jsonMappingId);
void printData();
MainChart* getChart();
//TODO add QString name parameter
//SeriesInfo(int sII, int jMI, int cT, int aI, int cA, QString sN, bool sD, QString pC, int pW, int pT, int mAD) :
void addPlot(int stateInfoId, int jsonMappingsId, int chartType, int axisId, int chartAlignment, QString seriesName, bool showDiff, QString penColor, int penWidth, int penType, int mAD);
void makeBarSets(QBarSeries*& series, int jsonMappingsId, int index);
void attachBarSeries(MainChart*& chart, int axisId, int jsonMappingsId, QAbstractAxis *axis, int index);
void attachLineSeries(MainChart*& chart, int axisId, int jsonMappingsId, QAbstractAxis *axis, int index);
void setBarCategoryAxis();
void clearBuilder();
//QVector<QAbstractAxis*> xAxis;
private:
QSqlDatabase& mdb;
QMap<QDate, SeriesData> sdm;
QVector<SeriesInfo> seriesInfo;
//axisId, QValueAxis
QHash<int, QValueAxis*> axisIdToAxis;
int xAxisType;
};
#endif // CHARTBUILDER_H