qwt_plot_barchart.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_BAR_CHART_H
  10. #define QWT_PLOT_BAR_CHART_H
  11. #include "qwt_global.h"
  12. #include "qwt_plot_abstract_barchart.h"
  13. #include "qwt_series_data.h"
  14. class QwtColumnRect;
  15. class QwtColumnSymbol;
  16. /*!
  17. \brief QwtPlotBarChart displays a series of a values as bars.
  18. Each bar might be customized individually by implementing
  19. a specialSymbol(). Otherwise it is rendered using a default symbol.
  20. Depending on its orientation() the bars are displayed horizontally
  21. or vertically. The bars cover the interval between the baseline()
  22. and the value.
  23. By activating the LegendBarTitles mode each sample will have
  24. its own entry on the legend.
  25. The most common use case of a bar chart is to display a
  26. list of y coordinates, where the x coordinate is simply the index
  27. in the list. But for other situations ( f.e. when values are related
  28. to dates ) it is also possible to set x coordinates explicitly.
  29. \sa QwtPlotMultiBarChart, QwtPlotHistogram, QwtPlotCurve::Sticks,
  30. QwtPlotSeriesItem::orientation(), QwtPlotAbstractBarChart::baseline()
  31. */
  32. class QWT_EXPORT QwtPlotBarChart:
  33. public QwtPlotAbstractBarChart, public QwtSeriesStore<QPointF>
  34. {
  35. public:
  36. /*!
  37. \brief Legend modes.
  38. The default setting is QwtPlotBarChart::LegendChartTitle.
  39. \sa setLegendMode(), legendMode()
  40. */
  41. enum LegendMode
  42. {
  43. /*!
  44. One entry on the legend showing the default symbol
  45. and the title() of the chart
  46. \sa QwtPlotItem::title()
  47. */
  48. LegendChartTitle,
  49. /*!
  50. One entry for each value showing the individual symbol
  51. of the corresponding bar and the bar title.
  52. \sa specialSymbol(), barTitle()
  53. */
  54. LegendBarTitles
  55. };
  56. explicit QwtPlotBarChart( const QString &title = QString() );
  57. explicit QwtPlotBarChart( const QwtText &title );
  58. virtual ~QwtPlotBarChart();
  59. virtual int rtti() const;
  60. void setSamples( const QVector<QPointF> & );
  61. void setSamples( const QVector<double> & );
  62. void setSamples( QwtSeriesData<QPointF> * );
  63. void setSymbol( QwtColumnSymbol * );
  64. const QwtColumnSymbol *symbol() const;
  65. void setLegendMode( LegendMode );
  66. LegendMode legendMode() const;
  67. virtual void drawSeries( QPainter *painter,
  68. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  69. const QRectF &canvasRect, int from, int to ) const;
  70. virtual QRectF boundingRect() const;
  71. virtual QwtColumnSymbol *specialSymbol(
  72. int sampleIndex, const QPointF& ) const;
  73. virtual QwtText barTitle( int sampleIndex ) const;
  74. protected:
  75. virtual void drawSample( QPainter *painter,
  76. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  77. const QRectF &canvasRect, const QwtInterval &boundingInterval,
  78. int index, const QPointF& sample ) const;
  79. virtual void drawBar( QPainter *,
  80. int sampleIndex, const QPointF& sample,
  81. const QwtColumnRect & ) const;
  82. QList<QwtLegendData> legendData() const;
  83. QwtGraphic legendIcon( int index, const QSizeF & ) const;
  84. private:
  85. void init();
  86. class PrivateData;
  87. PrivateData *d_data;
  88. };
  89. #endif