20 #include <QMouseEvent> 48 if ( mRatio.width() > 0 && mRatio.height() > 0 )
50 double width = std::fabs( p.
x() - mStartPoint.
x() );
51 double height = width * ( mRatio.width() / mRatio.height() );
52 if ( p.
y() - mStartPoint.
y() < 0 )
54 p.
setY( mStartPoint.
y() + height );
58 calculateEndPoint( mEndPoint );
65 mEndPoint = mStartPoint;
77 calculateEndPoint( mEndPoint );
87 if ( mStartPoint.
x() != mEndPoint.
x() && mStartPoint.
y() != mEndPoint.
y() )
97 void QgsMapToolExtent::calculateEndPoint(
QgsPointXY &point )
99 if ( mRatio.width() > 0 && mRatio.height() > 0 )
101 double width = std::fabs( point.
x() - mStartPoint.
x() );
102 double height = width * mRatio.height() / mRatio.width();
103 if ( point.
y() - mStartPoint.
y() < 0 )
105 point.
setY( mStartPoint.
y() + height );
109 void QgsMapToolExtent::drawExtent()
A rectangle specified with double values.
A class to represent a 2D point.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
Map canvas is a class for displaying all GIS data types on a canvas.
A class for drawing transient features (e.g.
void setY(double y)
Sets the y value of the point.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).