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 >
50 {
51  public:
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 >
114  : cachedBoundingRect( 0.0, 0.0, -1.0, -1.0 )
115 {
116 }
117 
118 template< typename T >
120 {
121 }
122 
123 template< typename T >
125 {
126 }
127 
134 template< typename T >
136 {
137  public:
140 
146 
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:
170 };
171 
172 template< typename T >
174 {
175 }
176 
177 template< typename T >
179  : m_samples( samples )
180 {
181 }
182 
183 template< typename T >
185 {
186  QwtSeriesData< T >::cachedBoundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
187  m_samples = samples;
188 }
189 
190 template< typename T >
192 {
193  return m_samples;
194 }
195 
196 template< typename T >
198 {
199  return m_samples.size();
200 }
201 
202 template< typename T >
204 {
205  return m_samples[ static_cast< int >( i ) ];
206 }
207 
209 class QWT_EXPORT QwtPointSeriesData : public QwtArraySeriesData< QPointF >
210 {
211  public:
214 
215  virtual QRectF boundingRect() const QWT_OVERRIDE;
216 };
217 
219 class QWT_EXPORT QwtPoint3DSeriesData : public QwtArraySeriesData< QwtPoint3D >
220 {
221  public:
224 
225  virtual QRectF boundingRect() const QWT_OVERRIDE;
226 };
227 
229 class QWT_EXPORT QwtIntervalSeriesData : public QwtArraySeriesData< QwtIntervalSample >
230 {
231  public:
234 
235  virtual QRectF boundingRect() const QWT_OVERRIDE;
236 };
237 
239 class QWT_EXPORT QwtSetSeriesData : public QwtArraySeriesData< QwtSetSample >
240 {
241  public:
244 
245  virtual QRectF boundingRect() const QWT_OVERRIDE;
246 };
247 
249 class QWT_EXPORT QwtVectorFieldData : public QwtArraySeriesData< QwtVectorFieldSample >
250 {
251  public:
254 
255  virtual QRectF boundingRect() const QWT_OVERRIDE;
256 };
257 
261 class QWT_EXPORT QwtTradingChartData : public QwtArraySeriesData< QwtOHLCSample >
262 {
263  public:
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
Template class for data, that is organized as QVector.
virtual T sample(size_t index) const override
virtual size_t size() const override
QwtArraySeriesData()
Constructor.
void setSamples(const QVector< T > &samples)
QwtArraySeriesData(const QVector< T > &samples)
QVector< T > m_samples
Vector of samples.
const QVector< T > samples() const
Interface for iterating over an array of intervals.
Interface for iterating over an array of 3D points.
A point in polar coordinates.
Interface for iterating over an array of points.
Abstract interface for iterating over samples.
virtual void setRectOfInterest(const QRectF &rect)
virtual size_t size() const =0
QwtSeriesData()
Constructor.
virtual ~QwtSeriesData()
Destructor.
QRectF cachedBoundingRect
Can be used to cache a calculated bounding rectangle.
virtual T sample(size_t i) const =0
virtual QRectF boundingRect() const =0
Interface for iterating over an array of samples.
Interface for iterating over an array of vector field samples.