~ubuntu-branches/ubuntu/oneiric/qwt/oneiric-proposed

« back to all changes in this revision

Viewing changes to qwt-5.1.2/examples/realtime_plot/incrementalplot.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2009-04-12 23:25:58 UTC
  • mfrom: (1.1.4 upstream) (2.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090412232558-3bl06x785yr8xm8u
Tags: 5.1.2-1
* New upstream release.
* Bump compat/debhelper to 7.
* Bump Standards-Version to 3.8.1. No changes needed.
* Invert Maintainers and Uploaders field.
* Fix lintian warnings:
  - dh_clean _k deprecated.
  - missing dependency on libc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <qwt_plot.h>
 
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>
 
8
#endif
 
9
 
 
10
CurveData::CurveData():
 
11
    d_count(0)
 
12
{
 
13
}
 
14
 
 
15
void CurveData::append(double *x, double *y, int count)
 
16
{
 
17
    int newSize = ( (d_count + count) / 1000 + 1 ) * 1000;
 
18
    if ( newSize > size() )
 
19
    {
 
20
        d_x.resize(newSize);
 
21
        d_y.resize(newSize);
 
22
    }
 
23
 
 
24
    for ( register int i = 0; i < count; i++ )
 
25
    {
 
26
        d_x[d_count + i] = x[i];
 
27
        d_y[d_count + i] = y[i];
 
28
    }
 
29
    d_count += count;
 
30
}
 
31
 
 
32
int CurveData::count() const
 
33
{
 
34
    return d_count;
 
35
}
 
36
 
 
37
int CurveData::size() const
 
38
{
 
39
    return d_x.size();
 
40
}
 
41
 
 
42
const double *CurveData::x() const
 
43
{
 
44
    return d_x.data();
 
45
}
 
46
 
 
47
const double *CurveData::y() const
 
48
{
 
49
    return d_y.data();
 
50
}
 
51
 
 
52
IncrementalPlot::IncrementalPlot(QWidget *parent): 
 
53
    QwtPlot(parent),
 
54
    d_data(NULL),
 
55
    d_curve(NULL)
 
56
{
 
57
    setAutoReplot(false);
 
58
}
 
59
 
 
60
IncrementalPlot::~IncrementalPlot()
 
61
{
 
62
    delete d_data;
 
63
}
 
64
 
 
65
void IncrementalPlot::appendData(double x, double y)
 
66
{
 
67
    appendData(&x, &y, 1);
 
68
}
 
69
 
 
70
void IncrementalPlot::appendData(double *x, double *y, int size)
 
71
{
 
72
    if ( d_data == NULL )
 
73
        d_data = new CurveData;
 
74
 
 
75
    if ( d_curve == NULL )
 
76
    {
 
77
        d_curve = new QwtPlotCurve("Test Curve");
 
78
        d_curve->setStyle(QwtPlotCurve::NoCurve);
 
79
        d_curve->setPaintAttribute(QwtPlotCurve::PaintFiltered);
 
80
    
 
81
        const QColor &c = Qt::white;
 
82
        d_curve->setSymbol(QwtSymbol(QwtSymbol::XCross,
 
83
            QBrush(c), QPen(c), QSize(5, 5)) );
 
84
 
 
85
        d_curve->attach(this);
 
86
    }
 
87
 
 
88
    d_data->append(x, y, size);
 
89
    d_curve->setRawData(d_data->x(), d_data->y(), d_data->count());
 
90
#ifdef __GNUC__
 
91
#endif
 
92
 
 
93
    const bool cacheMode = 
 
94
        canvas()->testPaintAttribute(QwtPlotCanvas::PaintCached);
 
95
 
 
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..
 
99
 
 
100
    canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
 
101
#endif
 
102
 
 
103
    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
 
104
    d_curve->draw(d_curve->dataSize() - size, d_curve->dataSize() - 1);
 
105
    canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, cacheMode);
 
106
 
 
107
#if QT_VERSION >= 0x040000 && defined(Q_WS_X11)
 
108
    canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, false);
 
109
#endif
 
110
}
 
111
 
 
112
void IncrementalPlot::removeData()
 
113
{
 
114
    delete d_curve;
 
115
    d_curve = NULL;
 
116
 
 
117
    delete d_data;
 
118
    d_data = NULL;
 
119
 
 
120
    replot();
 
121
}