/
GenericPlot.h
155 lines (120 loc) · 4.5 KB
/
GenericPlot.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
/*
* Copyright (c) 2020 Mark Liversedge (liversedge@gmail.com)
*
* This program 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 2 of the License, or (at your option)
* any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _GC_GenericPlot_h
#define _GC_GenericPlot_h 1
#include <QWidget>
#include <QPointF>
#include <QString>
#include <QDebug>
#include <QColor>
#include <QTextEdit>
#include <QScrollBar>
#include <QCheckBox>
#include <QSplitter>
#include <QByteArray>
#include <string.h>
#include <QtCharts>
#include <QGraphicsItem>
#include <QFontMetrics>
#include "Quadtree.h"
#include "GoldenCheetah.h"
#include "Settings.h"
#include "Context.h"
#include "Athlete.h"
#include "Colors.h"
#include "RCanvas.h"
#include "GenericSelectTool.h"
#include "GenericLegend.h"
// keep aligned to library.py
#define GC_CHART_LINE 1
#define GC_CHART_SCATTER 2
#define GC_CHART_BAR 3
#define GC_CHART_PIE 4
class GenericPlot;
class GenericLegend;
class GenericSelectTool;
class GenericAxisInfo;
// the chart
class GenericPlot : public QWidget {
Q_OBJECT
static constexpr double gl_minheight = 225;
public:
friend class GenericSelectTool;
friend class GenericLegend;
GenericPlot(QWidget *parent, Context *context);
// some helper functions
static QColor seriesColor(QAbstractSeries* series);
enum annotationType { LINE=0, // Continious range
RECTANGLE=1, // Date
TEXT=2, // Duration, Time
};
typedef enum annotationType AnnotationType;
public slots:
void configChanged(qint32);
// set chart settings
bool initialiseChart(QString title, int type, bool animate, int legendpos);
// add a curve, associating an axis
bool addCurve(QString name, QVector<double> xseries, QVector<double> yseries, QString xname, QString yname,
QStringList labels, QStringList colors,
int line, int symbol, int size, QString color, int opacity, bool opengl);
// adding annotations
void addAnnotation(AnnotationType, QAbstractSeries*, double yvalue);
// configure axis, after curves added
bool configureAxis(QString name, bool visible, int align, double min, double max,
int type, QString labelcolor, QString color, bool log, QStringList categories);
// post processing clean up / add decorations / helpers etc
void finaliseChart();
// do we want to see this series?
void setSeriesVisible(QString name, bool visible);
// watching scene events and managing interaction
bool eventHandler(int eventsource, void *obj, QEvent *event);
void barsetHover(bool status, int index, QBarSet *barset);
void plotAreaChanged();
protected:
// legend and selector need acces to these
QChartView *chartview;
GenericSelectTool *selector;
QChart *qchart;
QVBoxLayout *mainLayout;
QBoxLayout *leftLayout;
QBoxLayout *holder; // who has me at the mo?
// trap widget events and pass to event handler
bool eventFilter(QObject *, QEvent *e);
// axes geometry (hacked from scene)
// used by select tool to know when
// over an axis and where to paint
QMap<QAbstractAxis*,QRectF> axisRect;
// the legend
GenericLegend *legend;
// quadtrees
QMap<QAbstractSeries*, Quadtree*> quadtrees;
private:
Context *context;
int charttype;
// curves
QMap<QString, QAbstractSeries *>curves;
// axes
QMap<QString, GenericAxisInfo *>axisinfos;
// barsets
QList<QBarSet*> barsets;
QBarSeries *barseries;
// axis placement (before user interacts)
// alternates as axis added
bool left, bottom;
};
#endif