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