Fix tools with extent when map is rotated (add a messagebar)

This commit is contained in:
lbartoletti 2017-09-25 14:49:30 +02:00
parent 83d5e77434
commit e80cafb884
5 changed files with 30 additions and 16 deletions

View File

@ -76,13 +76,13 @@ class QgsMapToolAddRectangle: public QgsMapToolCapture
int side( ) const { return mSide; }
private:
//! Convenient member for the azimuth of the rotated rectangle. \see QgsMapToolRectangle3Points
//! Convenient member for the azimuth of the rotated rectangle or when map is rotated.
double mAzimuth = 0.0;
//! Convenient member for the first distance of the rotated rectangle. \see QgsMapToolRectangle3Points
//! Convenient member for the first distance of the rotated rectangle or when map is rotated.
double mDistance1 = 0.0;
//! Convenient member for the second distance of the rotated rectangle. \see QgsMapToolRectangle3Points
//! Convenient member for the second distance of the rotated rectangle or when map is rotated.
double mDistance2 = 0.0;
//! Convenient member for the side where the second distance is drawn. \see QgsMapToolRectangle3Points
//! Convenient member for the side where the second distance is drawn or when map is rotated.
int mSide = 1;
};

View File

@ -62,7 +62,13 @@ void QgsMapToolEllipseExtent::cadCanvasMoveEvent( QgsMapMouseEvent *e )
QgsPoint mapPoint( e->mapPoint() );
if ( mTempRubberBand )
{
mEllipse = QgsEllipse().fromExtent( mPoints.at( 0 ), mapPoint );
mTempRubberBand->setGeometry( mEllipse.toPolygon() );
if ( qgsDoubleNear( mCanvas->rotation(), 0.0 ) )
{
mEllipse = QgsEllipse().fromExtent( mPoints.at( 0 ), mapPoint );
mTempRubberBand->setGeometry( mEllipse.toPolygon() );
}
else
emit messageEmitted( tr( "Cannot use this tool when the map canvas is rotated" ), QgsMessageBar::WARNING );
}
}

View File

@ -29,10 +29,6 @@ class QgsMapToolRectangle3Points: public QgsMapToolAddRectangle
void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;
private:
double mAzimuth;
double mDistance1;
double mDistance2;
};
#endif // QGSMAPTOOLRECTANGLE3POINTS_H

View File

@ -69,12 +69,18 @@ void QgsMapToolRectangleCenter::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
case 1:
{
double xOffset = fabs( mapPoint.x() - mPoints.at( 0 ).x() );
double yOffset = fabs( mapPoint.y() - mPoints.at( 0 ).y() );
mRectangle = QgsRectangle( QgsPoint( mPoints.at( 0 ).x() - xOffset, mPoints.at( 0 ).y() - yOffset ), QgsPoint( mPoints.at( 0 ).x() + xOffset, mPoints.at( 0 ).y() + yOffset ) );
if ( qgsDoubleNear( mCanvas->rotation(), 0.0 ) )
{
double xOffset = fabs( mapPoint.x() - mPoints.at( 0 ).x() );
double yOffset = fabs( mapPoint.y() - mPoints.at( 0 ).y() );
mTempRubberBand->setGeometry( QgsMapToolAddRectangle::rectangleToPolygon() );
mRectangle = QgsRectangle( QgsPoint( mPoints.at( 0 ).x() - xOffset, mPoints.at( 0 ).y() - yOffset ), QgsPoint( mPoints.at( 0 ).x() + xOffset, mPoints.at( 0 ).y() + yOffset ) );
mTempRubberBand->setGeometry( QgsMapToolAddRectangle::rectangleToPolygon() );
}
else
emit messageEmitted( tr( "Cannot use this tool when the map canvas is rotated" ), QgsMessageBar::WARNING );
}
break;
default:

View File

@ -68,9 +68,15 @@ void QgsMapToolRectangleExtent::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
case 1:
{
mRectangle = QgsRectangle( mPoints.at( 0 ), mapPoint );
if ( qgsDoubleNear( mCanvas->rotation(), 0.0 ) )
{
mTempRubberBand->setGeometry( QgsMapToolAddRectangle::rectangleToPolygon() );
mRectangle = QgsRectangle( mPoints.at( 0 ), mapPoint );
mTempRubberBand->setGeometry( QgsMapToolAddRectangle::rectangleToPolygon( ) );
}
else
emit messageEmitted( tr( "Cannot use this tool when the map canvas is rotated" ), QgsMessageBar::WARNING );
}
break;
default: