QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgshistogramwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgshistogramwidget.h
3  --------------------
4  begin : May 2015
5  copyright : (C) 2015 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #ifndef QGSHISTOGRAMWIDGET_H
18 #define QGSHISTOGRAMWIDGET_H
19 
20 #include "ui_qgshistogramwidgetbase.h"
21 #include "qgis_sip.h"
22 
23 #include "qgshistogram.h"
24 #include "qgsstatisticalsummary.h"
26 #include <QPen>
27 #include <QBrush>
28 #include "qgis_gui.h"
29 
30 class QgsVectorLayer;
32 class QwtPlotPicker;
33 class QwtPlotMarker;
34 class QwtPlot;
35 class HistogramItem;
36 class QwtPlotHistogram;
37 
38 // fix for qwt5/qwt6 QwtDoublePoint vs. QPointF
39 typedef QPointF QwtDoublePoint;
40 
49 class GUI_EXPORT QgsHistogramWidget : public QWidget, private Ui::QgsHistogramWidgetBase
50 {
51  Q_OBJECT
52 
53  public:
54 
62  QgsHistogramWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsVectorLayer *layer = nullptr, const QString &fieldOrExp = QString() );
63 
64  ~QgsHistogramWidget() override;
65 
71  QgsVectorLayer *layer() { return mVectorLayer; }
72 
79  QString sourceFieldExp() const { return mSourceFieldExp; }
80 
89  void setPen( const QPen &pen ) { mPen = pen; }
90 
96  QPen pen() const { return mPen; }
97 
105  void setBrush( const QBrush &brush ) { mBrush = brush; }
106 
112  QBrush brush() const { return mBrush; }
113 
120  void setGraduatedRanges( const QgsRangeList &ranges );
121 
128  QgsRangeList graduatedRanges() const { return mRanges; }
129 
135  QString xAxisTitle() const { return mXAxisTitle; }
136 
143  void setXAxisTitle( const QString &title ) { mXAxisTitle = title; }
144 
150  QString yAxisTitle() const { return mYAxisTitle; }
151 
158  void setYAxisTitle( const QString &title ) { mYAxisTitle = title; }
159 
160  public slots:
161 
165  void refreshValues();
166 
171  void refresh();
172 
178  void setLayer( QgsVectorLayer *layer );
179 
185  void setSourceFieldExp( const QString &fieldOrExp );
186 
187  protected:
188 
192  virtual void drawHistogram();
193 
194  QwtPlot *mPlot = nullptr;
196  QList< QwtPlotMarker * > mRangeMarkers;
197 
198  private:
199 
200  QgsVectorLayer *mVectorLayer = nullptr;
201  QString mSourceFieldExp;
202  QList<double> mValues;
203  QgsStatisticalSummary mStats;
204  QgsHistogram mHistogram;
205  QVector<QColor> mHistoColors;
206  QPen mPen;
207  QBrush mBrush;
208  QPen mMeanPen;
209  QPen mStdevPen;
210  QPen mGridPen;
211  QString mXAxisTitle;
212  QString mYAxisTitle;
213 
214  void clearHistogram();
215 
216  QwtPlotHistogram *createPlotHistogram( const QString &title, const QBrush &brush, const QPen &pen = Qt::NoPen ) const;
217 
218 };
219 
220 #endif //QGSHISTOGRAMWIDGET_H
QgsHistogramWidget
Graphical histogram for displaying distributions of field values.
Definition: qgshistogramwidget.h:49
QgsStatisticalSummary
Calculator for summary statistics for a list of doubles.
Definition: qgsstatisticalsummary.h:43
QgsHistogramWidget::yAxisTitle
QString yAxisTitle() const
Returns the title for the histogram's y-axis.
Definition: qgshistogramwidget.h:150
qgshistogram.h
qgsstatisticalsummary.h
QgsHistogramWidget::xAxisTitle
QString xAxisTitle() const
Returns the title for the histogram's x-axis.
Definition: qgshistogramwidget.h:135
QgsHistogramWidget::mRanges
QgsRangeList mRanges
Definition: qgshistogramwidget.h:195
QgsHistogramWidget::pen
QPen pen() const
Returns the pen used when drawing histogram bars.
Definition: qgshistogramwidget.h:96
QgsHistogramWidget::setBrush
void setBrush(const QBrush &brush)
Sets the brush used for drawing histogram bars.
Definition: qgshistogramwidget.h:105
QgsHistogramWidget::setXAxisTitle
void setXAxisTitle(const QString &title)
Sets the title for the histogram's x-axis.
Definition: qgshistogramwidget.h:143
QgsHistogramWidget::setPen
void setPen(const QPen &pen)
Sets the pen to use when drawing histogram bars.
Definition: qgshistogramwidget.h:89
QgsRangeList
QList< QgsRendererRange > QgsRangeList
Definition: qgsrendererrange.h:98
QgsHistogramWidget::mRangeMarkers
QList< QwtPlotMarker * > mRangeMarkers
Definition: qgshistogramwidget.h:196
QgsGraduatedSymbolRenderer
Definition: qgsgraduatedsymbolrenderer.h:35
qgis_sip.h
QgsHistogramWidget::graduatedRanges
QgsRangeList graduatedRanges() const
Returns the graduated ranges associated with the histogram.
Definition: qgshistogramwidget.h:128
QgsHistogram
Calculator for a numeric histogram from a list of values.
Definition: qgshistogram.h:37
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsHistogramWidget::layer
QgsVectorLayer * layer()
Returns the layer currently associated with the widget.
Definition: qgshistogramwidget.h:71
QwtDoublePoint
QPointF QwtDoublePoint
Definition: qgshistogramwidget.h:36
QgsHistogramWidget::sourceFieldExp
QString sourceFieldExp() const
Returns the source field name or expression used to calculate values displayed in the histogram.
Definition: qgshistogramwidget.h:79
qgsgraduatedsymbolrenderer.h
QgsHistogramWidget::setYAxisTitle
void setYAxisTitle(const QString &title)
Sets the title for the histogram's y-axis.
Definition: qgshistogramwidget.h:158
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsHistogramWidget::brush
QBrush brush() const
Returns the brush used when drawing histogram bars.
Definition: qgshistogramwidget.h:112