Skip to content
Permalink
Browse files

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

  • Loading branch information
lbartoletti committed Sep 26, 2017
1 parent 83d5e77 commit e80cafb884188bd8cab4ec9502f8db46902e326d
@@ -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;
};

@@ -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 );
}
}
@@ -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
@@ -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:
@@ -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:

0 comments on commit e80cafb

Please sign in to comment.
You can’t perform that action at this time.