Qwt User's Guide 6.2.0

qwt_series_data.cpp
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 #include "qwt_series_data.h"
11 #include "qwt_point_polar.h"
12
13 static inline QRectF qwtBoundingRect( const QPointF& sample )
14 {
15 return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
16 }
17
18 static inline QRectF qwtBoundingRect( const QwtPoint3D& sample )
19 {
20 return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
21 }
22
23 static inline QRectF qwtBoundingRect( const QwtPointPolar& sample )
24 {
25 return QRectF( sample.azimuth(), sample.radius(), 0.0, 0.0 );
26 }
27
28 static inline QRectF qwtBoundingRect( const QwtIntervalSample& sample )
29 {
30 return QRectF( sample.interval.minValue(), sample.value,
31 sample.interval.maxValue() - sample.interval.minValue(), 0.0 );
32 }
33
34 static inline QRectF qwtBoundingRect( const QwtSetSample& sample )
35 {
36 if ( sample.set.empty() )
37 return QRectF( sample.value, 0.0, 0.0, -1.0 );
38
39 double minY = sample.set[0];
40 double maxY = sample.set[0];
41
42 for ( int i = 1; i < sample.set.size(); i++ )
43 {
44 if ( sample.set[i] < minY )
45 minY = sample.set[i];
46
47 if ( sample.set[i] > maxY )
48 maxY = sample.set[i];
49 }
50
51 return QRectF( sample.value, minY, 0.0, maxY - minY );
52 }
53
54 static inline QRectF qwtBoundingRect( const QwtOHLCSample& sample )
55 {
56 const QwtInterval interval = sample.boundingInterval();
57 return QRectF( interval.minValue(), sample.time, interval.width(), 0.0 );
58 }
59
60 static inline QRectF qwtBoundingRect( const QwtVectorFieldSample& sample )
61 {
62 /*
63 When displaying a sample as an arrow its length will be
64 proportional to the magnitude - but not the same.
65 As the factor between length and magnitude is not known
66 we can't include vx/vy into the bounding rectangle.
67 */
68
69 return QRectF( sample.x, sample.y, 0, 0 );
70 }
71
84 template< class T >
85 QRectF qwtBoundingRectT( const QwtSeriesData< T >& series, int from, int to )
86 {
87 QRectF boundingRect( 1.0, 1.0, -2.0, -2.0 ); // invalid;
88
89 if ( from < 0 )
90 from = 0;
91
92 if ( to < 0 )
93 to = series.size() - 1;
94
95 if ( to < from )
96 return boundingRect;
97
98 int i;
99 for ( i = from; i <= to; i++ )
100 {
101 const QRectF rect = qwtBoundingRect( series.sample( i ) );
102 if ( rect.width() >= 0.0 && rect.height() >= 0.0 )
103 {
104 boundingRect = rect;
105 i++;
106 break;
107 }
108 }
109
110 for ( ; i <= to; i++ )
111 {
112 const QRectF rect = qwtBoundingRect( series.sample( i ) );
113 if ( rect.width() >= 0.0 && rect.height() >= 0.0 )
114 {
115 boundingRect.setLeft( qMin( boundingRect.left(), rect.left() ) );
116 boundingRect.setRight( qMax( boundingRect.right(), rect.right() ) );
117 boundingRect.setTop( qMin( boundingRect.top(), rect.top() ) );
118 boundingRect.setBottom( qMax( boundingRect.bottom(), rect.bottom() ) );
119 }
120 }
121
122 return boundingRect;
123 }
124
136 QRectF qwtBoundingRect( const QwtSeriesData< QPointF >& series, int from, int to )
137 {
138 return qwtBoundingRectT< QPointF >( series, from, to );
139 }
140
152 QRectF qwtBoundingRect(
153 const QwtSeriesData< QwtPoint3D >& series, int from, int to )
154 {
155 return qwtBoundingRectT< QwtPoint3D >( series, from, to );
156 }
157
172 QRectF qwtBoundingRect(
173 const QwtSeriesData< QwtPointPolar >& series, int from, int to )
174 {
175 return qwtBoundingRectT< QwtPointPolar >( series, from, to );
176 }
177
189 QRectF qwtBoundingRect(
190 const QwtSeriesData< QwtIntervalSample >& series, int from, int to )
191 {
192 return qwtBoundingRectT< QwtIntervalSample >( series, from, to );
193 }
194
206 QRectF qwtBoundingRect(
207 const QwtSeriesData< QwtOHLCSample >& series, int from, int to )
208 {
209 return qwtBoundingRectT< QwtOHLCSample >( series, from, to );
210 }
211
223 QRectF qwtBoundingRect(
224 const QwtSeriesData< QwtSetSample >& series, int from, int to )
225 {
226 return qwtBoundingRectT< QwtSetSample >( series, from, to );
227 }
228
240 QRectF qwtBoundingRect(
241 const QwtSeriesData< QwtVectorFieldSample >& series, int from, int to )
242 {
243 return qwtBoundingRectT< QwtVectorFieldSample >( series, from, to );
244 }
245
250 QwtPointSeriesData::QwtPointSeriesData( const QVector< QPointF >& samples )
251 : QwtArraySeriesData< QPointF >( samples )
252 {
253 }
254
263 QRectF QwtPointSeriesData::boundingRect() const
264 {
265 if ( cachedBoundingRect.width() < 0.0 )
266 cachedBoundingRect = qwtBoundingRect( *this );
267
268 return cachedBoundingRect;
269 }
270
275 QwtPoint3DSeriesData::QwtPoint3DSeriesData(
276 const QVector< QwtPoint3D >& samples )
277 : QwtArraySeriesData< QwtPoint3D >( samples )
278 {
279 }
280
289 QRectF QwtPoint3DSeriesData::boundingRect() const
290 {
291 if ( cachedBoundingRect.width() < 0.0 )
292 cachedBoundingRect = qwtBoundingRect( *this );
293
294 return cachedBoundingRect;
295 }
296
301 QwtIntervalSeriesData::QwtIntervalSeriesData(
302 const QVector< QwtIntervalSample >& samples )
303 : QwtArraySeriesData< QwtIntervalSample >( samples )
304 {
305 }
306
315 QRectF QwtIntervalSeriesData::boundingRect() const
316 {
317 if ( cachedBoundingRect.width() < 0.0 )
318 cachedBoundingRect = qwtBoundingRect( *this );
319
320 return cachedBoundingRect;
321 }
322
327 QwtVectorFieldData::QwtVectorFieldData(
328 const QVector< QwtVectorFieldSample >& samples )
329 : QwtArraySeriesData< QwtVectorFieldSample >( samples )
330 {
331 }
332
341 QRectF QwtVectorFieldData::boundingRect() const
342 {
343 if ( cachedBoundingRect.width() < 0.0 )
344 cachedBoundingRect = qwtBoundingRect( *this );
345
346 return cachedBoundingRect;
347 }
348
353 QwtSetSeriesData::QwtSetSeriesData( const QVector< QwtSetSample >& samples )
354 : QwtArraySeriesData< QwtSetSample >( samples )
355 {
356 }
357
366 QRectF QwtSetSeriesData::boundingRect() const
367 {
368 if ( cachedBoundingRect.width() < 0.0 )
369 cachedBoundingRect = qwtBoundingRect( *this );
370
371 return cachedBoundingRect;
372 }
373
378 QwtTradingChartData::QwtTradingChartData( const QVector< QwtOHLCSample >& samples )
379 : QwtArraySeriesData< QwtOHLCSample >( samples )
380 {
381 }
382
391 QRectF QwtTradingChartData::boundingRect() const
392 {
393 if ( cachedBoundingRect.width() < 0.0 )
394 cachedBoundingRect = qwtBoundingRect( *this );
395
396 return cachedBoundingRect;
397 }
QVector
Definition: qwt_clipper.h:23
QwtArraySeriesData
Template class for data, that is organized as QVector.
Definition: qwt_series_data.h:136
QwtInterval
A class representing an interval.
Definition: qwt_interval.h:23
QwtInterval::minValue
double minValue() const
Definition: qwt_interval.h:192
QwtInterval::width
double width() const
Return the width of an interval.
Definition: qwt_interval.h:227
QwtInterval::maxValue
double maxValue() const
Definition: qwt_interval.h:198
QwtIntervalSample
A sample of the types (x1-x2, y) or (x, y1-y2)
Definition: qwt_samples.h:21
QwtIntervalSample::interval
QwtInterval interval
Interval.
Definition: qwt_samples.h:34
QwtIntervalSample::value
double value
Value.
Definition: qwt_samples.h:31
QwtIntervalSeriesData::boundingRect
virtual QRectF boundingRect() const override
Calculate the bounding rectangle.
Definition: qwt_series_data.cpp:315
QwtIntervalSeriesData::QwtIntervalSeriesData
QwtIntervalSeriesData(const QVector< QwtIntervalSample > &=QVector< QwtIntervalSample >())
Definition: qwt_series_data.cpp:301
QwtOHLCSample
Open-High-Low-Close sample used in financial charts.
Definition: qwt_samples.h:144
QwtOHLCSample::time
double time
Definition: qwt_samples.h:158
QwtOHLCSample::boundingInterval
QwtInterval boundingInterval() const
Calculate the bounding interval of the OHLC values.
Definition: qwt_samples.h:220
QwtPoint3D
QwtPoint3D class defines a 3D point in double coordinates.
Definition: qwt_point_3d.h:23
QwtPoint3D::y
double y() const
Definition: qwt_point_3d.h:109
QwtPoint3D::x
double x() const
Definition: qwt_point_3d.h:103
QwtPoint3DSeriesData::QwtPoint3DSeriesData
QwtPoint3DSeriesData(const QVector< QwtPoint3D > &=QVector< QwtPoint3D >())
Definition: qwt_series_data.cpp:275
QwtPoint3DSeriesData::boundingRect
virtual QRectF boundingRect() const override
Calculate the bounding rectangle.
Definition: qwt_series_data.cpp:289
QwtPointPolar
A point in polar coordinates.
Definition: qwt_point_polar.h:29
QwtPointPolar::radius
double radius() const
Returns the radius.
Definition: qwt_point_polar.h:102
QwtPointPolar::azimuth
double azimuth() const
Returns the azimuth.
Definition: qwt_point_polar.h:108
QwtPointSeriesData::boundingRect
virtual QRectF boundingRect() const override
Calculate the bounding rectangle.
Definition: qwt_series_data.cpp:263
QwtPointSeriesData::QwtPointSeriesData
QwtPointSeriesData(const QVector< QPointF > &=QVector< QPointF >())
Definition: qwt_series_data.cpp:250
QwtSeriesData
Abstract interface for iterating over samples.
Definition: qwt_series_data.h:50
QwtSeriesData::size
virtual size_t size() const =0
QwtSeriesData< QPointF >::cachedBoundingRect
QRectF cachedBoundingRect
Can be used to cache a calculated bounding rectangle.
Definition: qwt_series_data.h:106
QwtSeriesData::sample
virtual T sample(size_t i) const =0
QwtSetSample
A sample of the types (x1...xn, y) or (x, y1..yn)
Definition: qwt_samples.h:74
QwtSetSample::value
double value
value
Definition: qwt_samples.h:85
QwtSetSample::set
QVector< double > set
Vector of values associated to value.
Definition: qwt_samples.h:88
QwtSetSeriesData::boundingRect
virtual QRectF boundingRect() const override
Calculate the bounding rectangle.
Definition: qwt_series_data.cpp:366
QwtSetSeriesData::QwtSetSeriesData
QwtSetSeriesData(const QVector< QwtSetSample > &=QVector< QwtSetSample >())
Definition: qwt_series_data.cpp:353
QwtTradingChartData::QwtTradingChartData
QwtTradingChartData(const QVector< QwtOHLCSample > &=QVector< QwtOHLCSample >())
Definition: qwt_series_data.cpp:378
QwtTradingChartData::boundingRect
virtual QRectF boundingRect() const override
Calculate the bounding rectangle.
Definition: qwt_series_data.cpp:391
QwtVectorFieldData::QwtVectorFieldData
QwtVectorFieldData(const QVector< QwtVectorFieldSample > &=QVector< QwtVectorFieldSample >())
Definition: qwt_series_data.cpp:327
QwtVectorFieldData::boundingRect
virtual QRectF boundingRect() const override
Calculate the bounding rectangle.
Definition: qwt_series_data.cpp:341
QwtVectorFieldSample
Sample used in vector fields.
Definition: qwt_samples.h:244
QwtVectorFieldSample::y
double y
y coordinate of the position
Definition: qwt_samples.h:260
QwtVectorFieldSample::x
double x
x coordinate of the position
Definition: qwt_samples.h:257