55 , mVectorLayer(
layer )
56 , mSourceFieldExp( fieldOrExp )
57 , mXAxisTitle( QObject::tr(
"Value" ) )
58 , mYAxisTitle( QObject::tr(
"Count" ) )
65 QFrame *plotCanvasFrame =
dynamic_cast<QFrame *
>( mpPlot->canvas() );
66 if ( plotCanvasFrame )
67 plotCanvasFrame->setFrameStyle( QFrame::NoFrame );
77 mGridPen = QPen( QColor( 0, 0, 0, 40 ) );
78 mMeanPen = QPen( QColor( 10, 10, 10, 220 ) );
79 mMeanPen.setStyle( Qt::DashLine );
80 mStdevPen = QPen( QColor( 30, 30, 30, 200 ) );
81 mStdevPen.setStyle( Qt::DashLine );
83 if (
layer && !mSourceFieldExp.isEmpty() )
110 if ( !mVectorLayer || mSourceFieldExp.isEmpty() )
113 QApplication::setOverrideCursor( Qt::WaitCursor );
120 QApplication::restoreOverrideCursor();
125 std::sort( mValues.begin(), mValues.end() );
126 mHistogram.setValues( mValues );
127 mBinsSpinBox->blockSignals(
true );
128 mBinsSpinBox->setValue( std::max( mHistogram.optimalNumberBins(), 30 ) );
129 mBinsSpinBox->blockSignals(
false );
132 mStats.calculate( mValues );
134 mpPlot->setEnabled(
true );
135 mMeanCheckBox->setEnabled(
true );
136 mStdevCheckBox->setEnabled(
true );
137 mBinsSpinBox->setEnabled(
true );
139 QApplication::restoreOverrideCursor();
183 mpPlot->detachItems();
186 mpPlot->setAutoDelete(
true );
188 if ( !mXAxisTitle.isEmpty() )
189 mpPlot->setAxisTitle( QwtPlot::xBottom, mXAxisTitle );
190 if ( !mYAxisTitle.isEmpty() )
191 mpPlot->setAxisTitle( QwtPlot::yLeft, mYAxisTitle );
192 mpPlot->setAxisFont( QwtPlot::xBottom, this->font() );
193 mpPlot->setAxisFont( QwtPlot::yLeft, this->font() );
194 QFont titleFont = this->font();
195 titleFont.setBold(
true );
196 QwtText xAxisText = mpPlot->axisTitle( QwtPlot::xBottom );
197 xAxisText.setFont( titleFont );
198 mpPlot->setAxisTitle( QwtPlot::xBottom, xAxisText );
199 QwtText yAxisText = mpPlot->axisTitle( QwtPlot::yLeft );
200 yAxisText.setFont( titleFont );
201 mpPlot->setAxisTitle( QwtPlot::yLeft, yAxisText );
202 mpPlot->setAxisAutoScale( QwtPlot::yLeft );
203 mpPlot->setAxisAutoScale( QwtPlot::xBottom );
206 QwtPlotGrid *grid =
new QwtPlotGrid();
207 grid->enableX(
false );
208 grid->setPen( mGridPen );
209 grid->attach( mpPlot );
212 mHistoColors.clear();
215 mHistoColors << ( range.symbol() ? range.symbol()->color() : Qt::black );
219 QwtPlotHistogram *plotHistogram =
nullptr;
220 plotHistogram = createPlotHistogram( !
mRanges.isEmpty() ?
mRanges.at( 0 ).label() : QString(), !
mRanges.isEmpty() ? QBrush( mHistoColors.at( 0 ) ) : mBrush, !
mRanges.isEmpty() ? Qt::NoPen : mPen );
221 QVector<QwtIntervalSample> dataHisto;
223 int bins = mBinsSpinBox->value();
224 QList<double> edges = mHistogram.binEdges( bins );
225 QList<int> counts = mHistogram.counts( bins );
230 for (
int bin = 0; bin < bins; ++bin )
232 int binValue = counts.at( bin );
236 if ( rangeIndex <
mRanges.count() - 1 && edges.at( bin ) >
mRanges.at( rangeIndex ).upperValue() )
239 plotHistogram->setSamples( dataHisto );
240 plotHistogram->attach( mpPlot );
241 plotHistogram = createPlotHistogram(
mRanges.at( rangeIndex ).label(), mHistoColors.at( rangeIndex ) );
243 dataHisto << QwtIntervalSample( lastValue,
mRanges.at( rangeIndex - 1 ).upperValue(), edges.at( bin ) );
246 double upperEdge = !
mRanges.isEmpty() ? std::min( edges.at( bin + 1 ),
mRanges.at( rangeIndex ).upperValue() ) : edges.at( bin + 1 );
248 dataHisto << QwtIntervalSample( binValue, edges.at( bin ), upperEdge );
250 lastValue = binValue;
253 plotHistogram->setSamples( dataHisto );
254 plotHistogram->attach( mpPlot );
259 QwtPlotMarker *rangeMarker =
new QwtPlotMarker();
260 rangeMarker->attach( mpPlot );
261 rangeMarker->setLineStyle( QwtPlotMarker::VLine );
262 rangeMarker->setXValue( range.upperValue() );
263 rangeMarker->setLabel( QLocale().toString( range.upperValue() ) );
264 rangeMarker->setLabelOrientation( Qt::Vertical );
265 rangeMarker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
270 if ( mMeanCheckBox->isChecked() )
272 QwtPlotMarker *meanMarker =
new QwtPlotMarker();
273 meanMarker->attach( mpPlot );
274 meanMarker->setLineStyle( QwtPlotMarker::VLine );
275 meanMarker->setLinePen( mMeanPen );
276 meanMarker->setXValue( mStats.mean() );
277 meanMarker->setLabel( QString( QChar( 956 ) ) );
278 meanMarker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
282 if ( mStdevCheckBox->isChecked() )
284 QwtPlotMarker *stdev1Marker =
new QwtPlotMarker();
285 stdev1Marker->attach( mpPlot );
286 stdev1Marker->setLineStyle( QwtPlotMarker::VLine );
287 stdev1Marker->setLinePen( mStdevPen );
288 stdev1Marker->setXValue( mStats.mean() - mStats.stDev() );
289 stdev1Marker->setLabel( QString( QChar( 963 ) ) );
290 stdev1Marker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
291 stdev1Marker->show();
293 QwtPlotMarker *stdev2Marker =
new QwtPlotMarker();
294 stdev2Marker->attach( mpPlot );
295 stdev2Marker->setLineStyle( QwtPlotMarker::VLine );
296 stdev2Marker->setLinePen( mStdevPen );
297 stdev2Marker->setXValue( mStats.mean() + mStats.stDev() );
298 stdev2Marker->setLabel( QString( QChar( 963 ) ) );
299 stdev2Marker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop );
300 stdev2Marker->show();
303 mpPlot->setEnabled(
true );