source: ntrip/trunk/BNC/qwt/qwt_series_data.cpp@ 9383

Last change on this file since 9383 was 9383, checked in by stoecker, 3 years ago

update to qwt verion 6.1.1 to fix build with newer Qt5

File size: 8.6 KB
Line 
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
13static inline QRectF qwtBoundingRect( const QPointF &sample )
14{
15 return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
16}
17
18static inline QRectF qwtBoundingRect( const QwtPoint3D &sample )
19{
20 return QRectF( sample.x(), sample.y(), 0.0, 0.0 );
21}
22
23static inline QRectF qwtBoundingRect( const QwtPointPolar &sample )
24{
25 return QRectF( sample.azimuth(), sample.radius(), 0.0, 0.0 );
26}
27
28static 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
34static 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
54static 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/*!
61 \brief Calculate the bounding rectangle of a series subset
62
63 Slow implementation, that iterates over the series.
64
65 \param series Series
66 \param from Index of the first sample, <= 0 means from the beginning
67 \param to Index of the last sample, < 0 means to the end
68
69 \return Bounding rectangle
70*/
71
72template <class T>
73QRectF qwtBoundingRectT(
74 const QwtSeriesData<T>& series, int from, int to )
75{
76 QRectF boundingRect( 1.0, 1.0, -2.0, -2.0 ); // invalid;
77
78 if ( from < 0 )
79 from = 0;
80
81 if ( to < 0 )
82 to = series.size() - 1;
83
84 if ( to < from )
85 return boundingRect;
86
87 int i;
88 for ( i = from; i <= to; i++ )
89 {
90 const QRectF rect = qwtBoundingRect( series.sample( i ) );
91 if ( rect.width() >= 0.0 && rect.height() >= 0.0 )
92 {
93 boundingRect = rect;
94 i++;
95 break;
96 }
97 }
98
99 for ( ; 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.setLeft( qMin( boundingRect.left(), rect.left() ) );
105 boundingRect.setRight( qMax( boundingRect.right(), rect.right() ) );
106 boundingRect.setTop( qMin( boundingRect.top(), rect.top() ) );
107 boundingRect.setBottom( qMax( boundingRect.bottom(), rect.bottom() ) );
108 }
109 }
110
111 return boundingRect;
112}
113
114/*!
115 \brief Calculate the bounding rectangle of a series subset
116
117 Slow implementation, that iterates over the series.
118
119 \param series Series
120 \param from Index of the first sample, <= 0 means from the beginning
121 \param to Index of the last sample, < 0 means to the end
122
123 \return Bounding rectangle
124*/
125QRectF qwtBoundingRect(
126 const QwtSeriesData<QPointF> &series, int from, int to )
127{
128 return qwtBoundingRectT<QPointF>( series, from, to );
129}
130
131/*!
132 \brief Calculate the bounding rectangle of a series subset
133
134 Slow implementation, that iterates over the series.
135
136 \param series Series
137 \param from Index of the first sample, <= 0 means from the beginning
138 \param to Index of the last sample, < 0 means to the end
139
140 \return Bounding rectangle
141*/
142QRectF qwtBoundingRect(
143 const QwtSeriesData<QwtPoint3D> &series, int from, int to )
144{
145 return qwtBoundingRectT<QwtPoint3D>( series, from, to );
146}
147
148/*!
149 \brief Calculate the bounding rectangle of a series subset
150
151 The horizontal coordinates represent the azimuth, the
152 vertical coordinates the radius.
153
154 Slow implementation, that iterates over the series.
155
156 \param series Series
157 \param from Index of the first sample, <= 0 means from the beginning
158 \param to Index of the last sample, < 0 means to the end
159
160 \return Bounding rectangle
161*/
162QRectF qwtBoundingRect(
163 const QwtSeriesData<QwtPointPolar> &series, int from, int to )
164{
165 return qwtBoundingRectT<QwtPointPolar>( series, from, to );
166}
167
168/*!
169 \brief Calculate the bounding rectangle of a series subset
170
171 Slow implementation, that iterates over the series.
172
173 \param series Series
174 \param from Index of the first sample, <= 0 means from the beginning
175 \param to Index of the last sample, < 0 means to the end
176
177 \return Bounding rectangle
178*/
179QRectF qwtBoundingRect(
180 const QwtSeriesData<QwtIntervalSample>& series, int from, int to )
181{
182 return qwtBoundingRectT<QwtIntervalSample>( series, from, to );
183}
184
185/*!
186 \brief Calculate the bounding rectangle of a series subset
187
188 Slow implementation, that iterates over the series.
189
190 \param series Series
191 \param from Index of the first sample, <= 0 means from the beginning
192 \param to Index of the last sample, < 0 means to the end
193
194 \return Bounding rectangle
195*/
196QRectF qwtBoundingRect(
197 const QwtSeriesData<QwtOHLCSample>& series, int from, int to )
198{
199 return qwtBoundingRectT<QwtOHLCSample>( series, from, to );
200}
201
202/*!
203 \brief Calculate the bounding rectangle of a series subset
204
205 Slow implementation, that iterates over the series.
206
207 \param series Series
208 \param from Index of the first sample, <= 0 means from the beginning
209 \param to Index of the last sample, < 0 means to the end
210
211 \return Bounding rectangle
212*/
213QRectF qwtBoundingRect(
214 const QwtSeriesData<QwtSetSample>& series, int from, int to )
215{
216 return qwtBoundingRectT<QwtSetSample>( series, from, to );
217}
218
219/*!
220 Constructor
221 \param samples Samples
222*/
223QwtPointSeriesData::QwtPointSeriesData(
224 const QVector<QPointF> &samples ):
225 QwtArraySeriesData<QPointF>( samples )
226{
227}
228
229/*!
230 \brief Calculate the bounding rectangle
231
232 The bounding rectangle is calculated once by iterating over all
233 points and is stored for all following requests.
234
235 \return Bounding rectangle
236*/
237QRectF QwtPointSeriesData::boundingRect() const
238{
239 if ( d_boundingRect.width() < 0.0 )
240 d_boundingRect = qwtBoundingRect( *this );
241
242 return d_boundingRect;
243}
244
245/*!
246 Constructor
247 \param samples Samples
248*/
249QwtPoint3DSeriesData::QwtPoint3DSeriesData(
250 const QVector<QwtPoint3D> &samples ):
251 QwtArraySeriesData<QwtPoint3D>( samples )
252{
253}
254
255/*!
256 \brief Calculate the bounding rectangle
257
258 The bounding rectangle is calculated once by iterating over all
259 points and is stored for all following requests.
260
261 \return Bounding rectangle
262*/
263QRectF QwtPoint3DSeriesData::boundingRect() const
264{
265 if ( d_boundingRect.width() < 0.0 )
266 d_boundingRect = qwtBoundingRect( *this );
267
268 return d_boundingRect;
269}
270
271/*!
272 Constructor
273 \param samples Samples
274*/
275QwtIntervalSeriesData::QwtIntervalSeriesData(
276 const QVector<QwtIntervalSample> &samples ):
277 QwtArraySeriesData<QwtIntervalSample>( samples )
278{
279}
280
281/*!
282 \brief Calculate the bounding rectangle
283
284 The bounding rectangle is calculated once by iterating over all
285 points and is stored for all following requests.
286
287 \return Bounding rectangle
288*/
289QRectF QwtIntervalSeriesData::boundingRect() const
290{
291 if ( d_boundingRect.width() < 0.0 )
292 d_boundingRect = qwtBoundingRect( *this );
293
294 return d_boundingRect;
295}
296
297/*!
298 Constructor
299 \param samples Samples
300*/
301QwtSetSeriesData::QwtSetSeriesData(
302 const QVector<QwtSetSample> &samples ):
303 QwtArraySeriesData<QwtSetSample>( samples )
304{
305}
306
307/*!
308 \brief Calculate the bounding rectangle
309
310 The bounding rectangle is calculated once by iterating over all
311 points and is stored for all following requests.
312
313 \return Bounding rectangle
314*/
315QRectF QwtSetSeriesData::boundingRect() const
316{
317 if ( d_boundingRect.width() < 0.0 )
318 d_boundingRect = qwtBoundingRect( *this );
319
320 return d_boundingRect;
321}
322
323/*!
324 Constructor
325 \param samples Samples
326*/
327QwtTradingChartData::QwtTradingChartData(
328 const QVector<QwtOHLCSample> &samples ):
329 QwtArraySeriesData<QwtOHLCSample>( samples )
330{
331}
332
333/*!
334 \brief Calculate the bounding rectangle
335
336 The bounding rectangle is calculated once by iterating over all
337 points and is stored for all following requests.
338
339 \return Bounding rectangle
340*/
341QRectF QwtTradingChartData::boundingRect() const
342{
343 if ( d_boundingRect.width() < 0.0 )
344 d_boundingRect = qwtBoundingRect( *this );
345
346 return d_boundingRect;
347}
Note: See TracBrowser for help on using the repository browser.