QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
22 #include "qgshistogram.h"
23 #include "qgsstatisticalsummary.h"
25 #include <QPen>
26 #include <QBrush>
27 
28 class QgsVectorLayer;
30 class QwtPlotPicker;
31 class QwtPlotMarker;
32 class QwtPlot;
33 class HistogramItem;
34 class QwtPlotHistogram;
35 
36 // fix for qwt5/qwt6 QwtDoublePoint vs. QPointF
37 #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
38 typedef QPointF QwtDoublePoint;
39 #endif
40 
41 
49 class GUI_EXPORT QgsHistogramWidget : public QWidget, private Ui::QgsHistogramWidgetBase
50 {
51  Q_OBJECT
52 
53  public:
54 
61  QgsHistogramWidget( QWidget *parent = nullptr, QgsVectorLayer* layer = nullptr, const QString& fieldOrExp = QString() );
62 
64 
69  QgsVectorLayer* layer() { return mVectorLayer; }
70 
76  QString sourceFieldExp() const { return mSourceFieldExp; }
77 
85  void setPen( const QPen& pen ) { mPen = pen; }
86 
91  QPen pen() const { return mPen; }
92 
99  void setBrush( const QBrush& brush ) { mBrush = brush; }
100 
105  QBrush brush() const { return mBrush; }
106 
112  void setGraduatedRanges( const QgsRangeList& ranges );
113 
119  QgsRangeList graduatedRanges() const { return mRanges; }
120 
125  QString xAxisTitle() const { return mXAxisTitle; }
126 
132  void setXAxisTitle( const QString& title ) { mXAxisTitle = title; }
133 
138  QString yAxisTitle() const { return mYAxisTitle; }
139 
145  void setYAxisTitle( const QString& title ) { mYAxisTitle = title; }
146 
147  public slots:
148 
151  void refreshValues();
152 
156  void refresh();
157 
162  void setLayer( QgsVectorLayer* layer );
163 
168  void setSourceFieldExp( const QString& fieldOrExp );
169 
170  protected:
171 
174  virtual void drawHistogram();
175 
176  QwtPlot* mPlot;
179 
180  private:
181 
182  QgsVectorLayer * mVectorLayer;
183  QString mSourceFieldExp;
184  QList<double> mValues;
185  QgsStatisticalSummary mStats;
186  QgsHistogram mHistogram;
187  QVector<QColor> mHistoColors;
188  QPen mPen;
189  QBrush mBrush;
190  QPen mMeanPen;
191  QPen mStdevPen;
192  QPen mGridPen;
193  QString mXAxisTitle;
194  QString mYAxisTitle;
195 
196  void clearHistogram();
197 
198 #if defined(QWT_VERSION) && QWT_VERSION>=0x060000
199  QwtPlotHistogram* createPlotHistogram( const QString& title, const QBrush &brush, const QPen &pen = Qt::NoPen ) const;
200 #else
201  HistogramItem* createHistoItem( const QString& title, const QBrush& brush, const QPen& pen = Qt::NoPen ) const;
202 #endif
203 
204 };
205 
206 #endif //QGSHISTOGRAMWIDGET_H
QString xAxisTitle() const
Returns the title for the histogram&#39;s x-axis.
QString yAxisTitle() const
Returns the title for the histogram&#39;s y-axis.
void setBrush(const QBrush &brush)
Sets the brush used for drawing histogram bars.
Calculator for a numeric histogram from a list of values.
Definition: qgshistogram.h:33
QList< QwtPlotMarker *> mRangeMarkers
void setYAxisTitle(const QString &title)
Sets the title for the histogram&#39;s y-axis.
QBrush brush() const
Returns the brush used when drawing histogram bars.
QString sourceFieldExp() const
Returns the source field name or expression used to calculate values displayed in the histogram...
QPen pen() const
Returns the pen used when drawing histogram bars.
QgsRangeList graduatedRanges() const
Returns the graduated ranges associated with the histogram.
Graphical histogram for displaying distributions of field values.
void setXAxisTitle(const QString &title)
Sets the title for the histogram&#39;s x-axis.
Calculator for summary statistics for a list of doubles.
Represents a vector layer which manages a vector based data sets.
void setPen(const QPen &pen)
Sets the pen to use when drawing histogram bars.
QgsVectorLayer * layer()
Returns the layer currently associated with the widget.