Qwt User's Guide 6.1.3

- Main Page
- 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_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
57 virtual size_t size() const = 0;
58
64 virtual T sample( size_t i ) const = 0;
65
78 virtual QRectF boundingRect() const = 0;
79
91 virtual void setRectOfInterest( const QRectF &rect );
92
93 protected:
95 mutable QRectF d_boundingRect;
96
97 private:
98 QwtSeriesData<T> &operator=( const QwtSeriesData<T> & );
99 };
100
101 template <typename T>
102 QwtSeriesData<T>::QwtSeriesData():
103 d_boundingRect( 0.0, 0.0, -1.0, -1.0 )
104 {
105 }
106
107 template <typename T>
108 QwtSeriesData<T>::~QwtSeriesData()
109 {
110 }
111
112 template <typename T>
113 void QwtSeriesData<T>::setRectOfInterest( const QRectF & )
114 {
115 }
116
123 template <typename T>
124 class QwtArraySeriesData: public QwtSeriesData<T>
125 {
126 public:
128 QwtArraySeriesData();
129
134 QwtArraySeriesData( const QVector<T> &samples );
135
140 void setSamples( const QVector<T> &samples );
141
143 const QVector<T> samples() const;
144
146 virtual size_t size() const;
147
154 virtual T sample( size_t index ) const;
155
156 protected:
158 QVector<T> d_samples;
159 };
160
161 template <typename T>
162 QwtArraySeriesData<T>::QwtArraySeriesData()
163 {
164 }
165
166 template <typename T>
167 QwtArraySeriesData<T>::QwtArraySeriesData( const QVector<T> &samples ):
168 d_samples( samples )
169 {
170 }
171
172 template <typename T>
173 void QwtArraySeriesData<T>::setSamples( const QVector<T> &samples )
174 {
175 QwtSeriesData<T>::d_boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
176 d_samples = samples;
177 }
178
179 template <typename T>
180 const QVector<T> QwtArraySeriesData<T>::samples() const
181 {
182 return d_samples;
183 }
184
185 template <typename T>
186 size_t QwtArraySeriesData<T>::size() const
187 {
188 return d_samples.size();
189 }
190
191 template <typename T>
192 T QwtArraySeriesData<T>::sample( size_t i ) const
193 {
194 return d_samples[ static_cast<int>( i ) ];
195 }
196
198 class QWT_EXPORT QwtPointSeriesData: public QwtArraySeriesData<QPointF>
199 {
200 public:
201 QwtPointSeriesData(
202 const QVector<QPointF> & = QVector<QPointF>() );
203
204 virtual QRectF boundingRect() const;
205 };
206
208 class QWT_EXPORT QwtPoint3DSeriesData: public QwtArraySeriesData<QwtPoint3D>
209 {
210 public:
211 QwtPoint3DSeriesData(
212 const QVector<QwtPoint3D> & = QVector<QwtPoint3D>() );
213 virtual QRectF boundingRect() const;
214 };
215
217 class QWT_EXPORT QwtIntervalSeriesData: public QwtArraySeriesData<QwtIntervalSample>
218 {
219 public:
220 QwtIntervalSeriesData(
221 const QVector<QwtIntervalSample> & = QVector<QwtIntervalSample>() );
222
223 virtual QRectF boundingRect() const;
224 };
225
227 class QWT_EXPORT QwtSetSeriesData: public QwtArraySeriesData<QwtSetSample>
228 {
229 public:
230 QwtSetSeriesData(
231 const QVector<QwtSetSample> & = QVector<QwtSetSample>() );
232
233 virtual QRectF boundingRect() const;
234 };
235
239 class QWT_EXPORT QwtTradingChartData: public QwtArraySeriesData<QwtOHLCSample>
240 {
241 public:
242 QwtTradingChartData(
243 const QVector<QwtOHLCSample> & = QVector<QwtOHLCSample>() );
244
245 virtual QRectF boundingRect() const;
246 };
247
248 QWT_EXPORT QRectF qwtBoundingRect(
249 const QwtSeriesData<QPointF> &, int from = 0, int to = -1 );
250
251 QWT_EXPORT QRectF qwtBoundingRect(
252 const QwtSeriesData<QwtPoint3D> &, int from = 0, int to = -1 );
253
254 QWT_EXPORT QRectF qwtBoundingRect(
255 const QwtSeriesData<QwtPointPolar> &, int from = 0, int to = -1 );
256
257 QWT_EXPORT QRectF qwtBoundingRect(
258 const QwtSeriesData<QwtIntervalSample> &, int from = 0, int to = -1 );
259
260 QWT_EXPORT QRectF qwtBoundingRect(
261 const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 );
262
263 QWT_EXPORT QRectF qwtBoundingRect(
264 const QwtSeriesData<QwtOHLCSample> &, int from = 0, int to = -1 );
265
324 template <typename T, typename LessThan>
325 inline int qwtUpperSampleIndex( const QwtSeriesData<T> &series,
326 double value, LessThan lessThan )
327 {
328 const int indexMax = series.size() - 1;
329
330 if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) )
331 return -1;
332
333 int indexMin = 0;
334 int n = indexMax;
335
336 while ( n > 0 )
337 {
338 const int half = n >> 1;
339 const int indexMid = indexMin + half;
340
341 if ( lessThan( value, series.sample( indexMid ) ) )
342 {
343 n = half;
344 }
345 else
346 {
347 indexMin = indexMid + 1;
348 n -= half + 1;
349 }
350 }
351
352 return indexMin;
353 }
354
355 #endif
QwtArraySeriesData::setSamples
void setSamples(const QVector< T > &samples)
Definition: qwt_series_data.h:173
QwtSeriesData::boundingRect
virtual QRectF boundingRect() const =0
QwtSeriesData::QwtSeriesData
QwtSeriesData()
Constructor.
Definition: qwt_series_data.h:102
QwtPointSeriesData
Interface for iterating over an array of points.
Definition: qwt_series_data.h:198
QwtTradingChartData
Definition: qwt_series_data.h:239
QwtSetSeriesData
Interface for iterating over an array of samples.
Definition: qwt_series_data.h:227
QwtSeriesData::sample
virtual T sample(size_t i) const =0
QwtArraySeriesData::size
virtual size_t size() const
Definition: qwt_series_data.h:186
QwtArraySeriesData::d_samples
QVector< T > d_samples
Vector of samples.
Definition: qwt_series_data.h:158
QwtIntervalSeriesData
Interface for iterating over an array of intervals.
Definition: qwt_series_data.h:217
QwtArraySeriesData::QwtArraySeriesData
QwtArraySeriesData()
Constructor.
Definition: qwt_series_data.h:162
QwtSeriesData::setRectOfInterest
virtual void setRectOfInterest(const QRectF &rect)
Definition: qwt_series_data.h:113
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:180
QwtArraySeriesData::sample
virtual T sample(size_t index) const
Definition: qwt_series_data.h:192
QwtArraySeriesData
Template class for data, that is organized as QVector.
Definition: qwt_series_data.h:124
QwtSeriesData::size
virtual size_t size() const =0
QwtSeriesData::d_boundingRect
QRectF d_boundingRect
Can be used to cache a calculated bounding rectangle.
Definition: qwt_series_data.h:95
QwtSeriesData::~QwtSeriesData
virtual ~QwtSeriesData()
Destructor.
Definition: qwt_series_data.h:108
QwtPoint3DSeriesData
Interface for iterating over an array of 3D points.
Definition: qwt_series_data.h:208