QGIS API Documentation  2.99.0-Master (69af2f5)
qgscomposeritem.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposeritem.cpp
3  -------------------
4  begin : January 2005
5  copyright : (C) 2005 by Radim Blazek
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #include <QWidget>
18 #include <QDomNode>
19 #include <QFile>
20 #include <QGraphicsLineItem>
21 #include <QGraphicsScene>
22 #include <QGraphicsSceneMouseEvent>
23 #include <QGraphicsView>
24 #include <QPainter>
25 #include <QUuid>
26 #include <QGraphicsEffect>
27 
28 #include "qgsproject.h"
29 
30 #include "qgscomposition.h"
31 #include "qgscomposeritem.h"
32 #include "qgscomposerframe.h"
33 #include "qgscomposerutils.h"
34 #include "qgscomposermodel.h"
35 #include "qgscomposereffect.h"
36 
37 #include <limits>
38 #include "qgsapplication.h"
39 #include "qgsrectangle.h" //just for debugging
40 #include "qgslogger.h"
41 #include "qgssymbollayerutils.h" //for pointOnLineWithDistance
42 #include "qgspainting.h"
43 #include "qgsexpressioncontext.h"
44 
45 #include <cmath>
46 
47 QgsComposerItem::QgsComposerItem( QgsComposition *composition, bool manageZValue )
48  : QgsComposerObject( composition )
49  , QGraphicsRectItem( nullptr )
50  , mRemovedFromComposition( false )
51  , mBoundingResizeRectangle( nullptr )
52  , mHAlignSnapItem( nullptr )
53  , mVAlignSnapItem( nullptr )
54  , mFrame( false )
55  , mBackground( true )
56  , mBackgroundColor( QColor( 255, 255, 255, 255 ) )
57  , mItemPositionLocked( false )
58  , mLastValidViewScaleFactor( -1 )
59  , mItemRotation( 0 )
60  , mEvaluatedItemRotation( 0 )
61  , mBlendMode( QPainter::CompositionMode_SourceOver )
62  , mEffectsEnabled( true )
63  , mExcludeFromExports( false )
64  , mEvaluatedExcludeFromExports( false )
65  , mLastUsedPositionMode( UpperLeft )
66  , mIsGroupMember( false )
67  , mCurrentExportLayer( -1 )
68  , mId( QLatin1String( "" ) )
69  , mUuid( QUuid::createUuid().toString() )
70 {
71  init( manageZValue );
72 }
73 
74 QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition *composition, bool manageZValue )
75  : QgsComposerObject( composition )
76  , QGraphicsRectItem( 0, 0, width, height, nullptr )
77  , mRemovedFromComposition( false )
78  , mBoundingResizeRectangle( nullptr )
79  , mHAlignSnapItem( nullptr )
80  , mVAlignSnapItem( nullptr )
81  , mFrame( false )
82  , mFrameColor( QColor( 0, 0, 0 ) )
83  , mBackground( true )
84  , mBackgroundColor( QColor( 255, 255, 255, 255 ) )
85  , mItemPositionLocked( false )
87  , mItemRotation( 0 )
89  , mBlendMode( QPainter::CompositionMode_SourceOver )
90  , mEffectsEnabled( true )
91  , mExcludeFromExports( false )
94  , mIsGroupMember( false )
95  , mCurrentExportLayer( -1 )
96  , mId( QLatin1String( "" ) )
97  , mUuid( QUuid::createUuid().toString() )
98 {
99  init( manageZValue );
100  setPos( x, y );
101 }
102 
103 void QgsComposerItem::init( const bool manageZValue )
104 {
105  setFlag( QGraphicsItem::ItemIsSelectable, true );
106  //set default pen and brush
107  setBrush( mBackgroundColor );
108  QPen defaultPen( mFrameColor );
109  defaultPen.setWidthF( mFrameWidth );
110  defaultPen.setJoinStyle( mFrameJoinStyle );
111  setPen( defaultPen );
112  //let z-Value be managed by composition
113  if ( mComposition && manageZValue )
114  {
115  mCompositionManagesZValue = true;
116  mComposition->addItemToZList( this );
117  }
118  else
119  {
120  mCompositionManagesZValue = false;
121  }
122 
123  // Setup composer effect
124  mEffect = new QgsComposerEffect();
125  setGraphicsEffect( mEffect );
126 }
127 
129 {
130  if ( mComposition && mCompositionManagesZValue )
131  {
133  }
134 
136  delete mEffect;
137 
139 }
140 
142 {
143  QGraphicsRectItem::setSelected( s );
144  //inform model that id data has changed
145  if ( mComposition )
146  {
148  }
149  update(); //to draw selection boxes
150 }
151 
152 bool QgsComposerItem::_writeXml( QDomElement &itemElem, QDomDocument &doc ) const
153 {
154  if ( itemElem.isNull() )
155  {
156  return false;
157  }
158 
159  QDomElement composerItemElem = doc.createElement( QStringLiteral( "ComposerItem" ) );
160 
161  //frame
162  if ( mFrame )
163  {
164  composerItemElem.setAttribute( QStringLiteral( "frame" ), QStringLiteral( "true" ) );
165  }
166  else
167  {
168  composerItemElem.setAttribute( QStringLiteral( "frame" ), QStringLiteral( "false" ) );
169  }
170 
171  //background
172  if ( mBackground )
173  {
174  composerItemElem.setAttribute( QStringLiteral( "background" ), QStringLiteral( "true" ) );
175  }
176  else
177  {
178  composerItemElem.setAttribute( QStringLiteral( "background" ), QStringLiteral( "false" ) );
179  }
180 
181  //scene rect
182  QPointF pagepos = pagePos();
183  composerItemElem.setAttribute( QStringLiteral( "x" ), QString::number( pos().x() ) );
184  composerItemElem.setAttribute( QStringLiteral( "y" ), QString::number( pos().y() ) );
185  composerItemElem.setAttribute( QStringLiteral( "page" ), page() );
186  composerItemElem.setAttribute( QStringLiteral( "pagex" ), QString::number( pagepos.x() ) );
187  composerItemElem.setAttribute( QStringLiteral( "pagey" ), QString::number( pagepos.y() ) );
188  composerItemElem.setAttribute( QStringLiteral( "width" ), QString::number( rect().width() ) );
189  composerItemElem.setAttribute( QStringLiteral( "height" ), QString::number( rect().height() ) );
190  composerItemElem.setAttribute( QStringLiteral( "positionMode" ), QString::number( static_cast< int >( mLastUsedPositionMode ) ) );
191  composerItemElem.setAttribute( QStringLiteral( "zValue" ), QString::number( zValue() ) );
192  composerItemElem.setAttribute( QStringLiteral( "outlineWidth" ), QString::number( mFrameWidth ) );
193  composerItemElem.setAttribute( QStringLiteral( "frameJoinStyle" ), QgsSymbolLayerUtils::encodePenJoinStyle( mFrameJoinStyle ) );
194  composerItemElem.setAttribute( QStringLiteral( "itemRotation" ), QString::number( mItemRotation ) );
195  composerItemElem.setAttribute( QStringLiteral( "uuid" ), mUuid );
196  composerItemElem.setAttribute( QStringLiteral( "id" ), mId );
197  composerItemElem.setAttribute( QStringLiteral( "visibility" ), isVisible() );
198  //position lock for mouse moves/resizes
199  if ( mItemPositionLocked )
200  {
201  composerItemElem.setAttribute( QStringLiteral( "positionLock" ), QStringLiteral( "true" ) );
202  }
203  else
204  {
205  composerItemElem.setAttribute( QStringLiteral( "positionLock" ), QStringLiteral( "false" ) );
206  }
207 
208  composerItemElem.setAttribute( QStringLiteral( "lastValidViewScaleFactor" ), QString::number( mLastValidViewScaleFactor ) );
209 
210  //frame color
211  QDomElement frameColorElem = doc.createElement( QStringLiteral( "FrameColor" ) );
212  frameColorElem.setAttribute( QStringLiteral( "red" ), QString::number( mFrameColor.red() ) );
213  frameColorElem.setAttribute( QStringLiteral( "green" ), QString::number( mFrameColor.green() ) );
214  frameColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( mFrameColor.blue() ) );
215  frameColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( mFrameColor.alpha() ) );
216  composerItemElem.appendChild( frameColorElem );
217 
218  //background color
219  QDomElement bgColorElem = doc.createElement( QStringLiteral( "BackgroundColor" ) );
220  bgColorElem.setAttribute( QStringLiteral( "red" ), QString::number( mBackgroundColor.red() ) );
221  bgColorElem.setAttribute( QStringLiteral( "green" ), QString::number( mBackgroundColor.green() ) );
222  bgColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( mBackgroundColor.blue() ) );
223  bgColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( mBackgroundColor.alpha() ) );
224  composerItemElem.appendChild( bgColorElem );
225 
226  //blend mode
227  composerItemElem.setAttribute( QStringLiteral( "blendMode" ), QgsPainting::getBlendModeEnum( mBlendMode ) );
228 
229  //opacity
230  composerItemElem.setAttribute( QStringLiteral( "opacity" ), QString::number( mOpacity ) );
231 
232  composerItemElem.setAttribute( QStringLiteral( "excludeFromExports" ), mExcludeFromExports );
233 
234  QgsComposerObject::writeXml( composerItemElem, doc );
235  itemElem.appendChild( composerItemElem );
236 
237  return true;
238 }
239 
240 bool QgsComposerItem::_readXml( const QDomElement &itemElem, const QDomDocument &doc )
241 {
242  Q_UNUSED( doc );
243  if ( itemElem.isNull() )
244  {
245  return false;
246  }
247 
248  QgsComposerObject::readXml( itemElem, doc );
249 
250  //rotation
251  setItemRotation( itemElem.attribute( QStringLiteral( "itemRotation" ), QStringLiteral( "0" ) ).toDouble() );
252 
253  //uuid
254  mUuid = itemElem.attribute( QStringLiteral( "uuid" ), QUuid::createUuid().toString() );
255 
256  // temporary for groups imported from templates
257  mTemplateUuid = itemElem.attribute( QStringLiteral( "templateUuid" ) );
258 
259  //id
260  QString id = itemElem.attribute( QStringLiteral( "id" ), QLatin1String( "" ) );
261  setId( id );
262 
263  //frame
264  QString frame = itemElem.attribute( QStringLiteral( "frame" ) );
265  if ( frame.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 )
266  {
267  mFrame = true;
268  }
269  else
270  {
271  mFrame = false;
272  }
273 
274  //frame
275  QString background = itemElem.attribute( QStringLiteral( "background" ) );
276  if ( background.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 )
277  {
278  mBackground = true;
279  }
280  else
281  {
282  mBackground = false;
283  }
284 
285  //position lock for mouse moves/resizes
286  QString positionLock = itemElem.attribute( QStringLiteral( "positionLock" ) );
287  if ( positionLock.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 )
288  {
289  setPositionLock( true );
290  }
291  else
292  {
293  setPositionLock( false );
294  }
295 
296  //visibility
297  setVisibility( itemElem.attribute( QStringLiteral( "visibility" ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) );
298 
299  //position
300  int page;
301  double x, y, pagex, pagey, width, height;
302  bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOK;
303 
304  x = itemElem.attribute( QStringLiteral( "x" ) ).toDouble( &xOk );
305  y = itemElem.attribute( QStringLiteral( "y" ) ).toDouble( &yOk );
306  page = itemElem.attribute( QStringLiteral( "page" ) ).toInt( &pageOk );
307  pagex = itemElem.attribute( QStringLiteral( "pagex" ) ).toDouble( &pagexOk );
308  pagey = itemElem.attribute( QStringLiteral( "pagey" ) ).toDouble( &pageyOk );
309  width = itemElem.attribute( QStringLiteral( "width" ) ).toDouble( &widthOk );
310  height = itemElem.attribute( QStringLiteral( "height" ) ).toDouble( &heightOk );
311  mLastUsedPositionMode = static_cast< ItemPositionMode >( itemElem.attribute( QStringLiteral( "positionMode" ) ).toInt( &positionModeOK ) );
312  if ( !positionModeOK )
313  {
315  }
316  if ( pageOk && pagexOk && pageyOk )
317  {
318  xOk = true;
319  yOk = true;
320  x = pagex;
321  y = ( page - 1 ) * ( mComposition->paperHeight() + composition()->spaceBetweenPages() ) + pagey;
322  }
323 
324  if ( !xOk || !yOk || !widthOk || !heightOk )
325  {
326  return false;
327  }
328 
329  mLastValidViewScaleFactor = itemElem.attribute( QStringLiteral( "lastValidViewScaleFactor" ), QStringLiteral( "-1" ) ).toDouble();
330 
331  setZValue( itemElem.attribute( QStringLiteral( "zValue" ) ).toDouble() );
332 
334 
335  //pen
336  QDomNodeList frameColorList = itemElem.elementsByTagName( QStringLiteral( "FrameColor" ) );
337  if ( !frameColorList.isEmpty() )
338  {
339  QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
340  bool redOk, greenOk, blueOk, alphaOk, widthOk;
341  int penRed, penGreen, penBlue, penAlpha;
342  double penWidth;
343 
344  penWidth = itemElem.attribute( QStringLiteral( "outlineWidth" ) ).toDouble( &widthOk );
345  penRed = frameColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
346  penGreen = frameColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
347  penBlue = frameColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
348  penAlpha = frameColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
349  mFrameJoinStyle = QgsSymbolLayerUtils::decodePenJoinStyle( itemElem.attribute( QStringLiteral( "frameJoinStyle" ), QStringLiteral( "miter" ) ) );
350 
351  if ( redOk && greenOk && blueOk && alphaOk && widthOk )
352  {
353  mFrameColor = QColor( penRed, penGreen, penBlue, penAlpha );
354  mFrameWidth = penWidth;
355  QPen framePen( mFrameColor );
356  framePen.setWidthF( mFrameWidth );
357  framePen.setJoinStyle( mFrameJoinStyle );
358  setPen( framePen );
359  //apply any data defined settings
360  refreshFrameColor( false, context );
361  }
362  }
363 
364  //brush
365  QDomNodeList bgColorList = itemElem.elementsByTagName( QStringLiteral( "BackgroundColor" ) );
366  if ( !bgColorList.isEmpty() )
367  {
368  QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
369  bool redOk, greenOk, blueOk, alphaOk;
370  int bgRed, bgGreen, bgBlue, bgAlpha;
371  bgRed = bgColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
372  bgGreen = bgColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
373  bgBlue = bgColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
374  bgAlpha = bgColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
375  if ( redOk && greenOk && blueOk && alphaOk )
376  {
377  mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
378  setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
379  }
380  //apply any data defined settings
381  refreshBackgroundColor( false, context );
382  }
383 
384  //blend mode
385  setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( itemElem.attribute( QStringLiteral( "blendMode" ), QStringLiteral( "0" ) ).toUInt() ) ) );
386 
387  //opacity
388  if ( itemElem.hasAttribute( QStringLiteral( "opacity" ) ) )
389  {
390  setItemOpacity( itemElem.attribute( QStringLiteral( "opacity" ), QStringLiteral( "1" ) ).toDouble() );
391  }
392  else
393  {
394  setItemOpacity( 1.0 - itemElem.attribute( QStringLiteral( "transparency" ), QStringLiteral( "0" ) ).toInt() / 100.0 );
395  }
396 
397  mExcludeFromExports = itemElem.attribute( QStringLiteral( "excludeFromExports" ), QStringLiteral( "0" ) ).toInt();
399 
400  QRectF evaluatedRect = evalItemRect( QRectF( x, y, width, height ) );
401  setSceneRect( evaluatedRect );
402 
403  return true;
404 }
405 
407 {
408  if ( drawFrame == mFrame )
409  {
410  //no change
411  return;
412  }
413 
414  mFrame = drawFrame;
415  emit frameChanged();
416 }
417 
418 void QgsComposerItem::setFrameStrokeColor( const QColor &color )
419 {
420  if ( mFrameColor == color )
421  {
422  //no change
423  return;
424  }
425  mFrameColor = color;
426  QPen itemPen = pen();
427  itemPen.setColor( mFrameColor );
428  setPen( itemPen );
429  // apply any datadefined overrides
431  refreshFrameColor( true, context );
432  emit frameChanged();
433 }
434 
435 void QgsComposerItem::setFrameStrokeWidth( const double strokeWidth )
436 {
437  if ( qgsDoubleNear( mFrameWidth, strokeWidth ) )
438  {
439  //no change
440  return;
441  }
442  mFrameWidth = strokeWidth;
443  QPen itemPen = pen();
444  itemPen.setWidthF( mFrameWidth );
445  setPen( itemPen );
446  emit frameChanged();
447 }
448 
449 void QgsComposerItem::setFrameJoinStyle( const Qt::PenJoinStyle style )
450 {
451  if ( mFrameJoinStyle == style )
452  {
453  //no change
454  return;
455  }
456  mFrameJoinStyle = style;
457 
458  QPen itemPen = pen();
459  itemPen.setJoinStyle( mFrameJoinStyle );
460  setPen( itemPen );
461  emit frameChanged();
462 }
463 
465 {
466  if ( !hasFrame() )
467  {
468  return 0;
469  }
470 
471  return pen().widthF() / 2.0;
472 }
473 
475 {
476  double frameBleed = estimatedFrameBleed();
477  return rect().adjusted( -frameBleed, -frameBleed, frameBleed, frameBleed );
478 }
479 
481 {
482  if ( mComposition )
483  {
484  mComposition->beginCommand( this, commandText, c );
485  }
486 }
487 
489 {
490  if ( mComposition )
491  {
493  }
494 }
495 
497 {
498  if ( mComposition )
499  {
501  }
502 }
503 
505 {
506  Q_UNUSED( p );
508  {
509  return;
510  }
511 
512  if ( !isSelected() )
513  {
514  return;
515  }
516 
517  //logic for drawing additional graphics on selected items here (if required)
518 
519  //draw dotted border around locked, selected items
520  if ( positionLock() )
521  {
522  p->save();
523  p->setCompositionMode( QPainter::CompositionMode_Difference );
524 
525  // use a grey dashed pen - in difference mode this should always be visible
526  QPen selectedItemPen = QPen( QColor( 144, 144, 144, 255 ) );
527  selectedItemPen.setStyle( Qt::DotLine );
528  selectedItemPen.setWidth( 0 );
529  p->setPen( selectedItemPen );
530  p->setBrush( Qt::NoBrush );
531 
532  // drawPolygon causes issues on windows - corners of path may be missing resulting in triangles being drawn
533  // instead of rectangles! (Same cause as #13343)
534  QPainterPath path;
535  path.addPolygon( rect() );
536  p->drawPath( path );
537 
538  p->restore();
539  }
540 
541 }
542 
543 void QgsComposerItem::drawFrame( QPainter *p )
544 {
545  if ( mFrame && p )
546  {
547  p->save();
548  p->setPen( pen() );
549  p->setBrush( Qt::NoBrush );
550  p->setRenderHint( QPainter::Antialiasing, true );
551  p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
552  p->restore();
553  }
554 }
555 
556 void QgsComposerItem::setPositionLock( const bool lock )
557 {
558  if ( lock == mItemPositionLocked )
559  {
560  return;
561  }
562 
563  mItemPositionLocked = lock;
564 
565  //inform model that id data has changed
566  if ( mComposition )
567  {
569  }
570  update();
571  emit lockChanged();
572 }
573 
574 double QgsComposerItem::itemRotation( const PropertyValueType valueType ) const
575 {
577 }
578 
580 {
581  if ( !mUpdatesEnabled )
582  return;
583 
584  QGraphicsRectItem::update();
585 }
586 
587 void QgsComposerItem::move( double dx, double dy )
588 {
589  QRectF newSceneRect( pos().x() + dx, pos().y() + dy, rect().width(), rect().height() );
590  setSceneRect( evalItemRect( newSceneRect ) );
591 }
592 
594 {
595  double y = pos().y();
596  double h = composition()->paperHeight() + composition()->spaceBetweenPages();
597  int page = 1;
598  while ( y - h >= 0. )
599  {
600  y -= h;
601  ++page;
602  }
603  return page;
604 }
605 
607 {
608  QPointF p = pos();
609  double h = composition()->paperHeight() + composition()->spaceBetweenPages();
610  p.ry() -= ( page() - 1 ) * h;
611  return p;
612 }
613 
614 void QgsComposerItem::updatePagePos( double newPageWidth, double newPageHeight )
615 {
616  Q_UNUSED( newPageWidth )
617  QPointF curPagePos = pagePos();
618  int curPage = page() - 1;
619 
620  double y = curPage * ( newPageHeight + composition()->spaceBetweenPages() ) + curPagePos.y();
621  QRectF newSceneRect( pos().x(), y, rect().width(), rect().height() );
622 
623  setSceneRect( evalItemRect( newSceneRect ) );
624  emit sizeChanged();
625 }
626 
627 void QgsComposerItem::setItemPosition( double x, double y, ItemPositionMode itemPoint, int page )
628 {
629  double width = rect().width();
630  double height = rect().height();
631  setItemPosition( x, y, width, height, itemPoint, false, page );
632 }
633 
634 void QgsComposerItem::setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint, bool posIncludesFrame, int page )
635 {
636  double upperLeftX = x;
637  double upperLeftY = y;
638 
639  if ( page > 0 )
640  {
641  double h = composition()->paperHeight() + composition()->spaceBetweenPages();
642  upperLeftY += ( page - 1 ) * h;
643  }
644 
645  //store the item position mode
646  mLastUsedPositionMode = itemPoint;
647 
648  //adjust x-coordinate if placement is not done to a left point
649  if ( itemPoint == UpperMiddle || itemPoint == Middle || itemPoint == LowerMiddle )
650  {
651  upperLeftX -= width / 2.0;
652  }
653  else if ( itemPoint == UpperRight || itemPoint == MiddleRight || itemPoint == LowerRight )
654  {
655  upperLeftX -= width;
656  }
657 
658  //adjust y-coordinate if placement is not done to an upper point
659  if ( itemPoint == MiddleLeft || itemPoint == Middle || itemPoint == MiddleRight )
660  {
661  upperLeftY -= height / 2.0;
662  }
663  else if ( itemPoint == LowerLeft || itemPoint == LowerMiddle || itemPoint == LowerRight )
664  {
665  upperLeftY -= height;
666  }
667 
668  if ( posIncludesFrame )
669  {
670  //adjust position to account for frame size
671 
673  {
674  upperLeftX += estimatedFrameBleed();
675  upperLeftY += estimatedFrameBleed();
676  }
677  else
678  {
679  //adjust position for item rotation
680  QLineF lineToItemOrigin = QLineF( 0, 0, estimatedFrameBleed(), estimatedFrameBleed() );
681  lineToItemOrigin.setAngle( -45 - mEvaluatedItemRotation );
682  upperLeftX += lineToItemOrigin.x2();
683  upperLeftY += lineToItemOrigin.y2();
684  }
685 
686  width -= 2 * estimatedFrameBleed();
687  height -= 2 * estimatedFrameBleed();
688  }
689 
690  //consider data defined item size and position before finalising rect
691  QRectF newRect = evalItemRect( QRectF( upperLeftX, upperLeftY, width, height ) );
692 
693  setSceneRect( newRect );
694 }
695 
696 void QgsComposerItem::setSceneRect( const QRectF &rectangle )
697 {
698  //setRect in item coordinates
699  double newWidth = rectangle.width();
700  double newHeight = rectangle.height();
701  double xTranslation = rectangle.x();
702  double yTranslation = rectangle.y();
703 
704  //correction if width and/or height are negative
705  if ( rectangle.width() < 0 )
706  {
707  newWidth = - rectangle.width();
708  xTranslation -= newWidth;
709  }
710 
711  if ( rectangle.height() < 0 )
712  {
713  newHeight = - rectangle.height();
714  yTranslation -= newHeight;
715  }
716 
717  QGraphicsRectItem::setRect( QRectF( 0, 0, newWidth, newHeight ) );
718  setPos( QPointF( xTranslation, yTranslation ) );
719 
720  emit sizeChanged();
721 }
722 
723 QRectF QgsComposerItem::evalItemRect( const QRectF &newRect, const bool resizeOnly, const QgsExpressionContext *context )
724 {
725  QRectF result = newRect;
726 
727  //TODO QGIS 3.0
728  //maintain pre 2.12 API. remove when API break allowed
730  const QgsExpressionContext *evalContext = context ? context : &scopedContext;
731 
732  //data defined position or size set? if so, update rect with data defined values
733  bool ok = false;
734  double ddWidth = mDataDefinedProperties.valueAsDouble( QgsComposerObject::ItemWidth, *evalContext, 0, &ok );
735  //evaulate width and height first, since they may affect position if non-top-left reference point set
736  if ( ok )
737  {
738  result.setWidth( ddWidth );
739  }
740  double ddHeight = mDataDefinedProperties.valueAsDouble( QgsComposerObject::ItemHeight, *evalContext, 0, &ok );
741  if ( ok )
742  {
743  result.setHeight( ddHeight );
744  }
745 
746  double x = result.left();
747  //initially adjust for position mode to get x coordinate
748  if ( !resizeOnly )
749  {
750  //adjust x-coordinate if placement is not done to a left point
752  {
753  x += newRect.width() / 2.0;
754  }
756  {
757  x += newRect.width();
758  }
759  }
760  else
761  {
763  {
764  x += rect().width() / 2.0;
765  }
767  {
768  x += rect().width();
769  }
770  }
771  double ddPosX = mDataDefinedProperties.valueAsDouble( QgsComposerObject::PositionX, *evalContext, 0.0, &ok );
772  if ( ok )
773  {
774  x = ddPosX;
775  }
776 
777  double y = result.top();
778  //initially adjust for position mode to get y coordinate
779  if ( !resizeOnly )
780  {
781  //adjust y-coordinate if placement is not done to an upper point
783  {
784  y += newRect.height() / 2.0;
785  }
787  {
788  y += newRect.height();
789  }
790  }
791  else
792  {
794  {
795  y += rect().height() / 2.0;
796  }
798  {
799  y += rect().height();
800  }
801  }
802  double ddPosY = mDataDefinedProperties.valueAsDouble( QgsComposerObject::PositionY, *evalContext, 0, &ok );
803  if ( ok )
804  {
805  y = ddPosY;
806  }
807 
808  //adjust x-coordinate if placement is not done to a left point
810  {
811  x -= result.width() / 2.0;
812  }
814  {
815  x -= result.width();
816  }
817 
818  //adjust y-coordinate if placement is not done to an upper point
820  {
821  y -= result.height() / 2.0;
822  }
824  {
825  y -= result.height();
826  }
827 
828  result.moveLeft( x );
829  result.moveTop( y );
830 
831  return result;
832 }
833 
835 {
837  {
838  //preview mode or no composition, so ok to draw item
839  return true;
840  }
841 
842  //exporting composition, so check if item is excluded from exports
844 }
845 
847 {
850  return context;
851 }
852 
854 {
855  if ( mBackground && p )
856  {
857  p->save();
858  p->setBrush( brush() );//this causes a problem in atlas generation
859  p->setPen( Qt::NoPen );
860  p->setRenderHint( QPainter::Antialiasing, true );
861  p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
862  p->restore();
863  }
864 }
865 
867 {
869  setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
870  // apply any datadefined overrides
872  refreshBackgroundColor( true, context );
873 }
874 
875 void QgsComposerItem::setBlendMode( const QPainter::CompositionMode blendMode )
876 {
878  // Update the composer effect to use the new blend mode
880  refreshBlendMode( context );
881 }
882 
883 void QgsComposerItem::refreshBlendMode( const QgsExpressionContext &context )
884 {
885  QPainter::CompositionMode blendMode = mBlendMode;
886 
887  //data defined blend mode set?
888  bool ok = false;
889  QString blendStr = mDataDefinedProperties.valueAsString( QgsComposerObject::BlendMode, context, QString(), &ok );
890  if ( ok && !blendStr.isEmpty() )
891  {
892  QString blendstr = blendStr.trimmed();
893  QPainter::CompositionMode blendModeD = QgsSymbolLayerUtils::decodeBlendMode( blendstr );
894 
895  QgsDebugMsg( QString( "exprVal BlendMode:%1" ).arg( blendModeD ) );
896  blendMode = blendModeD;
897  }
898 
899  // Update the composer effect to use the new blend mode
900  mEffect->setCompositionMode( blendMode );
901 }
902 
903 void QgsComposerItem::setItemOpacity( const double opacity )
904 {
905  mOpacity = opacity;
907  refreshOpacity( true, context );
908 }
909 
910 void QgsComposerItem::refreshOpacity( const bool updateItem, const QgsExpressionContext &context )
911 {
912  //data defined opacity set?
913  double opacity = mDataDefinedProperties.valueAsDouble( QgsComposerObject::Opacity, context, mOpacity * 100.0 );
914 
915  // Set the QGraphicItem's opacity
916  setOpacity( opacity / 100.0 );
917 
918  if ( updateItem )
919  {
920  update();
921  }
922 }
923 
924 void QgsComposerItem::refreshFrameColor( const bool updateItem, const QgsExpressionContext &context )
925 {
926  //data defined stroke color set?
927  bool ok = false;
929  if ( ok )
930  {
931  QPen itemPen = pen();
932  itemPen.setColor( frameColor );
933  setPen( itemPen );
934  }
935  else
936  {
937  QPen itemPen = pen();
938  itemPen.setColor( mFrameColor );
939  setPen( itemPen );
940  }
941  if ( updateItem )
942  {
943  update();
944  }
945 }
946 
947 void QgsComposerItem::refreshBackgroundColor( const bool updateItem, const QgsExpressionContext &context )
948 {
949  //data defined color set?
950  bool ok = false;
952  if ( ok )
953  {
954  setBrush( QBrush( backgroundColor, Qt::SolidPattern ) );
955  }
956  else
957  {
958  setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
959  }
960  if ( updateItem )
961  {
962  update();
963  }
964 }
965 
967 {
968  //enable or disable the QgsComposerEffect applied to this item
970  mEffect->setEnabled( effectsEnabled );
971 }
972 
974 {
975  double result = -1;
976  if ( scene() )
977  {
978  QList<QGraphicsView *> viewList = scene()->views();
979  if ( !viewList.isEmpty() ) //if not, probably this function was called from non-gui code
980  {
981  QGraphicsView *currentView = viewList.at( 0 );
982  if ( currentView->isVisible() )
983  {
984  result = currentView->transform().m11();
985  mLastValidViewScaleFactor = result;
986  }
987  }
988  }
989  return result;
990 }
991 
993 {
994  //size of symbol boxes depends on zoom level in composer view
995  double viewScaleFactor = horizontalViewScaleFactor();
996  double rectHandlerSize = 10.0 / viewScaleFactor;
997 
998  //make sure the boxes don't get too large
999  if ( rectHandlerSize > ( rect().width() / 3 ) )
1000  {
1001  rectHandlerSize = rect().width() / 3;
1002  }
1003  if ( rectHandlerSize > ( rect().height() / 3 ) )
1004  {
1005  rectHandlerSize = rect().height() / 3;
1006  }
1007  return rectHandlerSize;
1008 }
1009 
1010 void QgsComposerItem::setItemRotation( const double r, const bool adjustPosition )
1011 {
1012  mItemRotation = r;
1013  if ( mItemRotation >= 360.0 || mItemRotation <= -360.0 )
1014  {
1015  mItemRotation = fmod( mItemRotation, 360.0 );
1016  }
1017 
1019  refreshRotation( true, adjustPosition, context );
1020 }
1021 
1022 void QgsComposerItem::refreshRotation( const bool updateItem, const bool adjustPosition, const QgsExpressionContext &context )
1023 {
1024  double rotation = mItemRotation;
1025 
1026  //data defined rotation set?
1027  rotation = mDataDefinedProperties.valueAsDouble( QgsComposerObject::ItemRotation, context, rotation );
1028 
1029  if ( qgsDoubleNear( rotation, mEvaluatedItemRotation ) )
1030  {
1031  return;
1032  }
1033 
1034  if ( adjustPosition )
1035  {
1036  //adjustPosition set, so shift the position of the item so that rotation occurs around item center
1037  //create a line from the centrepoint of the rect() to its origin, in scene coordinates
1038  QLineF refLine = QLineF( mapToScene( QPointF( rect().width() / 2.0, rect().height() / 2.0 ) ), mapToScene( QPointF( 0, 0 ) ) );
1039  //rotate this line by the current rotation angle
1040  refLine.setAngle( refLine.angle() - rotation + mEvaluatedItemRotation );
1041  //get new end point of line - this is the new item position
1042  QPointF rotatedReferencePoint = refLine.p2();
1043  setPos( rotatedReferencePoint );
1044  emit sizeChanged();
1045  }
1046 
1047  setTransformOriginPoint( 0, 0 );
1048  QGraphicsItem::setRotation( rotation );
1049 
1050  mEvaluatedItemRotation = rotation;
1051 
1052  emit itemRotationChanged( rotation );
1053 
1054  //update bounds of scene, since rotation may affect this
1056 
1057  if ( updateItem )
1058  {
1059  update();
1060  }
1061 }
1062 
1064 {
1065  if ( !mHAlignSnapItem )
1066  {
1067  mHAlignSnapItem = new QGraphicsLineItem( nullptr );
1068  QPen pen = QPen( QColor( Qt::red ) );
1069  pen.setWidthF( 0.0 );
1070  mHAlignSnapItem->setPen( pen );
1071  scene()->addItem( mHAlignSnapItem );
1072  mHAlignSnapItem->setZValue( 90 );
1073  }
1074  return mHAlignSnapItem;
1075 }
1076 
1078 {
1079  if ( !mVAlignSnapItem )
1080  {
1081  mVAlignSnapItem = new QGraphicsLineItem( nullptr );
1082  QPen pen = QPen( QColor( Qt::red ) );
1083  pen.setWidthF( 0.0 );
1084  mVAlignSnapItem->setPen( pen );
1085  scene()->addItem( mVAlignSnapItem );
1086  mVAlignSnapItem->setZValue( 90 );
1087  }
1088  return mVAlignSnapItem;
1089 }
1090 
1092 {
1093  if ( mHAlignSnapItem )
1094  {
1095  scene()->removeItem( mHAlignSnapItem );
1096  delete mHAlignSnapItem;
1097  mHAlignSnapItem = nullptr;
1098  }
1099 }
1100 
1102 {
1103  if ( mVAlignSnapItem )
1104  {
1105  scene()->removeItem( mVAlignSnapItem );
1106  delete mVAlignSnapItem;
1107  mVAlignSnapItem = nullptr;
1108  }
1109 }
1110 
1112 {
1115 }
1116 
1118 {
1119  updateItem();
1120 }
1121 
1123 {
1124  //maintain 2.10 API
1125  //TODO QGIS 3.0 - remove this
1127  const QgsExpressionContext *evalContext = context ? context : &scopedContext;
1128 
1129  //update data defined properties and redraw item to match
1130  if ( property == QgsComposerObject::PositionX || property == QgsComposerObject::PositionY ||
1131  property == QgsComposerObject::ItemWidth || property == QgsComposerObject::ItemHeight ||
1132  property == QgsComposerObject::AllProperties )
1133  {
1134  QRectF beforeRect = QRectF( pos().x(), pos().y(), rect().width(), rect().height() );
1135  QRectF evaluatedRect = evalItemRect( beforeRect, false, evalContext );
1136  if ( evaluatedRect != beforeRect )
1137  {
1138  setSceneRect( evaluatedRect );
1139  }
1140  }
1141  if ( property == QgsComposerObject::ItemRotation || property == QgsComposerObject::AllProperties )
1142  {
1143  refreshRotation( false, true, *evalContext );
1144  }
1145  if ( property == QgsComposerObject::Opacity || property == QgsComposerObject::AllProperties )
1146  {
1147  refreshOpacity( false, *evalContext );
1148  }
1149  if ( property == QgsComposerObject::BlendMode || property == QgsComposerObject::AllProperties )
1150  {
1151  refreshBlendMode( *evalContext );
1152  }
1153  if ( property == QgsComposerObject::FrameColor || property == QgsComposerObject::AllProperties )
1154  {
1155  refreshFrameColor( false, *evalContext );
1156  }
1158  {
1159  refreshBackgroundColor( false, *evalContext );
1160  }
1162  {
1163  bool exclude = mExcludeFromExports;
1164  //data defined exclude from exports set?
1165  exclude = mDataDefinedProperties.valueAsBool( QgsComposerObject::ExcludeFromExports, *evalContext, exclude );
1166  mEvaluatedExcludeFromExports = exclude;
1167  }
1168 
1169  update();
1170 }
1171 
1172 void QgsComposerItem::setId( const QString &id )
1173 {
1174  if ( id == mId )
1175  {
1176  return;
1177  }
1178 
1179  setToolTip( id );
1180  mId = id;
1181 
1182  //inform model that id data has changed
1183  if ( mComposition )
1184  {
1186  }
1187 
1188  emit itemChanged();
1189 }
1190 
1192 {
1194  setFlag( QGraphicsItem::ItemIsSelectable, !isGroupMember ); //item in groups cannot be selected
1195 }
1196 
1198 {
1199  //return id, if it's not empty
1200  if ( ! id().isEmpty() )
1201  {
1202  return id();
1203  }
1204 
1205  //for unnamed items, default to item type
1206  //(note some item types override this method to provide their own defaults)
1207  switch ( type() )
1208  {
1209  case ComposerArrow:
1210  return tr( "<arrow>" );
1211  case ComposerItemGroup:
1212  return tr( "<group>" );
1213  case ComposerLabel:
1214  return tr( "<label>" );
1215  case ComposerLegend:
1216  return tr( "<legend>" );
1217  case ComposerMap:
1218  return tr( "<map>" );
1219  case ComposerPicture:
1220  return tr( "<picture>" );
1221  case ComposerScaleBar:
1222  return tr( "<scale bar>" );
1223  case ComposerShape:
1224  return tr( "<shape>" );
1225  case ComposerTable:
1226  return tr( "<table>" );
1228  return tr( "<attribute table>" );
1229  case ComposerTextTable:
1230  return tr( "<text table>" );
1231  case ComposerFrame:
1232  return tr( "<frame>" );
1233  }
1234 
1235  return tr( "<item>" );
1236 }
1237 
1238 void QgsComposerItem::setVisibility( const bool visible )
1239 {
1240  if ( visible == isVisible() )
1241  {
1242  //nothing to do
1243  return;
1244  }
1245 
1246  QGraphicsItem::setVisible( visible );
1247 
1248  //inform model that id data has changed
1249  if ( mComposition )
1250  {
1252  }
1253 }
1254 
1256 {
1258 }
1259 
1260 void QgsComposerItem::setExcludeFromExports( const bool exclude )
1261 {
1262  mExcludeFromExports = exclude;
1264 }
bool mExcludeFromExports
Whether item should be excluded in exports.
void setCompositionMode(QPainter::CompositionMode compositionMode)
double horizontalViewScaleFactor() const
Returns the zoom factor of the graphics view.
virtual QString displayName() const
Get item display name.
A base class for objects which belong to a map composition.
bool isGroupMember() const
Returns whether this item is part of a group.
virtual QgsExpressionContext createExpressionContext() const
Creates an expression context relating to the objects&#39; current state.
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
void itemRotationChanged(double newRotation)
Is emitted on item rotation change.
virtual void setFrameStrokeWidth(const double strokeWidth)
Sets frame stroke width.
void addItemToZList(QgsComposerItem *item)
Adds item to z list. Usually called from constructor of QgsComposerItem.
QPointF pagePos() const
Returns the item&#39;s position relative to its current page.
QgsComposerModel * itemsModel()
Returns the items model attached to the composition.
#define QgsDebugMsg(str)
Definition: qgslogger.h:37
void itemChanged()
Emitted when the item changes.
bool effectsEnabled() const
Returns whether effects (e.g., blend modes) are enabled for the item.
double mFrameWidth
Item frame width.
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=0) const
Calculates the current value of the property with the specified key and interprets it as an boolean...
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
Definition: qgspainting.cpp:66
QRectF evalItemRect(const QRectF &newRect, const bool resizeOnly=false, const QgsExpressionContext *context=nullptr)
Evaluates an item&#39;s bounding rect to consider data defined position and size of item and reference po...
void removeItemFromZList(QgsComposerItem *item)
Removes item from z list. Usually called from destructor of QgsComposerItem.
virtual double estimatedFrameBleed() const
Returns the estimated amount the item&#39;s frame bleeds outside the item&#39;s actual rectangle.
double mLastValidViewScaleFactor
Backup to restore item appearance if no view scale factor is available.
ItemPositionMode mLastUsedPositionMode
The item&#39;s position mode.
void updateBounds()
Updates the scene bounds of the composition.
void updateItemVisibility(QgsComposerItem *item)
Must be called when an item&#39;s visibility changes.
QColor backgroundColor() const
Gets the background color for this item.
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Definition: qgspainting.cpp:6
virtual void setSelected(bool s)
Set selected, selected item should be highlighted.
virtual void drawFrame(QPainter *p)
Draw black frame around item.
virtual void setFrameEnabled(const bool drawFrame)
Set whether this item has a frame drawn around it or not.
double itemRotation(const QgsComposerObject::PropertyValueType valueType=QgsComposerObject::EvaluatedValue) const
Returns the current rotation for the composer item, in degrees clockwise.
QPainter::CompositionMode mBlendMode
Composition blend mode for item.
bool excludeFromExports(const QgsComposerObject::PropertyValueType valueType=QgsComposerObject::EvaluatedValue)
Returns whether the item should be excluded from composer exports and prints.
void setBlendMode(const QPainter::CompositionMode blendMode)
Sets the item&#39;s composition blending mode.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
Definition: qgis.h:203
void updateItemDisplayName(QgsComposerItem *item)
Must be called when an item&#39;s display name is modified.
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
DataDefinedProperty
Data defined properties for different item types.
QgsComposition::PlotStyle plotStyle() const
void setItemPosition(double x, double y, ItemPositionMode itemPoint=UpperLeft, int page=-1)
Moves the item to a new position (in canvas coordinates)
void updateItemLockStatus(QgsComposerItem *item)
Must be called when an item&#39;s lock status changes.
int page() const
Gets the page the item is currently on.
QColor valueAsColor(int key, const QgsExpressionContext &context, const QColor &defaultColor=QColor(), bool *ok=0) const
Calculates the current value of the property with the specified key and interprets it as a color...
void frameChanged()
Emitted if the item&#39;s frame style changes.
bool _writeXml(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document. Usually called from writeXml methods of ...
void setFrameJoinStyle(const Qt::PenJoinStyle style)
Sets join style used when drawing the item&#39;s frame.
void cancelCommand()
Deletes current command.
virtual void drawSelectionBoxes(QPainter *p)
Draws additional graphics on selected items.
void endCommand()
Saves end state of item and pushes command to the undo history.
QGraphicsRectItem * mBoundingResizeRectangle
Rectangle used during move and resize actions.
void updatePagePos(double newPageWidth, double newPageHeight)
Moves the item so that it retains its relative position on the page when the paper size changes...
bool mFrame
True if item fram needs to be painted.
virtual bool readXml(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
void endCommand()
Finish current command and push it onto the undo stack.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
virtual void refreshDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties, const QgsExpressionContext *context=nullptr) override
Refreshes a data defined property for the item by reevaluating the property&#39;s value and redrawing the...
QgsPropertyCollection mDataDefinedProperties
double mEvaluatedItemRotation
Temporary evaluated item rotation in degrees, clockwise.
bool mRemovedFromComposition
True if item has been removed from the composition.
void repaint() override
virtual ~QgsComposerItem()
static QPainter::CompositionMode decodeBlendMode(const QString &s)
void beginCommand(const QString &commandText, QgsComposerMergeCommand::Context c=QgsComposerMergeCommand::Unknown)
Starts new composer undo command.
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value...
bool _readXml(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document. Usually called from readXml methods of su...
static QgsExpressionContextScope * composerItemScope(const QgsComposerItem *composerItem)
Creates a new scope which contains variables and functions relating to a QgsComposerItem.
Graphics scene for map printing.
Return the current evaluated value for the property.
virtual void setExcludeFromExports(const bool exclude)
Sets whether the item should be excluded from composer exports and prints.
virtual QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the item&#39;s current state.
QGraphicsLineItem * hAlignSnapItem()
Return horizontal align snap item. Creates a new graphics line if 0.
void setPositionLock(const bool lock)
Locks / unlocks the item position for mouse drags.
QgsComposition * mComposition
Qt::PenJoinStyle mFrameJoinStyle
Frame join style.
QColor mBackgroundColor
Background color.
QGraphicsLineItem * mVAlignSnapItem
void setItemOpacity(const double opacity)
Sets the item&#39;s opacity.
virtual void setFrameStrokeColor(const QColor &color)
Sets frame stroke color.
QGraphicsLineItem * mHAlignSnapItem
void setBackgroundColor(const QColor &backgroundColor)
Sets the background color for this item.
int mCurrentExportLayer
The layer that needs to be exported.
const QgsComposition * composition() const
Returns the composition the item is attached to.
bool mItemPositionLocked
True if item position and size cannot be changed with mouse move.
QString valueAsString(int key, const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=0) const
Calculates the current value of the property with the specified key and interprets it as a string...
virtual void drawBackground(QPainter *p)
Draw background.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
virtual void setId(const QString &id)
Set item&#39;s id (which is not necessarly unique)
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
void sizeChanged()
Emitted if the rectangle changes.
void setIsGroupMember(const bool isGroupMember)
Sets whether this item is part of a group.
virtual void updateItem()
Updates (redraws) the item, with the possibility to do custom update for subclasses.
void setEffectsEnabled(const bool effectsEnabled)
Sets whether effects (e.g., blend modes) are enabled for the item.
void updateItemSelectStatus(QgsComposerItem *item)
Must be called when an item&#39;s selection status changes.
double paperHeight() const
Height of paper item.
bool hasFrame() const
Whether this item has a frame or not.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=0) const
Calculates the current value of the property with the specified key and interprets it as a double...
QgsComposerEffect * mEffect
QgsComposerItem(QgsComposition *composition, bool manageZValue=true)
Constructor.
virtual bool writeXml(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
bool positionLock() const
Returns whether position lock for mouse drags is enabled returns true if item is locked for mouse mov...
void lockChanged()
Emitted if the item&#39;s lock status changes.
bool mBackground
True if item background needs to be painted.
void move(double dx, double dy)
Moves item in canvas coordinates.
QPainter::CompositionMode blendMode() const
Returns the item&#39;s composition blending mode.
virtual void setVisibility(const bool visible)
Sets visibility for item.
bool mIsGroupMember
Whether or not this item is part of a group.
QString id() const
Get item&#39;s id (which is not necessarly unique)
double mItemRotation
Item rotation in degrees, clockwise.
QColor mFrameColor
Item frame color.
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
virtual void setItemRotation(const double rotation, const bool adjustPosition=false)
Sets the item rotation, in degrees clockwise.
double spaceBetweenPages() const
Returns the vertical space between pages in a composer view.
QGraphicsLineItem * vAlignSnapItem()
Return vertical align snap item. Creates a new graphics line if 0.
bool mEvaluatedExcludeFromExports
Temporary evaluated item exclusion.
virtual QRectF rectWithFrame() const
Returns the item&#39;s rectangular bounds, including any bleed caused by the item&#39;s frame.
All properties for item.
virtual int type() const override
Return correct graphics item type.
double mOpacity
Item opacity, between 0 and 1.
double rectHandlerBorderTolerance() const
Returns the current (zoom level dependent) tolerance to decide if mouse position is close enough to t...
void beginCommand(QgsComposerItem *item, const QString &commandText, const QgsComposerMergeCommand::Context c=QgsComposerMergeCommand::Unknown)
Allocates new item command and saves initial state in it.