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

Last change on this file since 9045 was 8127, checked in by stoecker, 8 years ago

update qwt and qwtpolar, many QT5 fixes (unfinished)

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