Qwt User's Guide: qwt_series_data.h Source File

Qwt User's Guide 6.1.4

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_samples.h"
15 #include "qwt_point_3d.h"
16 #include "qwt_point_polar.h"
17 #include <qvector.h>
18 #include <qrect.h>
19
46 template <typename T>
47 class QwtSeriesData
48 {
49 public:
51 QwtSeriesData();
52
54 virtual ~QwtSeriesData();
55
56 #ifndef QWT_PYTHON_WRAPPER
57
59 virtual size_t size() const = 0;
60
66 virtual T sample( size_t i ) const = 0;
67
80 virtual QRectF boundingRect() const = 0;
81
82 #else
83 // Needed for generating the python bindings, but not for using them !
84 virtual size_t size() const { return 0; }
85 virtual T sample( size_t i ) const { return T(); }
86 virtual QRectF boundingRect() const { return d_boundingRect; }
87 #endif
88
100 virtual void setRectOfInterest( const QRectF &rect );
101
102 protected:
104 mutable QRectF d_boundingRect;
105
106 private:
107 QwtSeriesData<T> &operator=( const QwtSeriesData<T> & );
108 };
109
110 template <typename T>
111 QwtSeriesData<T>::QwtSeriesData():
112 d_boundingRect( 0.0, 0.0, -1.0, -1.0 )
113 {
114 }
115
116 template <typename T>
117 QwtSeriesData<T>::~QwtSeriesData()
118 {
119 }
120
121 template <typename T>
122 void QwtSeriesData<T>::setRectOfInterest( const QRectF & )
123 {
124 }
125
132 template <typename T>
133 class QwtArraySeriesData: public QwtSeriesData<T>
134 {
135 public:
137 QwtArraySeriesData();
138
143 QwtArraySeriesData( const QVector<T> &samples );
144
149 void setSamples( const QVector<T> &samples );
150
152 const QVector<T> samples() const;
153
155 virtual size_t size() const;
156
163 virtual T sample( size_t index ) const;
164
165 protected:
167 QVector<T> d_samples;
168 };
169
170 template <typename T>
171 QwtArraySeriesData<T>::QwtArraySeriesData()
172 {
173 }
174
175 template <typename T>
176 QwtArraySeriesData<T>::QwtArraySeriesData( const QVector<T> &samples ):
177 d_samples( samples )
178 {
179 }
180
181 template <typename T>
182 void QwtArraySeriesData<T>::setSamples( const QVector<T> &samples )
183 {
184 QwtSeriesData<T>::d_boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
185 d_samples = samples;
186 }
187
188 template <typename T>
189 const QVector<T> QwtArraySeriesData<T>::samples() const
190 {
191 return d_samples;
192 }
193
194 template <typename T>
195 size_t QwtArraySeriesData<T>::size() const
196 {
197 return d_samples.size();
198 }
199
200 template <typename T>
201 T QwtArraySeriesData<T>::sample( size_t i ) const
202 {
203 return d_samples[ static_cast<int>( i ) ];
204 }
205
207 class QWT_EXPORT QwtPointSeriesData: public QwtArraySeriesData<QPointF>
208 {
209 public:
210 QwtPointSeriesData(
211 const QVector<QPointF> & = QVector<QPointF>() );
212
213 virtual QRectF boundingRect() const;
214 };
215
217 class QWT_EXPORT QwtPoint3DSeriesData: public QwtArraySeriesData<QwtPoint3D>
218 {
219 public:
220 QwtPoint3DSeriesData(
221 const QVector<QwtPoint3D> & = QVector<QwtPoint3D>() );
222 virtual QRectF boundingRect() const;
223 };
224
226 class QWT_EXPORT QwtIntervalSeriesData: public QwtArraySeriesData<QwtIntervalSample>
227 {
228 public:
229 QwtIntervalSeriesData(
230 const QVector<QwtIntervalSample> & = QVector<QwtIntervalSample>() );
231
232 virtual QRectF boundingRect() const;
233 };
234
236 class QWT_EXPORT QwtSetSeriesData: public QwtArraySeriesData<QwtSetSample>
237 {
238 public:
239 QwtSetSeriesData(
240 const QVector<QwtSetSample> & = QVector<QwtSetSample>() );
241
242 virtual QRectF boundingRect() const;
243 };
244
248 class QWT_EXPORT QwtTradingChartData: public QwtArraySeriesData<QwtOHLCSample>
249 {
250 public:
251 QwtTradingChartData(
252 const QVector<QwtOHLCSample> & = QVector<QwtOHLCSample>() );
253
254 virtual QRectF boundingRect() const;
255 };
256
257 QWT_EXPORT QRectF qwtBoundingRect(
258 const QwtSeriesData<QPointF> &, int from = 0, int to = -1 );
259
260 QWT_EXPORT QRectF qwtBoundingRect(
261 const QwtSeriesData<QwtPoint3D> &, int from = 0, int to = -1 );
262
263 QWT_EXPORT QRectF qwtBoundingRect(
264 const QwtSeriesData<QwtPointPolar> &, int from = 0, int to = -1 );
265
266 QWT_EXPORT QRectF qwtBoundingRect(
267 const QwtSeriesData<QwtIntervalSample> &, int from = 0, int to = -1 );
268
269 QWT_EXPORT QRectF qwtBoundingRect(
270 const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 );
271
272 QWT_EXPORT QRectF qwtBoundingRect(
273 const QwtSeriesData<QwtOHLCSample> &, int from = 0, int to = -1 );
274
330 template <typename T, typename LessThan>
331 inline int qwtUpperSampleIndex( const QwtSeriesData<T> &series,
332 double value, LessThan lessThan )
333 {
334 const int indexMax = series.size() - 1;
335
336 if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) )
337 return -1;
338
339 int indexMin = 0;
340 int n = indexMax;
341
342 while ( n > 0 )
343 {
344 const int half = n >> 1;
345 const int indexMid = indexMin + half;
346
347 if ( lessThan( value, series.sample( indexMid ) ) )
348 {
349 n = half;
350 }
351 else
352 {
353 indexMin = indexMid + 1;
354 n -= half + 1;
355 }
356 }
357
358 return indexMin;
359 }
360
361 #endif
QwtArraySeriesData::setSamples
void setSamples(const QVector< T > &samples)
Definition: qwt_series_data.h:182
QwtSeriesData::QwtSeriesData
QwtSeriesData()
Constructor.
Definition: qwt_series_data.h:111
QwtPointSeriesData
Interface for iterating over an array of points.
Definition: qwt_series_data.h:207
QwtTradingChartData
Definition: qwt_series_data.h:248
QwtSetSeriesData
Interface for iterating over an array of samples.
Definition: qwt_series_data.h:236
QwtSeriesData::boundingRect
virtual QRectF boundingRect() const =0
QwtArraySeriesData::d_samples
QVector< T > d_samples
Vector of samples.
Definition: qwt_series_data.h:167
QwtIntervalSeriesData
Interface for iterating over an array of intervals.
Definition: qwt_series_data.h:226
QwtArraySeriesData::QwtArraySeriesData
QwtArraySeriesData()
Constructor.
Definition: qwt_series_data.h:171
QwtSeriesData::setRectOfInterest
virtual void setRectOfInterest(const QRectF &rect)
Definition: qwt_series_data.h:122
QwtSeriesData
Abstract interface for iterating over samples.
Definition: qwt_series_data.h:47
QwtArraySeriesData::samples
const QVector< T > samples() const
Definition: qwt_series_data.h:189
QwtSeriesData::sample
virtual T sample(size_t i) const =0
QwtArraySeriesData
Template class for data, that is organized as QVector.
Definition: qwt_series_data.h:133
QwtArraySeriesData::sample
virtual T sample(size_t index) const
Definition: qwt_series_data.h:201
QwtArraySeriesData::size
virtual size_t size() const
Definition: qwt_series_data.h:195
QwtSeriesData::d_boundingRect
QRectF d_boundingRect
Can be used to cache a calculated bounding rectangle.
Definition: qwt_series_data.h:104
QwtSeriesData::~QwtSeriesData
virtual ~QwtSeriesData()
Destructor.
Definition: qwt_series_data.h:117
QwtPoint3DSeriesData
Interface for iterating over an array of 3D points.
Definition: qwt_series_data.h:217
QwtSeriesData::size
virtual size_t size() const =0