qwt_plot_histogram.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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_PLOT_HISTOGRAM_H
  10. #define QWT_PLOT_HISTOGRAM_H
  11. #include "qwt_global.h"
  12. #include "qwt_plot_seriesitem.h"
  13. #include "qwt_column_symbol.h"
  14. #include <qcolor.h>
  15. #include <qvector.h>
  16. class QwtIntervalData;
  17. class QString;
  18. class QPolygonF;
  19. /*!
  20. \brief QwtPlotHistogram represents a series of samples, where an interval
  21. is associated with a value ( \f$y = f([x1,x2])\f$ ).
  22. The representation depends on the style() and an optional symbol()
  23. that is displayed for each interval.
  24. \note The term "histogram" is used in a different way in the areas of
  25. digital image processing and statistics. Wikipedia introduces the
  26. terms "image histogram" and "color histogram" to avoid confusions.
  27. While "image histograms" can be displayed by a QwtPlotCurve there
  28. is no applicable plot item for a "color histogram" yet.
  29. \sa QwtPlotBarChart, QwtPlotMultiBarChart
  30. */
  31. class QWT_EXPORT QwtPlotHistogram:
  32. public QwtPlotSeriesItem, public QwtSeriesStore<QwtIntervalSample>
  33. {
  34. public:
  35. /*!
  36. Histogram styles.
  37. The default style is QwtPlotHistogram::Columns.
  38. \sa setStyle(), style(), setSymbol(), symbol(), setBaseline()
  39. */
  40. enum HistogramStyle
  41. {
  42. /*!
  43. Draw an outline around the area, that is build by all intervals
  44. using the pen() and fill it with the brush(). The outline style
  45. requires, that the intervals are in increasing order and
  46. not overlapping.
  47. */
  48. Outline,
  49. /*!
  50. Draw a column for each interval. When a symbol() has been set
  51. the symbol is used otherwise the column is displayed as
  52. plain rectangle using pen() and brush().
  53. */
  54. Columns,
  55. /*!
  56. Draw a simple line using the pen() for each interval.
  57. */
  58. Lines,
  59. /*!
  60. Styles >= UserStyle are reserved for derived
  61. classes that overload drawSeries() with
  62. additional application specific ways to display a histogram.
  63. */
  64. UserStyle = 100
  65. };
  66. explicit QwtPlotHistogram( const QString &title = QString() );
  67. explicit QwtPlotHistogram( const QwtText &title );
  68. virtual ~QwtPlotHistogram();
  69. virtual int rtti() const;
  70. void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
  71. void setPen( const QPen & );
  72. const QPen &pen() const;
  73. void setBrush( const QBrush & );
  74. const QBrush &brush() const;
  75. void setSamples( const QVector<QwtIntervalSample> & );
  76. void setSamples( QwtSeriesData<QwtIntervalSample> * );
  77. void setBaseline( double );
  78. double baseline() const;
  79. void setStyle( HistogramStyle style );
  80. HistogramStyle style() const;
  81. void setSymbol( const QwtColumnSymbol * );
  82. const QwtColumnSymbol *symbol() const;
  83. virtual void drawSeries( QPainter *,
  84. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  85. const QRectF &canvasRect, int from, int to ) const;
  86. virtual QRectF boundingRect() const;
  87. virtual QwtGraphic legendIcon( int index, const QSizeF & ) const;
  88. protected:
  89. virtual QwtColumnRect columnRect( const QwtIntervalSample &,
  90. const QwtScaleMap &, const QwtScaleMap & ) const;
  91. virtual void drawColumn( QPainter *, const QwtColumnRect &,
  92. const QwtIntervalSample & ) const;
  93. void drawColumns( QPainter *,
  94. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  95. int from, int to ) const;
  96. void drawOutline( QPainter *,
  97. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  98. int from, int to ) const;
  99. void drawLines( QPainter *,
  100. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  101. int from, int to ) const;
  102. private:
  103. void init();
  104. void flushPolygon( QPainter *, double baseLine, QPolygonF & ) const;
  105. class PrivateData;
  106. PrivateData *d_data;
  107. };
  108. #endif