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

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

update qwt and qwtpolar, many QT5 fixes (unfinished)

File size: 8.6 KB
RevLine 
[4271]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{
[8127]36 double minY = sample.set[0];
37 double maxY = sample.set[0];
[4271]38
[8127]39 for ( int i = 1; i < sample.set.size(); i++ )
[4271]40 {
[8127]41 if ( sample.set[i] < minY )
42 minY = sample.set[i];
43 if ( sample.set[i] > maxY )
44 maxY = sample.set[i];
[4271]45 }
46
[8127]47 double minX = sample.value;
48 double maxX = sample.value;
[4271]49
50 return QRectF( minX, minY, maxX - minX, maxY - minY );
51}
52
[8127]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
[4271]59/*!
[8127]60 \brief Calculate the bounding rectangle of a series subset
[4271]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>
[8127]72QRectF qwtBoundingRectT(
[4271]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/*!
[8127]114 \brief Calculate the bounding rectangle of a series subset
[4271]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*/
[8127]124QRectF qwtBoundingRect(
[4271]125 const QwtSeriesData<QPointF> &series, int from, int to )
126{
127 return qwtBoundingRectT<QPointF>( series, from, to );
128}
129
130/*!
[8127]131 \brief Calculate the bounding rectangle of a series subset
[4271]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*/
[8127]141QRectF qwtBoundingRect(
[4271]142 const QwtSeriesData<QwtPoint3D> &series, int from, int to )
143{
144 return qwtBoundingRectT<QwtPoint3D>( series, from, to );
145}
146
147/*!
[8127]148 \brief Calculate the bounding rectangle of a series subset
[4271]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*/
[8127]161QRectF qwtBoundingRect(
[4271]162 const QwtSeriesData<QwtPointPolar> &series, int from, int to )
163{
164 return qwtBoundingRectT<QwtPointPolar>( series, from, to );
165}
166
167/*!
[8127]168 \brief Calculate the bounding rectangle of a series subset
[4271]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*/
[8127]178QRectF qwtBoundingRect(
[4271]179 const QwtSeriesData<QwtIntervalSample>& series, int from, int to )
180{
181 return qwtBoundingRectT<QwtIntervalSample>( series, from, to );
182}
183
184/*!
[8127]185 \brief Calculate the bounding rectangle of a series subset
[4271]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*/
[8127]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(
[4271]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/*!
[8127]229 \brief Calculate the bounding rectangle
[4271]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/*!
[8127]255 \brief Calculate the bounding rectangle
[4271]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/*!
[8127]281 \brief Calculate the bounding rectangle
[4271]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/*!
[8127]307 \brief Calculate the bounding rectangle
[4271]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/*!
[8127]323 Constructor
324 \param samples Samples
[4271]325*/
[8127]326QwtTradingChartData::QwtTradingChartData(
327 const QVector<QwtOHLCSample> &samples ):
328 QwtArraySeriesData<QwtOHLCSample>( samples )
[4271]329{
330}
331
332/*!
[8127]333 \brief Calculate the bounding rectangle
[4271]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*/
[8127]340QRectF QwtTradingChartData::boundingRect() const
[4271]341{
[8127]342 if ( d_boundingRect.width() < 0.0 )
[4271]343 d_boundingRect = qwtBoundingRect( *this );
344
345 return d_boundingRect;
346}
Note: See TracBrowser for help on using the repository browser.