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