qwt_point_data.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #ifndef QWT_POINT_DATA_H
  10. #define QWT_POINT_DATA_H 1
  11. #include "qwt_global.h"
  12. #include "qwt_series_data.h"
  13. /*!
  14. \brief Interface for iterating over two QVector<double> objects.
  15. */
  16. class QWT_EXPORT QwtPointArrayData: public QwtSeriesData<QPointF>
  17. {
  18. public:
  19. QwtPointArrayData( const QVector<double> &x, const QVector<double> &y );
  20. QwtPointArrayData( const double *x, const double *y, size_t size );
  21. virtual QRectF boundingRect() const;
  22. virtual size_t size() const;
  23. virtual QPointF sample( size_t index ) const;
  24. const QVector<double> &xData() const;
  25. const QVector<double> &yData() const;
  26. private:
  27. QVector<double> d_x;
  28. QVector<double> d_y;
  29. };
  30. /*!
  31. \brief Data class containing two pointers to memory blocks of doubles.
  32. */
  33. class QWT_EXPORT QwtCPointerData: public QwtSeriesData<QPointF>
  34. {
  35. public:
  36. QwtCPointerData( const double *x, const double *y, size_t size );
  37. virtual QRectF boundingRect() const;
  38. virtual size_t size() const;
  39. virtual QPointF sample( size_t index ) const;
  40. const double *xData() const;
  41. const double *yData() const;
  42. private:
  43. const double *d_x;
  44. const double *d_y;
  45. size_t d_size;
  46. };
  47. /*!
  48. \brief Synthetic point data
  49. QwtSyntheticPointData provides a fixed number of points for an interval.
  50. The points are calculated in equidistant steps in x-direction.
  51. If the interval is invalid, the points are calculated for
  52. the "rectangle of interest", what normally is the displayed area on the
  53. plot canvas. In this mode you get different levels of detail, when
  54. zooming in/out.
  55. \par Example
  56. The following example shows how to implement a sinus curve.
  57. \code
  58. #include <cmath>
  59. #include <qwt_series_data.h>
  60. #include <qwt_plot_curve.h>
  61. #include <qwt_plot.h>
  62. #include <qapplication.h>
  63. class SinusData: public QwtSyntheticPointData
  64. {
  65. public:
  66. SinusData():
  67. QwtSyntheticPointData( 100 )
  68. {
  69. }
  70. virtual double y( double x ) const
  71. {
  72. return qSin( x );
  73. }
  74. };
  75. int main(int argc, char **argv)
  76. {
  77. QApplication a( argc, argv );
  78. QwtPlot plot;
  79. plot.setAxisScale( QwtPlot::xBottom, 0.0, 10.0 );
  80. plot.setAxisScale( QwtPlot::yLeft, -1.0, 1.0 );
  81. QwtPlotCurve *curve = new QwtPlotCurve( "y = sin(x)" );
  82. curve->setData( new SinusData() );
  83. curve->attach( &plot );
  84. plot.show();
  85. return a.exec();
  86. }
  87. \endcode
  88. */
  89. class QWT_EXPORT QwtSyntheticPointData: public QwtSeriesData<QPointF>
  90. {
  91. public:
  92. QwtSyntheticPointData( size_t size,
  93. const QwtInterval & = QwtInterval() );
  94. void setSize( size_t size );
  95. virtual size_t size() const;
  96. void setInterval( const QwtInterval& );
  97. QwtInterval interval() const;
  98. virtual QRectF boundingRect() const;
  99. virtual QPointF sample( size_t index ) const;
  100. /*!
  101. Calculate a y value for a x value
  102. \param x x value
  103. \return Corresponding y value
  104. */
  105. virtual double y( double x ) const = 0;
  106. virtual double x( uint index ) const;
  107. virtual void setRectOfInterest( const QRectF & );
  108. QRectF rectOfInterest() const;
  109. private:
  110. size_t d_size;
  111. QwtInterval d_interval;
  112. QRectF d_rectOfInterest;
  113. QwtInterval d_intervalOfInterest;
  114. };
  115. #endif