Qwt User's Guide: qwt_series_data.h Source File

Qwt User's Guide 6.2.0

qwt_series_data.h
1 /******************************************************************************
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
12
13 #include "qwt_global.h"
14 #include "qwt_samples.h"
15 #include "qwt_point_3d.h"
16
17 #include <qvector.h>
18 #include <qrect.h>
19
20 class QwtPointPolar;
21
48 template< typename T >
49 class QwtSeriesData
50 {
51 public:
53 QwtSeriesData();
54
56 virtual ~QwtSeriesData();
57
58 #ifndef QWT_PYTHON_WRAPPER
59
61 virtual size_t size() const = 0;
62
68 virtual T sample( size_t i ) const = 0;
69
82 virtual QRectF boundingRect() const = 0;
83
84 #else
85 // Needed for generating the python bindings, but not for using them !
86 virtual size_t size() const { return 0; }
87 virtual T sample( size_t i ) const { return T(); }
88 virtual QRectF boundingRect() const { return cachedBoundingRect; }
89 #endif
90
102 virtual void setRectOfInterest( const QRectF& rect );
103
104 protected:
106 mutable QRectF cachedBoundingRect;
107
108 private:
109 QwtSeriesData< T >& operator=( const QwtSeriesData< T >& );
110 };
111
112 template< typename T >
113 QwtSeriesData< T >::QwtSeriesData()
114 : cachedBoundingRect( 0.0, 0.0, -1.0, -1.0 )
115 {
116 }
117
118 template< typename T >
119 QwtSeriesData< T >::~QwtSeriesData()
120 {
121 }
122
123 template< typename T >
124 void QwtSeriesData< T >::setRectOfInterest( const QRectF& )
125 {
126 }
127
134 template< typename T >
135 class QwtArraySeriesData : public QwtSeriesData< T >
136 {
137 public:
139 QwtArraySeriesData();
140
145 explicit QwtArraySeriesData( const QVector< T >& samples );
146
151 void setSamples( const QVector< T >& samples );
152
154 const QVector< T > samples() const;
155
157 virtual size_t size() const QWT_OVERRIDE;
158
165 virtual T sample( size_t index ) const QWT_OVERRIDE;
166
167 protected:
169 QVector< T > m_samples;
170 };
171
172 template< typename T >
173 QwtArraySeriesData< T >::QwtArraySeriesData()
174 {
175 }
176
177 template< typename T >
178 QwtArraySeriesData< T >::QwtArraySeriesData( const QVector< T >& samples )
179 : m_samples( samples )
180 {
181 }
182
183 template< typename T >
184 void QwtArraySeriesData< T >::setSamples( const QVector< T >& samples )
185 {
186 QwtSeriesData< T >::cachedBoundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
187 m_samples = samples;
188 }
189
190 template< typename T >
191 const QVector< T > QwtArraySeriesData< T >::samples() const
192 {
193 return m_samples;
194 }
195
196 template< typename T >
197 size_t QwtArraySeriesData< T >::size() const
198 {
199 return m_samples.size();
200 }
201
202 template< typename T >
203 T QwtArraySeriesData< T >::sample( size_t i ) const
204 {
205 return m_samples[ static_cast< int >( i ) ];
206 }
207
209 class QWT_EXPORT QwtPointSeriesData : public QwtArraySeriesData< QPointF >
210 {
211 public:
212 QwtPointSeriesData(
213 const QVector< QPointF >& = QVector< QPointF >( ) );
214
215 virtual QRectF boundingRect() const QWT_OVERRIDE;
216 };
217
219 class QWT_EXPORT QwtPoint3DSeriesData : public QwtArraySeriesData< QwtPoint3D >
220 {
221 public:
222 QwtPoint3DSeriesData(
223 const QVector< QwtPoint3D >& = QVector< QwtPoint3D >( ) );
224
225 virtual QRectF boundingRect() const QWT_OVERRIDE;
226 };
227
229 class QWT_EXPORT QwtIntervalSeriesData : public QwtArraySeriesData< QwtIntervalSample >
230 {
231 public:
232 QwtIntervalSeriesData(
233 const QVector< QwtIntervalSample >& = QVector< QwtIntervalSample >( ) );
234
235 virtual QRectF boundingRect() const QWT_OVERRIDE;
236 };
237
239 class QWT_EXPORT QwtSetSeriesData : public QwtArraySeriesData< QwtSetSample >
240 {
241 public:
242 QwtSetSeriesData(
243 const QVector< QwtSetSample >& = QVector< QwtSetSample >( ) );
244
245 virtual QRectF boundingRect() const QWT_OVERRIDE;
246 };
247
249 class QWT_EXPORT QwtVectorFieldData : public QwtArraySeriesData< QwtVectorFieldSample >
250 {
251 public:
252 QwtVectorFieldData(
253 const QVector< QwtVectorFieldSample >& = QVector< QwtVectorFieldSample >( ) );
254
255 virtual QRectF boundingRect() const QWT_OVERRIDE;
256 };
257
261 class QWT_EXPORT QwtTradingChartData : public QwtArraySeriesData< QwtOHLCSample >
262 {
263 public:
264 QwtTradingChartData(
265 const QVector< QwtOHLCSample >& = QVector< QwtOHLCSample >( ) );
266
267 virtual QRectF boundingRect() const QWT_OVERRIDE;
268 };
269
270 QWT_EXPORT QRectF qwtBoundingRect(
271 const QwtSeriesData< QPointF >&, int from = 0, int to = -1 );
272
273 QWT_EXPORT QRectF qwtBoundingRect(
274 const QwtSeriesData< QwtPoint3D >&, int from = 0, int to = -1 );
275
276 QWT_EXPORT QRectF qwtBoundingRect(
277 const QwtSeriesData< QwtPointPolar >&, int from = 0, int to = -1 );
278
279 QWT_EXPORT QRectF qwtBoundingRect(
280 const QwtSeriesData< QwtIntervalSample >&, int from = 0, int to = -1 );
281
282 QWT_EXPORT QRectF qwtBoundingRect(
283 const QwtSeriesData< QwtSetSample >&, int from = 0, int to = -1 );
284
285 QWT_EXPORT QRectF qwtBoundingRect(
286 const QwtSeriesData< QwtOHLCSample >&, int from = 0, int to = -1 );
287
288 QWT_EXPORT QRectF qwtBoundingRect(
289 const QwtSeriesData< QwtVectorFieldSample >&, int from = 0, int to = -1 );
290
346 template< typename T, typename LessThan >
347 inline int qwtUpperSampleIndex( const QwtSeriesData< T >& series,
348 double value, LessThan lessThan )
349 {
350 const int indexMax = series.size() - 1;
351
352 if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) )
353 return -1;
354
355 int indexMin = 0;
356 int n = indexMax;
357
358 while ( n > 0 )
359 {
360 const int half = n >> 1;
361 const int indexMid = indexMin + half;
362
363 if ( lessThan( value, series.sample( indexMid ) ) )
364 {
365 n = half;
366 }
367 else
368 {
369 indexMin = indexMid + 1;
370 n -= half + 1;
371 }
372 }
373
374 return indexMin;
375 }
376
377 #endif
QVector
Definition: qwt_clipper.h:23
QwtArraySeriesData
Template class for data, that is organized as QVector.
Definition: qwt_series_data.h:136
QwtArraySeriesData::sample
virtual T sample(size_t index) const override
Definition: qwt_series_data.h:203
QwtArraySeriesData::size
virtual size_t size() const override
Definition: qwt_series_data.h:197
QwtArraySeriesData::QwtArraySeriesData
QwtArraySeriesData()
Constructor.
Definition: qwt_series_data.h:173
QwtArraySeriesData::setSamples
void setSamples(const QVector< T > &samples)
Definition: qwt_series_data.h:184
QwtArraySeriesData::QwtArraySeriesData
QwtArraySeriesData(const QVector< T > &samples)
Definition: qwt_series_data.h:178
QwtArraySeriesData::m_samples
QVector< T > m_samples
Vector of samples.
Definition: qwt_series_data.h:169
QwtArraySeriesData::samples
const QVector< T > samples() const
Definition: qwt_series_data.h:191
QwtIntervalSeriesData
Interface for iterating over an array of intervals.
Definition: qwt_series_data.h:230
QwtPoint3DSeriesData
Interface for iterating over an array of 3D points.
Definition: qwt_series_data.h:220
QwtPointPolar
A point in polar coordinates.
Definition: qwt_point_polar.h:29
QwtPointSeriesData
Interface for iterating over an array of points.
Definition: qwt_series_data.h:210
QwtSeriesData
Abstract interface for iterating over samples.
Definition: qwt_series_data.h:50
QwtSeriesData::setRectOfInterest
virtual void setRectOfInterest(const QRectF &rect)
Definition: qwt_series_data.h:124
QwtSeriesData::size
virtual size_t size() const =0
QwtSeriesData::QwtSeriesData
QwtSeriesData()
Constructor.
Definition: qwt_series_data.h:113
QwtSeriesData::~QwtSeriesData
virtual ~QwtSeriesData()
Destructor.
Definition: qwt_series_data.h:119
QwtSeriesData::cachedBoundingRect
QRectF cachedBoundingRect
Can be used to cache a calculated bounding rectangle.
Definition: qwt_series_data.h:106
QwtSeriesData::sample
virtual T sample(size_t i) const =0
QwtSeriesData::boundingRect
virtual QRectF boundingRect() const =0
QwtSetSeriesData
Interface for iterating over an array of samples.
Definition: qwt_series_data.h:240
QwtTradingChartData
Definition: qwt_series_data.h:262
QwtVectorFieldData
Interface for iterating over an array of vector field samples.
Definition: qwt_series_data.h:250