qwt_series_data.h
Go to the documentation of this file.
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 >
49 class QwtSeriesData
50 {
51  public:
53  QwtSeriesData();
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:
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 
145  explicit QwtArraySeriesData( const QVector< T >& samples );
146 
151  void setSamples( const QVector< T >& samples );
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 
210 {
211  public:
214 
215  virtual QRectF boundingRect() const QWT_OVERRIDE;
216 };
217 
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 
271  const QwtSeriesData< QPointF >&, int from = 0, int to = -1 );
272 
274  const QwtSeriesData< QwtPoint3D >&, int from = 0, int to = -1 );
275 
277  const QwtSeriesData< QwtPointPolar >&, int from = 0, int to = -1 );
278 
280  const QwtSeriesData< QwtIntervalSample >&, int from = 0, int to = -1 );
281 
283  const QwtSeriesData< QwtSetSample >&, int from = 0, int to = -1 );
284 
286  const QwtSeriesData< QwtOHLCSample >&, int from = 0, int to = -1 );
287 
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
virtual void setRectOfInterest(const QRectF &rect)
A point in polar coordinates.
QwtSeriesData()
Constructor.
QWT_EXPORT QRectF qwtBoundingRect(const QwtSeriesData< QPointF > &, int from=0, int to=-1)
Calculate the bounding rectangle of a series subset.
Interface for iterating over an array of samples.
virtual QRectF boundingRect() const =0
#define QWT_EXPORT
Definition: qwt_global.h:38
Abstract interface for iterating over samples.
const QVector< T > samples() const
Interface for iterating over an array of 3D points.
QVector< T > m_samples
Vector of samples.
virtual size_t size() const QWT_OVERRIDE
QwtArraySeriesData()
Constructor.
QwtSeriesData< T > & operator=(const QwtSeriesData< T > &)
QRectF cachedBoundingRect
Can be used to cache a calculated bounding rectangle.
virtual ~QwtSeriesData()
Destructor.
virtual T sample(size_t index) const QWT_OVERRIDE
Template class for data, that is organized as QVector.
void setSamples(const QVector< T > &samples)
Interface for iterating over an array of intervals.
virtual size_t size() const =0
virtual T sample(size_t i) const =0
Definition: core.h:1131
Interface for iterating over an array of vector field samples.
Interface for iterating over an array of points.
#define QWT_OVERRIDE
Definition: qwt_global.h:53
int qwtUpperSampleIndex(const QwtSeriesData< T > &series, double value, LessThan lessThan)


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:01:39