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