Qwt User's Guide  6.1.1
 All Classes Functions Variables Typedefs Enumerations Enumerator Pages
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>
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>
103  d_boundingRect( 0.0, 0.0, -1.0, -1.0 )
104 {
105 }
106 
107 template <typename T>
109 {
110 }
111 
112 template <typename T>
114 {
115 }
116 
123 template <typename T>
125 {
126 public:
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>
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>
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:
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:
212  const QVector<QwtPoint3D> & = QVector<QwtPoint3D>() );
213  virtual QRectF boundingRect() const;
214 };
215 
217 class QWT_EXPORT QwtIntervalSeriesData: public QwtArraySeriesData<QwtIntervalSample>
218 {
219 public:
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:
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:
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
void setSamples(const QVector< T > &samples)
Definition: qwt_series_data.h:173
QwtSeriesData()
Constructor.
Definition: qwt_series_data.h:102
Interface for iterating over an array of points.
Definition: qwt_series_data.h:198
Definition: qwt_series_data.h:239
Interface for iterating over an array of samples.
Definition: qwt_series_data.h:227
virtual size_t size() const
Definition: qwt_series_data.h:186
virtual QRectF boundingRect() const =0
QVector< T > d_samples
Vector of samples.
Definition: qwt_series_data.h:158
Interface for iterating over an array of intervals.
Definition: qwt_series_data.h:217
QwtArraySeriesData()
Constructor.
Definition: qwt_series_data.h:162
virtual void setRectOfInterest(const QRectF &rect)
Definition: qwt_series_data.h:113
Abstract interface for iterating over samples.
Definition: qwt_series_data.h:47
const QVector< T > samples() const
Definition: qwt_series_data.h:180
virtual T sample(size_t index) const
Definition: qwt_series_data.h:192
virtual T sample(size_t i) const =0
Template class for data, that is organized as QVector.
Definition: qwt_series_data.h:124
QRectF d_boundingRect
Can be used to cache a calculated bounding rectangle.
Definition: qwt_series_data.h:95
virtual ~QwtSeriesData()
Destructor.
Definition: qwt_series_data.h:108
Interface for iterating over an array of 3D points.
Definition: qwt_series_data.h:208
virtual size_t size() const =0