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
20class QwtPointPolar;
21
48template< 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
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
129template< typename T >
131 : cachedBoundingRect( 0.0, 0.0, -1.0, -1.0 )
132{
133}
134
135template< typename T >
139
140template< typename T >
142{
143}
144
151template< typename T >
153{
154 public:
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:
187};
188
189template< typename T >
193
194template< typename T >
196 : m_samples( samples )
197{
198}
199
200template< typename T >
202{
203 QwtSeriesData< T >::cachedBoundingRect = QRectF( 0.0, 0.0, -1.0, -1.0 );
204 m_samples = samples;
205}
206
207template< typename T >
209{
210 return m_samples;
211}
212
213template< typename T >
215{
216 return m_samples.size();
217}
218
219template< typename T >
221{
222 return m_samples[ static_cast< int >( i ) ];
223}
224
227
230
233
236
239
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
319template< typename T, typename LessThan >
320inline 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
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)
QVector< T > m_samples
Vector of samples.
const QVector< T > samples() const
A point in polar coordinates.
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.
T lastSample() const
virtual QRectF boundingRect() const
virtual T sample(size_t i) const =0
T firstSample() const