Qwt User's Guide
|
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 "qwt_global.h" 00014 #include "qwt_plot_seriesitem.h" 00015 #include "qwt_series_data.h" 00016 #include "qwt_text.h" 00017 #include <qpen.h> 00018 #include <qstring.h> 00019 00020 class QPainter; 00021 class QPolygonF; 00022 class QwtScaleMap; 00023 class QwtSymbol; 00024 class QwtCurveFitter; 00025 00055 class QWT_EXPORT QwtPlotCurve: 00056 public QwtPlotSeriesItem, public QwtSeriesStore<QPointF> 00057 { 00058 public: 00063 enum CurveStyle 00064 { 00068 NoCurve = -1, 00069 00075 Lines, 00076 00081 Sticks, 00082 00088 Steps, 00089 00096 Dots, 00097 00103 UserCurve = 100 00104 }; 00105 00110 enum CurveAttribute 00111 { 00116 Inverted = 0x01, 00117 00128 Fitted = 0x02 00129 }; 00130 00132 typedef QFlags<CurveAttribute> CurveAttributes; 00133 00141 enum LegendAttribute 00142 { 00147 LegendNoAttribute = 0x00, 00148 00153 LegendShowLine = 0x01, 00154 00158 LegendShowSymbol = 0x02, 00159 00164 LegendShowBrush = 0x04 00165 }; 00166 00168 typedef QFlags<LegendAttribute> LegendAttributes; 00169 00176 enum PaintAttribute 00177 { 00183 ClipPolygons = 0x01, 00184 00191 FilterPoints = 0x02, 00192 00198 MinimizeMemory = 0x04, 00199 00207 ImageBuffer = 0x08 00208 }; 00209 00211 typedef QFlags<PaintAttribute> PaintAttributes; 00212 00213 explicit QwtPlotCurve( const QString &title = QString::null ); 00214 explicit QwtPlotCurve( const QwtText &title ); 00215 00216 virtual ~QwtPlotCurve(); 00217 00218 virtual int rtti() const; 00219 00220 void setPaintAttribute( PaintAttribute, bool on = true ); 00221 bool testPaintAttribute( PaintAttribute ) const; 00222 00223 void setLegendAttribute( LegendAttribute, bool on = true ); 00224 bool testLegendAttribute( LegendAttribute ) const; 00225 00226 #ifndef QWT_NO_COMPAT 00227 void setRawSamples( const double *xData, const double *yData, int size ); 00228 void setSamples( const double *xData, const double *yData, int size ); 00229 void setSamples( const QVector<double> &xData, const QVector<double> &yData ); 00230 #endif 00231 void setSamples( const QVector<QPointF> & ); 00232 void setSamples( QwtSeriesData<QPointF> * ); 00233 00234 int closestPoint( const QPoint &pos, double *dist = NULL ) const; 00235 00236 double minXValue() const; 00237 double maxXValue() const; 00238 double minYValue() const; 00239 double maxYValue() const; 00240 00241 void setCurveAttribute( CurveAttribute, bool on = true ); 00242 bool testCurveAttribute( CurveAttribute ) const; 00243 00244 void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine ); 00245 void setPen( const QPen & ); 00246 const QPen &pen() const; 00247 00248 void setBrush( const QBrush & ); 00249 const QBrush &brush() const; 00250 00251 void setBaseline( double ); 00252 double baseline() const; 00253 00254 void setStyle( CurveStyle style ); 00255 CurveStyle style() const; 00256 00257 void setSymbol( QwtSymbol * ); 00258 const QwtSymbol *symbol() const; 00259 00260 void setCurveFitter( QwtCurveFitter * ); 00261 QwtCurveFitter *curveFitter() const; 00262 00263 virtual void drawSeries( QPainter *, 00264 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 00265 const QRectF &canvasRect, int from, int to ) const; 00266 00267 virtual QwtGraphic legendIcon( int index, const QSizeF & ) const; 00268 00269 protected: 00270 00271 void init(); 00272 00273 virtual void drawCurve( QPainter *p, int style, 00274 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 00275 const QRectF &canvasRect, int from, int to ) const; 00276 00277 virtual void drawSymbols( QPainter *p, const QwtSymbol &, 00278 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 00279 const QRectF &canvasRect, int from, int to ) const; 00280 00281 virtual void drawLines( QPainter *p, 00282 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 00283 const QRectF &canvasRect, int from, int to ) const; 00284 00285 virtual void drawSticks( QPainter *p, 00286 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 00287 const QRectF &canvasRect, int from, int to ) const; 00288 00289 virtual void drawDots( QPainter *p, 00290 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 00291 const QRectF &canvasRect, int from, int to ) const; 00292 00293 virtual void drawSteps( QPainter *p, 00294 const QwtScaleMap &xMap, const QwtScaleMap &yMap, 00295 const QRectF &canvasRect, int from, int to ) const; 00296 00297 virtual void fillCurve( QPainter *, 00298 const QwtScaleMap &, const QwtScaleMap &, 00299 const QRectF &canvasRect, QPolygonF & ) const; 00300 00301 void closePolyline( QPainter *, 00302 const QwtScaleMap &, const QwtScaleMap &, QPolygonF & ) const; 00303 00304 private: 00305 class PrivateData; 00306 PrivateData *d_data; 00307 }; 00308 00310 inline double QwtPlotCurve::minXValue() const 00311 { 00312 return boundingRect().left(); 00313 } 00314 00316 inline double QwtPlotCurve::maxXValue() const 00317 { 00318 return boundingRect().right(); 00319 } 00320 00322 inline double QwtPlotCurve::minYValue() const 00323 { 00324 return boundingRect().top(); 00325 } 00326 00328 inline double QwtPlotCurve::maxYValue() const 00329 { 00330 return boundingRect().bottom(); 00331 } 00332 00333 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotCurve::PaintAttributes ) 00334 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotCurve::LegendAttributes ) 00335 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotCurve::CurveAttributes ) 00336 00337 #endif