source: ntrip/trunk/BNC/qwt/qwt_point_data.cpp@ 10327

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

update to qwt verion 6.1.1 to fix build with newer Qt5

File size: 6.7 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_point_data.h"
11#include "qwt_math.h"
12#include <string.h>
13
14/*!
15 Constructor
16
17 \param x Array of x values
18 \param y Array of y values
19
20 \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples()
21*/
22QwtPointArrayData::QwtPointArrayData(
23 const QVector<double> &x, const QVector<double> &y ):
24 d_x( x ),
25 d_y( y )
26{
27}
28
29/*!
30 Constructor
31
32 \param x Array of x values
33 \param y Array of y values
34 \param size Size of the x and y arrays
35 \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples()
36*/
37QwtPointArrayData::QwtPointArrayData( const double *x,
38 const double *y, size_t size )
39{
40 d_x.resize( size );
41 ::memcpy( d_x.data(), x, size * sizeof( double ) );
42
43 d_y.resize( size );
44 ::memcpy( d_y.data(), y, size * sizeof( double ) );
45}
46
47/*!
48 \brief Calculate the bounding rectangle
49
50 The bounding rectangle is calculated once by iterating over all
51 points and is stored for all following requests.
52
53 \return Bounding rectangle
54*/
55QRectF QwtPointArrayData::boundingRect() const
56{
57 if ( d_boundingRect.width() < 0 )
58 d_boundingRect = qwtBoundingRect( *this );
59
60 return d_boundingRect;
61}
62
63//! \return Size of the data set
64size_t QwtPointArrayData::size() const
65{
66 return qMin( d_x.size(), d_y.size() );
67}
68
69/*!
70 Return the sample at position i
71
72 \param index Index
73 \return Sample at position i
74*/
75QPointF QwtPointArrayData::sample( size_t index ) const
76{
77 return QPointF( d_x[int( index )], d_y[int( index )] );
78}
79
80//! \return Array of the x-values
81const QVector<double> &QwtPointArrayData::xData() const
82{
83 return d_x;
84}
85
86//! \return Array of the y-values
87const QVector<double> &QwtPointArrayData::yData() const
88{
89 return d_y;
90}
91
92/*!
93 Constructor
94
95 \param x Array of x values
96 \param y Array of y values
97 \param size Size of the x and y arrays
98
99 \warning The programmer must assure that the memory blocks referenced
100 by the pointers remain valid during the lifetime of the
101 QwtPlotCPointer object.
102
103 \sa QwtPlotCurve::setData(), QwtPlotCurve::setRawSamples()
104*/
105QwtCPointerData::QwtCPointerData(
106 const double *x, const double *y, size_t size ):
107 d_x( x ),
108 d_y( y ),
109 d_size( size )
110{
111}
112
113/*!
114 \brief Calculate the bounding rectangle
115
116 The bounding rectangle is calculated once by iterating over all
117 points and is stored for all following requests.
118
119 \return Bounding rectangle
120*/
121QRectF QwtCPointerData::boundingRect() const
122{
123 if ( d_boundingRect.width() < 0 )
124 d_boundingRect = qwtBoundingRect( *this );
125
126 return d_boundingRect;
127}
128
129//! \return Size of the data set
130size_t QwtCPointerData::size() const
131{
132 return d_size;
133}
134
135/*!
136 Return the sample at position i
137
138 \param index Index
139 \return Sample at position i
140*/
141QPointF QwtCPointerData::sample( size_t index ) const
142{
143 return QPointF( d_x[int( index )], d_y[int( index )] );
144}
145
146//! \return Array of the x-values
147const double *QwtCPointerData::xData() const
148{
149 return d_x;
150}
151
152//! \return Array of the y-values
153const double *QwtCPointerData::yData() const
154{
155 return d_y;
156}
157
158/*!
159 Constructor
160
161 \param size Number of points
162 \param interval Bounding interval for the points
163
164 \sa setInterval(), setSize()
165*/
166QwtSyntheticPointData::QwtSyntheticPointData(
167 size_t size, const QwtInterval &interval ):
168 d_size( size ),
169 d_interval( interval )
170{
171}
172
173/*!
174 Change the number of points
175
176 \param size Number of points
177 \sa size(), setInterval()
178*/
179void QwtSyntheticPointData::setSize( size_t size )
180{
181 d_size = size;
182}
183
184/*!
185 \return Number of points
186 \sa setSize(), interval()
187*/
188size_t QwtSyntheticPointData::size() const
189{
190 return d_size;
191}
192
193/*!
194 Set the bounding interval
195
196 \param interval Interval
197 \sa interval(), setSize()
198*/
199void QwtSyntheticPointData::setInterval( const QwtInterval &interval )
200{
201 d_interval = interval.normalized();
202}
203
204/*!
205 \return Bounding interval
206 \sa setInterval(), size()
207*/
208QwtInterval QwtSyntheticPointData::interval() const
209{
210 return d_interval;
211}
212
213/*!
214 Set a the "rectangle of interest"
215
216 QwtPlotSeriesItem defines the current area of the plot canvas
217 as "rect of interest" ( QwtPlotSeriesItem::updateScaleDiv() ).
218
219 If interval().isValid() == false the x values are calculated
220 in the interval rect.left() -> rect.right().
221
222 \sa rectOfInterest()
223*/
224void QwtSyntheticPointData::setRectOfInterest( const QRectF &rect )
225{
226 d_rectOfInterest = rect;
227 d_intervalOfInterest = QwtInterval(
228 rect.left(), rect.right() ).normalized();
229}
230
231/*!
232 \return "rectangle of interest"
233 \sa setRectOfInterest()
234*/
235QRectF QwtSyntheticPointData::rectOfInterest() const
236{
237 return d_rectOfInterest;
238}
239
240/*!
241 \brief Calculate the bounding rectangle
242
243 This implementation iterates over all points, what could often
244 be implemented much faster using the characteristics of the series.
245 When there are many points it is recommended to overload and
246 reimplement this method using the characteristics of the series
247 ( if possible ).
248
249 \return Bounding rectangle
250*/
251QRectF QwtSyntheticPointData::boundingRect() const
252{
253 if ( d_size == 0 ||
254 !( d_interval.isValid() || d_intervalOfInterest.isValid() ) )
255 {
256 return QRectF( 1.0, 1.0, -2.0, -2.0 ); // something invalid
257 }
258
259 return qwtBoundingRect( *this );
260}
261
262/*!
263 Calculate the point from an index
264
265 \param index Index
266 \return QPointF(x(index), y(x(index)));
267
268 \warning For invalid indices ( index < 0 || index >= size() )
269 (0, 0) is returned.
270*/
271QPointF QwtSyntheticPointData::sample( size_t index ) const
272{
273 if ( index >= d_size )
274 return QPointF( 0, 0 );
275
276 const double xValue = x( index );
277 const double yValue = y( xValue );
278
279 return QPointF( xValue, yValue );
280}
281
282/*!
283 Calculate a x-value from an index
284
285 x values are calculated by dividing an interval into
286 equidistant steps. If !interval().isValid() the
287 interval is calculated from the "rectangle of interest".
288
289 \param index Index of the requested point
290 \return Calculated x coordinate
291
292 \sa interval(), rectOfInterest(), y()
293*/
294double QwtSyntheticPointData::x( uint index ) const
295{
296 const QwtInterval &interval = d_interval.isValid() ?
297 d_interval : d_intervalOfInterest;
298
299 if ( !interval.isValid() )
300 return 0.0;
301
302 if ( d_size <= 1 )
303 return interval.minValue();
304
305 const double dx = interval.width() / ( d_size - 1 );
306 return interval.minValue() + index * dx;
307}
Note: See TracBrowser for help on using the repository browser.