Qwt User's Guide 6.0.2

- Main Page
- Related Pages
- Classes

qwt_series_data.h
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_SERIES_DATA_H
11 #define QWT_SERIES_DATA_H 1
12
13 #include "qwt_global.h"
14 #include "qwt_interval.h"
15 #include "qwt_point_3d.h"
16 #include "qwt_point_polar.h"
17 #include <qvector.h>
18 #include <qrect.h>
19
21 class QWT_EXPORT QwtIntervalSample
22 {
23 public:
24 QwtIntervalSample();
25 QwtIntervalSample( double, const QwtInterval & );
26 QwtIntervalSample( double value, double min, double max );
27
28 bool operator==( const QwtIntervalSample & ) const;
29 bool operator!=( const QwtIntervalSample & ) const;
30
32 double value;
33
35 QwtInterval interval;
36 };
37
42 inline QwtIntervalSample::QwtIntervalSample():
43 value( 0.0 )
44 {
45 }
46
48 inline QwtIntervalSample::QwtIntervalSample(
49 double v, const QwtInterval &intv ):
50 value( v ),
51 interval( intv )
52 {
53 }
54
56 inline QwtIntervalSample::QwtIntervalSample(
57 double v, double min, double max ):
58 value( v ),
59 interval( min, max )
60 {
61 }
62
64 inline bool QwtIntervalSample::operator==(
65 const QwtIntervalSample &other ) const
66 {
67 return value == other.value && interval == other.interval;
68 }
69
71 inline bool QwtIntervalSample::operator!=(
72 const QwtIntervalSample &other ) const
73 {
74 return !( *this == other );
75 }
76
78 class QWT_EXPORT QwtSetSample
79 {
80 public:
81 QwtSetSample();
82 bool operator==( const QwtSetSample &other ) const;
83 bool operator!=( const QwtSetSample &other ) const;
84
86 double value;
87
89 QVector<double> set;
90 };
91
96 inline QwtSetSample::QwtSetSample():
97 value( 0.0 )
98 {
99 }
100
102 inline bool QwtSetSample::operator==( const QwtSetSample &other ) const
103 {
104 return value == other.value && set == other.set;
105 }
106
108 inline bool QwtSetSample::operator!=( const QwtSetSample &other ) const
109 {
110 return !( *this == other );
111 }
112
139 template <typename T>
140 class QwtSeriesData
141 {
142 public:
144 QwtSeriesData();
145
147 virtual ~QwtSeriesData();
148
150 virtual size_t size() const = 0;
151
157 virtual T sample( size_t i ) const = 0;
158
169 virtual QRectF boundingRect() const = 0;
170
182 virtual void setRectOfInterest( const QRectF &rect );
183
184 protected:
186 mutable QRectF d_boundingRect;
187
188 private:
189 QwtSeriesData<T> &operator=( const QwtSeriesData<T> & );
190 };
191
192 template <typename T>
193 QwtSeriesData<T>::QwtSeriesData():
194 d_boundingRect( 0.0, 0.0, -1.0, -1.0 )
195 {
196 }
197
198 template <typename T>
199 QwtSeriesData<T>::~QwtSeriesData()
200 {
201 }
202
203 template <typename T>
204 void QwtSeriesData<T>::setRectOfInterest( const QRectF & )
205 {
206 }
207
214 template <typename T>
215 class QwtArraySeriesData: public QwtSeriesData<T>
216 {
217 public:
219 QwtArraySeriesData();
220
225 QwtArraySeriesData( const QVector<T> &samples );
226
231 void setSamples( const QVector<T> &samples );
232
234 const QVector<T> samples() const;
235
237 virtual size_t size() const;
238
245 virtual T sample( size_t index ) const;
246
247 protected:
249 QVector<T> d_samples;
250 };
251
252 template <typename T>
253 QwtArraySeriesData<T>::QwtArraySeriesData()
254 {
255 }
256
257 template <typename T>
258 QwtArraySeriesData<T>::QwtArraySeriesData( const QVector<T> &samples ):
259 d_samples( samples )
260 {
261 }
262
263 template <typename T>
264 void QwtArraySeriesData<T>::setSamples( const QVector<T> &samples )
265 {
266 QwtSeriesData<T>::d_boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
267 d_samples = samples;
268 }
269
270 template <typename T>
271 const QVector<T> QwtArraySeriesData<T>::samples() const
272 {
273 return d_samples;
274 }
275
276 template <typename T>
277 size_t QwtArraySeriesData<T>::size() const
278 {
279 return d_samples.size();
280 }
281
282 template <typename T>
283 T QwtArraySeriesData<T>::sample( size_t i ) const
284 {
285 return d_samples[ static_cast<int>( i ) ];
286 }
287
289 class QWT_EXPORT QwtPointSeriesData: public QwtArraySeriesData<QPointF>
290 {
291 public:
292 QwtPointSeriesData(
293 const QVector<QPointF> & = QVector<QPointF>() );
294
295 virtual QRectF boundingRect() const;
296 };
297
299 class QWT_EXPORT QwtPoint3DSeriesData: public QwtArraySeriesData<QwtPoint3D>
300 {
301 public:
302 QwtPoint3DSeriesData(
303 const QVector<QwtPoint3D> & = QVector<QwtPoint3D>() );
304 virtual QRectF boundingRect() const;
305 };
306
308 class QWT_EXPORT QwtIntervalSeriesData: public QwtArraySeriesData<QwtIntervalSample>
309 {
310 public:
311 QwtIntervalSeriesData(
312 const QVector<QwtIntervalSample> & = QVector<QwtIntervalSample>() );
313
314 virtual QRectF boundingRect() const;
315 };
316
318 class QWT_EXPORT QwtSetSeriesData: public QwtArraySeriesData<QwtSetSample>
319 {
320 public:
321 QwtSetSeriesData(
322 const QVector<QwtSetSample> & = QVector<QwtSetSample>() );
323
324 virtual QRectF boundingRect() const;
325 };
326
330 class QWT_EXPORT QwtPointArrayData: public QwtSeriesData<QPointF>
331 {
332 public:
333 QwtPointArrayData( const QVector<double> &x, const QVector<double> &y );
334 QwtPointArrayData( const double *x, const double *y, size_t size );
335
336 virtual QRectF boundingRect() const;
337
338 virtual size_t size() const;
339 virtual QPointF sample( size_t i ) const;
340
341 const QVector<double> &xData() const;
342 const QVector<double> &yData() const;
343
344 private:
345 QVector<double> d_x;
346 QVector<double> d_y;
347 };
348
352 class QWT_EXPORT QwtCPointerData: public QwtSeriesData<QPointF>
353 {
354 public:
355 QwtCPointerData( const double *x, const double *y, size_t size );
356
357 virtual QRectF boundingRect() const;
358 virtual size_t size() const;
359 virtual QPointF sample( size_t i ) const;
360
361 const double *xData() const;
362 const double *yData() const;
363
364 private:
365 const double *d_x;
366 const double *d_y;
367 size_t d_size;
368 };
369
422 class QWT_EXPORT QwtSyntheticPointData: public QwtSeriesData<QPointF>
423 {
424 public:
425 QwtSyntheticPointData( size_t size,
426 const QwtInterval & = QwtInterval() );
427
428 void setSize( size_t size );
429 size_t size() const;
430
431 void setInterval( const QwtInterval& );
432 QwtInterval interval() const;
433
434 virtual QRectF boundingRect() const;
435 virtual QPointF sample( size_t i ) const;
436
443 virtual double y( double x ) const = 0;
444 virtual double x( uint index ) const;
445
446 virtual void setRectOfInterest( const QRectF & );
447 QRectF rectOfInterest() const;
448
449 private:
450 size_t d_size;
451 QwtInterval d_interval;
452 QRectF d_rectOfInterest;
453 QwtInterval d_intervalOfInterest;
454 };
455
456 QWT_EXPORT QRectF qwtBoundingRect(
457 const QwtSeriesData<QPointF> &, int from = 0, int to = -1 );
458 QWT_EXPORT QRectF qwtBoundingRect(
459 const QwtSeriesData<QwtPoint3D> &, int from = 0, int to = -1 );
460 QWT_EXPORT QRectF qwtBoundingRect(
461 const QwtSeriesData<QwtPointPolar> &, int from = 0, int to = -1 );
462 QWT_EXPORT QRectF qwtBoundingRect(
463 const QwtSeriesData<QwtIntervalSample> &, int from = 0, int to = -1 );
464 QWT_EXPORT QRectF qwtBoundingRect(
465 const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 );
466
467 #endif