qwt_series_data.h
Go to the documentation of this file.
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 
56 #ifndef QWT_PYTHON_WRAPPER
57 
59  virtual size_t size() const = 0;
60 
66  virtual T sample( size_t i ) const = 0;
67 
80  virtual QRectF boundingRect() const = 0;
81 
82 #else
83  // Needed for generating the python bindings, but not for using them !
84  virtual size_t size() const { return 0; }
85  virtual T sample( size_t i ) const { return T(); }
86  virtual QRectF boundingRect() const { return d_boundingRect; }
87 #endif
88 
100  virtual void setRectOfInterest( const QRectF &rect );
101 
102 protected:
104  mutable QRectF d_boundingRect;
105 
106 private:
108 };
109 
110 template <typename T>
112  d_boundingRect( 0.0, 0.0, -1.0, -1.0 )
113 {
114 }
115 
116 template <typename T>
118 {
119 }
120 
121 template <typename T>
123 {
124 }
125 
132 template <typename T>
134 {
135 public:
138 
143  explicit QwtArraySeriesData( const QVector<T> &samples );
144 
149  void setSamples( const QVector<T> &samples );
150 
152  const QVector<T> samples() const;
153 
155  virtual size_t size() const;
156 
163  virtual T sample( size_t index ) const;
164 
165 protected:
167  QVector<T> d_samples;
168 };
169 
170 template <typename T>
172 {
173 }
174 
175 template <typename T>
176 QwtArraySeriesData<T>::QwtArraySeriesData( const QVector<T> &samples ):
177  d_samples( samples )
178 {
179 }
180 
181 template <typename T>
183 {
184  QwtSeriesData<T>::d_boundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
185  d_samples = samples;
186 }
187 
188 template <typename T>
189 const QVector<T> QwtArraySeriesData<T>::samples() const
190 {
191  return d_samples;
192 }
193 
194 template <typename T>
196 {
197  return d_samples.size();
198 }
199 
200 template <typename T>
201 T QwtArraySeriesData<T>::sample( size_t i ) const
202 {
203  return d_samples[ static_cast<int>( i ) ];
204 }
205 
208 {
209 public:
211  const QVector<QPointF> & = QVector<QPointF>() );
212 
213  virtual QRectF boundingRect() const;
214 };
215 
218 {
219 public:
221  const QVector<QwtPoint3D> & = QVector<QwtPoint3D>() );
222  virtual QRectF boundingRect() const;
223 };
224 
226 class QWT_EXPORT QwtIntervalSeriesData: public QwtArraySeriesData<QwtIntervalSample>
227 {
228 public:
230  const QVector<QwtIntervalSample> & = QVector<QwtIntervalSample>() );
231 
232  virtual QRectF boundingRect() const;
233 };
234 
236 class QWT_EXPORT QwtSetSeriesData: public QwtArraySeriesData<QwtSetSample>
237 {
238 public:
240  const QVector<QwtSetSample> & = QVector<QwtSetSample>() );
241 
242  virtual QRectF boundingRect() const;
243 };
244 
249 {
250 public:
252  const QVector<QwtOHLCSample> & = QVector<QwtOHLCSample>() );
253 
254  virtual QRectF boundingRect() const;
255 };
256 
258  const QwtSeriesData<QPointF> &, int from = 0, int to = -1 );
259 
261  const QwtSeriesData<QwtPoint3D> &, int from = 0, int to = -1 );
262 
264  const QwtSeriesData<QwtPointPolar> &, int from = 0, int to = -1 );
265 
267  const QwtSeriesData<QwtIntervalSample> &, int from = 0, int to = -1 );
268 
270  const QwtSeriesData<QwtSetSample> &, int from = 0, int to = -1 );
271 
273  const QwtSeriesData<QwtOHLCSample> &, int from = 0, int to = -1 );
274 
333 template <typename T, typename LessThan>
334 inline int qwtUpperSampleIndex( const QwtSeriesData<T> &series,
335  double value, LessThan lessThan )
336 {
337  const int indexMax = series.size() - 1;
338 
339  if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) )
340  return -1;
341 
342  int indexMin = 0;
343  int n = indexMax;
344 
345  while ( n > 0 )
346  {
347  const int half = n >> 1;
348  const int indexMid = indexMin + half;
349 
350  if ( lessThan( value, series.sample( indexMid ) ) )
351  {
352  n = half;
353  }
354  else
355  {
356  indexMin = indexMid + 1;
357  n -= half + 1;
358  }
359  }
360 
361  return indexMin;
362 }
363 
364 #endif
virtual void setRectOfInterest(const QRectF &rect)
QwtSeriesData()
Constructor.
QRectF d_boundingRect
Can be used to cache a calculated bounding rectangle.
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
QVector< T > d_samples
Vector of samples.
#define QWT_EXPORT
Definition: qwt_global.h:38
const QVector< T > samples() const
Abstract interface for iterating over samples.
Interface for iterating over an array of 3D points.
virtual T sample(size_t index) const
virtual size_t size() const
QwtArraySeriesData()
Constructor.
QwtSeriesData< T > & operator=(const QwtSeriesData< T > &)
virtual ~QwtSeriesData()
Destructor.
size_t to
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
int i
size_t from
Interface for iterating over an array of points.
int n
int qwtUpperSampleIndex(const QwtSeriesData< T > &series, double value, LessThan lessThan)


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17