22#include "moc_qgsmaptoolextent.cpp"
48 if ( mRatio.width() > 0 && mRatio.height() > 0 )
50 const 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() )
102void QgsMapToolExtent::calculateEndPoint(
QgsPointXY &point )
104 if ( mRatio.width() > 0 && mRatio.height() > 0 )
106 const double width = std::fabs( point.
x() - mStartPoint.
x() );
107 double height = width * mRatio.height() / mRatio.width();
108 if ( point.
y() - mStartPoint.
y() < 0 )
110 point.
setY( mStartPoint.
y() + height );
114void QgsMapToolExtent::drawExtent()
119 const QgsRectangle rect( mStartPoint, mEndPoint );
122 mRubberBand->addPoint( QgsPointXY( rect.xMinimum(), rect.yMinimum() ),
false );
123 mRubberBand->addPoint( QgsPointXY( rect.xMaximum(), rect.yMinimum() ),
false );
124 mRubberBand->addPoint( QgsPointXY( rect.xMaximum(), rect.yMaximum() ),
false );
125 mRubberBand->addPoint( QgsPointXY( rect.xMinimum(), rect.yMaximum() ),
true );
A mouse event which is the result of a user interaction with a QgsMapCanvas.
void setY(double y)
Sets the y value of the point.
A rectangle specified with double values.
Responsible for drawing transient features (e.g.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).