source: ntrip/trunk/BNC/qwt/qwt_plot_curve.h@ 4390

Last change on this file since 4390 was 4271, checked in by mervart, 12 years ago
File size: 9.3 KB
Line 
1/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10#ifndef QWT_PLOT_CURVE_H
11#define QWT_PLOT_CURVE_H
12
13#include "qwt_global.h"
14#include "qwt_plot_seriesitem.h"
15#include "qwt_series_data.h"
16#include "qwt_text.h"
17#include <qpen.h>
18#include <qstring.h>
19
20class QPainter;
21class QPolygonF;
22class QwtScaleMap;
23class QwtSymbol;
24class QwtCurveFitter;
25
26/*!
27 \brief A plot item, that represents a series of points
28
29 A curve is the representation of a series of points in the x-y plane.
30 It supports different display styles, interpolation ( f.e. spline )
31 and symbols.
32
33 \par Usage
34 <dl><dt>a) Assign curve properties</dt>
35 <dd>When a curve is created, it is configured to draw black solid lines
36 with in QwtPlotCurve::Lines style and no symbols.
37 You can change this by calling
38 setPen(), setStyle() and setSymbol().</dd>
39 <dt>b) Connect/Assign data.</dt>
40 <dd>QwtPlotCurve gets its points using a QwtSeriesData object offering
41 a bridge to the real storage of the points ( like QAbstractItemModel ).
42 There are several convenience classes derived from QwtSeriesData, that also store
43 the points inside ( like QStandardItemModel ). QwtPlotCurve also offers
44 a couple of variations of setSamples(), that build QwtSeriesData objects from
45 arrays internally.</dd>
46 <dt>c) Attach the curve to a plot</dt>
47 <dd>See QwtPlotItem::attach()
48 </dd></dl>
49
50 \par Example:
51 see examples/bode
52
53 \sa QwtPointSeriesData, QwtSymbol, QwtScaleMap
54*/
55class QWT_EXPORT QwtPlotCurve: public QwtPlotSeriesItem<QPointF>
56{
57public:
58 /*!
59 Curve styles.
60 \sa setStyle(), style()
61 */
62 enum CurveStyle
63 {
64 /*!
65 Don't draw a curve. Note: This doesn't affect the symbols.
66 */
67 NoCurve = -1,
68
69 /*!
70 Connect the points with straight lines. The lines might
71 be interpolated depending on the 'Fitted' attribute. Curve
72 fitting can be configured using setCurveFitter().
73 */
74 Lines,
75
76 /*!
77 Draw vertical or horizontal sticks ( depending on the
78 orientation() ) from a baseline which is defined by setBaseline().
79 */
80 Sticks,
81
82 /*!
83 Connect the points with a step function. The step function
84 is drawn from the left to the right or vice versa,
85 depending on the QwtPlotCurve::Inverted attribute.
86 */
87 Steps,
88
89 /*!
90 Draw dots at the locations of the data points. Note:
91 This is different from a dotted line (see setPen()), and faster
92 as a curve in QwtPlotCurve::NoStyle style and a symbol
93 painting a point.
94 */
95 Dots,
96
97 /*!
98 Styles >= QwtPlotCurve::UserCurve are reserved for derived
99 classes of QwtPlotCurve that overload drawCurve() with
100 additional application specific curve types.
101 */
102 UserCurve = 100
103 };
104
105 /*!
106 Attribute for drawing the curve
107 \sa setCurveAttribute(), testCurveAttribute(), curveFitter()
108 */
109 enum CurveAttribute
110 {
111 /*!
112 For QwtPlotCurve::Steps only.
113 Draws a step function from the right to the left.
114 */
115 Inverted = 0x01,
116
117 /*!
118 Only in combination with QwtPlotCurve::Lines
119 A QwtCurveFitter tries to
120 interpolate/smooth the curve, before it is painted.
121
122 \note Curve fitting requires temorary memory
123 for calculating coefficients and additional points.
124 If painting in QwtPlotCurve::Fitted mode is slow it might be better
125 to fit the points, before they are passed to QwtPlotCurve.
126 */
127 Fitted = 0x02
128 };
129
130 //! Curve attributes
131 typedef QFlags<CurveAttribute> CurveAttributes;
132
133 /*!
134 Attributes how to represent the curve on the legend
135
136 \sa setLegendAttribute(), testLegendAttribute(),
137 drawLegendIdentifier()
138 */
139
140 enum LegendAttribute
141 {
142 /*!
143 QwtPlotCurve tries to find a color representing the curve
144 and paints a rectangle with it.
145 */
146 LegendNoAttribute = 0x00,
147
148 /*!
149 If the style() is not QwtPlotCurve::NoCurve a line
150 is painted with the curve pen().
151 */
152 LegendShowLine = 0x01,
153
154 /*!
155 If the curve has a valid symbol it is painted.
156 */
157 LegendShowSymbol = 0x02,
158
159 /*!
160 If the curve has a brush a rectangle filled with the
161 curve brush() is painted.
162 */
163 LegendShowBrush = 0x04
164 };
165
166 //! Legend attributes
167 typedef QFlags<LegendAttribute> LegendAttributes;
168
169 /*!
170 Attributes to modify the drawing algorithm.
171 The default setting enables ClipPolygons
172
173 \sa setPaintAttribute(), testPaintAttribute()
174 */
175 enum PaintAttribute
176 {
177 /*!
178 Clip polygons before painting them. In situations, where points
179 are far outside the visible area (f.e when zooming deep) this
180 might be a substantial improvement for the painting performance
181 */
182 ClipPolygons = 0x01,
183
184 /*!
185 Paint the symbol to a QPixmap and paint the pixmap
186 instead rendering the symbol for each point. The flag has
187 no effect, when the curve is not painted to the canvas
188 ( f.e when exporting the plot to a PDF document ).
189 */
190 CacheSymbols = 0x02
191 };
192
193 //! Paint attributes
194 typedef QFlags<PaintAttribute> PaintAttributes;
195
196 explicit QwtPlotCurve( const QString &title = QString::null );
197 explicit QwtPlotCurve( const QwtText &title );
198
199 virtual ~QwtPlotCurve();
200
201 virtual int rtti() const;
202
203 void setPaintAttribute( PaintAttribute, bool on = true );
204 bool testPaintAttribute( PaintAttribute ) const;
205
206 void setLegendAttribute( LegendAttribute, bool on = true );
207 bool testLegendAttribute( LegendAttribute ) const;
208
209#ifndef QWT_NO_COMPAT
210 void setRawSamples( const double *xData, const double *yData, int size );
211 void setSamples( const double *xData, const double *yData, int size );
212 void setSamples( const QVector<double> &xData, const QVector<double> &yData );
213#endif
214 void setSamples( const QVector<QPointF> & );
215
216 int closestPoint( const QPoint &pos, double *dist = NULL ) const;
217
218 double minXValue() const;
219 double maxXValue() const;
220 double minYValue() const;
221 double maxYValue() const;
222
223 void setCurveAttribute( CurveAttribute, bool on = true );
224 bool testCurveAttribute( CurveAttribute ) const;
225
226 void setPen( const QPen & );
227 const QPen &pen() const;
228
229 void setBrush( const QBrush & );
230 const QBrush &brush() const;
231
232 void setBaseline( double ref );
233 double baseline() const;
234
235 void setStyle( CurveStyle style );
236 CurveStyle style() const;
237
238 void setSymbol( const QwtSymbol *s );
239 const QwtSymbol *symbol() const;
240
241 void setCurveFitter( QwtCurveFitter * );
242 QwtCurveFitter *curveFitter() const;
243
244 virtual void drawSeries( QPainter *,
245 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
246 const QRectF &canvasRect, int from, int to ) const;
247
248 virtual void updateLegend( QwtLegend * ) const;
249 virtual void drawLegendIdentifier( QPainter *, const QRectF & ) const;
250
251protected:
252
253 void init();
254
255 virtual void drawCurve( QPainter *p, int style,
256 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
257 const QRectF &canvasRect, int from, int to ) const;
258
259 virtual void drawSymbols( QPainter *p, const QwtSymbol &,
260 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
261 const QRectF &canvasRect, int from, int to ) const;
262
263 void drawLines( QPainter *p,
264 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
265 const QRectF &canvasRect, int from, int to ) const;
266
267 void drawSticks( QPainter *p,
268 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
269 const QRectF &canvasRect, int from, int to ) const;
270
271 void drawDots( QPainter *p,
272 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
273 const QRectF &canvasRect, int from, int to ) const;
274
275 void drawSteps( QPainter *p,
276 const QwtScaleMap &xMap, const QwtScaleMap &yMap,
277 const QRectF &canvasRect, int from, int to ) const;
278
279 virtual void fillCurve( QPainter *,
280 const QwtScaleMap &, const QwtScaleMap &,
281 const QRectF &canvasRect, QPolygonF & ) const;
282
283 void closePolyline( QPainter *,
284 const QwtScaleMap &, const QwtScaleMap &, QPolygonF & ) const;
285
286private:
287 class PrivateData;
288 PrivateData *d_data;
289};
290
291//! boundingRect().left()
292inline double QwtPlotCurve::minXValue() const
293{
294 return boundingRect().left();
295}
296
297//! boundingRect().right()
298inline double QwtPlotCurve::maxXValue() const
299{
300 return boundingRect().right();
301}
302
303//! boundingRect().top()
304inline double QwtPlotCurve::minYValue() const
305{
306 return boundingRect().top();
307}
308
309//! boundingRect().bottom()
310inline double QwtPlotCurve::maxYValue() const
311{
312 return boundingRect().bottom();
313}
314
315Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotCurve::PaintAttributes )
316Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotCurve::LegendAttributes )
317Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotCurve::CurveAttributes )
318
319#endif
Note: See TracBrowser for help on using the repository browser.