qwt_series_data.cpp
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 #include "qwt_series_data.h"
11 #include "qwt_math.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  double minY = sample.set[0];
37  double maxY = sample.set[0];
38 
39  for ( int i = 1; i < sample.set.size(); i++ )
40  {
41  if ( sample.set[i] < minY )
42  minY = sample.set[i];
43  if ( sample.set[i] > maxY )
44  maxY = sample.set[i];
45  }
46 
47  double minX = sample.value;
48  double maxX = sample.value;
49 
50  return QRectF( minX, minY, maxX - minX, maxY - minY );
51 }
52 
53 static inline QRectF qwtBoundingRect( const QwtOHLCSample &sample )
54 {
55  const QwtInterval interval = sample.boundingInterval();
56  return QRectF( interval.minValue(), sample.time, interval.width(), 0.0 );
57 }
58 
71 template <class T>
73  const QwtSeriesData<T>& series, int from, int to )
74 {
75  QRectF boundingRect( 1.0, 1.0, -2.0, -2.0 ); // invalid;
76 
77  if ( from < 0 )
78  from = 0;
79 
80  if ( to < 0 )
81  to = series.size() - 1;
82 
83  if ( to < from )
84  return boundingRect;
85 
86  int i;
87  for ( i = from; i <= to; i++ )
88  {
89  const QRectF rect = qwtBoundingRect( series.sample( i ) );
90  if ( rect.width() >= 0.0 && rect.height() >= 0.0 )
91  {
92  boundingRect = rect;
93  i++;
94  break;
95  }
96  }
97 
98  for ( ; i <= to; i++ )
99  {
100  const QRectF rect = qwtBoundingRect( series.sample( i ) );
101  if ( rect.width() >= 0.0 && rect.height() >= 0.0 )
102  {
103  boundingRect.setLeft( qMin( boundingRect.left(), rect.left() ) );
104  boundingRect.setRight( qMax( boundingRect.right(), rect.right() ) );
105  boundingRect.setTop( qMin( boundingRect.top(), rect.top() ) );
106  boundingRect.setBottom( qMax( boundingRect.bottom(), rect.bottom() ) );
107  }
108  }
109 
110  return boundingRect;
111 }
112 
125  const QwtSeriesData<QPointF> &series, int from, int to )
126 {
127  return qwtBoundingRectT<QPointF>( series, from, to );
128 }
129 
142  const QwtSeriesData<QwtPoint3D> &series, int from, int to )
143 {
144  return qwtBoundingRectT<QwtPoint3D>( series, from, to );
145 }
146 
162  const QwtSeriesData<QwtPointPolar> &series, int from, int to )
163 {
164  return qwtBoundingRectT<QwtPointPolar>( series, from, to );
165 }
166 
179  const QwtSeriesData<QwtIntervalSample>& series, int from, int to )
180 {
181  return qwtBoundingRectT<QwtIntervalSample>( series, from, to );
182 }
183 
196  const QwtSeriesData<QwtOHLCSample>& series, int from, int to )
197 {
198  return qwtBoundingRectT<QwtOHLCSample>( series, from, to );
199 }
200 
213  const QwtSeriesData<QwtSetSample>& series, int from, int to )
214 {
215  return qwtBoundingRectT<QwtSetSample>( series, from, to );
216 }
217 
223  const QVector<QPointF> &samples ):
224  QwtArraySeriesData<QPointF>( samples )
225 {
226 }
227 
237 {
238  if ( d_boundingRect.width() < 0.0 )
239  d_boundingRect = qwtBoundingRect( *this );
240 
241  return d_boundingRect;
242 }
243 
249  const QVector<QwtPoint3D> &samples ):
250  QwtArraySeriesData<QwtPoint3D>( samples )
251 {
252 }
253 
263 {
264  if ( d_boundingRect.width() < 0.0 )
265  d_boundingRect = qwtBoundingRect( *this );
266 
267  return d_boundingRect;
268 }
269 
275  const QVector<QwtIntervalSample> &samples ):
277 {
278 }
279 
289 {
290  if ( d_boundingRect.width() < 0.0 )
291  d_boundingRect = qwtBoundingRect( *this );
292 
293  return d_boundingRect;
294 }
295 
301  const QVector<QwtSetSample> &samples ):
302  QwtArraySeriesData<QwtSetSample>( samples )
303 {
304 }
305 
315 {
316  if ( d_boundingRect.width() < 0.0 )
317  d_boundingRect = qwtBoundingRect( *this );
318 
319  return d_boundingRect;
320 }
321 
327  const QVector<QwtOHLCSample> &samples ):
329 {
330 }
331 
341 {
342  if ( d_boundingRect.width() < 0.0 )
343  d_boundingRect = qwtBoundingRect( *this );
344 
345  return d_boundingRect;
346 }
Open-High-Low-Close sample used in financial charts.
Definition: qwt_samples.h:146
QwtTradingChartData(const QVector< QwtOHLCSample > &=QVector< QwtOHLCSample >())
A point in polar coordinates.
QwtIntervalSeriesData(const QVector< QwtIntervalSample > &=QVector< QwtIntervalSample >())
QwtInterval boundingInterval() const
Calculate the bounding interval of the OHLC values.
Definition: qwt_samples.h:224
QRectF d_boundingRect
Can be used to cache a calculated bounding rectangle.
double value
value
Definition: qwt_samples.h:88
A class representing an interval.
Definition: qwt_interval.h:26
virtual QRectF boundingRect() const
Calculate the bounding rectangle.
const QVector< QPointF > samples() const
double minValue() const
Definition: qwt_interval.h:193
Abstract interface for iterating over samples.
double radius() const
Returns the radius.
double y() const
Definition: qwt_point_3d.h:122
virtual QRectF boundingRect() const
Calculate the bounding rectangle.
double azimuth() const
Returns the azimuth.
double maxValue() const
Definition: qwt_interval.h:199
A sample of the types (x1...xn, y) or (x, y1..yn)
Definition: qwt_samples.h:76
QwtPoint3D class defines a 3D point in double coordinates.
Definition: qwt_point_3d.h:24
virtual QRectF boundingRect() const
Calculate the bounding rectangle.
A sample of the types (x1-x2, y) or (x, y1-y2)
Definition: qwt_samples.h:19
static QRectF qwtBoundingRect(const QPointF &sample)
QwtSetSeriesData(const QVector< QwtSetSample > &=QVector< QwtSetSample >())
Template class for data, that is organized as QVector.
double x() const
Definition: qwt_point_3d.h:116
virtual QRectF boundingRect() const
Calculate the bounding rectangle.
virtual size_t size() const =0
virtual T sample(size_t i) const =0
QwtPointSeriesData(const QVector< QPointF > &=QVector< QPointF >())
double value
Value.
Definition: qwt_samples.h:30
QRectF qwtBoundingRectT(const QwtSeriesData< T > &series, int from, int to)
Calculate the bounding rectangle of a series subset.
QwtPoint3DSeriesData(const QVector< QwtPoint3D > &=QVector< QwtPoint3D >())
int i
double width() const
Return the width of an interval.
Definition: qwt_interval.h:228
virtual QRectF boundingRect() const
Calculate the bounding rectangle.
QVector< double > set
Vector of values associated to value.
Definition: qwt_samples.h:91
QwtInterval interval
Interval.
Definition: qwt_samples.h:33


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