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

« back to all changes in this revision

Viewing changes to qwt-5.1.2/examples/simple_plot/simple.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2009-07-01 16:08:21 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090701160821-gog44m4w7x2f4u6o
Tags: 5.2.0-1
* New upstream release.
* Add branch pull patch from svn r544.
* Bump Standards-Version to 3.8.2. No changes needed.
* Update installed manpages.
* Use qwt as base name for directory (drop version).
* Add missing warnings patch.
* Rewrite debian/rules: use dh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <qapplication.h>
2
 
#include <qwt_plot.h>
3
 
#include <qwt_plot_marker.h>
4
 
#include <qwt_plot_curve.h>
5
 
#include <qwt_legend.h>
6
 
#include <qwt_data.h>
7
 
#include <qwt_text.h>
8
 
#include <math.h>
9
 
 
10
 
//-----------------------------------------------------------------
11
 
//              simple.cpp
12
 
//
13
 
//      A simple example which shows how to use QwtPlot and QwtData
14
 
//-----------------------------------------------------------------
15
 
 
16
 
class SimpleData: public QwtData
17
 
{
18
 
    // The x values depend on its index and the y values
19
 
    // can be calculated from the corresponding x value. 
20
 
    // So we don�t need to store the values.
21
 
    // Such an implementation is slower because every point 
22
 
    // has to be recalculated for every replot, but it demonstrates how
23
 
    // QwtData can be used.
24
 
 
25
 
public:
26
 
    SimpleData(double(*y)(double), size_t size):
27
 
        d_size(size),
28
 
        d_y(y)
29
 
    {
30
 
    }
31
 
 
32
 
    virtual QwtData *copy() const
33
 
    {
34
 
        return new SimpleData(d_y, d_size);
35
 
    }
36
 
 
37
 
    virtual size_t size() const
38
 
    {
39
 
        return d_size;
40
 
    }
41
 
 
42
 
    virtual double x(size_t i) const
43
 
    {
44
 
        return 0.1 * i;
45
 
    }
46
 
 
47
 
    virtual double y(size_t i) const
48
 
    {
49
 
        return d_y(x(i));
50
 
    }
51
 
private:
52
 
    size_t d_size;
53
 
    double(*d_y)(double);
54
 
};
55
 
 
56
 
class Plot : public QwtPlot
57
 
{
58
 
public:
59
 
    Plot();
60
 
};
61
 
 
62
 
 
63
 
Plot::Plot()
64
 
{
65
 
    setTitle("A Simple QwtPlot Demonstration");
66
 
    insertLegend(new QwtLegend(), QwtPlot::RightLegend);
67
 
 
68
 
    // Set axis titles
69
 
    setAxisTitle(xBottom, "x -->");
70
 
    setAxisTitle(yLeft, "y -->");
71
 
    
72
 
    // Insert new curves
73
 
    QwtPlotCurve *cSin = new QwtPlotCurve("y = sin(x)");
74
 
#if QT_VERSION >= 0x040000
75
 
    cSin->setRenderHint(QwtPlotItem::RenderAntialiased);
76
 
#endif
77
 
    cSin->setPen(QPen(Qt::red));
78
 
    cSin->attach(this);
79
 
 
80
 
    QwtPlotCurve *cCos = new QwtPlotCurve("y = cos(x)");
81
 
#if QT_VERSION >= 0x040000
82
 
    cCos->setRenderHint(QwtPlotItem::RenderAntialiased);
83
 
#endif
84
 
    cCos->setPen(QPen(Qt::blue));
85
 
    cCos->attach(this);
86
 
 
87
 
    // Create sin and cos data
88
 
    const int nPoints = 100;
89
 
    cSin->setData(SimpleData(::sin, nPoints));
90
 
    cCos->setData(SimpleData(::cos, nPoints));
91
 
 
92
 
    // Insert markers
93
 
    
94
 
    //  ...a horizontal line at y = 0...
95
 
    QwtPlotMarker *mY = new QwtPlotMarker();
96
 
    mY->setLabel(QString::fromLatin1("y = 0"));
97
 
    mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
98
 
    mY->setLineStyle(QwtPlotMarker::HLine);
99
 
    mY->setYValue(0.0);
100
 
    mY->attach(this);
101
 
 
102
 
    //  ...a vertical line at x = 2 * pi
103
 
    QwtPlotMarker *mX = new QwtPlotMarker();
104
 
    mX->setLabel(QString::fromLatin1("x = 2 pi"));
105
 
    mX->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
106
 
    mX->setLineStyle(QwtPlotMarker::VLine);
107
 
    mX->setXValue(6.284);
108
 
    mX->attach(this);
109
 
}
110
 
 
111
 
int main(int argc, char **argv)
112
 
{
113
 
    QApplication a(argc, argv);
114
 
 
115
 
    Plot plot;
116
 
#if QT_VERSION < 0x040000
117
 
    a.setMainWidget(&plot);
118
 
#endif
119
 
    plot.resize(600,400);
120
 
    plot.show();
121
 
    return a.exec(); 
122
 
}