-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathCustomPlot.cpp
More file actions
91 lines (75 loc) · 2.18 KB
/
Copy pathCustomPlot.cpp
File metadata and controls
91 lines (75 loc) · 2.18 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
88
89
90
#include "CustomPlot.h"
CustomPlot::CustomPlot(int _numGraphs, QWidget *parent)
: m_graphCount(_numGraphs), QCustomPlot(parent)
{
}
QCPGraph *CustomPlot::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis)
{
if (!keyAxis) keyAxis = xAxis;
if (!valueAxis) valueAxis = yAxis;
if (!keyAxis || !valueAxis)
{
qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)";
return 0;
}
if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this)
{
qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent";
return 0;
}
QCPGraph *newGraph = new CustomGraph(keyAxis, valueAxis);
if (addPlottable(newGraph))
{
newGraph->setName(QLatin1String("Graph ")+QString::number(mGraphs.size()));
return newGraph;
} else
{
delete newGraph;
return 0;
}
}
CustomGraph *CustomPlot::graph(int index) const
{
return (CustomGraph*)QCustomPlot::graph(index);
}
void CustomPlot::setIncremental(bool _mode)
{
m_incrementalDraw = _mode;
}
CustomGraph *CustomPlot::graph() const
{
return (CustomGraph*)QCustomPlot::graph();
}
void CustomPlot::drawIncrementally()
{
QCPPainter painter;
painter.begin(&paintBuffer());
painter.save();
CustomGraph* _graph0 = graph(0);
painter.setCompositionMode(QPainter::RasterOp_SourceXorDestination);
_graph0->restoreLine(&painter);
painter.restore();
QRectF _clip;
for (int i=m_graphCount; i>0; i--)
{
CustomGraph* _graph = graph(graphCount()-i);
_graph->drawLine(&painter);
QRectF r = _graph->getClipRect();
if (i == m_graphCount)
_clip = r;
else
_clip = _clip.united(r);
}
painter.setCompositionMode(QPainter::RasterOp_SourceXorDestination);
_graph0->drawLine(&painter);
_clip = _clip.united(_graph0->getClipRect());
m_clipRect = QRect(_clip.x(), _clip.y(), _clip.width(), _clip.height());
painter.end();
update(m_clipRect);
}
void CustomPlot::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter(this);
painter.drawPixmap(event->rect().topLeft(), mPaintBuffer, event->rect());
}