51 , mVectorLayer(
layer )
52 , mSourceFieldExp( fieldOrExp )
53 , mXAxisTitle( QObject::tr(
"Value" ) )
54 , mYAxisTitle( QObject::tr(
"Count" ) )
61 QFrame *plotCanvasFrame =
dynamic_cast<QFrame *
>( mpPlot->canvas() );
62 if ( plotCanvasFrame )
63 plotCanvasFrame->setFrameStyle( QFrame::NoFrame );
66 mMeanCheckBox->setChecked( settings.
value( u
"HistogramWidget/showMean"_s,
false ).toBool() );
67 mStdevCheckBox->setChecked( settings.
value( u
"HistogramWidget/showStdev"_s,
false ).toBool() );
74 mGridPen = QPen( QColor( 0, 0, 0, 40 ) );
75 mMeanPen = QPen( QColor( 10, 10, 10, 220 ) );
76 mMeanPen.setStyle( Qt::DashLine );
77 mStdevPen = QPen( QColor( 30, 30, 30, 200 ) );
78 mStdevPen.setStyle( Qt::DashLine );
80 if (
layer && !mSourceFieldExp.isEmpty() )
108 if ( !mVectorLayer || mSourceFieldExp.isEmpty() )
111 QApplication::setOverrideCursor( Qt::WaitCursor );
118 QApplication::restoreOverrideCursor();
123 std::sort( mValues.begin(), mValues.end() );
124 mHistogram.setValues( mValues );
125 mBinsSpinBox->blockSignals(
true );
126 mBinsSpinBox->setValue( std::max( mHistogram.optimalNumberBins(), 30 ) );
127 mBinsSpinBox->blockSignals(
false );
130 mStats.calculate( mValues );
132 mpPlot->setEnabled(
true );
133 mMeanCheckBox->setEnabled(
true );
134 mStdevCheckBox->setEnabled(
true );
135 mBinsSpinBox->setEnabled(
true );
137 QApplication::restoreOverrideCursor();
181 mpPlot->detachItems();
184 mpPlot->setAutoDelete(
true );
186 if ( !mXAxisTitle.isEmpty() )
187 mpPlot->setAxisTitle( QwtPlot::xBottom, mXAxisTitle );
188 if ( !mYAxisTitle.isEmpty() )
189 mpPlot->setAxisTitle( QwtPlot::yLeft, mYAxisTitle );
190 mpPlot->setAxisFont( QwtPlot::xBottom, this->font() );
191 mpPlot->setAxisFont( QwtPlot::yLeft, this->font() );
192 QFont titleFont = this->font();
193 titleFont.setBold(
true );
194 QwtText xAxisText = mpPlot->axisTitle( QwtPlot::xBottom );
195 xAxisText.setFont( titleFont );
196 mpPlot->setAxisTitle( QwtPlot::xBottom, xAxisText );
197 QwtText yAxisText = mpPlot->axisTitle( QwtPlot::yLeft );
198 yAxisText.setFont( titleFont );
199 mpPlot->setAxisTitle( QwtPlot::yLeft, yAxisText );
200 mpPlot->setAxisAutoScale( QwtPlot::yLeft );
201 mpPlot->setAxisAutoScale( QwtPlot::xBottom );
204 QwtPlotGrid *grid =
new QwtPlotGrid();
205 grid->enableX(
false );
206 grid->setPen( mGridPen );
207 grid->attach( mpPlot );
210 mHistoColors.clear();
213 mHistoColors << ( range.symbol() ? range.symbol()->color() : Qt::black );
217 QwtPlotHistogram *plotHistogram =
nullptr;
218 plotHistogram = createPlotHistogram( !
mRanges.isEmpty() ?
mRanges.at( 0 ).label() : QString(), !
mRanges.isEmpty() ? QBrush( mHistoColors.at( 0 ) ) : mBrush, !
mRanges.isEmpty() ? Qt::NoPen : mPen );
219 QVector<QwtIntervalSample> dataHisto;
221 int bins = mBinsSpinBox->value();
222 QList<double> edges = mHistogram.binEdges( bins );
223 QList<int> counts = mHistogram.counts( bins );
228 for (
int bin = 0; bin < bins; ++bin )
230 int binValue = counts.at( bin );
234 if ( rangeIndex <
mRanges.count() - 1 && edges.at( bin ) >
mRanges.at( rangeIndex ).upperValue() )
237 plotHistogram->setSamples( dataHisto );
238 plotHistogram->attach( mpPlot );
239 plotHistogram = createPlotHistogram(
mRanges.at( rangeIndex ).label(), mHistoColors.at( rangeIndex ) );
241 dataHisto << QwtIntervalSample( lastValue,
mRanges.at( rangeIndex - 1 ).upperValue(), edges.at( bin ) );
244 double upperEdge = !
mRanges.isEmpty() ? std::min( edges.at( bin + 1 ),
mRanges.at( rangeIndex ).upperValue() )
245 : edges.at( bin + 1 );
247 dataHisto << QwtIntervalSample( binValue, edges.at( bin ), upperEdge );
249 lastValue = binValue;
252 plotHistogram->setSamples( dataHisto );
253 plotHistogram->attach( mpPlot );
258 QwtPlotMarker *rangeMarker =
new QwtPlotMarker();
259 rangeMarker->attach( mpPlot );
260 rangeMarker->setLineStyle( QwtPlotMarker::VLine );
261 rangeMarker->setXValue( range.upperValue() );
262 rangeMarker->setLabel( QLocale().toString( range.upperValue() ) );
263 rangeMarker->setLabelOrientation( Qt::Vertical );
264 rangeMarker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
269 if ( mMeanCheckBox->isChecked() )
271 QwtPlotMarker *meanMarker =
new QwtPlotMarker();
272 meanMarker->attach( mpPlot );
273 meanMarker->setLineStyle( QwtPlotMarker::VLine );
274 meanMarker->setLinePen( mMeanPen );
275 meanMarker->setXValue( mStats.mean() );
276 meanMarker->setLabel( QString( QChar( 956 ) ) );
277 meanMarker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
281 if ( mStdevCheckBox->isChecked() )
283 QwtPlotMarker *stdev1Marker =
new QwtPlotMarker();
284 stdev1Marker->attach( mpPlot );
285 stdev1Marker->setLineStyle( QwtPlotMarker::VLine );
286 stdev1Marker->setLinePen( mStdevPen );
287 stdev1Marker->setXValue( mStats.mean() - mStats.stDev() );
288 stdev1Marker->setLabel( QString( QChar( 963 ) ) );
289 stdev1Marker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
290 stdev1Marker->show();
292 QwtPlotMarker *stdev2Marker =
new QwtPlotMarker();
293 stdev2Marker->attach( mpPlot );
294 stdev2Marker->setLineStyle( QwtPlotMarker::VLine );
295 stdev2Marker->setLinePen( mStdevPen );
296 stdev2Marker->setXValue( mStats.mean() + mStats.stDev() );
297 stdev2Marker->setLabel( QString( QChar( 963 ) ) );
298 stdev2Marker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
299 stdev2Marker->show();
302 mpPlot->setEnabled(
true );