@@ -61,6 +61,7 @@ QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue
6161 , mItemPositionLocked( false )
6262 , mLastValidViewScaleFactor( -1 )
6363 , mItemRotation( 0 )
64+ , mEvaluatedItemRotation( 0 )
6465 , mBlendMode( QPainter::CompositionMode_SourceOver )
6566 , mEffectsEnabled( true )
6667 , mTransparency( 0 )
@@ -87,6 +88,7 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q
8788 , mItemPositionLocked( false )
8889 , mLastValidViewScaleFactor( -1 )
8990 , mItemRotation( 0 )
91+ , mEvaluatedItemRotation( 0 )
9092 , mBlendMode( QPainter::CompositionMode_SourceOver )
9193 , mEffectsEnabled( true )
9294 , mTransparency( 0 )
@@ -120,6 +122,7 @@ void QgsComposerItem::init( bool manageZValue )
120122 setGraphicsEffect ( mEffect );
121123
122124 // data defined strings
125+ mDataDefinedNames .insert ( ItemRotation, QString ( " dataDefinedRotation" ) );
123126 mDataDefinedNames .insert ( Transparency, QString ( " dataDefinedTransparency" ) );
124127 mDataDefinedNames .insert ( BlendMode, QString ( " dataDefinedBlendMode" ) );
125128
@@ -531,6 +534,11 @@ void QgsComposerItem::setPositionLock( bool lock )
531534 mItemPositionLocked = lock;
532535}
533536
537+ double QgsComposerItem::itemRotation ( PropertyValueType valueType ) const
538+ {
539+ return valueType == EvaluatedValue ? mEvaluatedItemRotation : mItemRotation ;
540+ }
541+
534542void QgsComposerItem::move ( double dx, double dy )
535543{
536544 QRectF newSceneRect ( pos ().x () + dx, pos ().y () + dy, rect ().width (), rect ().height () );
@@ -612,7 +620,7 @@ void QgsComposerItem::setItemPosition( double x, double y, double width, double
612620 {
613621 // adjust position to account for frame size
614622
615- if ( mItemRotation == 0 )
623+ if ( mEvaluatedItemRotation == 0 )
616624 {
617625 upperLeftX += estimatedFrameBleed ();
618626 upperLeftY += estimatedFrameBleed ();
@@ -621,7 +629,7 @@ void QgsComposerItem::setItemPosition( double x, double y, double width, double
621629 {
622630 // adjust position for item rotation
623631 QLineF lineToItemOrigin = QLineF ( 0 , 0 , estimatedFrameBleed (), estimatedFrameBleed () );
624- lineToItemOrigin.setAngle ( -45 - mItemRotation );
632+ lineToItemOrigin.setAngle ( -45 - mEvaluatedItemRotation );
625633 upperLeftX += lineToItemOrigin.x2 ();
626634 upperLeftY += lineToItemOrigin.y2 ();
627635 }
@@ -935,39 +943,68 @@ void QgsComposerItem::setRotation( double r )
935943
936944void QgsComposerItem::setItemRotation ( double r, bool adjustPosition )
937945{
946+ if ( r >= 360 )
947+ {
948+ mItemRotation = (( int )r ) % 360 ;
949+ }
950+ else
951+ {
952+ mItemRotation = r;
953+ }
954+
955+ refreshRotation ( true , adjustPosition );
956+ }
957+
958+ void QgsComposerItem::refreshRotation ( bool updateItem , bool adjustPosition )
959+ {
960+ double rotation = mItemRotation ;
961+
962+ // data defined rotation set?
963+ QVariant exprVal;
964+ if ( dataDefinedEvaluate ( QgsComposerItem::ItemRotation, exprVal ) )
965+ {
966+ bool ok;
967+ double rotD = exprVal.toDouble ( &ok );
968+ QgsDebugMsg ( QString ( " exprVal Rotation:%1" ).arg ( rotD ) );
969+ if ( ok )
970+ {
971+ rotation = rotD;
972+ }
973+ }
974+
938975 if ( adjustPosition )
939976 {
940977 // adjustPosition set, so shift the position of the item so that rotation occurs around item center
941978 // create a line from the centrepoint of the rect() to its origin, in scene coordinates
942979 QLineF refLine = QLineF ( mapToScene ( QPointF ( rect ().width () / 2.0 , rect ().height () / 2.0 ) ) , mapToScene ( QPointF ( 0 , 0 ) ) );
943980 // rotate this line by the current rotation angle
944- refLine.setAngle ( refLine.angle () - r + mItemRotation );
981+ refLine.setAngle ( refLine.angle () - rotation + mEvaluatedItemRotation );
945982 // get new end point of line - this is the new item position
946983 QPointF rotatedReferencePoint = refLine.p2 ();
947984 setPos ( rotatedReferencePoint );
948985 emit sizeChanged ();
949986 }
950987
951- if ( r > 360 )
952- {
953- mItemRotation = (( int )r ) % 360 ;
954- }
955- else
956- {
957- mItemRotation = r;
958- }
959-
960988 setTransformOriginPoint ( 0 , 0 );
961- QGraphicsItem::setRotation ( mItemRotation );
989+ QGraphicsItem::setRotation ( rotation );
962990
963- emit itemRotationChanged ( r );
964- update ();
991+ mEvaluatedItemRotation = rotation;
992+
993+ emit itemRotationChanged ( rotation );
994+
995+ // update bounds of scene, since rotation may affect this
996+ mComposition ->updateBounds ();
997+
998+ if ( updateItem )
999+ {
1000+ update ();
1001+ }
9651002}
9661003
9671004bool QgsComposerItem::imageSizeConsideringRotation ( double & width, double & height ) const
9681005{
9691006 // kept for api compatibility with QGIS 2.0, use item rotation
970- return imageSizeConsideringRotation ( width, height, mItemRotation );
1007+ return imageSizeConsideringRotation ( width, height, mEvaluatedItemRotation );
9711008}
9721009
9731010QRectF QgsComposerItem::largestRotatedRectWithinBounds ( QRectF originalRect, QRectF boundsRect, double rotation ) const
@@ -1108,7 +1145,7 @@ bool QgsComposerItem::imageSizeConsideringRotation( double& width, double& heigh
11081145bool QgsComposerItem::cornerPointOnRotatedAndScaledRect ( double & x, double & y, double width, double height ) const
11091146{
11101147 // kept for api compatibility with QGIS 2.0, use item rotation
1111- return cornerPointOnRotatedAndScaledRect ( x, y, width, height, mItemRotation );
1148+ return cornerPointOnRotatedAndScaledRect ( x, y, width, height, mEvaluatedItemRotation );
11121149}
11131150
11141151bool QgsComposerItem::cornerPointOnRotatedAndScaledRect ( double & x, double & y, double width, double height, double rotation ) const
@@ -1151,7 +1188,7 @@ bool QgsComposerItem::cornerPointOnRotatedAndScaledRect( double& x, double& y, d
11511188void QgsComposerItem::sizeChangedByRotation ( double & width, double & height )
11521189{
11531190 // kept for api compatibility with QGIS 2.0, use item rotation
1154- return sizeChangedByRotation ( width, height, mItemRotation );
1191+ return sizeChangedByRotation ( width, height, mEvaluatedItemRotation );
11551192}
11561193
11571194void QgsComposerItem::sizeChangedByRotation ( double & width, double & height, double rotation )
@@ -1289,6 +1326,10 @@ void QgsComposerItem::repaint()
12891326void QgsComposerItem::refreshDataDefinedProperty ( QgsComposerItem::DataDefinedProperty property )
12901327{
12911328 // update data defined properties and redraw item to match
1329+ if ( property == QgsComposerItem::ItemRotation || property == QgsComposerItem::AllProperties )
1330+ {
1331+ refreshRotation ( false , true );
1332+ }
12921333 if ( property == QgsComposerItem::Transparency || property == QgsComposerItem::AllProperties )
12931334 {
12941335 refreshTransparency ( false );
0 commit comments