46 , mVectorLayer( layer )
47 , mSourceFieldExp( fieldOrExp )
48 , mXAxisTitle( QObject::tr(
"Value" ) )
49 , mYAxisTitle( QObject::tr(
"Count" ) )
56 QFrame *plotCanvasFrame =
dynamic_cast<QFrame *
>( mpPlot->canvas() );
57 if ( plotCanvasFrame )
58 plotCanvasFrame->setFrameStyle( QFrame::NoFrame );
61 mMeanCheckBox->setChecked( settings.
value( QStringLiteral(
"HistogramWidget/showMean" ),
false ).toBool() );
62 mStdevCheckBox->setChecked( settings.
value( QStringLiteral(
"HistogramWidget/showStdev" ),
false ).toBool() );
69 mGridPen = QPen( QColor( 0, 0, 0, 40 ) );
70 mMeanPen = QPen( QColor( 10, 10, 10, 220 ) );
71 mMeanPen.setStyle( Qt::DashLine );
72 mStdevPen = QPen( QColor( 30, 30, 30, 200 ) );
73 mStdevPen.setStyle( Qt::DashLine );
75 if (
layer && !mSourceFieldExp.isEmpty() )
176 mpPlot->detachItems();
179 mpPlot->setAutoDelete(
true );
181 if ( !mXAxisTitle.isEmpty() )
182 mpPlot->setAxisTitle( QwtPlot::xBottom, mXAxisTitle );
183 if ( !mYAxisTitle.isEmpty() )
184 mpPlot->setAxisTitle( QwtPlot::yLeft, mYAxisTitle );
185 mpPlot->setAxisFont( QwtPlot::xBottom, this->font() );
186 mpPlot->setAxisFont( QwtPlot::yLeft, this->font() );
187 QFont titleFont = this->font();
188 titleFont.setBold(
true );
189 QwtText xAxisText = mpPlot->axisTitle( QwtPlot::xBottom );
190 xAxisText.setFont( titleFont );
191 mpPlot->setAxisTitle( QwtPlot::xBottom, xAxisText );
192 QwtText yAxisText = mpPlot->axisTitle( QwtPlot::yLeft );
193 yAxisText.setFont( titleFont );
194 mpPlot->setAxisTitle( QwtPlot::yLeft, yAxisText );
195 mpPlot->setAxisAutoScale( QwtPlot::yLeft );
196 mpPlot->setAxisAutoScale( QwtPlot::xBottom );
199 QwtPlotGrid *grid =
new QwtPlotGrid();
200 grid->enableX(
false );
201 grid->setPen( mGridPen );
202 grid->attach( mpPlot );
205 mHistoColors.clear();
208 mHistoColors << ( range.symbol() ? range.symbol()->color() : Qt::black );
212 QwtPlotHistogram *plotHistogram =
nullptr;
213 plotHistogram = createPlotHistogram( !
mRanges.isEmpty() ?
mRanges.at( 0 ).label() : QString(), !
mRanges.isEmpty() ? QBrush( mHistoColors.at( 0 ) ) : mBrush, !
mRanges.isEmpty() ? Qt::NoPen : mPen );
214 QVector<QwtIntervalSample> dataHisto;
216 int bins = mBinsSpinBox->value();
217 QList<double> edges = mHistogram.
binEdges( bins );
218 QList<int> counts = mHistogram.
counts( bins );
223 for (
int bin = 0; bin < bins; ++bin )
225 int binValue = counts.at( bin );
229 if ( rangeIndex <
mRanges.count() - 1 && edges.at( bin ) >
mRanges.at( rangeIndex ).upperValue() )
232 plotHistogram->setSamples( dataHisto );
233 plotHistogram->attach( mpPlot );
234 plotHistogram = createPlotHistogram(
mRanges.at( rangeIndex ).label(), mHistoColors.at( rangeIndex ) );
236 dataHisto << QwtIntervalSample( lastValue,
mRanges.at( rangeIndex - 1 ).upperValue(), edges.at( bin ) );
239 double upperEdge = !
mRanges.isEmpty() ? std::min( edges.at( bin + 1 ),
mRanges.at( rangeIndex ).upperValue() )
240 : edges.at( bin + 1 );
242 dataHisto << QwtIntervalSample( binValue, edges.at( bin ), upperEdge );
244 lastValue = binValue;
247 plotHistogram->setSamples( dataHisto );
248 plotHistogram->attach( mpPlot );
253 QwtPlotMarker *rangeMarker =
new QwtPlotMarker();
254 rangeMarker->attach( mpPlot );
255 rangeMarker->setLineStyle( QwtPlotMarker::VLine );
256 rangeMarker->setXValue( range.upperValue() );
257 rangeMarker->setLabel( QLocale().toString( range.upperValue() ) );
258 rangeMarker->setLabelOrientation( Qt::Vertical );
259 rangeMarker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
264 if ( mMeanCheckBox->isChecked() )
266 QwtPlotMarker *meanMarker =
new QwtPlotMarker();
267 meanMarker->attach( mpPlot );
268 meanMarker->setLineStyle( QwtPlotMarker::VLine );
269 meanMarker->setLinePen( mMeanPen );
270 meanMarker->setXValue( mStats.
mean() );
271 meanMarker->setLabel( QString( QChar( 956 ) ) );
272 meanMarker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
276 if ( mStdevCheckBox->isChecked() )
278 QwtPlotMarker *stdev1Marker =
new QwtPlotMarker();
279 stdev1Marker->attach( mpPlot );
280 stdev1Marker->setLineStyle( QwtPlotMarker::VLine );
281 stdev1Marker->setLinePen( mStdevPen );
282 stdev1Marker->setXValue( mStats.
mean() - mStats.
stDev() );
283 stdev1Marker->setLabel( QString( QChar( 963 ) ) );
284 stdev1Marker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
285 stdev1Marker->show();
287 QwtPlotMarker *stdev2Marker =
new QwtPlotMarker();
288 stdev2Marker->attach( mpPlot );
289 stdev2Marker->setLineStyle( QwtPlotMarker::VLine );
290 stdev2Marker->setLinePen( mStdevPen );
291 stdev2Marker->setXValue( mStats.
mean() + mStats.
stDev() );
292 stdev2Marker->setLabel( QString( QChar( 963 ) ) );
293 stdev2Marker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
294 stdev2Marker->show();
297 mpPlot->setEnabled(
true );