@@ -31,6 +31,7 @@ QgsComposerArrow::QgsComposerArrow( QgsComposition* c )
31
31
, mStartYIdx( 0 )
32
32
, mMarkerMode( DefaultMarker )
33
33
, mArrowColor( QColor( 0 , 0 , 0 ) )
34
+ , mBoundsBehaviour( 24 )
34
35
{
35
36
initGraphicsSettings ();
36
37
}
@@ -41,6 +42,7 @@ QgsComposerArrow::QgsComposerArrow( const QPointF& startPoint, const QPointF& st
41
42
, mStopPoint( stopPoint )
42
43
, mMarkerMode( DefaultMarker )
43
44
, mArrowColor( QColor( 0 , 0 , 0 ) )
45
+ , mBoundsBehaviour( 24 )
44
46
{
45
47
mStartXIdx = mStopPoint .x () < mStartPoint .x ();
46
48
mStartYIdx = mStopPoint .y () < mStartPoint .y ();
@@ -77,6 +79,11 @@ void QgsComposerArrow::paint( QPainter* painter, const QStyleOptionGraphicsItem
77
79
78
80
// draw arrow
79
81
QPen arrowPen = mPen ;
82
+ if ( mBoundsBehaviour == 22 )
83
+ {
84
+ // if arrow was created in versions prior to 2.4, use the old rendering style
85
+ arrowPen.setCapStyle ( Qt::FlatCap );
86
+ }
80
87
arrowPen.setColor ( mArrowColor );
81
88
painter->setPen ( arrowPen );
82
89
painter->setBrush ( QBrush ( mArrowColor ) );
@@ -134,9 +141,17 @@ void QgsComposerArrow::drawHardcodedMarker( QPainter *p, MarkerType type )
134
141
QBrush arrowBrush = p->brush ();
135
142
arrowBrush.setColor ( mArrowColor );
136
143
p->setBrush ( arrowBrush );
137
- QVector2D dir = QVector2D ( mStopPoint - mStartPoint ).normalized ();
138
- QPointF stop = mStopPoint + ( dir * 0.5 * mArrowHeadWidth ).toPointF ();
139
- drawArrowHead ( p, stop.x () - pos ().x (), stop.y () - pos ().y (), angle ( mStartPoint , stop ), mArrowHeadWidth );
144
+ if ( mBoundsBehaviour == 22 )
145
+ {
146
+ // if arrow was created in versions prior to 2.4, use the old rendering style
147
+ drawArrowHead ( p, mStopPoint .x () - pos ().x (), mStopPoint .y () - pos ().y (), angle ( mStartPoint , mStopPoint ), mArrowHeadWidth );
148
+ }
149
+ else
150
+ {
151
+ QVector2D dir = QVector2D ( mStopPoint - mStartPoint ).normalized ();
152
+ QPointF stop = mStopPoint + ( dir * 0.5 * mArrowHeadWidth ).toPointF ();
153
+ drawArrowHead ( p, stop.x () - pos ().x (), stop.y () - pos ().y (), angle ( mStartPoint , stop ), mArrowHeadWidth );
154
+ }
140
155
}
141
156
142
157
void QgsComposerArrow::drawSVGMarker ( QPainter* p, MarkerType type, const QString &markerPath )
@@ -205,7 +220,30 @@ void QgsComposerArrow::drawSVGMarker( QPainter* p, MarkerType type, const QStrin
205
220
r.render ( &imagePainter );
206
221
207
222
p->save ();
208
- p->translate ( canvasPoint.x () , canvasPoint.y () );
223
+ if ( mBoundsBehaviour == 22 )
224
+ {
225
+ // if arrow was created in versions prior to 2.4, use the old rendering style
226
+ // rotate image fix point for backtransform
227
+ QPointF fixPoint;
228
+ if ( type == StartMarker )
229
+ {
230
+ fixPoint.setX ( 0 ); fixPoint.setY ( arrowHeadHeight / 2.0 );
231
+ }
232
+ else
233
+ {
234
+ fixPoint.setX ( 0 ); fixPoint.setY ( -arrowHeadHeight / 2.0 );
235
+ }
236
+ QPointF rotatedFixPoint;
237
+ double angleRad = ang / 180 * M_PI;
238
+ rotatedFixPoint.setX ( fixPoint.x () * cos ( angleRad ) + fixPoint.y () * -sin ( angleRad ) );
239
+ rotatedFixPoint.setY ( fixPoint.x () * sin ( angleRad ) + fixPoint.y () * cos ( angleRad ) );
240
+ p->translate ( canvasPoint.x () - rotatedFixPoint.x () , canvasPoint.y () - rotatedFixPoint.y () );
241
+ }
242
+ else
243
+ {
244
+ p->translate ( canvasPoint.x () , canvasPoint.y () );
245
+ }
246
+
209
247
p->rotate ( ang );
210
248
p->translate ( -mArrowHeadWidth / 2.0 , -arrowHeadHeight / 2.0 );
211
249
@@ -264,20 +302,41 @@ void QgsComposerArrow::setArrowHeadWidth( double width )
264
302
double QgsComposerArrow::computeMarkerMargin () const
265
303
{
266
304
double margin = 0 ;
267
- if ( mMarkerMode == DefaultMarker )
268
- {
269
- margin = mPen .widthF () / std::sqrt ( 2.0 ) + mArrowHeadWidth / 2.0 ;
270
- }
271
- else if ( mMarkerMode == NoMarker )
305
+
306
+ if ( mBoundsBehaviour == 22 )
272
307
{
273
- margin = mPen .widthF () / std::sqrt ( 2.0 );
308
+ // if arrow was created in versions prior to 2.4, use the old rendering style
309
+ if ( mMarkerMode == DefaultMarker )
310
+ {
311
+ margin = mPen .widthF () / 2.0 + mArrowHeadWidth / 2.0 ;
312
+ }
313
+ else if ( mMarkerMode == NoMarker )
314
+ {
315
+ margin = mPen .widthF () / 2.0 ;
316
+ }
317
+ else if ( mMarkerMode == SVGMarker )
318
+ {
319
+ double maxArrowHeight = qMax ( mStartArrowHeadHeight , mStopArrowHeadHeight );
320
+ margin = mPen .widthF () / 2 + qMax ( mArrowHeadWidth / 2.0 , maxArrowHeight / 2.0 );
321
+ }
274
322
}
275
- else if ( mMarkerMode == SVGMarker )
323
+ else
276
324
{
277
- double startMarkerMargin = std::sqrt ( 0.25 * ( mStartArrowHeadHeight * mStartArrowHeadHeight + mArrowHeadWidth * mArrowHeadWidth ) );
278
- double stopMarkerMargin = std::sqrt ( 0.25 * ( mStopArrowHeadHeight * mStopArrowHeadHeight + mArrowHeadWidth * mArrowHeadWidth ) );
279
- double markerMargin = qMax ( startMarkerMargin, stopMarkerMargin );
280
- margin = qMax ( mPen .widthF () / std::sqrt ( 2.0 ), markerMargin );
325
+ if ( mMarkerMode == DefaultMarker )
326
+ {
327
+ margin = mPen .widthF () / std::sqrt ( 2.0 ) + mArrowHeadWidth / 2.0 ;
328
+ }
329
+ else if ( mMarkerMode == NoMarker )
330
+ {
331
+ margin = mPen .widthF () / std::sqrt ( 2.0 );
332
+ }
333
+ else if ( mMarkerMode == SVGMarker )
334
+ {
335
+ double startMarkerMargin = std::sqrt ( 0.25 * ( mStartArrowHeadHeight * mStartArrowHeadHeight + mArrowHeadWidth * mArrowHeadWidth ) );
336
+ double stopMarkerMargin = std::sqrt ( 0.25 * ( mStopArrowHeadHeight * mStopArrowHeadHeight + mArrowHeadWidth * mArrowHeadWidth ) );
337
+ double markerMargin = qMax ( startMarkerMargin, stopMarkerMargin );
338
+ margin = qMax ( mPen .widthF () / std::sqrt ( 2.0 ), markerMargin );
339
+ }
281
340
}
282
341
return margin;
283
342
}
@@ -306,6 +365,7 @@ bool QgsComposerArrow::writeXML( QDomElement& elem, QDomDocument & doc ) const
306
365
composerArrowElem.setAttribute ( " markerMode" , mMarkerMode );
307
366
composerArrowElem.setAttribute ( " startMarkerFile" , mStartMarkerFile );
308
367
composerArrowElem.setAttribute ( " endMarkerFile" , mEndMarkerFile );
368
+ composerArrowElem.setAttribute ( " boundsBehaviourVersion" , QString::number ( mBoundsBehaviour ) );
309
369
310
370
// arrow color
311
371
QDomElement arrowColorElem = doc.createElement ( " ArrowColor" );
@@ -338,6 +398,8 @@ bool QgsComposerArrow::readXML( const QDomElement& itemElem, const QDomDocument&
338
398
setStartMarker ( itemElem.attribute ( " startMarkerFile" , " " ) );
339
399
setEndMarker ( itemElem.attribute ( " endMarkerFile" , " " ) );
340
400
mMarkerMode = QgsComposerArrow::MarkerMode ( itemElem.attribute ( " markerMode" , " 0" ).toInt () );
401
+ // if bounds behaviour version is not set, default to 2.2 behaviour
402
+ mBoundsBehaviour = itemElem.attribute ( " boundsBehaviourVersion" , " 22" ).toInt ();
341
403
342
404
// arrow color
343
405
QDomNodeList arrowColorList = itemElem.elementsByTagName ( " ArrowColor" );
0 commit comments