@@ -61,6 +61,7 @@ QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue
61
61
, mItemPositionLocked( false )
62
62
, mLastValidViewScaleFactor( -1 )
63
63
, mItemRotation( 0 )
64
+ , mEvaluatedItemRotation( 0 )
64
65
, mBlendMode( QPainter::CompositionMode_SourceOver )
65
66
, mEffectsEnabled( true )
66
67
, mTransparency( 0 )
@@ -87,6 +88,7 @@ QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, Q
87
88
, mItemPositionLocked( false )
88
89
, mLastValidViewScaleFactor( -1 )
89
90
, mItemRotation( 0 )
91
+ , mEvaluatedItemRotation( 0 )
90
92
, mBlendMode( QPainter::CompositionMode_SourceOver )
91
93
, mEffectsEnabled( true )
92
94
, mTransparency( 0 )
@@ -120,6 +122,7 @@ void QgsComposerItem::init( bool manageZValue )
120
122
setGraphicsEffect ( mEffect );
121
123
122
124
// data defined strings
125
+ mDataDefinedNames .insert ( ItemRotation, QString ( " dataDefinedRotation" ) );
123
126
mDataDefinedNames .insert ( Transparency, QString ( " dataDefinedTransparency" ) );
124
127
mDataDefinedNames .insert ( BlendMode, QString ( " dataDefinedBlendMode" ) );
125
128
@@ -531,6 +534,11 @@ void QgsComposerItem::setPositionLock( bool lock )
531
534
mItemPositionLocked = lock;
532
535
}
533
536
537
+ double QgsComposerItem::itemRotation ( PropertyValueType valueType ) const
538
+ {
539
+ return valueType == EvaluatedValue ? mEvaluatedItemRotation : mItemRotation ;
540
+ }
541
+
534
542
void QgsComposerItem::move ( double dx, double dy )
535
543
{
536
544
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
612
620
{
613
621
// adjust position to account for frame size
614
622
615
- if ( mItemRotation == 0 )
623
+ if ( mEvaluatedItemRotation == 0 )
616
624
{
617
625
upperLeftX += estimatedFrameBleed ();
618
626
upperLeftY += estimatedFrameBleed ();
@@ -621,7 +629,7 @@ void QgsComposerItem::setItemPosition( double x, double y, double width, double
621
629
{
622
630
// adjust position for item rotation
623
631
QLineF lineToItemOrigin = QLineF ( 0 , 0 , estimatedFrameBleed (), estimatedFrameBleed () );
624
- lineToItemOrigin.setAngle ( -45 - mItemRotation );
632
+ lineToItemOrigin.setAngle ( -45 - mEvaluatedItemRotation );
625
633
upperLeftX += lineToItemOrigin.x2 ();
626
634
upperLeftY += lineToItemOrigin.y2 ();
627
635
}
@@ -935,39 +943,68 @@ void QgsComposerItem::setRotation( double r )
935
943
936
944
void QgsComposerItem::setItemRotation ( double r, bool adjustPosition )
937
945
{
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
+
938
975
if ( adjustPosition )
939
976
{
940
977
// adjustPosition set, so shift the position of the item so that rotation occurs around item center
941
978
// create a line from the centrepoint of the rect() to its origin, in scene coordinates
942
979
QLineF refLine = QLineF ( mapToScene ( QPointF ( rect ().width () / 2.0 , rect ().height () / 2.0 ) ) , mapToScene ( QPointF ( 0 , 0 ) ) );
943
980
// rotate this line by the current rotation angle
944
- refLine.setAngle ( refLine.angle () - r + mItemRotation );
981
+ refLine.setAngle ( refLine.angle () - rotation + mEvaluatedItemRotation );
945
982
// get new end point of line - this is the new item position
946
983
QPointF rotatedReferencePoint = refLine.p2 ();
947
984
setPos ( rotatedReferencePoint );
948
985
emit sizeChanged ();
949
986
}
950
987
951
- if ( r > 360 )
952
- {
953
- mItemRotation = (( int )r ) % 360 ;
954
- }
955
- else
956
- {
957
- mItemRotation = r;
958
- }
959
-
960
988
setTransformOriginPoint ( 0 , 0 );
961
- QGraphicsItem::setRotation ( mItemRotation );
989
+ QGraphicsItem::setRotation ( rotation );
962
990
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
+ }
965
1002
}
966
1003
967
1004
bool QgsComposerItem::imageSizeConsideringRotation ( double & width, double & height ) const
968
1005
{
969
1006
// kept for api compatibility with QGIS 2.0, use item rotation
970
- return imageSizeConsideringRotation ( width, height, mItemRotation );
1007
+ return imageSizeConsideringRotation ( width, height, mEvaluatedItemRotation );
971
1008
}
972
1009
973
1010
QRectF QgsComposerItem::largestRotatedRectWithinBounds ( QRectF originalRect, QRectF boundsRect, double rotation ) const
@@ -1108,7 +1145,7 @@ bool QgsComposerItem::imageSizeConsideringRotation( double& width, double& heigh
1108
1145
bool QgsComposerItem::cornerPointOnRotatedAndScaledRect ( double & x, double & y, double width, double height ) const
1109
1146
{
1110
1147
// 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 );
1112
1149
}
1113
1150
1114
1151
bool 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
1151
1188
void QgsComposerItem::sizeChangedByRotation ( double & width, double & height )
1152
1189
{
1153
1190
// kept for api compatibility with QGIS 2.0, use item rotation
1154
- return sizeChangedByRotation ( width, height, mItemRotation );
1191
+ return sizeChangedByRotation ( width, height, mEvaluatedItemRotation );
1155
1192
}
1156
1193
1157
1194
void QgsComposerItem::sizeChangedByRotation ( double & width, double & height, double rotation )
@@ -1289,6 +1326,10 @@ void QgsComposerItem::repaint()
1289
1326
void QgsComposerItem::refreshDataDefinedProperty ( QgsComposerItem::DataDefinedProperty property )
1290
1327
{
1291
1328
// update data defined properties and redraw item to match
1329
+ if ( property == QgsComposerItem::ItemRotation || property == QgsComposerItem::AllProperties )
1330
+ {
1331
+ refreshRotation ( false , true );
1332
+ }
1292
1333
if ( property == QgsComposerItem::Transparency || property == QgsComposerItem::AllProperties )
1293
1334
{
1294
1335
refreshTransparency ( false );
0 commit comments