2
#include <qwt_plot_canvas.h>
3
#include <qwt_plot_curve.h>
4
#include <qwt_symbol.h>
5
#include "incrementalplot.h"
6
#if QT_VERSION >= 0x040000
7
#include <qpaintengine.h>
10
CurveData::CurveData():
15
void CurveData::append(double *x, double *y, int count)
17
int newSize = ( (d_count + count) / 1000 + 1 ) * 1000;
18
if ( newSize > size() )
24
for ( register int i = 0; i < count; i++ )
26
d_x[d_count + i] = x[i];
27
d_y[d_count + i] = y[i];
32
int CurveData::count() const
37
int CurveData::size() const
42
const double *CurveData::x() const
47
const double *CurveData::y() const
52
IncrementalPlot::IncrementalPlot(QWidget *parent):
60
IncrementalPlot::~IncrementalPlot()
65
void IncrementalPlot::appendData(double x, double y)
67
appendData(&x, &y, 1);
70
void IncrementalPlot::appendData(double *x, double *y, int size)
73
d_data = new CurveData;
75
if ( d_curve == NULL )
77
d_curve = new QwtPlotCurve("Test Curve");
78
d_curve->setStyle(QwtPlotCurve::NoCurve);
79
d_curve->setPaintAttribute(QwtPlotCurve::PaintFiltered);
81
const QColor &c = Qt::white;
82
d_curve->setSymbol(QwtSymbol(QwtSymbol::XCross,
83
QBrush(c), QPen(c), QSize(5, 5)) );
85
d_curve->attach(this);
88
d_data->append(x, y, size);
89
d_curve->setRawData(d_data->x(), d_data->y(), d_data->count());
93
const bool cacheMode =
94
canvas()->testPaintAttribute(QwtPlotCanvas::PaintCached);
96
#if QT_VERSION >= 0x040000 && defined(Q_WS_X11)
97
// Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent
98
// works on X11. This has an tremendous effect on the performance..
100
canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
103
canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
104
d_curve->draw(d_curve->dataSize() - size, d_curve->dataSize() - 1);
105
canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, cacheMode);
107
#if QT_VERSION >= 0x040000 && defined(Q_WS_X11)
108
canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, false);
112
void IncrementalPlot::removeData()