Qwt User's Guide 6.3.0

Loading...
Searching...
No Matches
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 >
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
70#else
71 // Needed for generating the python bindings, but not for using them !
72 virtual size_t size() const { return 0; }
73 virtual T sample( size_t i ) const { return T(); }
74#endif
75
80 inline T firstSample() const { return sample( 0 ); }
81
86 inline T lastSample() const { return sample( size() - 1 ); }
87
100 virtual QRectF boundingRect() const
101 {
102 if ( cachedBoundingRect.width() < 0.0 )
103 cachedBoundingRect = qwtBoundingRect( *this );
104
105 return cachedBoundingRect;
106 }
107
119 virtual void setRectOfInterest( const QRectF& rect );
120
121 protected:
123 mutable QRectF cachedBoundingRect;
124
125 private:
126 QwtSeriesData< T >& operator=( const QwtSeriesData< T >& );
127};
128
129 template< typename T >
130 QwtSeriesData< T >::QwtSeriesData()
131 : cachedBoundingRect( 0.0, 0.0, -1.0, -1.0 )
132{
133}
134
135 template< typename T >
136 QwtSeriesData< T >::~QwtSeriesData()
137{
138}
139
140 template< typename T >
141 void QwtSeriesData< T >::setRectOfInterest( const QRectF& )
142{
143}
144
151 template< typename T >
152 class QwtArraySeriesData : public QwtSeriesData< T >
153{
154 public:
156 QwtArraySeriesData();
157
162 explicit QwtArraySeriesData( const QVector< T >& samples );
163
168 void setSamples( const QVector< T >& samples );
169
171 const QVector< T > samples() const;
172
174 virtual size_t size() const QWT_OVERRIDE;
175
182 virtual T sample( size_t index ) const QWT_OVERRIDE;
183
184 protected:
186 QVector< T > m_samples;
187};
188
189 template< typename T >
190 QwtArraySeriesData< T >::QwtArraySeriesData()
191{
192}
193
194 template< typename T >
195 QwtArraySeriesData< T >::QwtArraySeriesData( const QVector< T >& samples )
196 : m_samples( samples )
197{
198}
199
200 template< typename T >
201 void QwtArraySeriesData< T >::setSamples( const QVector< T >& samples )
202{
203 QwtSeriesData< T >::cachedBoundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
204 m_samples = samples;
205}
206
207 template< typename T >
208 const QVector< T > QwtArraySeriesData< T >::samples() const
209{
210 return m_samples;
211}
212
213 template< typename T >
214 size_t QwtArraySeriesData< T >::size() const
215{
216 return m_samples.size();
217}
218
219 template< typename T >
220T QwtArraySeriesData< T >::sample( size_t i ) const
221{
222 return m_samples[ static_cast< int >( i ) ];
223}
224
226 typedef QwtArraySeriesData< QPointF > QwtPointSeriesData;
227
229 typedef QwtArraySeriesData< QwtPoint3D > QwtPoint3DSeriesData;
230
232 typedef QwtArraySeriesData< QwtIntervalSample > QwtIntervalSeriesData;
233
235 typedef QwtArraySeriesData< QwtSetSample > QwtSetSeriesData;
236
238 typedef QwtArraySeriesData< QwtVectorFieldSample > QwtVectorFieldData;
239
241 typedef QwtArraySeriesData< QwtOHLCSample > QwtTradingChartData;
242
243QWT_EXPORT QRectF qwtBoundingRect(
244 const QwtSeriesData< QPointF >&, int from = 0, int to = -1 );
245
246QWT_EXPORT QRectF qwtBoundingRect(
247 const QwtSeriesData< QwtPoint3D >&, int from = 0, int to = -1 );
248
249QWT_EXPORT QRectF qwtBoundingRect(
250 const QwtSeriesData< QwtPointPolar >&, int from = 0, int to = -1 );
251
252QWT_EXPORT QRectF qwtBoundingRect(
253 const QwtSeriesData< QwtIntervalSample >&, int from = 0, int to = -1 );
254
255QWT_EXPORT QRectF qwtBoundingRect(
256 const QwtSeriesData< QwtSetSample >&, int from = 0, int to = -1 );
257
258QWT_EXPORT QRectF qwtBoundingRect(
259 const QwtSeriesData< QwtOHLCSample >&, int from = 0, int to = -1 );
260
261QWT_EXPORT QRectF qwtBoundingRect(
262 const QwtSeriesData< QwtVectorFieldSample >&, int from = 0, int to = -1 );
263
319 template< typename T, typename LessThan >
320 inline int qwtUpperSampleIndex( const QwtSeriesData< T >& series,
321 double value, LessThan lessThan )
322{
323 const int indexMax = series.size() - 1;
324
325 if ( indexMax < 0 || !lessThan( value, series.sample( indexMax ) ) )
326 return -1;
327
328 int indexMin = 0;
329 int n = indexMax;
330
331 while ( n > 0 )
332 {
333 const int half = n >> 1;
334 const int indexMid = indexMin + half;
335
336 if ( lessThan( value, series.sample( indexMid ) ) )
337 {
338 n = half;
339 }
340 else
341 {
342 indexMin = indexMid + 1;
343 n -= half + 1;
344 }
345 }
346
347 return indexMin;
348}
349
350#endif
QVector
Definition qwt_clipper.h:23
QwtArraySeriesData
Template class for data, that is organized as QVector.
Definition qwt_series_data.h:153
QwtArraySeriesData::sample
virtual T sample(size_t index) const override
Definition qwt_series_data.h:220
QwtArraySeriesData::size
virtual size_t size() const override
Definition qwt_series_data.h:214
QwtArraySeriesData::QwtArraySeriesData
QwtArraySeriesData()
Constructor.
Definition qwt_series_data.h:190
QwtArraySeriesData::setSamples
void setSamples(const QVector< T > &samples)
Definition qwt_series_data.h:201
QwtArraySeriesData::m_samples
QVector< T > m_samples
Vector of samples.
Definition qwt_series_data.h:186
QwtArraySeriesData::samples
const QVector< T > samples() const
Definition qwt_series_data.h:208
QwtPointPolar
A point in polar coordinates.
Definition qwt_point_polar.h:29
QwtSeriesData
Abstract interface for iterating over samples.
Definition qwt_series_data.h:50
QwtSeriesData::setRectOfInterest
virtual void setRectOfInterest(const QRectF &rect)
Definition qwt_series_data.h:141
QwtSeriesData::size
virtual size_t size() const =0
QwtSeriesData::QwtSeriesData
QwtSeriesData()
Constructor.
Definition qwt_series_data.h:130
QwtSeriesData::~QwtSeriesData
virtual ~QwtSeriesData()
Destructor.
Definition qwt_series_data.h:136
QwtSeriesData::cachedBoundingRect
QRectF cachedBoundingRect
Can be used to cache a calculated bounding rectangle.
Definition qwt_series_data.h:123
QwtSeriesData::lastSample
T lastSample() const
Definition qwt_series_data.h:86
QwtSeriesData::boundingRect
virtual QRectF boundingRect() const
Definition qwt_series_data.h:100
QwtSeriesData::sample
virtual T sample(size_t i) const =0
QwtSeriesData::firstSample
T firstSample() const
Definition qwt_series_data.h:80