Qwt User's Guide  6.1-rc3
 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 
76  virtual QRectF boundingRect() const = 0;
77 
89  virtual void setRectOfInterest( const QRectF &rect );
90 
91 protected:
93  mutable QRectF d_boundingRect;
94 
95 private:
96  QwtSeriesData<T> &operator=( const QwtSeriesData<T> & );
97 };
98 
99 template <typename T>
101  d_boundingRect( 0.0, 0.0, -1.0, -1.0 )
102 {
103 }
104 
105 template <typename T>
107 {
108 }
109 
110 template <typename T>
112 {
113 }
114 
121 template <typename T>
123 {
124 public:
127 
132  QwtArraySeriesData( const QVector<T> &samples );
133 
138  void setSamples( const QVector<T> &samples );
139 
141  const QVector<T> samples() const;
142 
144  virtual size_t size() const;
145 
152  virtual T sample( size_t index ) const;
153 
154 protected:
156  QVector<T> d_samples;
157 };
158 
159 template <typename T>
161 {
162 }
163 
164 template <typename T>
165 QwtArraySeriesData<T>::QwtArraySeriesData( const QVector<T> &samples ):
166  d_samples( samples )
167 {
168 }
169 
170 template <typename T>
171 void QwtArraySeriesData<T>::setSamples( const QVector<T> &samples )
172 {
173  QwtSeriesData<T>::d_boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
174  d_samples = samples;
175 }
176 
177 template <typename T>
178 const QVector<T> QwtArraySeriesData<T>::samples() const
179 {
180  return d_samples;
181 }
182 
183 template <typename T>
185 {
186  return d_samples.size();
187 }
188 
189 template <typename T>
190 T QwtArraySeriesData<T>::sample( size_t i ) const
191 {
192  return d_samples[ static_cast<int>( i ) ];
193 }
194 
196 class QWT_EXPORT QwtPointSeriesData: public QwtArraySeriesData<QPointF>
197 {
198 public:
200  const QVector<QPointF> & = QVector<QPointF>() );
201 
202  virtual QRectF boundingRect() const;
203 };
204 
206 class QWT_EXPORT QwtPoint3DSeriesData: public QwtArraySeriesData<QwtPoint3D>
207 {
208 public:
210  const QVector<QwtPoint3D> & = QVector<QwtPoint3D>() );
211  virtual QRectF boundingRect() const;
212 };
213 
215 class QWT_EXPORT QwtIntervalSeriesData: public QwtArraySeriesData<QwtIntervalSample>
216 {
217 public:
219  const QVector<QwtIntervalSample> & = QVector<QwtIntervalSample>() );
220 
221  virtual QRectF boundingRect() const;
222 };
223 
225 class QWT_EXPORT QwtSetSeriesData: public QwtArraySeriesData<QwtSetSample>
226 {
227 public:
229  const QVector<QwtSetSample> & = QVector<QwtSetSample>() );
230 
231  virtual QRectF boundingRect() const;
232 };
233 
237 class QWT_EXPORT QwtTradingChartData: public QwtArraySeriesData<QwtOHLCSample>
238 {
239 public:
241  const QVector<QwtOHLCSample> & = QVector<QwtOHLCSample>() );
242 
243  virtual QRectF boundingRect() const;
244 };
245 
246 QWT_EXPORT QRectF qwtBoundingRect(
247  const QwtSeriesData<QPointF> &, int from = 0, int to = -1 );
248 
249 QWT_EXPORT QRectF qwtBoundingRect(
250  const QwtSeriesData<QwtPoint3D> &, int from = 0, int to = -1 );
251 
252 QWT_EXPORT QRectF qwtBoundingRect(
253  const QwtSeriesData<QwtPointPolar> &, int from = 0, int to = -1 );
254 
255 QWT_EXPORT QRectF qwtBoundingRect(
256  const QwtSeriesData<QwtIntervalSample> &, int from = 0, int to = -1 );
257 
258 QWT_EXPORT QRectF qwtBoundingRect(
259  const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 );
260 
261 QWT_EXPORT QRectF qwtBoundingRect(
262  const QwtSeriesData<QwtOHLCSample> &, int from = 0, int to = -1 );
263 
322 template <typename T, typename LessThan>
323 inline int qwtUpperSampleIndex( const QwtSeriesData<T> &series,
324  double value, LessThan lessThan )
325 {
326  const int indexMax = series.size() - 1;
327 
328  if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) )
329  return -1;
330 
331  int indexMin = 0;
332  int n = indexMax;
333 
334  while ( n > 0 )
335  {
336  const int half = n >> 1;
337  const int indexMid = indexMin + half;
338 
339  if ( lessThan( value, series.sample( indexMid ) ) )
340  {
341  n = half;
342  }
343  else
344  {
345  indexMin = indexMid + 1;
346  n -= half + 1;
347  }
348  }
349 
350  return indexMin;
351 }
352 
353 #endif