19#include "moc_qgsgraduatedhistogramwidget.cpp"
31#include <qwt_global.h>
32#include <qwt_plot_canvas.h>
34#include <qwt_plot_curve.h>
35#include <qwt_plot_grid.h>
36#include <qwt_plot_marker.h>
37#include <qwt_plot_picker.h>
38#include <qwt_picker_machine.h>
39#include <qwt_plot_layout.h>
40#include <qwt_plot_renderer.h>
41#include <qwt_plot_histogram.h>
42#include <qwt_scale_map.h>
51 mFilter =
new QgsGraduatedHistogramEventFilter(
mPlot );
53 connect( mFilter, &QgsGraduatedHistogramEventFilter::mousePress,
this, &QgsGraduatedHistogramWidget::mousePress );
54 connect( mFilter, &QgsGraduatedHistogramEventFilter::mouseRelease,
this, &QgsGraduatedHistogramWidget::mouseRelease );
56 mHistoPicker =
new QwtPlotPicker(
mPlot->canvas() );
57 mHistoPicker->setTrackerMode( QwtPicker::ActiveOnly );
58 mHistoPicker->setRubberBand( QwtPicker::VLineRubberBand );
59 mHistoPicker->setStateMachine(
new QwtPickerDragPointMachine );
72 bool pickerEnabled =
false;
75 setToolTip( tr(
"Ranges are overlapping and can't be edited by the histogram" ) );
80 setToolTip( tr(
"Ranges have gaps and can't be edited by the histogram" ) );
83 else if ( mRenderer->
ranges().isEmpty() )
85 setToolTip( QString() );
90 setToolTip( QString() );
97 mHistoPicker->setEnabled( pickerEnabled );
98 mFilter->blockSignals( !pickerEnabled );
101void QgsGraduatedHistogramWidget::mousePress(
double value )
103 mPressedValue = value;
105 int closestRangeIndex = 0;
106 int minPixelDistance = 9999;
107 findClosestRange( mPressedValue, closestRangeIndex, minPixelDistance );
109 if ( minPixelDistance <= 6 )
117void QgsGraduatedHistogramWidget::mouseRelease(
double value )
119 int closestRangeIndex = 0;
120 int minPixelDistance = 9999;
121 findClosestRange( mPressedValue, closestRangeIndex, minPixelDistance );
123 if ( minPixelDistance <= 6 )
131 if ( value <= mRenderer->ranges().at( closestRangeIndex ).lowerValue() || value >= mRenderer->
ranges().at( closestRangeIndex + 1 ).upperValue() )
153void QgsGraduatedHistogramWidget::findClosestRange(
double value,
int &closestRangeIndex,
int &pixelDistance )
const
157 double minDistance = std::numeric_limits<double>::max();
158 const int pressedPixel =
mPlot->canvasMap( QwtPlot::xBottom ).transform( value );
159 for (
int i = 0; i < ranges.count() - 1; ++i )
161 if ( std::fabs( mPressedValue - ranges.at( i ).upperValue() ) < minDistance )
163 closestRangeIndex = i;
164 minDistance = std::fabs( mPressedValue - ranges.at( i ).upperValue() );
165 pixelDistance = std::fabs( pressedPixel -
mPlot->canvasMap( QwtPlot::xBottom ).transform( ranges.at( i ).upperValue() ) );
172QgsGraduatedHistogramEventFilter::QgsGraduatedHistogramEventFilter( QwtPlot *plot )
176 mPlot->canvas()->installEventFilter(
this );
179bool QgsGraduatedHistogramEventFilter::eventFilter( QObject *
object, QEvent *event )
181 if ( !mPlot->isEnabled() )
182 return QObject::eventFilter(
object, event );
184 switch ( event->type() )
186 case QEvent::MouseButtonPress:
188 const QMouseEvent *mouseEvent =
static_cast<QMouseEvent *
>( event );
189 if ( mouseEvent->button() == Qt::LeftButton )
191 emit mousePress( posToValue( mouseEvent->pos() ) );
195 case QEvent::MouseButtonRelease:
197 const QMouseEvent *mouseEvent =
static_cast<QMouseEvent *
>( event );
198 if ( mouseEvent->button() == Qt::LeftButton )
200 emit mouseRelease( posToValue( mouseEvent->pos() ) );
208 return QObject::eventFilter(
object, event );
211double QgsGraduatedHistogramEventFilter::posToValue( QPointF point )
const
216 return mPlot->canvasMap( QwtPlot::xBottom ).invTransform( point.x() );
A vector feature renderer which uses numeric attributes to classify features into different ranges.
void addBreak(double breakValue, bool updateSymbols=true)
Add a breakpoint by splitting existing classes so that the specified value becomes a break between tw...
bool rangesOverlap() const
Tests whether classes assigned to the renderer have ranges which overlap.
bool updateRangeUpperValue(int rangeIndex, double value)
bool updateRangeLowerValue(int rangeIndex, double value)
const QgsRangeList & ranges() const
Returns a list of all ranges used in the classification.
bool rangesHaveGaps() const
Tests whether classes assigned to the renderer have gaps between the ranges.
QList< QgsRendererRange > QgsRangeList