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 
00056 class QWT_EXPORT QwtPlotCurve: public QwtPlotItem
00057 {
00058 public:
00059     enum CurveType
00060     {
00061         Yfx,
00062         Xfy
00063     };
00064 
00069     enum CurveStyle
00070     {
00071         NoCurve,
00072 
00073         Lines,
00074         Sticks,
00075         Steps,
00076         Dots,
00077 
00078         UserCurve = 100
00079     };
00080 
00085     enum CurveAttribute
00086     {
00087         Inverted = 1,
00088         Fitted = 2
00089     };
00090 
00095     enum PaintAttribute
00096     {
00097         PaintFiltered = 1,
00098         ClipPolygons = 2
00099     };
00100 
00101     explicit QwtPlotCurve();
00102     explicit QwtPlotCurve(const QwtText &title);
00103     explicit QwtPlotCurve(const QString &title);
00104 
00105     virtual ~QwtPlotCurve();
00106 
00107     virtual int rtti() const;
00108 
00109     void setCurveType(CurveType);
00110     CurveType curveType() const;
00111 
00112     void setPaintAttribute(PaintAttribute, bool on = true);
00113     bool testPaintAttribute(PaintAttribute) const;
00114 
00115     void setRawData(const double *x, const double *y, int size);
00116     void setData(const double *xData, const double *yData, int size);
00117     void setData(const QwtArray<double> &xData, const QwtArray<double> &yData);
00118 #if QT_VERSION < 0x040000
00119     void setData(const QwtArray<QwtDoublePoint> &data);
00120 #else
00121     void setData(const QPolygonF &data);
00122 #endif
00123     void setData(const QwtData &data);
00124     
00125     int closestPoint(const QPoint &pos, double *dist = NULL) const;
00126 
00127     QwtData &data();
00128     const QwtData &data() const;
00129 
00130     int dataSize() const;
00131     inline double x(int i) const;
00132     inline double y(int i) const;
00133 
00134     virtual QwtDoubleRect boundingRect() const;
00135 
00137     inline double minXValue() const { return boundingRect().left(); }
00139     inline double maxXValue() const { return boundingRect().right(); }
00141     inline double minYValue() const { return boundingRect().top(); }
00143     inline double maxYValue() const { return boundingRect().bottom(); }
00144 
00145     void setCurveAttribute(CurveAttribute, bool on = true);
00146     bool testCurveAttribute(CurveAttribute) const;
00147 
00148     void setPen(const QPen &);
00149     const QPen &pen() const;
00150 
00151     void setBrush(const QBrush &);
00152     const QBrush &brush() const;
00153 
00154     void setBaseline(double ref);
00155     double baseline() const;
00156 
00157     void setStyle(CurveStyle style);
00158     CurveStyle style() const;
00159 
00160     void setSymbol(const QwtSymbol &s);
00161     const QwtSymbol& symbol() const;
00162 
00163     void setCurveFitter(QwtCurveFitter *);
00164     QwtCurveFitter *curveFitter() const;
00165 
00166     virtual void draw(QPainter *p, 
00167         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00168         const QRect &) const;
00169 
00170     virtual void draw(QPainter *p, 
00171         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00172         int from, int to) const;
00173 
00174     void draw(int from, int to) const;
00175 
00176     virtual void updateLegend(QwtLegend *) const;
00177 
00178 protected:
00179 
00180     void init();
00181 
00182     virtual void drawCurve(QPainter *p, int style,
00183         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00184         int from, int to) const;
00185 
00186     virtual void drawSymbols(QPainter *p, const QwtSymbol &,
00187         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00188         int from, int to) const;
00189 
00190     void drawLines(QPainter *p,
00191         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00192         int from, int to) const;
00193     void drawSticks(QPainter *p,
00194         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00195         int from, int to) const;
00196     void drawDots(QPainter *p,
00197         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00198         int from, int to) const;
00199     void drawSteps(QPainter *p,
00200         const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00201         int from, int to) const;
00202 
00203     void fillCurve(QPainter *,
00204         const QwtScaleMap &, const QwtScaleMap &,
00205         QwtPolygon &) const;
00206     void closePolyline(const QwtScaleMap &, const QwtScaleMap &,
00207         QwtPolygon &) const;
00208 
00209 private:
00210     QwtData *d_xy;
00211 
00212     class PrivateData;
00213     PrivateData *d_data;
00214 };
00215 
00217 inline QwtData &QwtPlotCurve::data()
00218 {
00219     return *d_xy;
00220 }
00221 
00223 inline const QwtData &QwtPlotCurve::data() const
00224 {
00225     return *d_xy;
00226 }
00227 
00232 inline double QwtPlotCurve::x(int i) const 
00233 { 
00234     return d_xy->x(i); 
00235 }
00236 
00241 inline double QwtPlotCurve::y(int i) const 
00242 { 
00243     return d_xy->y(i); 
00244 }
00245 
00246 #endif

Generated on Mon Feb 26 21:22:37 2007 for Qwt User's Guide by  doxygen 1.4.6