Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_point_data.h
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_point_data.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_point_data.h
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #ifndef QWT_POINT_DATA_H 11 #define QWT_POINT_DATA_H 111 #define QWT_POINT_DATA_H 12 12 13 13 #include "qwt_global.h" 14 14 #include "qwt_series_data.h" 15 15 16 /*! 17 \brief Interface for iterating over two QVector<double> objects. 18 */ 19 class QWT_EXPORT QwtPointArrayData: public QwtSeriesData<QPointF> 20 { 21 public: 22 QwtPointArrayData( const QVector<double> &x, const QVector<double> &y ); 23 QwtPointArrayData( const double *x, const double *y, size_t size ); 24 25 virtual QRectF boundingRect() const; 26 27 virtual size_t size() const; 28 virtual QPointF sample( size_t index ) const; 29 30 const QVector<double> &xData() const; 31 const QVector<double> &yData() const; 32 33 private: 34 QVector<double> d_x; 35 QVector<double> d_y; 16 #include <cstring> 17 18 /*! 19 \brief Interface for iterating over two QVector<T> objects. 20 */ 21 template< typename T > 22 class QwtPointArrayData : public QwtSeriesData< QPointF > 23 { 24 public: 25 QwtPointArrayData( const QVector< T >& x, const QVector< T >& y ); 26 QwtPointArrayData( const T* x, const T* y, size_t size ); 27 28 virtual size_t size() const QWT_OVERRIDE; 29 virtual QPointF sample( size_t index ) const QWT_OVERRIDE; 30 31 const QVector< T >& xData() const; 32 const QVector< T >& yData() const; 33 34 private: 35 QVector< T > m_x; 36 QVector< T > m_y; 36 37 }; 37 38 38 39 /*! 39 \brief Data class containing two pointers to memory blocks of doubles.40 */ 41 class QWT_EXPORT QwtCPointerData: public QwtSeriesData<QPointF>42 { 43 public: 44 QwtCPointerData( const double *x, const double *y, size_t size );45 46 virtual QRectF boundingRect() const; 47 virtual size_t size() const; 48 virtual QPointF sample( size_t index ) const; 49 50 const double *xData() const;51 const double *yData() const;52 53 private: 54 const double *d_x;55 const double *d_y;56 size_t d_size;40 \brief Data class containing two pointers to memory blocks of T. 41 */ 42 template< typename T > 43 class QwtCPointerData : public QwtSeriesData< QPointF > 44 { 45 public: 46 QwtCPointerData( const T* x, const T* y, size_t size ); 47 48 virtual size_t size() const QWT_OVERRIDE; 49 virtual QPointF sample( size_t index ) const QWT_OVERRIDE; 50 51 const T* xData() const; 52 const T* yData() const; 53 54 private: 55 const T* m_x; 56 const T* m_y; 57 size_t m_size; 57 58 }; 58 59 59 60 /*! 60 \brief Synthetic point data 61 62 QwtSyntheticPointData provides a fixed number of points for an interval. 63 The points are calculated in equidistant steps in x-direction. 64 65 If the interval is invalid, the points are calculated for 66 the "rectangle of interest", what normally is the displayed area on the 67 plot canvas. In this mode you get different levels of detail, when 68 zooming in/out. 69 70 \par Example 71 72 The following example shows how to implement a sinus curve. 73 74 \code 75 #include <cmath> 76 #include <qwt_series_data.h> 77 #include <qwt_plot_curve.h> 78 #include <qwt_plot.h> 79 #include <qapplication.h> 80 81 class SinusData: public QwtSyntheticPointData 82 { 83 public: 61 \brief Interface for iterating over a QVector<T>. 62 63 The memory contains the y coordinates, while the index is 64 interpreted as x coordinate. 65 */ 66 template< typename T > 67 class QwtValuePointData : public QwtSeriesData< QPointF > 68 { 69 public: 70 QwtValuePointData( const QVector< T >& y ); 71 QwtValuePointData( const T* y, size_t size ); 72 73 virtual size_t size() const QWT_OVERRIDE; 74 virtual QPointF sample( size_t index ) const QWT_OVERRIDE; 75 76 const QVector< T >& yData() const; 77 78 private: 79 QVector< T > m_y; 80 }; 81 82 /*! 83 \brief Data class containing a pointer to memory of y coordinates 84 85 The memory contains the y coordinates, while the index is 86 interpreted as x coordinate. 87 */ 88 template< typename T > 89 class QwtCPointerValueData : public QwtSeriesData< QPointF > 90 { 91 public: 92 QwtCPointerValueData( const T* y, size_t size ); 93 94 virtual size_t size() const QWT_OVERRIDE; 95 virtual QPointF sample( size_t index ) const QWT_OVERRIDE; 96 97 const T* yData() const; 98 99 private: 100 const T* m_y; 101 size_t m_size; 102 }; 103 104 /*! 105 \brief Synthetic point data 106 107 QwtSyntheticPointData provides a fixed number of points for an interval. 108 The points are calculated in equidistant steps in x-direction. 109 110 If the interval is invalid, the points are calculated for 111 the "rectangle of interest", what normally is the displayed area on the 112 plot canvas. In this mode you get different levels of detail, when 113 zooming in/out. 114 115 \par Example 116 117 The following example shows how to implement a sinus curve. 118 119 \code 120 #include <cmath> 121 #include <qwt_series_data.h> 122 #include <qwt_plot_curve.h> 123 #include <qwt_plot.h> 124 #include <qapplication.h> 125 126 class SinusData: public QwtSyntheticPointData 127 { 128 public: 84 129 SinusData(): 85 130 QwtSyntheticPointData( 100 ) … … 91 136 return qSin( x ); 92 137 } 93 }; 94 95 int main(int argc, char **argv) 96 { 138 }; 139 140 int main(int argc, char **argv) 141 { 97 142 QApplication a( argc, argv ); 98 143 99 144 QwtPlot plot; 100 plot.setAxisScale( Qwt Plot::xBottom, 0.0, 10.0 );101 plot.setAxisScale( Qwt Plot::yLeft, -1.0, 1.0 );145 plot.setAxisScale( QwtAxis::XBottom, 0.0, 10.0 ); 146 plot.setAxisScale( QwtAxis::YLeft, -1.0, 1.0 ); 102 147 103 148 QwtPlotCurve *curve = new QwtPlotCurve( "y = sin(x)" ); … … 107 152 plot.show(); 108 153 return a.exec(); 109 } 154 } 110 155 \endcode 111 */ 112 class QWT_EXPORT QwtSyntheticPointData: public QwtSeriesData< QPointF>113 { 114 public: 156 */ 157 class QWT_EXPORT QwtSyntheticPointData : public QwtSeriesData< QPointF > 158 { 159 public: 115 160 QwtSyntheticPointData( size_t size, 116 const QwtInterval & = QwtInterval() );161 const QwtInterval& = QwtInterval() ); 117 162 118 163 void setSize( size_t size ); 119 virtual size_t size() const; 164 virtual size_t size() const QWT_OVERRIDE; 120 165 121 166 void setInterval( const QwtInterval& ); 122 167 QwtInterval interval() const; 123 168 124 virtual QRectF boundingRect() const; 125 virtual QPointF sample( size_t index ) const; 169 virtual QRectF boundingRect() const QWT_OVERRIDE; 170 virtual QPointF sample( size_t index ) const QWT_OVERRIDE; 126 171 127 172 /*! … … 134 179 virtual double x( uint index ) const; 135 180 136 virtual void setRectOfInterest( const QRectF & );181 virtual void setRectOfInterest( const QRectF& ) QWT_OVERRIDE; 137 182 QRectF rectOfInterest() const; 138 183 139 private: 140 size_t d_size;141 QwtInterval d_interval;142 QRectF d_rectOfInterest;143 QwtInterval d_intervalOfInterest;184 private: 185 size_t m_size; 186 QwtInterval m_interval; 187 QRectF m_rectOfInterest; 188 QwtInterval m_intervalOfInterest; 144 189 }; 145 190 191 /*! 192 Constructor 193 194 \param x Array of x values 195 \param y Array of y values 196 197 \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples() 198 */ 199 template< typename T > 200 QwtPointArrayData< T >::QwtPointArrayData( 201 const QVector< T >& x, const QVector< T >& y ) 202 : m_x( x ) 203 , m_y( y ) 204 { 205 } 206 207 /*! 208 Constructor 209 210 \param x Array of x values 211 \param y Array of y values 212 \param size Size of the x and y arrays 213 \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples() 214 */ 215 template< typename T > 216 QwtPointArrayData< T >::QwtPointArrayData( const T* x, const T* y, size_t size ) 217 { 218 m_x.resize( size ); 219 std::memcpy( m_x.data(), x, size * sizeof( T ) ); 220 221 m_y.resize( size ); 222 std::memcpy( m_y.data(), y, size * sizeof( T ) ); 223 } 224 225 //! \return Size of the data set 226 template< typename T > 227 size_t QwtPointArrayData< T >::size() const 228 { 229 return qMin( m_x.size(), m_y.size() ); 230 } 231 232 /*! 233 Return the sample at position i 234 235 \param index Index 236 \return Sample at position i 237 */ 238 template< typename T > 239 QPointF QwtPointArrayData< T >::sample( size_t index ) const 240 { 241 return QPointF( m_x[int( index )], m_y[int( index )] ); 242 } 243 244 //! \return Array of the x-values 245 template< typename T > 246 const QVector< T >& QwtPointArrayData< T >::xData() const 247 { 248 return m_x; 249 } 250 251 //! \return Array of the y-values 252 template< typename T > 253 const QVector< T >& QwtPointArrayData< T >::yData() const 254 { 255 return m_y; 256 } 257 258 /*! 259 Constructor 260 261 \param y Array of y values 262 263 \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples() 264 */ 265 template< typename T > 266 QwtValuePointData< T >::QwtValuePointData( const QVector< T >& y ) 267 : m_y( y ) 268 { 269 } 270 271 /*! 272 Constructor 273 274 \param y Array of y values 275 \param size Size of the x and y arrays 276 \sa QwtPlotCurve::setData(), QwtPlotCurve::setSamples() 277 */ 278 template< typename T > 279 QwtValuePointData< T >::QwtValuePointData( const T* y, size_t size ) 280 { 281 m_y.resize( size ); 282 std::memcpy( m_y.data(), y, size * sizeof( T ) ); 283 } 284 285 //! \return Size of the data set 286 template< typename T > 287 size_t QwtValuePointData< T >::size() const 288 { 289 return m_y.size(); 290 } 291 292 /*! 293 Return the sample at position i 294 295 \param index Index 296 \return Sample at position i 297 */ 298 template< typename T > 299 QPointF QwtValuePointData< T >::sample( size_t index ) const 300 { 301 return QPointF( index, m_y[int( index )] ); 302 } 303 304 //! \return Array of the y-values 305 template< typename T > 306 const QVector< T >& QwtValuePointData< T >::yData() const 307 { 308 return m_y; 309 } 310 311 /*! 312 Constructor 313 314 \param x Array of x values 315 \param y Array of y values 316 \param size Size of the x and y arrays 317 318 \warning The programmer must assure that the memory blocks referenced 319 by the pointers remain valid during the lifetime of the 320 QwtPlotCPointer object. 321 322 \sa QwtPlotCurve::setData(), QwtPlotCurve::setRawSamples() 323 */ 324 325 template< typename T > 326 QwtCPointerData< T >::QwtCPointerData( const T* x, const T* y, size_t size ) 327 : m_x( x ) 328 , m_y( y ) 329 , m_size( size ) 330 { 331 } 332 333 //! \return Size of the data set 334 template< typename T > 335 size_t QwtCPointerData< T >::size() const 336 { 337 return m_size; 338 } 339 340 /*! 341 Return the sample at position i 342 343 \param index Index 344 \return Sample at position i 345 */ 346 template< typename T > 347 QPointF QwtCPointerData< T >::sample( size_t index ) const 348 { 349 return QPointF( m_x[int( index )], m_y[int( index )] ); 350 } 351 352 //! \return Array of the x-values 353 template< typename T > 354 const T* QwtCPointerData< T >::xData() const 355 { 356 return m_x; 357 } 358 359 //! \return Array of the y-values 360 template< typename T > 361 const T* QwtCPointerData< T >::yData() const 362 { 363 return m_y; 364 } 365 366 /*! 367 Constructor 368 369 \param y Array of y values 370 \param size Size of the x and y arrays 371 372 \warning The programmer must assure that the memory blocks referenced 373 by the pointers remain valid during the lifetime of the 374 QwtCPointerValueData object. 375 376 \sa QwtPlotCurve::setData(), QwtPlotCurve::setRawSamples() 377 */ 378 379 template< typename T > 380 QwtCPointerValueData< T >::QwtCPointerValueData( const T* y, size_t size ) 381 : m_y( y ) 382 , m_size( size ) 383 { 384 } 385 386 //! \return Size of the data set 387 template< typename T > 388 size_t QwtCPointerValueData< T >::size() const 389 { 390 return m_size; 391 } 392 393 /*! 394 Return the sample at position i 395 396 \param index Index 397 \return Sample at position i 398 */ 399 template< typename T > 400 QPointF QwtCPointerValueData< T >::sample( size_t index ) const 401 { 402 return QPointF( index, m_y[ int( index ) ] ); 403 } 404 405 //! \return Array of the y-values 406 template< typename T > 407 const T* QwtCPointerValueData< T >::yData() const 408 { 409 return m_y; 410 } 411 146 412 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
