1
#include <qapplication.h>
3
#include <qwt_plot_marker.h>
4
#include <qwt_plot_curve.h>
5
#include <qwt_legend.h>
11
//-----------------------------------------------------------------
14
// A simple example which shows how to use QwtPlot and QwtData
15
//-----------------------------------------------------------------
17
class SimpleData: public QwtData
19
// The x values depend on its index and the y values
20
// can be calculated from the corresponding x value.
21
// So we don�t need to store the values.
22
// Such an implementation is slower because every point
23
// has to be recalculated for every replot, but it demonstrates how
24
// QwtData can be used.
27
SimpleData(double(*y)(double), size_t size):
33
virtual QwtData *copy() const
35
return new SimpleData(d_y, d_size);
38
virtual size_t size() const
43
virtual double x(size_t i) const
48
virtual double y(size_t i) const
57
class Plot : public QwtPlot
66
setTitle("A Simple QwtPlot Demonstration");
67
insertLegend(new QwtLegend(), QwtPlot::RightLegend);
70
setAxisTitle(xBottom, "x -->");
71
setAxisTitle(yLeft, "y -->");
74
QwtPlotCurve *cSin = new QwtPlotCurve("y = sin(x)");
75
#if QT_VERSION >= 0x040000
76
cSin->setRenderHint(QwtPlotItem::RenderAntialiased);
78
cSin->setPen(QPen(Qt::red));
81
QwtPlotCurve *cCos = new QwtPlotCurve("y = cos(x)");
82
#if QT_VERSION >= 0x040000
83
cCos->setRenderHint(QwtPlotItem::RenderAntialiased);
85
cCos->setPen(QPen(Qt::blue));
88
// Create sin and cos data
89
const int nPoints = 100;
90
cSin->setData(SimpleData(::sin, nPoints));
91
cCos->setData(SimpleData(::cos, nPoints));
95
// ...a horizontal line at y = 0...
96
QwtPlotMarker *mY = new QwtPlotMarker();
97
mY->setLabel(QString::fromLatin1("y = 0"));
98
mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
99
mY->setLineStyle(QwtPlotMarker::HLine);
103
// ...a vertical line at x = 2 * pi
104
QwtPlotMarker *mX = new QwtPlotMarker();
105
mX->setLabel(QString::fromLatin1("x = 2 pi"));
106
mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);
107
mX->setLabelOrientation(Qt::Vertical);
108
mX->setLineStyle(QwtPlotMarker::VLine);
109
mX->setLinePen(QPen(Qt::black, 0, Qt::DashDotLine));
110
mX->setXValue(2.0 * M_PI);
114
int main(int argc, char **argv)
116
QApplication a(argc, argv);
119
#if QT_VERSION < 0x040000
120
a.setMainWidget(&plot);
122
plot.resize(600,400);