mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
Remove duplicate code
This commit is contained in:
parent
7f7edd2be3
commit
3009999748
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -45,7 +45,6 @@ class QgsElevationProfileToolMeasure : public QgsPlotTool
|
||||
void cleared();
|
||||
|
||||
private:
|
||||
static QPointF constrainPointToRect( QPointF point, const QRectF &rect );
|
||||
|
||||
QgsElevationProfileCanvas *mElevationCanvas = nullptr;
|
||||
|
||||
|
||||
@ -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 )
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user