-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcustomgraph.cpp
More file actions
88 lines (75 loc) · 2.22 KB
/
Copy pathcustomgraph.cpp
File metadata and controls
88 lines (75 loc) · 2.22 KB
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
#include "customgraph.h"
CustomGraph::CustomGraph(QCPAxis *keyAxis, QCPAxis *valueAxis)
: QCPGraph(keyAxis, valueAxis)
{
m_prevLineCoords << QPointF(0, 0) << QPointF(0, 0);
}
void CustomGraph::drawLine(QCPPainter *painter)
{
int len = data()->size();
if (len < 2)
return;
LineStyle style = mLineStyle;
mLineStyle = QCPGraph::lsLine;
// fill vectors with data appropriate to plot style:
QVector<QPointF> *lineCoords = new QVector<QPointF>;
getPlotData(lineCoords, nullptr);
if (len != lineCoords->size()) {
delete lineCoords;
return; // HUCK for wheel & mouse events
}
QVector<QPointF> _drawCoords;
_drawCoords << lineCoords->at(len-2) << lineCoords->at(len-1);
painter->save();
painter->setClipRect(getClipRect(_drawCoords));
drawLinePlot(painter, &_drawCoords);
if (name() == "Graph 1")
{
m_prevLineCoords[0] = _drawCoords[0];
m_prevLineCoords[1] = _drawCoords[1];
}
painter->restore();
delete lineCoords;
mLineStyle = style;
}
void CustomGraph::restoreLine(QCPPainter *painter)
{
if (name() != "Graph 1")
return;
painter->save();
painter->setClipRect(getClipRect(m_prevLineCoords));
drawLinePlot(painter, &m_prevLineCoords);
painter->restore();
}
QRectF CustomGraph::getClipRect()
{
QRectF _clip;
if (data()->size() > 1) {
QCPDataMap::iterator iter = data()->end();
QCPData _last = *(--iter);
QCPData _prev = *(--iter);
QPointF _ptPrev = coordsToPixels(_prev.key, _prev.value);
QPointF _ptLast = coordsToPixels(_last.key, _last.value);
QRectF _clipRect(_ptPrev, _ptLast);
return _clipRect.normalized().adjusted(-2, -2, 2, 2);
}
return _clip;
}
QRectF CustomGraph::getClipRect(QVector<QPointF>& _lineCoords)
{
QRectF _clip;
if (_lineCoords.size() > 1) {
QRectF _clipRect(_lineCoords[0], _lineCoords[1]);
return _clipRect.normalized().adjusted(-2, -2, 2, 2);
}
return _clip;
}
void CustomGraph::draw(QCPPainter *painter)
{
if (checked()) {
//qDebug() << "CustomGraph::draw" << name();
QCPGraph::draw(painter);
} else {
//qDebug() << "CustomGraph::skip" << name();
}
}