|
| 1 | + |
| 2 | +/** \ingroup gui |
| 3 | + * \class QgsHistogramWidget |
| 4 | + * \brief Graphical histogram for displaying distributions of field values. |
| 5 | + * |
| 6 | + * \note Added in version 2.9 |
| 7 | + */ |
| 8 | + |
| 9 | +class QgsHistogramWidget : QWidget |
| 10 | +{ |
| 11 | +%TypeHeaderCode |
| 12 | +#include <qgshistogramwidget.h> |
| 13 | +%End |
| 14 | + |
| 15 | + public: |
| 16 | + |
| 17 | + /** QgsHistogramWidget constructor. If layer and fieldOrExp are specified then the histogram |
| 18 | + * will be initially populated with the corresponding values. |
| 19 | + * @param parent parent widget |
| 20 | + * @param layer source vector layer |
| 21 | + * @param fieldOrExp field name or expression string |
| 22 | + */ |
| 23 | + QgsHistogramWidget( QWidget *parent /TransferThis/ = 0, QgsVectorLayer* layer = 0, const QString& fieldOrExp = QString() ); |
| 24 | + |
| 25 | + ~QgsHistogramWidget(); |
| 26 | + |
| 27 | + /** Returns the layer currently associated with the widget. |
| 28 | + * @see setLayer |
| 29 | + * @see sourceFieldExp |
| 30 | + */ |
| 31 | + QgsVectorLayer* layer(); |
| 32 | + |
| 33 | + /** Returns the source field name or expression used to calculate values displayed |
| 34 | + * in the histogram. |
| 35 | + * @see setSourceFieldExp |
| 36 | + * @see layer |
| 37 | + */ |
| 38 | + QString sourceFieldExp() const; |
| 39 | + |
| 40 | + /** Sets the pen to use when drawing histogram bars. If set to Qt::NoPen then the |
| 41 | + * pen will be automatically calculated. If ranges have been set using @link setGraduatedRanges @endlink |
| 42 | + * then the pen and brush will have no effect. |
| 43 | + * @param pen histogram pen |
| 44 | + * @see pen |
| 45 | + * @see setBrush |
| 46 | + */ |
| 47 | + void setPen( const QPen& pen ); |
| 48 | + |
| 49 | + /** Returns the pen used when drawing histogram bars. |
| 50 | + * @see setPen |
| 51 | + * @see brush |
| 52 | + */ |
| 53 | + QPen pen() const; |
| 54 | + |
| 55 | + /** Sets the brush used for drawing histogram bars. If ranges have been set using @link setGraduatedRanges @endlink |
| 56 | + * then the pen and brush will have no effect. |
| 57 | + * @param brush histogram brush |
| 58 | + * @see brush |
| 59 | + * @see setPen |
| 60 | + */ |
| 61 | + void setBrush( const QBrush& brush ); |
| 62 | + |
| 63 | + /** Returns the brush used when drawing histogram bars. |
| 64 | + * @see setBrush |
| 65 | + * @see pen |
| 66 | + */ |
| 67 | + QBrush brush() const; |
| 68 | + |
| 69 | + /** Sets the graduated ranges associated with the histogram. If set, the ranges will be used to colour the histogram |
| 70 | + * bars and for showing vertical dividers at the histogram breaks. |
| 71 | + * @param ranges graduated range list |
| 72 | + */ |
| 73 | + void setGraduatedRanges( const QgsRangeList& ranges ); |
| 74 | + |
| 75 | + /** Returns the graduated ranges associated with the histogram. If set, the ranges will be used to colour the histogram |
| 76 | + * bars and for showing vertical dividers at the histogram breaks. |
| 77 | + * @returns graduated range list |
| 78 | + * @see setGraduatedRanges |
| 79 | + */ |
| 80 | + QgsRangeList graduatedRanges() const; |
| 81 | + |
| 82 | + public slots: |
| 83 | + |
| 84 | + /** Triggers a refresh of the histogram when the widget is next repainted. |
| 85 | + */ |
| 86 | + void refreshHistogram(); |
| 87 | + |
| 88 | + /** Sets the vector layer associated with the histogram. |
| 89 | + * @param layer source vector layer |
| 90 | + * @see setSourceFieldExp |
| 91 | + */ |
| 92 | + void setLayer( QgsVectorLayer* layer ); |
| 93 | + |
| 94 | + /** Sets the source field or expression to use for values in the histogram. |
| 95 | + * @param fieldOrExp field name or expression string |
| 96 | + * @see setLayer |
| 97 | + */ |
| 98 | + void setSourceFieldExp( const QString& fieldOrExp ); |
| 99 | + |
| 100 | + protected: |
| 101 | + |
| 102 | + /** Updates and redraws the histogram. |
| 103 | + */ |
| 104 | + virtual void drawHistogram(); |
| 105 | + |
| 106 | + virtual void paintEvent( QPaintEvent * event ); |
| 107 | +}; |
0 commit comments