QGIS API Documentation  2.99.0-Master (314842d)
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 
575 {
576  if ( !mUpdatesEnabled )
577  return;
578 
579  QGraphicsRectItem::update();
580 }
581 
582 void QgsComposerItem::move( double dx, double dy )
583 {
584  QRectF newSceneRect( pos().x() + dx, pos().y() + dy, rect().width(), rect().height() );
585  setSceneRect( evalItemRect( newSceneRect ) );
586 }
587 
589 {
590  double y = pos().y();
591  double h = composition()->paperHeight() + composition()->spaceBetweenPages();
592  int page = 1;
593  while ( y - h >= 0. )
594  {
595  y -= h;
596  ++page;
597  }
598  return page;
599 }
600 
602 {
603  QPointF p = pos();
604  double h = composition()->paperHeight() + composition()->spaceBetweenPages();
605  p.ry() -= ( page() - 1 ) * h;
606  return p;
607 }
608 
609 void QgsComposerItem::updatePagePos( double newPageWidth, double newPageHeight )
610 {
611  Q_UNUSED( newPageWidth )
612  QPointF curPagePos = pagePos();
613  int curPage = page() - 1;
614 
615  double y = curPage * ( newPageHeight + composition()->spaceBetweenPages() ) + curPagePos.y();
616  QRectF newSceneRect( pos().x(), y, rect().width(), rect().height() );
617 
618  setSceneRect( evalItemRect( newSceneRect ) );
619  emit sizeChanged();
620 }
621 
622 void QgsComposerItem::setItemPosition( double x, double y, ItemPositionMode itemPoint, int page )
623 {
624  double width = rect().width();
625  double height = rect().height();
626  setItemPosition( x, y, width, height, itemPoint, false, page );
627 }
628 
629 void QgsComposerItem::setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint, bool posIncludesFrame, int page )
630 {
631  double upperLeftX = x;
632  double upperLeftY = y;
633 
634  if ( page > 0 )
635  {
636  double h = composition()->paperHeight() + composition()->spaceBetweenPages();
637  upperLeftY += ( page - 1 ) * h;
638  }
639 
640  //store the item position mode
641  mLastUsedPositionMode = itemPoint;
642 
643  //adjust x-coordinate if placement is not done to a left point
644  if ( itemPoint == UpperMiddle || itemPoint == Middle || itemPoint == LowerMiddle )
645  {
646  upperLeftX -= width / 2.0;
647  }
648  else if ( itemPoint == UpperRight || itemPoint == MiddleRight || itemPoint == LowerRight )
649  {
650  upperLeftX -= width;
651  }
652 
653  //adjust y-coordinate if placement is not done to an upper point
654  if ( itemPoint == MiddleLeft || itemPoint == Middle || itemPoint == MiddleRight )
655  {
656  upperLeftY -= height / 2.0;
657  }
658  else if ( itemPoint == LowerLeft || itemPoint == LowerMiddle || itemPoint == LowerRight )
659  {
660  upperLeftY -= height;
661  }
662 
663  if ( posIncludesFrame )
664  {
665  //adjust position to account for frame size
666 
668  {
669  upperLeftX += estimatedFrameBleed();
670  upperLeftY += estimatedFrameBleed();
671  }
672  else
673  {
674  //adjust position for item rotation
675  QLineF lineToItemOrigin = QLineF( 0, 0, estimatedFrameBleed(), estimatedFrameBleed() );
676  lineToItemOrigin.setAngle( -45 - mEvaluatedItemRotation );
677  upperLeftX += lineToItemOrigin.x2();
678  upperLeftY += lineToItemOrigin.y2();
679  }
680 
681  width -= 2 * estimatedFrameBleed();
682  height -= 2 * estimatedFrameBleed();
683  }
684 
685  //consider data defined item size and position before finalising rect
686  QRectF newRect = evalItemRect( QRectF( upperLeftX, upperLeftY, width, height ) );
687 
688  setSceneRect( newRect );
689 }
690 
691 void QgsComposerItem::setSceneRect( const QRectF &rectangle )
692 {
693  //setRect in item coordinates
694  double newWidth = rectangle.width();
695  double newHeight = rectangle.height();
696  double xTranslation = rectangle.x();
697  double yTranslation = rectangle.y();
698 
699  //correction if width and/or height are negative
700  if ( rectangle.width() < 0 )
701  {
702  newWidth = - rectangle.width();
703  xTranslation -= newWidth;
704  }
705 
706  if ( rectangle.height() < 0 )
707  {
708  newHeight = - rectangle.height();
709  yTranslation -= newHeight;
710  }
711 
712  QGraphicsRectItem::setRect( QRectF( 0, 0, newWidth, newHeight ) );
713  setPos( QPointF( xTranslation, yTranslation ) );
714 
715  emit sizeChanged();
716 }
717 
718 QRectF QgsComposerItem::evalItemRect( const QRectF &newRect, const bool resizeOnly, const QgsExpressionContext *context )
719 {
720  QRectF result = newRect;
721 
722  //TODO QGIS 3.0
723  //maintain pre 2.12 API. remove when API break allowed
725  const QgsExpressionContext *evalContext = context ? context : &scopedContext;
726 
727  //data defined position or size set? if so, update rect with data defined values
728  bool ok = false;
729  double ddWidth = mDataDefinedProperties.valueAsDouble( QgsComposerObject::ItemWidth, *evalContext, 0, &ok );
730  //evaulate width and height first, since they may affect position if non-top-left reference point set
731  if ( ok )
732  {
733  result.setWidth( ddWidth );
734  }
735  double ddHeight = mDataDefinedProperties.valueAsDouble( QgsComposerObject::ItemHeight, *evalContext, 0, &ok );
736  if ( ok )
737  {
738  result.setHeight( ddHeight );
739  }
740 
741  double x = result.left();
742  //initially adjust for position mode to get x coordinate
743  if ( !resizeOnly )
744  {
745  //adjust x-coordinate if placement is not done to a left point
747  {
748  x += newRect.width() / 2.0;
749  }
751  {
752  x += newRect.width();
753  }
754  }
755  else
756  {
758  {
759  x += rect().width() / 2.0;
760  }
762  {
763  x += rect().width();
764  }
765  }
766  double ddPosX = mDataDefinedProperties.valueAsDouble( QgsComposerObject::PositionX, *evalContext, 0.0, &ok );
767  if ( ok )
768  {
769  x = ddPosX;
770  }
771 
772  double y = result.top();
773  //initially adjust for position mode to get y coordinate
774  if ( !resizeOnly )
775  {
776  //adjust y-coordinate if placement is not done to an upper point
778  {
779  y += newRect.height() / 2.0;
780  }
782  {
783  y += newRect.height();
784  }
785  }
786  else
787  {
789  {
790  y += rect().height() / 2.0;
791  }
793  {
794  y += rect().height();
795  }
796  }
797  double ddPosY = mDataDefinedProperties.valueAsDouble( QgsComposerObject::PositionY, *evalContext, 0, &ok );
798  if ( ok )
799  {
800  y = ddPosY;
801  }
802 
803  //adjust x-coordinate if placement is not done to a left point
805  {
806  x -= result.width() / 2.0;
807  }
809  {
810  x -= result.width();
811  }
812 
813  //adjust y-coordinate if placement is not done to an upper point
815  {
816  y -= result.height() / 2.0;
817  }
819  {
820  y -= result.height();
821  }
822 
823  result.moveLeft( x );
824  result.moveTop( y );
825 
826  return result;
827 }
828 
830 {
832  {
833  //preview mode or no composition, so ok to draw item
834  return true;
835  }
836 
837  //exporting composition, so check if item is excluded from exports
839 }
840 
842 {
845  return context;
846 }
847 
849 {
850  if ( mBackground && p )
851  {
852  p->save();
853  p->setBrush( brush() );//this causes a problem in atlas generation
854  p->setPen( Qt::NoPen );
855  p->setRenderHint( QPainter::Antialiasing, true );
856  p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
857  p->restore();
858  }
859 }
860 
862 {
864  setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
865  // apply any datadefined overrides
867  refreshBackgroundColor( true, context );
868 }
869 
870 void QgsComposerItem::setBlendMode( const QPainter::CompositionMode blendMode )
871 {
873  // Update the composer effect to use the new blend mode
875  refreshBlendMode( context );
876 }
877 
878 void QgsComposerItem::refreshBlendMode( const QgsExpressionContext &context )
879 {
880  QPainter::CompositionMode blendMode = mBlendMode;
881 
882  //data defined blend mode set?
883  bool ok = false;
884  QString blendStr = mDataDefinedProperties.valueAsString( QgsComposerObject::BlendMode, context, QString(), &ok );
885  if ( ok && !blendStr.isEmpty() )
886  {
887  QString blendstr = blendStr.trimmed();
888  QPainter::CompositionMode blendModeD = QgsSymbolLayerUtils::decodeBlendMode( blendstr );
889 
890  QgsDebugMsg( QString( "exprVal BlendMode:%1" ).arg( blendModeD ) );
891  blendMode = blendModeD;
892  }
893 
894  // Update the composer effect to use the new blend mode
895  mEffect->setCompositionMode( blendMode );
896 }
897 
899 {
902  refreshTransparency( true, context );
903 }
904 
905 void QgsComposerItem::refreshTransparency( const bool updateItem, const QgsExpressionContext &context )
906 {
907  //data defined transparency set?
909 
910  // Set the QGraphicItem's opacity
911  setOpacity( 1. - ( transparency / 100. ) );
912 
913  if ( updateItem )
914  {
915  update();
916  }
917 }
918 
919 void QgsComposerItem::refreshFrameColor( const bool updateItem, const QgsExpressionContext &context )
920 {
921  //data defined stroke color set?
922  bool ok = false;
924  if ( ok )
925  {
926  QPen itemPen = pen();
927  itemPen.setColor( frameColor );
928  setPen( itemPen );
929  }
930  else
931  {
932  QPen itemPen = pen();
933  itemPen.setColor( mFrameColor );
934  setPen( itemPen );
935  }
936  if ( updateItem )
937  {
938  update();
939  }
940 }
941 
942 void QgsComposerItem::refreshBackgroundColor( const bool updateItem, const QgsExpressionContext &context )
943 {
944  //data defined color set?
945  bool ok = false;
947  if ( ok )
948  {
949  setBrush( QBrush( backgroundColor, Qt::SolidPattern ) );
950  }
951  else
952  {
953  setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
954  }
955  if ( updateItem )
956  {
957  update();
958  }
959 }
960 
962 {
963  //enable or disable the QgsComposerEffect applied to this item
965  mEffect->setEnabled( effectsEnabled );
966 }
967 
969 {
970  double result = -1;
971  if ( scene() )
972  {
973  QList<QGraphicsView *> viewList = scene()->views();
974  if ( !viewList.isEmpty() ) //if not, probably this function was called from non-gui code
975  {
976  QGraphicsView *currentView = viewList.at( 0 );
977  if ( currentView->isVisible() )
978  {
979  result = currentView->transform().m11();
980  mLastValidViewScaleFactor = result;
981  }
982  }
983  }
984  return result;
985 }
986 
988 {
989  //size of symbol boxes depends on zoom level in composer view
990  double viewScaleFactor = horizontalViewScaleFactor();
991  double rectHandlerSize = 10.0 / viewScaleFactor;
992 
993  //make sure the boxes don't get too large
994  if ( rectHandlerSize > ( rect().width() / 3 ) )
995  {
996  rectHandlerSize = rect().width() / 3;
997  }
998  if ( rectHandlerSize > ( rect().height() / 3 ) )
999  {
1000  rectHandlerSize = rect().height() / 3;
1001  }
1002  return rectHandlerSize;
1003 }
1004 
1005 void QgsComposerItem::setItemRotation( const double r, const bool adjustPosition )
1006 {
1007  if ( r >= 360 )
1008  {
1009  mItemRotation = ( static_cast< int >( r ) ) % 360;
1010  }
1011  else
1012  {
1013  mItemRotation = r;
1014  }
1015 
1017  refreshRotation( true, adjustPosition, context );
1018 }
1019 
1020 void QgsComposerItem::refreshRotation( const bool updateItem, const bool adjustPosition, const QgsExpressionContext &context )
1021 {
1022  double rotation = mItemRotation;
1023 
1024  //data defined rotation set?
1025  rotation = mDataDefinedProperties.valueAsDouble( QgsComposerObject::ItemRotation, context, rotation );
1026 
1027  if ( qgsDoubleNear( rotation, mEvaluatedItemRotation ) )
1028  {
1029  return;
1030  }
1031 
1032  if ( adjustPosition )
1033  {
1034  //adjustPosition set, so shift the position of the item so that rotation occurs around item center
1035  //create a line from the centrepoint of the rect() to its origin, in scene coordinates
1036  QLineF refLine = QLineF( mapToScene( QPointF( rect().width() / 2.0, rect().height() / 2.0 ) ), mapToScene( QPointF( 0, 0 ) ) );
1037  //rotate this line by the current rotation angle
1038  refLine.setAngle( refLine.angle() - rotation + mEvaluatedItemRotation );
1039  //get new end point of line - this is the new item position
1040  QPointF rotatedReferencePoint = refLine.p2();
1041  setPos( rotatedReferencePoint );
1042  emit sizeChanged();
1043  }
1044 
1045  setTransformOriginPoint( 0, 0 );
1046  QGraphicsItem::setRotation( rotation );
1047 
1048  mEvaluatedItemRotation = rotation;
1049 
1050  emit itemRotationChanged( rotation );
1051 
1052  //update bounds of scene, since rotation may affect this
1054 
1055  if ( updateItem )
1056  {
1057  update();
1058  }
1059 }
1060 
1062 {
1063  if ( !mHAlignSnapItem )
1064  {
1065  mHAlignSnapItem = new QGraphicsLineItem( nullptr );
1066  QPen pen = QPen( QColor( Qt::red ) );
1067  pen.setWidthF( 0.0 );
1068  mHAlignSnapItem->setPen( pen );
1069  scene()->addItem( mHAlignSnapItem );
1070  mHAlignSnapItem->setZValue( 90 );
1071  }
1072  return mHAlignSnapItem;
1073 }
1074 
1076 {
1077  if ( !mVAlignSnapItem )
1078  {
1079  mVAlignSnapItem = new QGraphicsLineItem( nullptr );
1080  QPen pen = QPen( QColor( Qt::red ) );
1081  pen.setWidthF( 0.0 );
1082  mVAlignSnapItem->setPen( pen );
1083  scene()->addItem( mVAlignSnapItem );
1084  mVAlignSnapItem->setZValue( 90 );
1085  }
1086  return mVAlignSnapItem;
1087 }
1088 
1090 {
1091  if ( mHAlignSnapItem )
1092  {
1093  scene()->removeItem( mHAlignSnapItem );
1094  delete mHAlignSnapItem;
1095  mHAlignSnapItem = nullptr;
1096  }
1097 }
1098 
1100 {
1101  if ( mVAlignSnapItem )
1102  {
1103  scene()->removeItem( mVAlignSnapItem );
1104  delete mVAlignSnapItem;
1105  mVAlignSnapItem = nullptr;
1106  }
1107 }
1108 
1110 {
1113 }
1114 
1116 {
1117  updateItem();
1118 }
1119 
1121 {
1122  //maintain 2.10 API
1123  //TODO QGIS 3.0 - remove this
1125  const QgsExpressionContext *evalContext = context ? context : &scopedContext;
1126 
1127  //update data defined properties and redraw item to match
1128  if ( property == QgsComposerObject::PositionX || property == QgsComposerObject::PositionY ||
1129  property == QgsComposerObject::ItemWidth || property == QgsComposerObject::ItemHeight ||
1130  property == QgsComposerObject::AllProperties )
1131  {
1132  QRectF beforeRect = QRectF( pos().x(), pos().y(), rect().width(), rect().height() );
1133  QRectF evaluatedRect = evalItemRect( beforeRect, false, evalContext );
1134  if ( evaluatedRect != beforeRect )
1135  {
1136  setSceneRect( evaluatedRect );
1137  }
1138  }
1139  if ( property == QgsComposerObject::ItemRotation || property == QgsComposerObject::AllProperties )
1140  {
1141  refreshRotation( false, true, *evalContext );
1142  }
1143  if ( property == QgsComposerObject::Transparency || property == QgsComposerObject::AllProperties )
1144  {
1145  refreshTransparency( false, *evalContext );
1146  }
1147  if ( property == QgsComposerObject::BlendMode || property == QgsComposerObject::AllProperties )
1148  {
1149  refreshBlendMode( *evalContext );
1150  }
1151  if ( property == QgsComposerObject::FrameColor || property == QgsComposerObject::AllProperties )
1152  {
1153  refreshFrameColor( false, *evalContext );
1154  }
1156  {
1157  refreshBackgroundColor( false, *evalContext );
1158  }
1160  {
1161  bool exclude = mExcludeFromExports;
1162  //data defined exclude from exports set?
1163  exclude = mDataDefinedProperties.valueAsBool( QgsComposerObject::ExcludeFromExports, *evalContext, exclude );
1164  mEvaluatedExcludeFromExports = exclude;
1165  }
1166 
1167  update();
1168 }
1169 
1170 void QgsComposerItem::setId( const QString &id )
1171 {
1172  if ( id == mId )
1173  {
1174  return;
1175  }
1176 
1177  setToolTip( id );
1178  mId = id;
1179 
1180  //inform model that id data has changed
1181  if ( mComposition )
1182  {
1184  }
1185 
1186  emit itemChanged();
1187 }
1188 
1190 {
1192  setFlag( QGraphicsItem::ItemIsSelectable, !isGroupMember ); //item in groups cannot be selected
1193 }
1194 
1196 {
1197  //return id, if it's not empty
1198  if ( ! id().isEmpty() )
1199  {
1200  return id();
1201  }
1202 
1203  //for unnamed items, default to item type
1204  //(note some item types override this method to provide their own defaults)
1205  switch ( type() )
1206  {
1207  case ComposerArrow:
1208  return tr( "<arrow>" );
1209  case ComposerItemGroup:
1210  return tr( "<group>" );
1211  case ComposerLabel:
1212  return tr( "<label>" );
1213  case ComposerLegend:
1214  return tr( "<legend>" );
1215  case ComposerMap:
1216  return tr( "<map>" );
1217  case ComposerPicture:
1218  return tr( "<picture>" );
1219  case ComposerScaleBar:
1220  return tr( "<scale bar>" );
1221  case ComposerShape:
1222  return tr( "<shape>" );
1223  case ComposerTable:
1224  return tr( "<table>" );
1226  return tr( "<attribute table>" );
1227  case ComposerTextTable:
1228  return tr( "<text table>" );
1229  case ComposerFrame:
1230  return tr( "<frame>" );
1231  }
1232 
1233  return tr( "<item>" );
1234 }
1235 
1236 void QgsComposerItem::setVisibility( const bool visible )
1237 {
1238  if ( visible == isVisible() )
1239  {
1240  //nothing to do
1241  return;
1242  }
1243 
1244  QGraphicsItem::setVisible( visible );
1245 
1246  //inform model that id data has changed
1247  if ( mComposition )
1248  {
1250  }
1251 }
1252 
1254 {
1256 }
1257 
1258 void QgsComposerItem::setExcludeFromExports( const bool exclude )
1259 {
1260  mExcludeFromExports = exclude;
1262 }
bool mExcludeFromExports
Whether item should be excluded in exports.
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...
void setCompositionMode(QPainter::CompositionMode compositionMode)
double horizontalViewScaleFactor() const
Returns the zoom factor of the graphics view.
virtual QString displayName() const
Get item display name.
int mTransparency
Item transparency.
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.
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...
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:36
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.
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.
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.
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.
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.
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.
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.
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.
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...
QgsComposition * mComposition
Qt::PenJoinStyle mFrameJoinStyle
Frame join style.
QColor mBackgroundColor
Background color.
QGraphicsLineItem * mVAlignSnapItem
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...
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.
virtual void setItemRotation(const double r, const bool adjustPosition=false)
Sets the item rotation.
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.
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.
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...
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)
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.
void setTransparency(const int transparency)
Sets the item&#39;s transparency.
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 rectHandlerBorderTolerance() const
Returns the current (zoom level dependent) tolerance to decide if mouse position is close enough to t...
int transparency() const
Returns the item&#39;s transparency.
void beginCommand(QgsComposerItem *item, const QString &commandText, const QgsComposerMergeCommand::Context c=QgsComposerMergeCommand::Unknown)
Allocates new item command and saves initial state in it.