diff --git a/src/app/composer/qgscomposeritemwidget.cpp b/src/app/composer/qgscomposeritemwidget.cpp index ca9a795e3227..457f0ef193ae 100644 --- a/src/app/composer/qgscomposeritemwidget.cpp +++ b/src/app/composer/qgscomposeritemwidget.cpp @@ -504,7 +504,7 @@ void QgsComposerItemWidget::on_mItemRotationSpinBox_valueChanged( double val ) if ( mItem ) { mItem->beginCommand( tr( "Item rotation changed" ), QgsComposerMergeCommand::ItemRotation ); - mItem->setItemRotation( val ); + mItem->setItemRotation( val, true ); mItem->update(); mItem->endCommand(); } diff --git a/src/core/composer/qgscomposeritem.cpp b/src/core/composer/qgscomposeritem.cpp index a62564446857..93a2b8fbad37 100644 --- a/src/core/composer/qgscomposeritem.cpp +++ b/src/core/composer/qgscomposeritem.cpp @@ -486,8 +486,6 @@ void QgsComposerItem::setSceneRect( const QRectF& rectangle ) QRectF newRect( 0, 0, newWidth, newHeight ); QGraphicsRectItem::setRect( newRect ); - //rotate item around its centre point - setTransformOriginPoint( QPointF( rect().width() / 2.0, rect().height() / 2.0 ) ); setPos( xTranslation, yTranslation ); emit sizeChanged(); @@ -712,8 +710,21 @@ void QgsComposerItem::setRotation( double r ) setItemRotation( r ); } -void QgsComposerItem::setItemRotation( double r ) +void QgsComposerItem::setItemRotation( double r, bool adjustPosition ) { + if ( adjustPosition ) + { + //adjustPosition set, so shift the position of the item so that rotation occurs around item center + //create a line from the centrepoint of the rect() to its origin, in scene coordinates + QLineF refLine = QLineF( mapToScene( QPointF( rect().width() / 2.0, rect().height() / 2.0 ) ) , mapToScene( QPointF( 0 , 0 ) ) ); + //rotate this line by the current rotation angle + refLine.setAngle( refLine.angle() - r + mItemRotation ); + //get new end point of line - this is the new item position + QPointF rotatedReferencePoint = refLine.p2(); + setPos( rotatedReferencePoint ); + emit sizeChanged(); + } + if ( r > 360 ) { mItemRotation = (( int )r ) % 360; @@ -723,8 +734,7 @@ void QgsComposerItem::setItemRotation( double r ) mItemRotation = r; } - //rotate item around its centre point - setTransformOriginPoint( QPointF( rect().width() / 2.0, rect().height() / 2.0 ) ); + setTransformOriginPoint( 0, 0 ); QGraphicsItem::setRotation( mItemRotation ); emit itemRotationChanged( r ); diff --git a/src/core/composer/qgscomposeritem.h b/src/core/composer/qgscomposeritem.h index 4ef92bb17ed5..95d228c57a63 100644 --- a/src/core/composer/qgscomposeritem.h +++ b/src/core/composer/qgscomposeritem.h @@ -320,9 +320,12 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem virtual void setRotation( double r ); /**Sets the item rotation + @param r item rotation in degrees + @param adjustPosition set to true if item should be shifted so that rotation occurs + around item center. If false, rotation occurs around item origin @note this method was added in version 2.1 */ - virtual void setItemRotation( double r ); + virtual void setItemRotation( double r, bool adjustPosition = false ); void repaint();