Qwt User's Guide 5.2.2

qwt_plot_curve.h

00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
00002  * Qwt Widget Library
00003  * Copyright (C) 1997   Josef Wilgen
00004  * Copyright (C) 2002   Uwe Rathmann
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the Qwt License, Version 1.0
00008  *****************************************************************************/
00009 
00010 #ifndef QWT_PLOT_CURVE_H
00011 #define QWT_PLOT_CURVE_H
00012 
00013 #include <qpen.h>
00014 #include <qstring.h>
00015 #include "qwt_global.h"
00016 #include "qwt_plot_item.h"
00017 #include "qwt_text.h"
00018 #include "qwt_polygon.h"
00019 #include "qwt_data.h"
00020 
00021 class QPainter;
00022 class QwtScaleMap;
00023 class QwtSymbol;
00024 class QwtCurveFitter;
00025 
00054 class QWT_EXPORT QwtPlotCurve: public QwtPlotItem
00055 {
00056 public:
00073     enum CurveType
00074     {
00075         Yfx,
00076         Xfy
00077     };
00078 
00106     enum CurveStyle
00107     {
00108         NoCurve,
00109 
00110         Lines,
00111         Sticks,
00112         Steps,
00113         Dots,
00114 
00115         UserCurve = 100
00116     };
00117 
00134     enum CurveAttribute
00135     {
00136         Inverted = 1,
00137         Fitted = 2
00138     };
00139 
00158     enum PaintAttribute
00159     {
00160         PaintFiltered = 1,
00161         ClipPolygons = 2
00162     };
00163 
00164     explicit QwtPlotCurve();
00165     explicit QwtPlotCurve(const QwtText &title);
00166     explicit QwtPlotCurve(const QString &title);
00167 
00168     virtual ~QwtPlotCurve();
00169 
00170     virtual int rtti() const;
00171 
00172     void setCurveType(CurveType);
00173     CurveType curveType() const;
00174 
00175     void setPaintAttribute(PaintAttribute, bool on = true);
00176     bool testPaintAttribute(PaintAttribute) const;
00177 
00178     void setRawData(const double *x, const double *y, int size);
00179     void setData(const double *xData, const double *yData, int size);
00180     void setData(const QwtArray<double> &xData, const QwtArray<double> &yData);
00181 #if QT_VERSION < 0x040000
00182     void setData(const QwtArray<QwtDoublePoint> &data);
00183 #else
00184     void setData(const QPolygonF &data);
00185 #endif
00186     void setData(const QwtData &data);
00187     
00188     int closestPoint(const QPoint &pos, double *dist = NULL) const;
00189 
00190     QwtData &data();
00191     const QwtData &data() const;
00192 
00193     int dataSize() const;
00194     double x(int i) const;
00195     double y(int i) const;
00196 
00197     virtual QwtDoubleRect boundingRect() const;
00198 
00199     double minXValue() const;
00200     double maxXValue() const;
00201     double minYValue() const;
00202     double maxYValue() const;
00203 
00204     void setCurveAttribute(CurveAttribute, bool on = true);
00205     bool testCurveAttribute(CurveAttribute) const;
00206 
00207     void setPen(const QPen &);
00208     const QPen &pen() const;
00209 
00210     void setBrush(const QBrush &);
00211     const QBrush &brush() const;
00212 
00213     void setBaseline(double ref);
00214     double baseline() const;
00215 
00216     void setStyle(CurveStyle style);
00217     CurveStyle style() const;
00218 
00219     void setSymbol(const QwtSymbol &s);
00220     const QwtSymbol& symbol() const;
00221 
00222     void setCurveFitter(QwtCurveFitter *);
00223     QwtCurveFitter *curveFitter() const;
00224 
00225     virtual void draw(QPainter *p, 
00226         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00227         const QRect &) const;
00228 
00229     virtual void draw(QPainter *p, 
00230         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00231         int from, int to) const;
00232 
00233     void draw(int from, int to) const;
00234 
00235     virtual void updateLegend(QwtLegend *) const;
00236 
00237 protected:
00238 
00239     void init();
00240 
00241     virtual void drawCurve(QPainter *p, int style,
00242         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00243         int from, int to) const;
00244 
00245     virtual void drawSymbols(QPainter *p, const QwtSymbol &,
00246         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00247         int from, int to) const;
00248 
00249     void drawLines(QPainter *p,
00250         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00251         int from, int to) const;
00252     void drawSticks(QPainter *p,
00253         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00254         int from, int to) const;
00255     void drawDots(QPainter *p,
00256         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00257         int from, int to) const;
00258     void drawSteps(QPainter *p,
00259         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00260         int from, int to) const;
00261 
00262     void fillCurve(QPainter *,
00263         const QwtScaleMap &, const QwtScaleMap &,
00264         QwtPolygon &) const;
00265     void closePolyline(const QwtScaleMap &, const QwtScaleMap &,
00266         QwtPolygon &) const;
00267 
00268 private:
00269     QwtData *d_xy;
00270 
00271     class PrivateData;
00272     PrivateData *d_data;
00273 };
00274 
00276 inline QwtData &QwtPlotCurve::data()
00277 {
00278     return *d_xy;
00279 }
00280 
00282 inline const QwtData &QwtPlotCurve::data() const
00283 {
00284     return *d_xy;
00285 }
00286 
00291 inline double QwtPlotCurve::x(int i) const 
00292 { 
00293     return d_xy->x(i); 
00294 }
00295 
00300 inline double QwtPlotCurve::y(int i) const 
00301 { 
00302     return d_xy->y(i); 
00303 }
00304 
00306 inline double QwtPlotCurve::minXValue() const 
00307 { 
00308     return boundingRect().left(); 
00309 }
00310 
00312 inline double QwtPlotCurve::maxXValue() const 
00313 { 
00314     return boundingRect().right(); 
00315 }
00316 
00318 inline double QwtPlotCurve::minYValue() const 
00319 { 
00320     return boundingRect().top(); 
00321 }
00322 
00324 inline double QwtPlotCurve::maxYValue() const 
00325 { 
00326     return boundingRect().bottom(); 
00327 }
00328 
00329 #endif