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