Skip to content

Commit

Permalink
Fix tools with extent when map is rotated (add a messagebar)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti committed Sep 26, 2017
1 parent 83d5e77 commit e80cafb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/app/qgsmaptooladdrectangle.h
Expand Up @@ -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;
};

Expand Down
10 changes: 8 additions & 2 deletions src/app/qgsmaptoolellipseextent.cpp
Expand Up @@ -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 );
}
}
4 changes: 0 additions & 4 deletions src/app/qgsmaptoolrectangle3points.h
Expand Up @@ -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
14 changes: 10 additions & 4 deletions src/app/qgsmaptoolrectanglecenter.cpp
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions src/app/qgsmaptoolrectangleextent.cpp
Expand Up @@ -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:
Expand Down

0 comments on commit e80cafb

Please sign in to comment.