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