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() ||
132 value >= mRenderer->
ranges().at( closestRangeIndex + 1 ).upperValue() )
154void QgsGraduatedHistogramWidget::findClosestRange(
double value,
int &closestRangeIndex,
int &pixelDistance )
const
158 double minDistance = std::numeric_limits<double>::max();
159 const int pressedPixel =
mPlot->canvasMap( QwtPlot::xBottom ).transform( value );
160 for (
int i = 0; i < ranges.count() - 1; ++i )
162 if ( std::fabs( mPressedValue - ranges.at( i ).upperValue() ) < minDistance )
164 closestRangeIndex = i;
165 minDistance = std::fabs( mPressedValue - ranges.at( i ).upperValue() );
166 pixelDistance = std::fabs( pressedPixel -
mPlot->canvasMap( QwtPlot::xBottom ).transform( ranges.at( i ).upperValue() ) );
173QgsGraduatedHistogramEventFilter::QgsGraduatedHistogramEventFilter( QwtPlot *plot )
177 mPlot->canvas()->installEventFilter(
this );
180bool QgsGraduatedHistogramEventFilter::eventFilter( QObject *
object, QEvent *event )
182 if ( !mPlot->isEnabled() )
183 return QObject::eventFilter(
object, event );
185 switch ( event->type() )
187 case QEvent::MouseButtonPress:
189 const QMouseEvent *mouseEvent =
static_cast<QMouseEvent *
>( event );
190 if ( mouseEvent->button() == Qt::LeftButton )
192 emit mousePress( posToValue( mouseEvent->pos() ) );
196 case QEvent::MouseButtonRelease:
198 const QMouseEvent *mouseEvent =
static_cast<QMouseEvent *
>( event );
199 if ( mouseEvent->button() == Qt::LeftButton )
201 emit mouseRelease( posToValue( mouseEvent->pos() ) );
209 return QObject::eventFilter(
object, event );
212double QgsGraduatedHistogramEventFilter::posToValue( QPointF point )
const
217 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