1
#include <qapplication.h>
3
#include <qwt_plot_marker.h>
4
#include <qwt_plot_curve.h>
5
#include <qwt_legend.h>
10
//-----------------------------------------------------------------
13
// A simple example which shows how to use QwtPlot and QwtData
14
//-----------------------------------------------------------------
16
class SimpleData: public QwtData
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.
26
SimpleData(double(*y)(double), size_t size):
32
virtual QwtData *copy() const
34
return new SimpleData(d_y, d_size);
37
virtual size_t size() const
42
virtual double x(size_t i) const
47
virtual double y(size_t i) const
56
class Plot : public QwtPlot
65
setTitle("A Simple QwtPlot Demonstration");
66
insertLegend(new QwtLegend(), QwtPlot::RightLegend);
69
setAxisTitle(xBottom, "x -->");
70
setAxisTitle(yLeft, "y -->");
73
QwtPlotCurve *cSin = new QwtPlotCurve("y = sin(x)");
74
#if QT_VERSION >= 0x040000
75
cSin->setRenderHint(QwtPlotItem::RenderAntialiased);
77
cSin->setPen(QPen(Qt::red));
80
QwtPlotCurve *cCos = new QwtPlotCurve("y = cos(x)");
81
#if QT_VERSION >= 0x040000
82
cCos->setRenderHint(QwtPlotItem::RenderAntialiased);
84
cCos->setPen(QPen(Qt::blue));
87
// Create sin and cos data
88
const int nPoints = 100;
89
cSin->setData(SimpleData(::sin, nPoints));
90
cCos->setData(SimpleData(::cos, nPoints));
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);
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);
111
int main(int argc, char **argv)
113
QApplication a(argc, argv);
116
#if QT_VERSION < 0x040000
117
a.setMainWidget(&plot);
119
plot.resize(600,400);