Remove duplicate code

This commit is contained in:
Nyall Dawson 2022-05-06 10:01:12 +10:00
parent 7f7edd2be3
commit 3009999748
7 changed files with 25 additions and 32 deletions

View File

@ -236,6 +236,11 @@ a "click and drag". If ``False`` is returned, the operation should be
instead treated as just a click on ``startViewPoint``.
%End
static QPointF constrainPointToRect( QPointF point, const QRectF &rect );
%Docstring
Constrains a point to force it to fall within the specified rectangle.
%End

View File

@ -148,18 +148,3 @@ void QgsElevationProfileToolIdentify::plotMoveEvent( QgsPlotMouseEvent *event )
mRubberBand->update( movePoint, Qt::KeyboardModifiers() );
}
QPointF QgsElevationProfileToolIdentify::constrainPointToRect( QPointF point, const QRectF &rect )
{
if ( point.x() < rect.left() )
point.setX( rect.left() );
else if ( point.x() > rect.right() )
point.setX( rect.right() );
if ( point.y() < rect.top() )
point.setY( rect.top() );
else if ( point.y() > rect.bottom() )
point.setY( rect.bottom() );
return point;
}

View File

@ -40,8 +40,6 @@ class QgsElevationProfileToolIdentify : public QgsPlotTool
void plotMoveEvent( QgsPlotMouseEvent *event ) override;
private:
static QPointF constrainPointToRect( QPointF point, const QRectF &rect );
//! Start position for mouse press
QPointF mMousePressStartPos;
QgsPointXY mSnappedMousePressStartPos;

View File

@ -107,19 +107,5 @@ void QgsElevationProfileToolMeasure::plotReleaseEvent( QgsPlotMouseEvent *event
}
}
QPointF QgsElevationProfileToolMeasure::constrainPointToRect( QPointF point, const QRectF &rect )
{
if ( point.x() < rect.left() )
point.setX( rect.left() );
else if ( point.x() > rect.right() )
point.setX( rect.right() );
if ( point.y() < rect.top() )
point.setY( rect.top() );
else if ( point.y() > rect.bottom() )
point.setY( rect.bottom() );
return point;
}
QgsElevationProfileToolMeasure::~QgsElevationProfileToolMeasure() = default;

View File

@ -45,7 +45,6 @@ class QgsElevationProfileToolMeasure : public QgsPlotTool
void cleared();
private:
static QPointF constrainPointToRect( QPointF point, const QRectF &rect );
QgsElevationProfileCanvas *mElevationCanvas = nullptr;

View File

@ -50,6 +50,21 @@ bool QgsPlotTool::isClickAndDrag( QPoint startViewPoint, QPoint endViewPoint ) c
return std::abs( diffX ) >= 2 || std::abs( diffY ) >= 2;
}
QPointF QgsPlotTool::constrainPointToRect( QPointF point, const QRectF &rect )
{
if ( point.x() < rect.left() )
point.setX( rect.left() );
else if ( point.x() > rect.right() )
point.setX( rect.right() );
if ( point.y() < rect.top() )
point.setY( rect.top() );
else if ( point.y() > rect.bottom() )
point.setY( rect.bottom() );
return point;
}
QgsPlotTool::~QgsPlotTool()
{
if ( mCanvas )

View File

@ -258,6 +258,11 @@ class GUI_EXPORT QgsPlotTool : public QObject
*/
bool isClickAndDrag( QPoint startViewPoint, QPoint endViewPoint ) const;
/**
* Constrains a point to force it to fall within the specified rectangle.
*/
static QPointF constrainPointToRect( QPointF point, const QRectF &rect );
//! The pointer to the canvas
QgsPlotCanvas *mCanvas = nullptr;