class FunctionData: public QwtSyntheticPointData{public: FunctionData(double(*y)(double)): QwtSyntheticPointData(100), d_y(y) { } virtual double y(double x) const { return d_y(x); }private: double(*d_y)(double);};
QwtPlotCurve *cSin = new QwtPlotCurve("y = sin(x)"); cSin->setRenderHint(QwtPlotItem::RenderAntialiased); cSin->setLegendAttribute(QwtPlotCurve::LegendShowLine, true); cSin->setPen(QPen(Qt::red)); cSin->attach(this); QwtPlotCurve *cCos = new QwtPlotCurve("y = cos(x)"); cCos->setRenderHint(QwtPlotItem::RenderAntialiased); cCos->setLegendAttribute(QwtPlotCurve::LegendShowLine, true); cCos->setPen(QPen(Qt::blue)); cCos->attach(this); // Create sin and cos data cSin->setData(new FunctionData(::sin)); cCos->setData(new FunctionData(::cos));
C++ (Qt)class Parabola: public QwtSyntheticPointData{public: Parabola(): QwtSyntheticPointData(100) { } virtual double y(double x) const { return m_a*x*x+m_b*x+m_c; } double a() const { return m_a; } double b() const { return m_b; } double c() const { return m_c; } void setA(const double &a) { m_a = a; } ...};
class Parabola: public QwtSyntheticPointData{public: Parabola(): QwtSyntheticPointData(100) { } virtual double y(double x) const { return m_a*x*x+m_b*x+m_c; } double a() const { return m_a; } double b() const { return m_b; } double c() const { return m_c; } void setA(const double &a) { m_a = a; } ...};
C++ (Qt) QwtPlotCurve *parabola = new QwtPlotCurve("y = a*x^2+b*x+c"); parabola->setRenderHint(QwtPlotItem::RenderAntialiased); parabola->setLegendAttribute(QwtPlotCurve::LegendShowLine, true); parabola->setPen(QPen(Qt::red)); parabola->attach(this); paradola->setData(new Parabola(a, b, c));
C++ (Qt)class Parabola: public QwtSyntheticPointData{public: Parabola(const double &a = 1.0, const double &b = 0.0, const double &c = 0.0) : QwtSyntheticPointData(100), m_a(a), m_b(b), m_c(c) { } virtual double y(double x) const { return m_a*x*x+m_b*x+m_c; } double m_a; double m_b; double m_c;}
C++ (Qt)const double &value
C++ (Qt)double value
C++ (Qt)void setDamp(double damping);