00001
00002
00003
00004
00005
00006
00007
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_data.h"
00019
00020 class QPainter;
00021 class QwtScaleMap;
00022 class QwtSymbol;
00023
00024 #if QT_VERSION < 0x040000
00025 class QPointArray;
00026 #else
00027 class QPolygon;
00028 #endif
00029
00060 class QWT_EXPORT QwtPlotCurve: public QwtPlotItem
00061 {
00062 public:
00067 enum CurveStyle
00068 {
00069 NoCurve,
00070 Lines,
00071 Sticks,
00072 Steps,
00073 Dots,
00074 Spline,
00075 UserCurve = 100
00076 };
00077
00082 enum CurveAttribute
00083 {
00084 Auto = 0,
00085 Yfx = 1,
00086 Xfy = 2,
00087 Parametric = 4,
00088 Periodic = 8,
00089 Inverted = 16
00090 };
00091
00096 enum PaintAttribute
00097 {
00098 PaintFiltered = 1,
00099 ClipPolygons = 2
00100 };
00101
00102 explicit QwtPlotCurve();
00103 explicit QwtPlotCurve(const QwtText &title);
00104 explicit QwtPlotCurve(const QString &title);
00105 explicit QwtPlotCurve(const QwtPlotCurve &c);
00106
00107 virtual ~QwtPlotCurve();
00108
00109 const QwtPlotCurve& operator= (const QwtPlotCurve &c);
00110
00111 virtual int rtti() const;
00112
00113 void setPaintAttribute(PaintAttribute, bool on = true);
00114 bool testPaintAttribute(PaintAttribute) const;
00115
00116 void setRawData(const double *x, const double *y, int size);
00117 void setData(const double *xData, const double *yData, int size);
00118 void setData(const QwtArray<double> &xData, const QwtArray<double> &yData);
00119 void setData(const QwtArray<QwtDoublePoint> &data);
00120 void setData(const QwtData &data);
00121
00122 int closestPoint(const QPoint &pos, double *dist = NULL) const;
00123
00124 QwtData &data();
00125 const QwtData &data() const;
00126
00127 int dataSize() const;
00128 inline double x(int i) const;
00129 inline double y(int i) const;
00130
00131 virtual QwtDoubleRect boundingRect() const;
00132
00134 inline double minXValue() const { return boundingRect().left(); }
00136 inline double maxXValue() const { return boundingRect().right(); }
00138 inline double minYValue() const { return boundingRect().top(); }
00140 inline double maxYValue() const { return boundingRect().bottom(); }
00141
00142 void setCurveAttribute(CurveAttribute, bool on = true);
00143 bool testCurveAttribute(CurveAttribute) const;
00144
00145 void setTitle(const QString &title);
00146 void setTitle(const QwtText &title);
00147 const QwtText &title() const;
00148
00149 void setPen(const QPen &);
00150 const QPen &pen() const;
00151
00152 void setBrush(const QBrush &);
00153 const QBrush &brush() const;
00154
00155 void setBaseline(double ref);
00156 double baseline() const;
00157
00158 void setStyle(CurveStyle style);
00159 CurveStyle style() const;
00160
00161 void setSymbol(const QwtSymbol &s);
00162 const QwtSymbol& symbol() const;
00163
00164 void setSplineSize(int s);
00165 int splineSize() const;
00166
00167 virtual void draw(QPainter *p,
00168 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00169 const QRect &) const;
00170
00171 virtual void draw(QPainter *p,
00172 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00173 int from, int to) const;
00174
00175 void draw(int from, int to) const;
00176
00177 virtual void updateLegend(QwtLegend *) const;
00178
00179 protected:
00180
00181 void init(const QwtText &title);
00182 void copy(const QwtPlotCurve &c);
00183
00184 virtual void drawCurve(QPainter *p, int style,
00185 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00186 int from, int to) const;
00187
00188 virtual void drawSymbols(QPainter *p, const QwtSymbol &,
00189 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00190 int from, int to) const;
00191
00192 void drawLines(QPainter *p,
00193 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00194 int from, int to) const;
00195 void drawSticks(QPainter *p,
00196 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00197 int from, int to) const;
00198 void drawDots(QPainter *p,
00199 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00200 int from, int to) const;
00201 void drawSteps(QPainter *p,
00202 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
00203 int from, int to) const;
00204 void drawSpline(QPainter *p,
00205 const QwtScaleMap &xMap, const QwtScaleMap &yMap) const;
00206
00207 #if QT_VERSION < 0x040000
00208 void fillCurve(QPainter *,
00209 const QwtScaleMap &, const QwtScaleMap &,
00210 QPointArray &) const;
00211 void closePolyline(const QwtScaleMap &, const QwtScaleMap &,
00212 QPointArray &) const;
00213 #else
00214 void fillCurve(QPainter *,
00215 const QwtScaleMap &, const QwtScaleMap &,
00216 QPolygon &) const;
00217 void closePolyline(const QwtScaleMap &, const QwtScaleMap &,
00218 QPolygon &) const;
00219 #endif
00220
00221 int verifyRange(int &i1, int &i2) const;
00222
00223 private:
00224 QwtData *d_xy;
00225
00226 class PrivateData;
00227 PrivateData *d_data;
00228 };
00229
00231 inline QwtData &QwtPlotCurve::data()
00232 {
00233 return *d_xy;
00234 }
00235
00237 inline const QwtData &QwtPlotCurve::data() const
00238 {
00239 return *d_xy;
00240 }
00241
00246 inline double QwtPlotCurve::x(int i) const
00247 {
00248 return d_xy->x(i);
00249 }
00250
00255 inline double QwtPlotCurve::y(int i) const
00256 {
00257 return d_xy->y(i);
00258 }
00259
00260 #endif