QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgslayoutitem.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutitem.cpp
3  -------------------
4  begin : June 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #include "qgslayoutitem.h"
18 #include "qgslayout.h"
19 #include "qgslayoututils.h"
20 #include "qgspagesizeregistry.h"
22 #include "qgslayoutmodel.h"
23 #include "qgssymbollayerutils.h"
24 #include "qgslayoutitemgroup.h"
25 #include "qgspainting.h"
26 #include "qgslayouteffect.h"
27 #include "qgslayoutundostack.h"
29 #include "qgslayoutitempage.h"
30 #include "qgsimageoperation.h"
32 
33 #include <QPainter>
34 #include <QStyleOptionGraphicsItem>
35 #include <QUuid>
36 
37 #define CACHE_SIZE_LIMIT 5000
38 
40  : mRenderContext( context )
41  , mViewScaleFactor( viewScaleFactor )
42 {
43 }
44 
45 
46 
47 QgsLayoutItem::QgsLayoutItem( QgsLayout *layout, bool manageZValue )
48  : QgsLayoutObject( layout )
49  , QGraphicsRectItem( nullptr )
50  , mUuid( QUuid::createUuid().toString() )
51 {
52  setZValue( QgsLayout::ZItem );
53 
54  // needed to access current view transform during paint operations
55  setFlags( flags() | QGraphicsItem::ItemUsesExtendedStyleOption | QGraphicsItem::ItemIsSelectable );
56 
57  setCacheMode( QGraphicsItem::DeviceCoordinateCache );
58 
59  //record initial position
61  mItemPosition = QgsLayoutPoint( scenePos().x(), scenePos().y(), initialUnits );
62  mItemSize = QgsLayoutSize( rect().width(), rect().height(), initialUnits );
63 
64  // required to initially setup background/frame style
65  refreshBackgroundColor( false );
66  refreshFrame( false );
67 
68  initConnectionsToLayout();
69 
70  //let z-Value be managed by layout
71  if ( mLayout && manageZValue )
72  {
73  mLayoutManagesZValue = true;
74  mLayout->itemsModel()->addItemAtTop( this );
75  }
76  else
77  {
78  mLayoutManagesZValue = false;
79  }
80 
81  // Setup layout effect
82  mEffect.reset( new QgsLayoutEffect() );
83  if ( mLayout )
84  {
85  mEffect->setEnabled( mLayout->renderContext().flags() & QgsLayoutRenderContext::FlagUseAdvancedEffects );
86  connect( &mLayout->renderContext(), &QgsLayoutRenderContext::flagsChanged, this, [ = ]( QgsLayoutRenderContext::Flags flags )
87  {
88  mEffect->setEnabled( flags & QgsLayoutRenderContext::FlagUseAdvancedEffects );
89  } );
90  }
91  setGraphicsEffect( mEffect.get() );
92 }
93 
95 {
96  cleanup();
97 }
98 
100 {
101  if ( mLayout && mLayoutManagesZValue )
102  {
103  mLayout->itemsModel()->removeItem( this );
104  }
105 }
106 
108 {
109  //return id, if it's not empty
110  if ( !id().isEmpty() )
111  {
112  return id();
113  }
114 
115  //for unnamed items, default to item type
116  if ( QgsLayoutItemAbstractMetadata *metadata = QgsApplication::layoutItemRegistry()->itemMetadata( type() ) )
117  {
118  return tr( "<%1>" ).arg( metadata->visibleName() );
119  }
120 
121  return tr( "<item>" );
122 }
123 
125 {
127 }
128 
129 QgsLayoutItem::Flags QgsLayoutItem::itemFlags() const
130 {
131  return nullptr;
132 }
133 
134 void QgsLayoutItem::setId( const QString &id )
135 {
136  if ( id == mId )
137  {
138  return;
139  }
140 
141  if ( !shouldBlockUndoCommands() )
142  mLayout->undoStack()->beginCommand( this, tr( "Change Item ID" ) );
143 
144  mId = id;
145 
146  if ( !shouldBlockUndoCommands() )
147  mLayout->undoStack()->endCommand();
148 
149  setToolTip( id );
150 
151  //inform model that id data has changed
152  if ( mLayout )
153  {
154  mLayout->itemsModel()->updateItemDisplayName( this );
155  }
156 
157  emit changed();
158 }
159 
160 void QgsLayoutItem::setSelected( bool selected )
161 {
162  QGraphicsRectItem::setSelected( selected );
163  //inform model that id data has changed
164  if ( mLayout )
165  {
166  mLayout->itemsModel()->updateItemSelectStatus( this );
167  }
168 }
169 
170 void QgsLayoutItem::setVisibility( const bool visible )
171 {
172  if ( visible == isVisible() )
173  {
174  //nothing to do
175  return;
176  }
177 
178  std::unique_ptr< QgsAbstractLayoutUndoCommand > command;
179  if ( !shouldBlockUndoCommands() )
180  {
181  command.reset( createCommand( visible ? tr( "Show Item" ) : tr( "Hide Item" ), 0 ) );
182  command->saveBeforeState();
183  }
184 
185  QGraphicsItem::setVisible( visible );
186 
187  if ( command )
188  {
189  command->saveAfterState();
190  mLayout->undoStack()->push( command.release() );
191  }
192 
193  //inform model that visibility has changed
194  if ( mLayout )
195  {
196  mLayout->itemsModel()->updateItemVisibility( this );
197  }
198 }
199 
200 void QgsLayoutItem::setLocked( const bool locked )
201 {
202  if ( locked == mIsLocked )
203  {
204  return;
205  }
206 
207  if ( !shouldBlockUndoCommands() )
208  mLayout->undoStack()->beginCommand( this, locked ? tr( "Lock Item" ) : tr( "Unlock Item" ) );
209 
210  mIsLocked = locked;
211 
212  if ( !shouldBlockUndoCommands() )
213  mLayout->undoStack()->endCommand();
214 
215  //inform model that id data has changed
216  if ( mLayout )
217  {
218  mLayout->itemsModel()->updateItemLockStatus( this );
219  }
220 
221  update();
222  emit lockChanged();
223 }
224 
226 {
227  return !mParentGroupUuid.isEmpty() && mLayout && static_cast< bool >( mLayout->itemByUuid( mParentGroupUuid ) );
228 }
229 
231 {
232  if ( !mLayout || mParentGroupUuid.isEmpty() )
233  return nullptr;
234 
235  return qobject_cast< QgsLayoutItemGroup * >( mLayout->itemByUuid( mParentGroupUuid ) );
236 }
237 
239 {
240  if ( !group )
241  mParentGroupUuid.clear();
242  else
243  mParentGroupUuid = group->uuid();
244  setFlag( QGraphicsItem::ItemIsSelectable, !static_cast< bool>( group ) ); //item in groups cannot be selected
245 }
246 
248 {
250 }
251 
253 {
254  return 0;
255 }
256 
258 {
259 
260 }
261 
263 {
264 
265 }
266 
268 {
270  if ( !mLayout || mLayout->renderContext().currentExportLayer() == -1 )
271  return false;
272 
273  // QGIS 4- return false from base class implementation
274 
275  const int layers = numberExportLayers();
276  return mLayout->renderContext().currentExportLayer() < layers;
278 }
279 
281 {
283 }
284 
285 void QgsLayoutItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget * )
286 {
287  if ( !painter || !painter->device() || !shouldDrawItem() )
288  {
289  return;
290  }
291 
292  //TODO - remember to disable saving/restoring on graphics view!!
293 
294  if ( shouldDrawDebugRect() )
295  {
296  drawDebugRect( painter );
297  return;
298  }
299 
300  bool previewRender = !mLayout || mLayout->renderContext().isPreviewRender();
301  double destinationDpi = previewRender ? QgsLayoutUtils::scaleFactorFromItemStyle( itemStyle ) * 25.4 : mLayout->renderContext().dpi();
302  bool useImageCache = false;
303  bool forceRasterOutput = containsAdvancedEffects() && ( !mLayout || !( mLayout->renderContext().flags() & QgsLayoutRenderContext::FlagForceVectorOutput ) );
304 
305  if ( useImageCache || forceRasterOutput )
306  {
307  double widthInPixels = 0;
308  double heightInPixels = 0;
309 
310  if ( previewRender )
311  {
312  widthInPixels = boundingRect().width() * QgsLayoutUtils::scaleFactorFromItemStyle( itemStyle );
313  heightInPixels = boundingRect().height() * QgsLayoutUtils::scaleFactorFromItemStyle( itemStyle );
314  }
315  else
316  {
317  double layoutUnitsToPixels = mLayout ? mLayout->convertFromLayoutUnits( 1, QgsUnitTypes::LayoutPixels ).length() : destinationDpi / 25.4;
318  widthInPixels = boundingRect().width() * layoutUnitsToPixels;
319  heightInPixels = boundingRect().height() * layoutUnitsToPixels;
320  }
321 
322  // limit size of image for better performance
323  if ( previewRender && ( widthInPixels > CACHE_SIZE_LIMIT || heightInPixels > CACHE_SIZE_LIMIT ) )
324  {
325  double scale = 1.0;
326  if ( widthInPixels > heightInPixels )
327  {
328  scale = widthInPixels / CACHE_SIZE_LIMIT;
329  widthInPixels = CACHE_SIZE_LIMIT;
330  heightInPixels /= scale;
331  }
332  else
333  {
334  scale = heightInPixels / CACHE_SIZE_LIMIT;
335  heightInPixels = CACHE_SIZE_LIMIT;
336  widthInPixels /= scale;
337  }
338  destinationDpi = destinationDpi / scale;
339  }
340 
341  if ( previewRender && !mItemCachedImage.isNull() && qgsDoubleNear( mItemCacheDpi, destinationDpi ) )
342  {
343  // can reuse last cached image
344  QgsRenderContext context = QgsLayoutUtils::createRenderContextForLayout( mLayout, painter, destinationDpi );
345  painter->save();
346  preparePainter( painter );
347  double cacheScale = destinationDpi / mItemCacheDpi;
348  painter->scale( cacheScale / context.scaleFactor(), cacheScale / context.scaleFactor() );
349  painter->drawImage( boundingRect().x() * context.scaleFactor() / cacheScale,
350  boundingRect().y() * context.scaleFactor() / cacheScale, mItemCachedImage );
351  painter->restore();
352  return;
353  }
354  else
355  {
356  QImage image = QImage( widthInPixels, heightInPixels, QImage::Format_ARGB32 );
357  image.fill( Qt::transparent );
358  image.setDotsPerMeterX( 1000 * destinationDpi * 25.4 );
359  image.setDotsPerMeterY( 1000 * destinationDpi * 25.4 );
360  QPainter p( &image );
361 
362  preparePainter( &p );
365  // painter is already scaled to dots
366  // need to translate so that item origin is at 0,0 in painter coordinates (not bounding rect origin)
367  p.translate( -boundingRect().x() * context.scaleFactor(), -boundingRect().y() * context.scaleFactor() );
368  // scale to layout units for background and frame rendering
369  p.scale( context.scaleFactor(), context.scaleFactor() );
370  drawBackground( context );
371  p.scale( 1 / context.scaleFactor(), 1 / context.scaleFactor() );
372  double viewScale = QgsLayoutUtils::scaleFactorFromItemStyle( itemStyle );
373  QgsLayoutItemRenderContext itemRenderContext( context, viewScale );
374  draw( itemRenderContext );
375  p.scale( context.scaleFactor(), context.scaleFactor() );
376  drawFrame( context );
377  p.scale( 1 / context.scaleFactor(), 1 / context.scaleFactor() );
378  p.end();
379 
380  QgsImageOperation::multiplyOpacity( image, mEvaluatedOpacity );
381 
382  painter->save();
383  // scale painter from mm to dots
384  painter->scale( 1.0 / context.scaleFactor(), 1.0 / context.scaleFactor() );
385  painter->drawImage( boundingRect().x() * context.scaleFactor(),
386  boundingRect().y() * context.scaleFactor(), image );
387  painter->restore();
388 
389  if ( previewRender )
390  {
391  mItemCacheDpi = destinationDpi;
392  mItemCachedImage = image;
393  }
394  }
395  }
396  else
397  {
398  // no caching or flattening
399  painter->save();
400  preparePainter( painter );
401  QgsRenderContext context = QgsLayoutUtils::createRenderContextForLayout( mLayout, painter, destinationDpi );
403  drawBackground( context );
404 
405  // scale painter from mm to dots
406  painter->scale( 1.0 / context.scaleFactor(), 1.0 / context.scaleFactor() );
407  double viewScale = QgsLayoutUtils::scaleFactorFromItemStyle( itemStyle );
408  QgsLayoutItemRenderContext itemRenderContext( context, viewScale );
409  draw( itemRenderContext );
410 
411  painter->scale( context.scaleFactor(), context.scaleFactor() );
412  drawFrame( context );
413 
414  painter->restore();
415  }
416 }
417 
419 {
420  if ( point == mReferencePoint )
421  {
422  return;
423  }
424 
425  mReferencePoint = point;
426 
427  //also need to adjust stored position
428  updateStoredItemPosition();
430 }
431 
432 void QgsLayoutItem::attemptResize( const QgsLayoutSize &s, bool includesFrame )
433 {
434  if ( !mLayout )
435  {
436  mItemSize = s;
437  setRect( 0, 0, s.width(), s.height() );
438  return;
439  }
440 
441  QgsLayoutSize size = s;
442 
443  if ( includesFrame )
444  {
445  //adjust position to account for frame size
446  double bleed = mLayout->convertFromLayoutUnits( estimatedFrameBleed(), size.units() ).length();
447  size.setWidth( size.width() - 2 * bleed );
448  size.setHeight( size.height() - 2 * bleed );
449  }
450 
451  QgsLayoutSize evaluatedSize = applyDataDefinedSize( size );
452  QSizeF targetSizeLayoutUnits = mLayout->convertToLayoutUnits( evaluatedSize );
453  QSizeF actualSizeLayoutUnits = applyMinimumSize( targetSizeLayoutUnits );
454  actualSizeLayoutUnits = applyFixedSize( actualSizeLayoutUnits );
455  actualSizeLayoutUnits = applyItemSizeConstraint( actualSizeLayoutUnits );
456 
457  if ( actualSizeLayoutUnits == rect().size() )
458  {
459  return;
460  }
461 
462  QgsLayoutSize actualSizeTargetUnits = mLayout->convertFromLayoutUnits( actualSizeLayoutUnits, size.units() );
463  mItemSize = actualSizeTargetUnits;
464 
465  setRect( 0, 0, actualSizeLayoutUnits.width(), actualSizeLayoutUnits.height() );
467  emit sizePositionChanged();
468 }
469 
470 void QgsLayoutItem::attemptMove( const QgsLayoutPoint &p, bool useReferencePoint, bool includesFrame, int page )
471 {
472  if ( !mLayout )
473  {
474  mItemPosition = p;
475  setPos( p.toQPointF() );
476  return;
477  }
478 
479  QgsLayoutPoint point = p;
480  if ( page >= 0 )
481  {
482  point = mLayout->pageCollection()->pagePositionToAbsolute( page, p );
483  }
484 
485  if ( includesFrame )
486  {
487  //adjust position to account for frame size
488  double bleed = mLayout->convertFromLayoutUnits( estimatedFrameBleed(), point.units() ).length();
489  point.setX( point.x() + bleed );
490  point.setY( point.y() + bleed );
491  }
492 
493  QgsLayoutPoint evaluatedPoint = point;
494  if ( !useReferencePoint )
495  {
496  evaluatedPoint = topLeftToReferencePoint( point );
497  }
498 
499  evaluatedPoint = applyDataDefinedPosition( evaluatedPoint );
500  QPointF evaluatedPointLayoutUnits = mLayout->convertToLayoutUnits( evaluatedPoint );
501  QPointF topLeftPointLayoutUnits = adjustPointForReferencePosition( evaluatedPointLayoutUnits, rect().size(), mReferencePoint );
502  if ( topLeftPointLayoutUnits == scenePos() && point.units() == mItemPosition.units() )
503  {
504  //TODO - add test for second condition
505  return;
506  }
507 
508  QgsLayoutPoint referencePointTargetUnits = mLayout->convertFromLayoutUnits( evaluatedPointLayoutUnits, point.units() );
509  mItemPosition = referencePointTargetUnits;
510  setScenePos( topLeftPointLayoutUnits );
511  emit sizePositionChanged();
512 }
513 
514 void QgsLayoutItem::attemptSetSceneRect( const QRectF &rect, bool includesFrame )
515 {
516  QPointF newPos = rect.topLeft();
517 
518  blockSignals( true );
519  // translate new size to current item units
520  QgsLayoutSize newSize = mLayout->convertFromLayoutUnits( rect.size(), mItemSize.units() );
521  attemptResize( newSize, includesFrame );
522 
523  // translate new position to current item units
524  QgsLayoutPoint itemPos = mLayout->convertFromLayoutUnits( newPos, mItemPosition.units() );
525  attemptMove( itemPos, false, includesFrame );
526  blockSignals( false );
527  emit sizePositionChanged();
528 }
529 
530 void QgsLayoutItem::attemptMoveBy( double deltaX, double deltaY )
531 {
532  if ( !mLayout )
533  {
534  moveBy( deltaX, deltaY );
535  return;
536  }
537 
538  QgsLayoutPoint itemPos = positionWithUnits();
539  QgsLayoutPoint deltaPos = mLayout->convertFromLayoutUnits( QPointF( deltaX, deltaY ), itemPos.units() );
540  itemPos.setX( itemPos.x() + deltaPos.x() );
541  itemPos.setY( itemPos.y() + deltaPos.y() );
542  attemptMove( itemPos );
543 }
544 
546 {
547  if ( !mLayout )
548  return -1;
549 
550  return mLayout->pageCollection()->pageNumberForPoint( pos() );
551 }
552 
553 QPointF QgsLayoutItem::pagePos() const
554 {
555  QPointF p = positionAtReferencePoint( mReferencePoint );
556 
557  if ( !mLayout )
558  return p;
559 
560  // try to get page
561  QgsLayoutItemPage *pageItem = mLayout->pageCollection()->page( page() );
562  if ( !pageItem )
563  return p;
564 
565  p.ry() -= pageItem->pos().y();
566  return p;
567 }
568 
570 {
571  QPointF p = pagePos();
572  if ( !mLayout )
573  return QgsLayoutPoint( p );
574 
575  return mLayout->convertFromLayoutUnits( p, mItemPosition.units() );
576 }
577 
578 void QgsLayoutItem::setScenePos( const QPointF destinationPos )
579 {
580  //since setPos does not account for item rotation, use difference between
581  //current scenePos (which DOES account for rotation) and destination pos
582  //to calculate how much the item needs to move
583  if ( parentItem() )
584  setPos( pos() + ( destinationPos - scenePos() ) + parentItem()->scenePos() );
585  else
586  setPos( pos() + ( destinationPos - scenePos() ) );
587 }
588 
589 bool QgsLayoutItem::shouldBlockUndoCommands() const
590 {
591  return !mLayout || mLayout != scene() || mBlockUndoCommands;
592 }
593 
595 {
596  if ( !mLayout || mLayout->renderContext().isPreviewRender() )
597  {
598  //preview mode so OK to draw item
599  return true;
600  }
601 
602  //exporting layout, so check if item is excluded from exports
603  return !mEvaluatedExcludeFromExports;
604 }
605 
607 {
608  return mItemRotation;
609 }
610 
611 bool QgsLayoutItem::writeXml( QDomElement &parentElement, QDomDocument &doc, const QgsReadWriteContext &context ) const
612 {
613  QDomElement element = doc.createElement( QStringLiteral( "LayoutItem" ) );
614  element.setAttribute( QStringLiteral( "type" ), QString::number( type() ) );
615 
616  element.setAttribute( QStringLiteral( "uuid" ), mUuid );
617  element.setAttribute( QStringLiteral( "templateUuid" ), mUuid );
618  element.setAttribute( QStringLiteral( "id" ), mId );
619  element.setAttribute( QStringLiteral( "referencePoint" ), QString::number( static_cast< int >( mReferencePoint ) ) );
620  element.setAttribute( QStringLiteral( "position" ), mItemPosition.encodePoint() );
621  element.setAttribute( QStringLiteral( "positionOnPage" ), pagePositionWithUnits().encodePoint() );
622  element.setAttribute( QStringLiteral( "size" ), mItemSize.encodeSize() );
623  element.setAttribute( QStringLiteral( "itemRotation" ), QString::number( mItemRotation ) );
624  element.setAttribute( QStringLiteral( "groupUuid" ), mParentGroupUuid );
625 
626  element.setAttribute( QStringLiteral( "zValue" ), QString::number( zValue() ) );
627  element.setAttribute( QStringLiteral( "visibility" ), isVisible() );
628  //position lock for mouse moves/resizes
629  if ( mIsLocked )
630  {
631  element.setAttribute( QStringLiteral( "positionLock" ), QStringLiteral( "true" ) );
632  }
633  else
634  {
635  element.setAttribute( QStringLiteral( "positionLock" ), QStringLiteral( "false" ) );
636  }
637 
638  //frame
639  if ( mFrame )
640  {
641  element.setAttribute( QStringLiteral( "frame" ), QStringLiteral( "true" ) );
642  }
643  else
644  {
645  element.setAttribute( QStringLiteral( "frame" ), QStringLiteral( "false" ) );
646  }
647 
648  //background
649  if ( mBackground )
650  {
651  element.setAttribute( QStringLiteral( "background" ), QStringLiteral( "true" ) );
652  }
653  else
654  {
655  element.setAttribute( QStringLiteral( "background" ), QStringLiteral( "false" ) );
656  }
657 
658  //frame color
659  QDomElement frameColorElem = doc.createElement( QStringLiteral( "FrameColor" ) );
660  frameColorElem.setAttribute( QStringLiteral( "red" ), QString::number( mFrameColor.red() ) );
661  frameColorElem.setAttribute( QStringLiteral( "green" ), QString::number( mFrameColor.green() ) );
662  frameColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( mFrameColor.blue() ) );
663  frameColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( mFrameColor.alpha() ) );
664  element.appendChild( frameColorElem );
665  element.setAttribute( QStringLiteral( "outlineWidthM" ), mFrameWidth.encodeMeasurement() );
666  element.setAttribute( QStringLiteral( "frameJoinStyle" ), QgsSymbolLayerUtils::encodePenJoinStyle( mFrameJoinStyle ) );
667 
668  //background color
669  QDomElement bgColorElem = doc.createElement( QStringLiteral( "BackgroundColor" ) );
670  bgColorElem.setAttribute( QStringLiteral( "red" ), QString::number( mBackgroundColor.red() ) );
671  bgColorElem.setAttribute( QStringLiteral( "green" ), QString::number( mBackgroundColor.green() ) );
672  bgColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( mBackgroundColor.blue() ) );
673  bgColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( mBackgroundColor.alpha() ) );
674  element.appendChild( bgColorElem );
675 
676  //blend mode
677  element.setAttribute( QStringLiteral( "blendMode" ), QgsPainting::getBlendModeEnum( mBlendMode ) );
678 
679  //opacity
680  element.setAttribute( QStringLiteral( "opacity" ), QString::number( mOpacity ) );
681 
682  element.setAttribute( QStringLiteral( "excludeFromExports" ), mExcludeFromExports );
683 
684  writeObjectPropertiesToElement( element, doc, context );
685 
686  writePropertiesToElement( element, doc, context );
687  parentElement.appendChild( element );
688 
689  return true;
690 }
691 
692 bool QgsLayoutItem::readXml( const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context )
693 {
694  if ( element.nodeName() != QStringLiteral( "LayoutItem" ) )
695  {
696  return false;
697  }
698 
699  readObjectPropertiesFromElement( element, doc, context );
700 
701  mBlockUndoCommands = true;
702  mUuid = element.attribute( QStringLiteral( "uuid" ), QUuid::createUuid().toString() );
703  setId( element.attribute( QStringLiteral( "id" ) ) );
704  mReferencePoint = static_cast< ReferencePoint >( element.attribute( QStringLiteral( "referencePoint" ) ).toInt() );
705  setItemRotation( element.attribute( QStringLiteral( "itemRotation" ), QStringLiteral( "0" ) ).toDouble() );
706  attemptMove( QgsLayoutPoint::decodePoint( element.attribute( QStringLiteral( "position" ) ) ) );
707  attemptResize( QgsLayoutSize::decodeSize( element.attribute( QStringLiteral( "size" ) ) ) );
708 
709  mParentGroupUuid = element.attribute( QStringLiteral( "groupUuid" ) );
710  if ( !mParentGroupUuid.isEmpty() )
711  {
712  if ( QgsLayoutItemGroup *group = parentGroup() )
713  {
714  group->addItem( this );
715  }
716  }
717  mTemplateUuid = element.attribute( QStringLiteral( "templateUuid" ) );
718 
719  //position lock for mouse moves/resizes
720  QString positionLock = element.attribute( QStringLiteral( "positionLock" ) );
721  if ( positionLock.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 )
722  {
723  setLocked( true );
724  }
725  else
726  {
727  setLocked( false );
728  }
729  //visibility
730  setVisibility( element.attribute( QStringLiteral( "visibility" ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) );
731  setZValue( element.attribute( QStringLiteral( "zValue" ) ).toDouble() );
732 
733  //frame
734  QString frame = element.attribute( QStringLiteral( "frame" ) );
735  if ( frame.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 )
736  {
737  mFrame = true;
738  }
739  else
740  {
741  mFrame = false;
742  }
743 
744  //frame
745  QString background = element.attribute( QStringLiteral( "background" ) );
746  if ( background.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 )
747  {
748  mBackground = true;
749  }
750  else
751  {
752  mBackground = false;
753  }
754 
755  //pen
756  mFrameWidth = QgsLayoutMeasurement::decodeMeasurement( element.attribute( QStringLiteral( "outlineWidthM" ) ) );
757  mFrameJoinStyle = QgsSymbolLayerUtils::decodePenJoinStyle( element.attribute( QStringLiteral( "frameJoinStyle" ), QStringLiteral( "miter" ) ) );
758  QDomNodeList frameColorList = element.elementsByTagName( QStringLiteral( "FrameColor" ) );
759  if ( !frameColorList.isEmpty() )
760  {
761  QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
762  bool redOk = false;
763  bool greenOk = false;
764  bool blueOk = false;
765  bool alphaOk = false;
766  int penRed, penGreen, penBlue, penAlpha;
767 
768  penRed = frameColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
769  penGreen = frameColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
770  penBlue = frameColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
771  penAlpha = frameColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
772 
773  if ( redOk && greenOk && blueOk && alphaOk )
774  {
775  mFrameColor = QColor( penRed, penGreen, penBlue, penAlpha );
776  }
777  }
778  refreshFrame( false );
779 
780  //brush
781  QDomNodeList bgColorList = element.elementsByTagName( QStringLiteral( "BackgroundColor" ) );
782  if ( !bgColorList.isEmpty() )
783  {
784  QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
785  bool redOk, greenOk, blueOk, alphaOk;
786  int bgRed, bgGreen, bgBlue, bgAlpha;
787  bgRed = bgColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
788  bgGreen = bgColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
789  bgBlue = bgColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
790  bgAlpha = bgColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
791  if ( redOk && greenOk && blueOk && alphaOk )
792  {
793  mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
794  setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
795  }
796  //apply any data defined settings
797  refreshBackgroundColor( false );
798  }
799 
800  //blend mode
801  setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( element.attribute( QStringLiteral( "blendMode" ), QStringLiteral( "0" ) ).toUInt() ) ) );
802 
803  //opacity
804  if ( element.hasAttribute( QStringLiteral( "opacity" ) ) )
805  {
806  setItemOpacity( element.attribute( QStringLiteral( "opacity" ), QStringLiteral( "1" ) ).toDouble() );
807  }
808  else
809  {
810  setItemOpacity( 1.0 - element.attribute( QStringLiteral( "transparency" ), QStringLiteral( "0" ) ).toInt() / 100.0 );
811  }
812 
813  mExcludeFromExports = element.attribute( QStringLiteral( "excludeFromExports" ), QStringLiteral( "0" ) ).toInt();
814  mEvaluatedExcludeFromExports = mExcludeFromExports;
815 
816  bool result = readPropertiesFromElement( element, doc, context );
817 
818  mBlockUndoCommands = false;
819 
820  emit changed();
821  update();
822  return result;
823 }
824 
826 {
827 }
828 
829 QgsAbstractLayoutUndoCommand *QgsLayoutItem::createCommand( const QString &text, int id, QUndoCommand *parent )
830 {
831  return new QgsLayoutItemUndoCommand( this, text, id, parent );
832 }
833 
834 void QgsLayoutItem::setFrameEnabled( bool drawFrame )
835 {
836  if ( drawFrame == mFrame )
837  {
838  //no change
839  return;
840  }
841 
842  mFrame = drawFrame;
843  refreshFrame( true );
844  emit frameChanged();
845 }
846 
847 void QgsLayoutItem::setFrameStrokeColor( const QColor &color )
848 {
849  if ( mFrameColor == color )
850  {
851  //no change
852  return;
853  }
854  mFrameColor = color;
855  // apply any datadefined overrides
856  refreshFrame( true );
857  emit frameChanged();
858 }
859 
861 {
862  if ( mFrameWidth == width )
863  {
864  //no change
865  return;
866  }
867  mFrameWidth = width;
868  refreshFrame();
869  emit frameChanged();
870 }
871 
872 void QgsLayoutItem::setFrameJoinStyle( const Qt::PenJoinStyle style )
873 {
874  if ( mFrameJoinStyle == style )
875  {
876  //no change
877  return;
878  }
879  mFrameJoinStyle = style;
880 
881  QPen itemPen = pen();
882  itemPen.setJoinStyle( mFrameJoinStyle );
883  setPen( itemPen );
884  emit frameChanged();
885 }
886 
887 void QgsLayoutItem::setBackgroundEnabled( bool drawBackground )
888 {
889  mBackground = drawBackground;
890  update();
891 }
892 
893 void QgsLayoutItem::setBackgroundColor( const QColor &color )
894 {
895  mBackgroundColor = color;
896  // apply any datadefined overrides
897  refreshBackgroundColor( true );
898 }
899 
900 void QgsLayoutItem::setBlendMode( const QPainter::CompositionMode mode )
901 {
902  mBlendMode = mode;
903  // Update the item effect to use the new blend mode
905 }
906 
907 void QgsLayoutItem::setItemOpacity( double opacity )
908 {
909  mOpacity = opacity;
910  refreshOpacity( mItemCachedImage.isNull() );
911  if ( !mItemCachedImage.isNull() )
912  invalidateCache();
913 }
914 
916 {
917  return mExcludeFromExports;
918 }
919 
921 {
922  mExcludeFromExports = exclude;
924 }
925 
927 {
928  return itemFlags() & Flag::FlagOverridesPaint ? false : mEvaluatedOpacity < 1.0;
929 }
930 
932 {
933  return ( itemFlags() & Flag::FlagOverridesPaint && itemOpacity() < 1.0 ) ||
934  blendMode() != QPainter::CompositionMode_SourceOver;
935 }
936 
938 {
939  if ( !frameEnabled() )
940  {
941  return 0;
942  }
943 
944  return pen().widthF() / 2.0;
945 }
946 
948 {
949  double frameBleed = estimatedFrameBleed();
950  return rect().adjusted( -frameBleed, -frameBleed, frameBleed, frameBleed );
951 }
952 
953 void QgsLayoutItem::moveContent( double, double )
954 {
955 
956 }
957 
959 {
960 
961 }
962 
963 void QgsLayoutItem::zoomContent( double, QPointF )
964 {
965 
966 }
967 
968 void QgsLayoutItem::beginCommand( const QString &commandText, UndoCommand command )
969 {
970  if ( !mLayout )
971  return;
972 
973  mLayout->undoStack()->beginCommand( this, commandText, command );
974 }
975 
977 {
978  if ( mLayout )
979  mLayout->undoStack()->endCommand();
980 }
981 
983 {
984  if ( mLayout )
985  mLayout->undoStack()->cancelCommand();
986 }
987 
988 QgsLayoutPoint QgsLayoutItem::applyDataDefinedPosition( const QgsLayoutPoint &position )
989 {
990  if ( !mLayout )
991  {
992  return position;
993  }
994 
996  double evaluatedX = mDataDefinedProperties.valueAsDouble( QgsLayoutObject::PositionX, context, position.x() );
997  double evaluatedY = mDataDefinedProperties.valueAsDouble( QgsLayoutObject::PositionY, context, position.y() );
998  return QgsLayoutPoint( evaluatedX, evaluatedY, position.units() );
999 }
1000 
1001 void QgsLayoutItem::applyDataDefinedOrientation( double &width, double &height, const QgsExpressionContext &context )
1002 {
1003  bool ok = false;
1004  QString orientationString = mDataDefinedProperties.valueAsString( QgsLayoutObject::PaperOrientation, context, QString(), &ok );
1005  if ( ok && !orientationString.isEmpty() )
1006  {
1007  QgsLayoutItemPage::Orientation orientation = QgsLayoutUtils::decodePaperOrientation( orientationString, ok );
1008  if ( ok )
1009  {
1010  double heightD = 0.0, widthD = 0.0;
1011  switch ( orientation )
1012  {
1014  {
1015  heightD = std::max( height, width );
1016  widthD = std::min( height, width );
1017  break;
1018  }
1020  {
1021  heightD = std::min( height, width );
1022  widthD = std::max( height, width );
1023  break;
1024  }
1025  }
1026  width = widthD;
1027  height = heightD;
1028  }
1029  }
1030 }
1031 
1033 {
1034  if ( !mLayout )
1035  {
1036  return size;
1037  }
1038 
1043  return size;
1044 
1045 
1047 
1048  // lowest priority is page size
1050  QgsPageSize matchedSize;
1051  double evaluatedWidth = size.width();
1052  double evaluatedHeight = size.height();
1053  if ( QgsApplication::pageSizeRegistry()->decodePageSize( pageSize, matchedSize ) )
1054  {
1055  QgsLayoutSize convertedSize = mLayout->renderContext().measurementConverter().convert( matchedSize.size, size.units() );
1056  evaluatedWidth = convertedSize.width();
1057  evaluatedHeight = convertedSize.height();
1058  }
1059 
1060  // highest priority is dd width/height
1061  evaluatedWidth = mDataDefinedProperties.valueAsDouble( QgsLayoutObject::ItemWidth, context, evaluatedWidth );
1062  evaluatedHeight = mDataDefinedProperties.valueAsDouble( QgsLayoutObject::ItemHeight, context, evaluatedHeight );
1063 
1064  //which is finally overwritten by data defined orientation
1065  applyDataDefinedOrientation( evaluatedWidth, evaluatedHeight, context );
1066 
1067  return QgsLayoutSize( evaluatedWidth, evaluatedHeight, size.units() );
1068 }
1069 
1070 double QgsLayoutItem::applyDataDefinedRotation( const double rotation )
1071 {
1072  if ( !mLayout )
1073  {
1074  return rotation;
1075  }
1076 
1078  double evaluatedRotation = mDataDefinedProperties.valueAsDouble( QgsLayoutObject::ItemRotation, context, rotation );
1079  return evaluatedRotation;
1080 }
1081 
1083 {
1084  //update data defined properties and update item to match
1085 
1086  //evaluate width and height first, since they may affect position if non-top-left reference point set
1087  if ( property == QgsLayoutObject::ItemWidth || property == QgsLayoutObject::ItemHeight ||
1088  property == QgsLayoutObject::AllProperties )
1089  {
1090  refreshItemSize();
1091  }
1092  if ( property == QgsLayoutObject::PositionX || property == QgsLayoutObject::PositionY ||
1093  property == QgsLayoutObject::AllProperties )
1094  {
1096  }
1097  if ( property == QgsLayoutObject::ItemRotation || property == QgsLayoutObject::AllProperties )
1098  {
1100  }
1101  if ( property == QgsLayoutObject::Opacity || property == QgsLayoutObject::AllProperties )
1102  {
1103  refreshOpacity( false );
1104  }
1105  if ( property == QgsLayoutObject::FrameColor || property == QgsLayoutObject::AllProperties )
1106  {
1107  refreshFrame( false );
1108  }
1109  if ( property == QgsLayoutObject::BackgroundColor || property == QgsLayoutObject::AllProperties )
1110  {
1111  refreshBackgroundColor( false );
1112  }
1113  if ( property == QgsLayoutObject::BlendMode || property == QgsLayoutObject::AllProperties )
1114  {
1115  refreshBlendMode();
1116  }
1118  {
1119  bool exclude = mExcludeFromExports;
1120  //data defined exclude from exports set?
1122  }
1123 
1124  update();
1125 }
1126 
1127 void QgsLayoutItem::setItemRotation( double angle, const bool adjustPosition )
1128 {
1129  if ( angle >= 360.0 || angle <= -360.0 )
1130  {
1131  angle = std::fmod( angle, 360.0 );
1132  }
1133 
1134  QPointF point = adjustPosition ? positionAtReferencePoint( QgsLayoutItem::Middle )
1135  : pos();
1136  double rotationRequired = angle - rotation();
1137  rotateItem( rotationRequired, point );
1138 
1139  mItemRotation = angle;
1140 }
1141 
1142 void QgsLayoutItem::updateStoredItemPosition()
1143 {
1144  QPointF layoutPosReferencePoint = positionAtReferencePoint( mReferencePoint );
1145  mItemPosition = mLayout->convertFromLayoutUnits( layoutPosReferencePoint, mItemPosition.units() );
1146 }
1147 
1148 void QgsLayoutItem::rotateItem( const double angle, const QPointF transformOrigin )
1149 {
1150  double evaluatedAngle = angle + rotation();
1151  evaluatedAngle = QgsLayoutUtils::normalizedAngle( evaluatedAngle, true );
1152  mItemRotation = evaluatedAngle;
1153 
1154  QPointF itemTransformOrigin = mapFromScene( transformOrigin );
1155 
1156  refreshItemRotation( &itemTransformOrigin );
1157 }
1158 
1160 {
1163  return context;
1164 }
1165 
1167 {
1168  Q_UNUSED( visitor );
1169  return true;
1170 }
1171 
1173 {
1175  refreshItemSize();
1176 
1178 }
1179 
1181 {
1182  if ( !mItemCachedImage.isNull() )
1183  {
1184  mItemCachedImage = QImage();
1185  mItemCacheDpi = -1;
1186  update();
1187  }
1188 }
1189 
1191 {
1192  update();
1193 }
1194 
1195 void QgsLayoutItem::drawDebugRect( QPainter *painter )
1196 {
1197  if ( !painter )
1198  {
1199  return;
1200  }
1201 
1202  painter->save();
1203  painter->setRenderHint( QPainter::Antialiasing, false );
1204  painter->setPen( Qt::NoPen );
1205  painter->setBrush( QColor( 100, 255, 100, 200 ) );
1206  painter->drawRect( rect() );
1207  painter->restore();
1208 }
1209 
1211 {
1212  if ( !mFrame || !context.painter() )
1213  return;
1214 
1215  QPainter *p = context.painter();
1216  p->save();
1217  p->setPen( pen() );
1218  p->setBrush( Qt::NoBrush );
1219 
1220  if ( context.flags() & QgsRenderContext::Antialiasing )
1221  p->setRenderHint( QPainter::Antialiasing, true );
1222 
1223  p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
1224  p->restore();
1225 }
1226 
1228 {
1229  if ( !mBackground || !context.painter() )
1230  return;
1231 
1232  QPainter *p = context.painter();
1233  p->save();
1234  p->setBrush( brush() );
1235  p->setPen( Qt::NoPen );
1236 
1237  if ( context.flags() & QgsRenderContext::Antialiasing )
1238  p->setRenderHint( QPainter::Antialiasing, true );
1239 
1240  p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
1241  p->restore();
1242 }
1243 
1245 {
1246  mFixedSize = size;
1247  refreshItemSize();
1248 }
1249 
1251 {
1252  mMinimumSize = size;
1253  refreshItemSize();
1254 }
1255 
1256 QSizeF QgsLayoutItem::applyItemSizeConstraint( const QSizeF targetSize )
1257 {
1258  return targetSize;
1259 }
1260 
1262 {
1263  attemptResize( mItemSize );
1264 }
1265 
1267 {
1268  attemptMove( mItemPosition );
1269 }
1270 
1271 QPointF QgsLayoutItem::itemPositionAtReferencePoint( const ReferencePoint reference, const QSizeF size ) const
1272 {
1273  switch ( reference )
1274  {
1275  case UpperMiddle:
1276  return QPointF( size.width() / 2.0, 0 );
1277  case UpperRight:
1278  return QPointF( size.width(), 0 );
1279  case MiddleLeft:
1280  return QPointF( 0, size.height() / 2.0 );
1281  case Middle:
1282  return QPointF( size.width() / 2.0, size.height() / 2.0 );
1283  case MiddleRight:
1284  return QPointF( size.width(), size.height() / 2.0 );
1285  case LowerLeft:
1286  return QPointF( 0, size.height() );
1287  case LowerMiddle:
1288  return QPointF( size.width() / 2.0, size.height() );
1289  case LowerRight:
1290  return QPointF( size.width(), size.height() );
1291  case UpperLeft:
1292  return QPointF( 0, 0 );
1293  }
1294  // no warnings
1295  return QPointF( 0, 0 );
1296 }
1297 
1298 QPointF QgsLayoutItem::adjustPointForReferencePosition( const QPointF position, const QSizeF size, const ReferencePoint reference ) const
1299 {
1300  QPointF itemPosition = mapFromScene( position ); //need to map from scene to handle item rotation
1301  QPointF adjustedPointInsideItem = itemPosition - itemPositionAtReferencePoint( reference, size );
1302  return mapToScene( adjustedPointInsideItem );
1303 }
1304 
1306 {
1307  QPointF pointWithinItem = itemPositionAtReferencePoint( reference, rect().size() );
1308  return mapToScene( pointWithinItem );
1309 }
1310 
1312 {
1313  QPointF topLeft = mLayout->convertToLayoutUnits( point );
1314  QPointF refPoint = topLeft + itemPositionAtReferencePoint( mReferencePoint, rect().size() );
1315  return mLayout->convertFromLayoutUnits( refPoint, point.units() );
1316 }
1317 
1318 bool QgsLayoutItem::writePropertiesToElement( QDomElement &, QDomDocument &, const QgsReadWriteContext & ) const
1319 {
1320  return true;
1321 }
1322 
1323 bool QgsLayoutItem::readPropertiesFromElement( const QDomElement &, const QDomDocument &, const QgsReadWriteContext & )
1324 {
1325 
1326  return true;
1327 }
1328 
1329 void QgsLayoutItem::initConnectionsToLayout()
1330 {
1331  if ( !mLayout )
1332  return;
1333 
1334 }
1335 
1336 void QgsLayoutItem::preparePainter( QPainter *painter )
1337 {
1338  if ( !painter || !painter->device() )
1339  {
1340  return;
1341  }
1342 
1343  painter->setRenderHint( QPainter::Antialiasing, shouldDrawAntialiased() );
1344 }
1345 
1346 bool QgsLayoutItem::shouldDrawAntialiased() const
1347 {
1348  if ( !mLayout )
1349  {
1350  return true;
1351  }
1352  return mLayout->renderContext().testFlag( QgsLayoutRenderContext::FlagAntialiasing ) && !mLayout->renderContext().testFlag( QgsLayoutRenderContext::FlagDebug );
1353 }
1354 
1355 bool QgsLayoutItem::shouldDrawDebugRect() const
1356 {
1357  return mLayout && mLayout->renderContext().testFlag( QgsLayoutRenderContext::FlagDebug );
1358 }
1359 
1360 QSizeF QgsLayoutItem::applyMinimumSize( const QSizeF targetSize )
1361 {
1362  if ( !mLayout || minimumSize().isEmpty() )
1363  {
1364  return targetSize;
1365  }
1366  QSizeF minimumSizeLayoutUnits = mLayout->convertToLayoutUnits( minimumSize() );
1367  return targetSize.expandedTo( minimumSizeLayoutUnits );
1368 }
1369 
1370 QSizeF QgsLayoutItem::applyFixedSize( const QSizeF targetSize )
1371 {
1372  if ( !mLayout || fixedSize().isEmpty() )
1373  {
1374  return targetSize;
1375  }
1376 
1377  QSizeF size = targetSize;
1378  QSizeF fixedSizeLayoutUnits = mLayout->convertToLayoutUnits( fixedSize() );
1379  if ( fixedSizeLayoutUnits.width() > 0 )
1380  size.setWidth( fixedSizeLayoutUnits.width() );
1381  if ( fixedSizeLayoutUnits.height() > 0 )
1382  size.setHeight( fixedSizeLayoutUnits.height() );
1383 
1384  return size;
1385 }
1386 
1387 void QgsLayoutItem::refreshItemRotation( QPointF *origin )
1388 {
1389  double r = mItemRotation;
1390 
1391  //data defined rotation set?
1393 
1394  if ( qgsDoubleNear( r, rotation() ) && !origin )
1395  {
1396  return;
1397  }
1398 
1399  QPointF transformPoint = origin ? *origin : mapFromScene( positionAtReferencePoint( QgsLayoutItem::Middle ) );
1400 
1401  if ( !transformPoint.isNull() )
1402  {
1403  //adjustPosition set, so shift the position of the item so that rotation occurs around item center
1404  //create a line from the transform point to the item's origin, in scene coordinates
1405  QLineF refLine = QLineF( mapToScene( transformPoint ), mapToScene( QPointF( 0, 0 ) ) );
1406  //rotate this line by the current rotation angle
1407  refLine.setAngle( refLine.angle() - r + rotation() );
1408  //get new end point of line - this is the new item position
1409  QPointF rotatedReferencePoint = refLine.p2();
1410  setPos( rotatedReferencePoint );
1411  }
1412 
1413  setTransformOriginPoint( 0, 0 );
1414  QGraphicsItem::setRotation( r );
1415 
1416  //adjust stored position of item to match scene pos of reference point
1417  updateStoredItemPosition();
1418  emit sizePositionChanged();
1419 
1420  emit rotationChanged( r );
1421 
1422  //update bounds of scene, since rotation may affect this
1423  mLayout->updateBounds();
1424 }
1425 
1426 void QgsLayoutItem::refreshOpacity( bool updateItem )
1427 {
1428  //data defined opacity set?
1430 
1431  // Set the QGraphicItem's opacity
1432  mEvaluatedOpacity = opacity / 100.0;
1433 
1435  {
1436  // item handles it's own painting, so it won't use the built-in opacity handling in QgsLayoutItem::paint, and
1437  // we have to rely on QGraphicsItem opacity to handle this
1438  setOpacity( mEvaluatedOpacity );
1439  }
1440 
1441  if ( updateItem )
1442  {
1443  update();
1444  }
1445 }
1446 
1447 void QgsLayoutItem::refreshFrame( bool updateItem )
1448 {
1449  if ( !mFrame )
1450  {
1451  setPen( Qt::NoPen );
1452  return;
1453  }
1454 
1455  //data defined stroke color set?
1456  bool ok = false;
1457  QColor frameColor = mDataDefinedProperties.valueAsColor( QgsLayoutObject::FrameColor, createExpressionContext(), mFrameColor, &ok );
1458  QPen itemPen;
1459  if ( ok )
1460  {
1461  itemPen = QPen( frameColor );
1462  }
1463  else
1464  {
1465  itemPen = QPen( mFrameColor );
1466  }
1467  itemPen.setJoinStyle( mFrameJoinStyle );
1468 
1469  if ( mLayout )
1470  itemPen.setWidthF( mLayout->convertToLayoutUnits( mFrameWidth ) );
1471  else
1472  itemPen.setWidthF( mFrameWidth.length() );
1473 
1474  setPen( itemPen );
1475 
1476  if ( updateItem )
1477  {
1478  update();
1479  }
1480 }
1481 
1483 {
1484  //data defined fill color set?
1485  bool ok = false;
1487  if ( ok )
1488  {
1489  setBrush( QBrush( backgroundColor, Qt::SolidPattern ) );
1490  }
1491  else
1492  {
1493  setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
1494  }
1495  if ( updateItem )
1496  {
1497  update();
1498  }
1499 }
1500 
1502 {
1503  QPainter::CompositionMode blendMode = mBlendMode;
1504 
1505  //data defined blend mode set?
1506  bool ok = false;
1508  if ( ok && !blendStr.isEmpty() )
1509  {
1510  QString blendstr = blendStr.trimmed();
1511  QPainter::CompositionMode blendModeD = QgsSymbolLayerUtils::decodeBlendMode( blendstr );
1512  blendMode = blendModeD;
1513  }
1514 
1515  // Update the item effect to use the new blend mode
1516  mEffect->setCompositionMode( blendMode );
1517 }
1518 
QgsLayoutRenderContext::FlagUseAdvancedEffects
@ FlagUseAdvancedEffects
Enable advanced effects such as blend modes.
Definition: qgslayoutrendercontext.h:45
QgsLayoutItem::shouldDrawItem
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
Definition: qgslayoutitem.cpp:594
QgsLayoutItem::cleanup
virtual void cleanup()
Called just before a batch of items are deleted, allowing them to run cleanup tasks.
Definition: qgslayoutitem.cpp:99
QgsLayoutItem::parentGroup
QgsLayoutItemGroup * parentGroup() const
Returns the item's parent group, if the item is part of a QgsLayoutItemGroup group.
Definition: qgslayoutitem.cpp:230
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
QgsLayoutItem::itemOpacity
double itemOpacity() const
Returns the item's opacity.
Definition: qgslayoutitem.h:840
QgsLayoutItem::id
QString id() const
Returns the item's ID name.
Definition: qgslayoutitem.h:354
qgslayoutitemgroup.h
QgsLayoutObject::layout
const QgsLayout * layout() const
Returns the layout the object is attached to.
Definition: qgslayoutobject.cpp:118
qgsexpressioncontextutils.h
QgsLayoutItem::applyItemSizeConstraint
virtual QSizeF applyItemSizeConstraint(QSizeF targetSize)
Applies any item-specific size constraint handling to a given targetSize in layout units.
Definition: qgslayoutitem.cpp:1256
QgsAbstractPropertyCollection::valueAsDouble
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
Definition: qgspropertycollection.cpp:66
QgsSymbolLayerUtils::decodeBlendMode
static QPainter::CompositionMode decodeBlendMode(const QString &s)
Definition: qgssymbollayerutils.cpp:745
QgsLayoutObject::ItemRotation
@ ItemRotation
Rotation of item.
Definition: qgslayoutobject.h:149
qgslayoutundostack.h
QgsApplication::pageSizeRegistry
static QgsPageSizeRegistry * pageSizeRegistry()
Returns the application's page size registry, used for managing layout page sizes.
Definition: qgsapplication.cpp:2204
QgsLayoutItem::UndoCommand
UndoCommand
Layout item undo commands, used for collapsing undo commands.
Definition: qgslayoutitem.h:215
QgsLayoutItem::refreshItemSize
void refreshItemSize()
Refreshes an item's size by rechecking it against any possible item fixed or minimum sizes.
Definition: qgslayoutitem.cpp:1261
QgsLayoutItem::writePropertiesToElement
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
Definition: qgslayoutitem.cpp:1318
QgsLayoutItemPage
Item representing the paper in a layout.
Definition: qgslayoutitempage.h:54
QgsLayoutItem::sizePositionChanged
void sizePositionChanged()
Emitted when the item's size or position changes.
QgsLayoutSize::width
double width() const
Returns the width of the size.
Definition: qgslayoutsize.h:76
QgsLayoutObject::refresh
virtual void refresh()
Refreshes the object, causing a recalculation of any property overrides.
Definition: qgslayoutobject.h:304
QgsLayoutSize::units
QgsUnitTypes::LayoutUnit units() const
Returns the units for the size.
Definition: qgslayoutsize.h:103
QgsLayoutItem::setFrameEnabled
virtual void setFrameEnabled(bool drawFrame)
Sets whether this item has a frame drawn around it or not.
Definition: qgslayoutitem.cpp:834
QgsLayoutItem::drawDebugRect
virtual void drawDebugRect(QPainter *painter)
Draws a debugging rectangle of the item's current bounds within the specified painter.
Definition: qgslayoutitem.cpp:1195
QgsLayoutItem::frameEnabled
bool frameEnabled() const
Returns true if the item includes a frame.
Definition: qgslayoutitem.h:727
QgsPainting::BlendMode
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
Definition: qgspainting.h:49
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsLayoutItem::setMinimumSize
virtual void setMinimumSize(const QgsLayoutSize &size)
Sets the minimum allowed size for the layout item.
Definition: qgslayoutitem.cpp:1250
QgsUnitTypes::LayoutPixels
@ LayoutPixels
Pixels.
Definition: qgsunittypes.h:189
QgsLayoutItem::Middle
@ Middle
Center of item.
Definition: qgslayoutitem.h:207
QgsLayoutItem::setFixedSize
virtual void setFixedSize(const QgsLayoutSize &size)
Sets a fixed size for the layout item, which prevents it from being freely resized.
Definition: qgslayoutitem.cpp:1244
QgsLayoutItem::setFrameStrokeWidth
virtual void setFrameStrokeWidth(QgsLayoutMeasurement width)
Sets the frame stroke width.
Definition: qgslayoutitem.cpp:860
QgsLayout::ZItem
@ ZItem
Minimum z value for items.
Definition: qgslayout.h:59
QgsLayoutItem::beginCommand
void beginCommand(const QString &commandText, UndoCommand command=UndoNone)
Starts new undo command for this item.
Definition: qgslayoutitem.cpp:968
QgsLayoutItem::MiddleRight
@ MiddleRight
Middle right of item.
Definition: qgslayoutitem.h:208
QgsLayoutEffect
Definition: qgslayouteffect.h:35
QgsLayoutMeasurement::length
double length() const
Returns the length of the measurement.
Definition: qgslayoutmeasurement.h:48
QgsLayoutItem::attemptMoveBy
void attemptMoveBy(double deltaX, double deltaY)
Attempts to shift the item's position by a specified deltaX and deltaY, in layout units.
Definition: qgslayoutitem.cpp:530
QgsLayoutItem::nextExportPart
virtual bool nextExportPart()
Moves to the next export part for a multi-layered export item, during a multi-layered export.
Definition: qgslayoutitem.cpp:267
QgsLayoutItem::finalizeRestoreFromXml
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
Definition: qgslayoutitem.cpp:825
qgssymbollayerutils.h
QgsLayoutObject::PaperOrientation
@ PaperOrientation
Paper orientation.
Definition: qgslayoutobject.h:142
QgsLayoutItem::CanGroupWithAnyOtherItem
@ CanGroupWithAnyOtherItem
Item can be placed on a layer with any other item (default behavior)
Definition: qgslayoutitem.h:426
QgsImageOperation::multiplyOpacity
static void multiplyOpacity(QImage &image, double factor)
Multiplies opacity of image pixel values by a factor.
Definition: qgsimageoperation.cpp:322
QgsLayoutItem::MiddleLeft
@ MiddleLeft
Middle left of item.
Definition: qgslayoutitem.h:206
QgsLayoutItemRenderContext
Definition: qgslayoutitem.h:44
QgsLayoutItem::attemptSetSceneRect
void attemptSetSceneRect(const QRectF &rect, bool includesFrame=false)
Attempts to update the item's position and size to match the passed rect in layout coordinates.
Definition: qgslayoutitem.cpp:514
QgsLayoutItem::refreshBackgroundColor
void refreshBackgroundColor(bool updateItem=true)
Refresh item's background color, considering data defined colors.
Definition: qgslayoutitem.cpp:1482
QgsLayoutObject::ItemHeight
@ ItemHeight
Height of item.
Definition: qgslayoutobject.h:148
QgsUnitTypes::LayoutUnit
LayoutUnit
Layout measurement units.
Definition: qgsunittypes.h:180
QgsLayoutPoint::y
double y() const
Returns y coordinate of point.
Definition: qgslayoutpoint.h:86
QgsLayoutObject::mDataDefinedProperties
QgsPropertyCollection mDataDefinedProperties
Definition: qgslayoutobject.h:337
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsStyleEntityVisitorInterface
Definition: qgsstyleentityvisitor.h:33
QgsLayout::units
QgsUnitTypes::LayoutUnit units() const
Returns the native units for the layout.
Definition: qgslayout.h:328
QgsLayoutItem::refreshDataDefinedProperty
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
Definition: qgslayoutitem.cpp:1082
QgsLayoutItem::rectWithFrame
virtual QRectF rectWithFrame() const
Returns the item's rectangular bounds, including any bleed caused by the item's frame.
Definition: qgslayoutitem.cpp:947
QgsLayoutItem::numberExportLayers
virtual Q_DECL_DEPRECATED int numberExportLayers() const
Returns the number of layers that this item requires for exporting during layered exports (e....
Definition: qgslayoutitem.cpp:252
QgsExpressionContextUtils::layoutItemScope
static QgsExpressionContextScope * layoutItemScope(const QgsLayoutItem *item)
Creates a new scope which contains variables and functions relating to a QgsLayoutItem.
Definition: qgsexpressioncontextutils.cpp:609
QgsLayoutItem::cancelCommand
void cancelCommand()
Cancels the current item command and discards it.
Definition: qgslayoutitem.cpp:982
QgsLayoutItem::page
int page() const
Returns the page the item is currently on, with the first page returning 0.
Definition: qgslayoutitem.cpp:545
qgsimageoperation.h
QgsLayoutItem::drawFrame
virtual void drawFrame(QgsRenderContext &context)
Draws the frame around the item.
Definition: qgslayoutitem.cpp:1210
QgsLayoutItem::refreshItemPosition
void refreshItemPosition()
Refreshes an item's position by rechecking it against any possible overrides such as data defined pos...
Definition: qgslayoutitem.cpp:1266
qgslayoutitemundocommand.h
QgsLayoutSize::decodeSize
static QgsLayoutSize decodeSize(const QString &string)
Decodes a size from a string.
Definition: qgslayoutsize.cpp:57
QgsRenderContext::scaleFactor
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Definition: qgsrendercontext.h:317
QgsLayoutItem::excludeFromExports
bool excludeFromExports() const
Returns whether the item should be excluded from layout exports and prints.
Definition: qgslayoutitem.cpp:915
QgsLayoutObject::changed
void changed()
Emitted when the object's properties change.
QgsLayoutSize::setHeight
void setHeight(const double height)
Sets the height for the size.
Definition: qgslayoutsize.h:97
QgsLayoutItem::ReferencePoint
ReferencePoint
Fixed position reference point.
Definition: qgslayoutitem.h:201
QgsLayoutItem::writeXml
bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores the item state in a DOM element.
Definition: qgslayoutitem.cpp:611
QgsLayoutItem::refreshFrame
void refreshFrame(bool updateItem=true)
Refresh item's frame, considering data defined colors and frame size.
Definition: qgslayoutitem.cpp:1447
QgsLayoutItem::pagePositionWithUnits
QgsLayoutPoint pagePositionWithUnits() const
Returns the item's position (in item units) relative to the top left corner of its current page.
Definition: qgslayoutitem.cpp:569
QgsLayoutItem::readPropertiesFromElement
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets item state from a DOM element.
Definition: qgslayoutitem.cpp:1323
QgsLayoutMeasurement::encodeMeasurement
QString encodeMeasurement() const
Encodes the layout measurement to a string.
Definition: qgslayoutmeasurement.cpp:28
QgsLayoutItem::draw
virtual void draw(QgsLayoutItemRenderContext &context)=0
Draws the item's contents using the specified item render context.
QgsLayoutObject::BlendMode
@ BlendMode
Item blend mode.
Definition: qgslayoutobject.h:152
QgsLayoutItem::setSelected
virtual void setSelected(bool selected)
Sets whether the item should be selected.
Definition: qgslayoutitem.cpp:160
QgsLayoutItem::minimumSize
virtual QgsLayoutSize minimumSize() const
Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely r...
Definition: qgslayoutitem.h:557
QgsLayoutItem::setExcludeFromExports
void setExcludeFromExports(bool exclude)
Sets whether the item should be excluded from layout exports and prints.
Definition: qgslayoutitem.cpp:920
QgsLayoutItem::redraw
virtual void redraw()
Triggers a redraw (update) of the item.
Definition: qgslayoutitem.cpp:1190
QgsLayoutItem::type
int type() const override
Returns a unique graphics item type identifier.
Definition: qgslayoutitem.cpp:124
QgsLayoutItemAbstractMetadata
Stores metadata about one layout item class.
Definition: qgslayoutitemregistry.h:45
QgsPainting::getBlendModeEnum
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
Definition: qgspainting.cpp:80
QgsLayoutItem::readXml
bool readXml(const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets the item state from a DOM element.
Definition: qgslayoutitem.cpp:692
QgsLayoutItem::endCommand
void endCommand()
Completes the current item command and push it onto the layout's undo stack.
Definition: qgslayoutitem.cpp:976
qgslayoututils.h
QgsLayoutItem::drawBackground
virtual void drawBackground(QgsRenderContext &context)
Draws the background for the item.
Definition: qgslayoutitem.cpp:1227
QgsLayoutItem::containsAdvancedEffects
virtual bool containsAdvancedEffects() const
Returns true if the item contains contents with blend modes or transparency effects which can only be...
Definition: qgslayoutitem.cpp:926
QgsLayoutUtils::createRenderContextForLayout
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
Definition: qgslayoututils.cpp:138
Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:752
QgsLayoutObject::PositionX
@ PositionX
X position on page.
Definition: qgslayoutobject.h:145
QgsLayoutObject::AllProperties
@ AllProperties
All properties for item.
Definition: qgslayoutobject.h:135
QgsLayoutItem::setBlendMode
void setBlendMode(QPainter::CompositionMode mode)
Sets the item's composition blending mode.
Definition: qgslayoutitem.cpp:900
QgsLayoutItem::estimatedFrameBleed
virtual double estimatedFrameBleed() const
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.
Definition: qgslayoutitem.cpp:937
QgsLayoutItem::backgroundColor
QColor backgroundColor() const
Returns the background color for this item.
Definition: qgslayoutitem.h:812
QgsLayoutItem::rotateItem
virtual void rotateItem(double angle, QPointF transformOrigin)
Rotates the item by a specified angle in degrees clockwise around a specified reference point.
Definition: qgslayoutitem.cpp:1148
QgsLayoutItem::stopLayeredExport
virtual void stopLayeredExport()
Stops a multi-layer export operation.
Definition: qgslayoutitem.cpp:262
QgsLayoutItem::ExportLayerDetail
Contains details of a particular export layer relating to a layout item.
Definition: qgslayoutitem.h:487
QgsLayoutSize::encodeSize
QString encodeSize() const
Encodes the layout size to a string.
Definition: qgslayoutsize.cpp:52
QgsLayoutItem::lockChanged
void lockChanged()
Emitted if the item's lock status changes.
QgsLayoutItem::exportLayerBehavior
virtual ExportLayerBehavior exportLayerBehavior() const
Returns the behavior of this item during exporting to layered exports (e.g.
Definition: qgslayoutitem.cpp:247
QgsLayoutPoint::setY
void setY(const double y)
Sets y coordinate of point.
Definition: qgslayoutpoint.h:93
QgsPageSize
A named page size for layouts.
Definition: qgspagesizeregistry.h:32
QgsLayoutItem::ExportLayerBehavior
ExportLayerBehavior
Behavior of item when exporting to layered outputs.
Definition: qgslayoutitem.h:424
qgslayoutitem.h
QgsLayoutItem::accept
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
Definition: qgslayoutitem.cpp:1166
QgsLayoutItem::requiresRasterization
virtual bool requiresRasterization() const
Returns true if the item is drawn in such a way that forces the whole layout to be rasterized when ex...
Definition: qgslayoutitem.cpp:931
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:315
QgsLayoutItem::isGroupMember
bool isGroupMember() const
Returns true if the item is part of a QgsLayoutItemGroup group.
Definition: qgslayoutitem.cpp:225
QgsLayoutItem::frameChanged
void frameChanged()
Emitted if the item's frame style changes.
QgsLayoutItem::invalidateCache
virtual void invalidateCache()
Forces a deferred update of any cached image the item uses.
Definition: qgslayoutitem.cpp:1180
QgsLayoutItem::zoomContent
virtual void zoomContent(double factor, QPointF point)
Zooms content of item.
Definition: qgslayoutitem.cpp:963
QgsPainting::getCompositionMode
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Definition: qgspainting.cpp:20
QgsLayoutItem::setLocked
void setLocked(bool locked)
Sets whether the item is locked, preventing mouse interactions with the item.
Definition: qgslayoutitem.cpp:200
QgsLayoutItem::setBackgroundColor
void setBackgroundColor(const QColor &color)
Sets the background color for this item.
Definition: qgslayoutitem.cpp:893
QgsLayoutItem::positionWithUnits
QgsLayoutPoint positionWithUnits() const
Returns the item's current position, including units.
Definition: qgslayoutitem.h:641
QgsLayoutItem::FlagOverridesPaint
@ FlagOverridesPaint
Item overrides the default layout item painting method.
Definition: qgslayoutitem.h:301
QgsLayoutItem::setVisibility
virtual void setVisibility(bool visible)
Sets whether the item is visible.
Definition: qgslayoutitem.cpp:170
QgsLayoutItem::setBackgroundEnabled
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
Definition: qgslayoutitem.cpp:887
QgsLayoutObject::ExcludeFromExports
@ ExcludeFromExports
Exclude item from exports.
Definition: qgslayoutobject.h:153
qgspainting.h
QgsLayoutItem::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Handles preparing a paint surface for the layout item and painting the item's content.
Definition: qgslayoutitem.cpp:285
QgsLayoutItem::setFrameStrokeColor
void setFrameStrokeColor(const QColor &color)
Sets the frame stroke color.
Definition: qgslayoutitem.cpp:847
QgsLayoutItemPage::Landscape
@ Landscape
Landscape orientation.
Definition: qgslayoutitempage.h:65
QgsLayoutItem::itemRotation
double itemRotation() const
Returns the current rotation for the item, in degrees clockwise.
Definition: qgslayoutitem.cpp:606
QgsLayoutItem::setFrameJoinStyle
void setFrameJoinStyle(Qt::PenJoinStyle style)
Sets the join style used when drawing the item's frame.
Definition: qgslayoutitem.cpp:872
qgslayouteffect.h
QgsLayoutRenderContext::flagsChanged
void flagsChanged(QgsLayoutRenderContext::Flags flags)
Emitted whenever the context's flags change.
QgsLayoutItem::refreshBlendMode
void refreshBlendMode()
Refresh item's blend mode, considering data defined blend mode.
Definition: qgslayoutitem.cpp:1501
QgsLayoutItem::adjustPointForReferencePosition
QPointF adjustPointForReferencePosition(QPointF point, QSizeF size, ReferencePoint reference) const
Adjusts the specified point at which a reference position of the item sits and returns the top left c...
Definition: qgslayoutitem.cpp:1298
qgslayout.h
QgsLayoutItem::topLeftToReferencePoint
QgsLayoutPoint topLeftToReferencePoint(const QgsLayoutPoint &point) const
Returns the position for the reference point of the item, if the top-left of the item was placed at t...
Definition: qgslayoutitem.cpp:1311
QgsLayoutItem::rotationChanged
void rotationChanged(double newRotation)
Emitted on item rotation change.
QgsLayoutItem::~QgsLayoutItem
~QgsLayoutItem() override
Definition: qgslayoutitem.cpp:94
QgsLayoutItem::startLayeredExport
virtual void startLayeredExport()
Starts a multi-layer export operation.
Definition: qgslayoutitem.cpp:257
QgsLayoutItemGroup
Definition: qgslayoutitemgroup.h:28
qgspagesizeregistry.h
QgsAbstractPropertyCollection::valueAsString
QString valueAsString(int key, const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a string.
Definition: qgspropertycollection.cpp:42
QgsLayoutItem::LowerRight
@ LowerRight
Lower right corner of item.
Definition: qgslayoutitem.h:211
QgsLayoutItem::refresh
void refresh() override
Refreshes the item, causing a recalculation of any property overrides and recalculation of its positi...
Definition: qgslayoutitem.cpp:1172
QgsExpressionContext::appendScope
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Definition: qgsexpressioncontext.cpp:490
QgsLayoutSize::height
double height() const
Returns the height of the size.
Definition: qgslayoutsize.h:90
QgsLayoutItem::LowerLeft
@ LowerLeft
Lower left corner of item.
Definition: qgslayoutitem.h:209
QgsLayoutObject::createExpressionContext
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the objects' current state.
Definition: qgslayoutobject.cpp:148
QgsLayoutItem::setId
virtual void setId(const QString &id)
Set the item's id name.
Definition: qgslayoutitem.cpp:134
QgsLayoutItem::blendMode
QPainter::CompositionMode blendMode() const
Returns the item's composition blending mode.
Definition: qgslayoutitem.h:825
QgsLayoutItem::attemptMove
virtual void attemptMove(const QgsLayoutPoint &point, bool useReferencePoint=true, bool includesFrame=false, int page=-1)
Attempts to move the item to a specified point.
Definition: qgslayoutitem.cpp:470
QgsLayoutItem::setParentGroup
void setParentGroup(QgsLayoutItemGroup *group)
Sets the item's parent group.
Definition: qgslayoutitem.cpp:238
QgsLayoutSize::setWidth
void setWidth(const double width)
Sets the width for the size.
Definition: qgslayoutsize.h:83
QgsLayoutObject::BackgroundColor
@ BackgroundColor
Item background color.
Definition: qgslayoutobject.h:155
CACHE_SIZE_LIMIT
#define CACHE_SIZE_LIMIT
Definition: qgslayoutitem.cpp:37
qgslayoutitempage.h
QgsLayoutItem::setReferencePoint
void setReferencePoint(ReferencePoint point)
Sets the reference point for positioning of the layout item.
Definition: qgslayoutitem.cpp:418
QgsLayoutItem::itemFlags
virtual Flags itemFlags() const
Returns the item's flags, which indicate how the item behaves.
Definition: qgslayoutitem.cpp:129
QgsLayoutItem::uuid
virtual QString uuid() const
Returns the item identification string.
Definition: qgslayoutitem.h:340
QgsApplication::layoutItemRegistry
static QgsLayoutItemRegistry * layoutItemRegistry()
Returns the application's layout item registry, used for layout item types.
Definition: qgsapplication.cpp:2159
QgsLayoutPoint::setX
void setX(const double x)
Sets the x coordinate of point.
Definition: qgslayoutpoint.h:79
QgsLayoutItem::positionAtReferencePoint
QPointF positionAtReferencePoint(ReferencePoint reference) const
Returns the current position (in layout units) of a reference point for the item.
Definition: qgslayoutitem.cpp:1305
QgsLayoutObject::readObjectPropertiesFromElement
bool readObjectPropertiesFromElement(const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets object properties from a DOM element.
Definition: qgslayoutobject.cpp:181
QgsLayoutPoint::toQPointF
QPointF toQPointF() const
Converts the layout point to a QPointF.
Definition: qgslayoutpoint.cpp:50
QgsAbstractLayoutUndoCommand
Definition: qgslayoutundocommand.h:34
QgsLayoutObject::PositionY
@ PositionY
Y position on page.
Definition: qgslayoutobject.h:146
QgsLayoutObject::mLayout
QPointer< QgsLayout > mLayout
Definition: qgslayoutobject.h:335
QgsAbstractPropertyCollection::valueAsBool
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an boolean.
Definition: qgspropertycollection.cpp:88
QgsLayoutItemPage::Orientation
Orientation
Page orientation.
Definition: qgslayoutitempage.h:62
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
QgsLayoutItem::displayName
virtual QString displayName() const
Gets item display name.
Definition: qgslayoutitem.cpp:107
QgsLayoutItemPage::Portrait
@ Portrait
Portrait orientation.
Definition: qgslayoutitempage.h:64
QgsLayoutItem::exportLayerDetails
virtual QgsLayoutItem::ExportLayerDetail exportLayerDetails() const
Returns the details for the specified current export layer.
Definition: qgslayoutitem.cpp:280
QgsLayoutItem::setItemRotation
virtual void setItemRotation(double rotation, bool adjustPosition=true)
Sets the layout item's rotation, in degrees clockwise.
Definition: qgslayoutitem.cpp:1127
QgsLayoutItem::applyDataDefinedSize
QgsLayoutSize applyDataDefinedSize(const QgsLayoutSize &size)
Applies any present data defined size overrides to the specified layout size.
Definition: qgslayoutitem.cpp:1032
QgsLayoutItem::UpperRight
@ UpperRight
Upper right corner of item.
Definition: qgslayoutitem.h:205
QgsLayoutPoint::decodePoint
static QgsLayoutPoint decodePoint(const QString &string)
Decodes a point from a string.
Definition: qgslayoutpoint.cpp:60
QgsLayoutItem::attemptResize
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
Definition: qgslayoutitem.cpp:432
QgsSymbolLayerUtils::decodePenJoinStyle
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
Definition: qgssymbollayerutils.cpp:188
QgsRenderContext::Antialiasing
@ Antialiasing
Use antialiasing while drawing.
Definition: qgsrendercontext.h:78
qgslayoutpagecollection.h
QgsLayoutRenderContext::FlagForceVectorOutput
@ FlagForceVectorOutput
Force output in vector format where possible, even if items require rasterization to keep their corre...
Definition: qgslayoutrendercontext.h:46
QgsLayoutSize
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:40
QgsRenderContext::setExpressionContext
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Definition: qgsrendercontext.h:572
QgsLayoutItem::moveContent
virtual void moveContent(double dx, double dy)
Moves the content of the item, by a specified dx and dy in layout units.
Definition: qgslayoutitem.cpp:953
QgsLayoutItemRenderContext::QgsLayoutItemRenderContext
QgsLayoutItemRenderContext(QgsRenderContext &context, double viewScaleFactor=1.0)
Constructor for QgsLayoutItemRenderContext.
Definition: qgslayoutitem.cpp:39
QgsSymbolLayerUtils::encodePenJoinStyle
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
Definition: qgssymbollayerutils.cpp:173
QgsLayoutObject::Opacity
@ Opacity
Item opacity.
Definition: qgslayoutobject.h:151
QgsLayoutItem::UpperMiddle
@ UpperMiddle
Upper center of item.
Definition: qgslayoutitem.h:204
QgsUnitTypes::LayoutMillimeters
@ LayoutMillimeters
Millimeters.
Definition: qgsunittypes.h:182
QgsPageSize::size
QgsLayoutSize size
Page size.
Definition: qgspagesizeregistry.h:54
QgsLayoutObject::FrameColor
@ FrameColor
Item frame color.
Definition: qgslayoutobject.h:154
QgsLayoutItem::setMoveContentPreviewOffset
virtual void setMoveContentPreviewOffset(double dx, double dy)
Sets temporary offset for the item, by a specified dx and dy in layout units.
Definition: qgslayoutitem.cpp:958
QgsLayoutItem::refreshOpacity
void refreshOpacity(bool updateItem=true)
Refresh item's opacity, considering data defined opacity.
Definition: qgslayoutitem.cpp:1426
QgsRenderContext::painter
QPainter * painter()
Returns the destination QPainter for the render operation.
Definition: qgsrendercontext.h:174
QgsLayoutItem::setItemOpacity
void setItemOpacity(double opacity)
Sets the item's opacity.
Definition: qgslayoutitem.cpp:907
QgsLayoutRenderContext::FlagDebug
@ FlagDebug
Debug/testing mode, items are drawn as solid rectangles.
Definition: qgslayoutrendercontext.h:42
QgsLayoutItem::createCommand
QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id, QUndoCommand *parent=nullptr) override
Creates a new layout undo command with the specified text and parent.
Definition: qgslayoutitem.cpp:829
QgsLayoutRenderContext::FlagAntialiasing
@ FlagAntialiasing
Use antialiasing when drawing items.
Definition: qgslayoutrendercontext.h:44
QgsLayoutItemRegistry::LayoutItem
@ LayoutItem
Base class for items.
Definition: qgslayoutitemregistry.h:308
QgsPropertyCollection::isActive
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
Definition: qgspropertycollection.cpp:258
QgsLayoutPoint
This class provides a method of storing points, consisting of an x and y coordinate,...
Definition: qgslayoutpoint.h:39
Q_NOWARN_DEPRECATED_PUSH
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:751
QgsLayoutItem::QgsLayoutItem
QgsLayoutItem(QgsLayout *layout, bool manageZValue=true)
Constructor for QgsLayoutItem, with the specified parent layout.
Definition: qgslayoutitem.cpp:47
QgsLayoutUtils::scaleFactorFromItemStyle
static double scaleFactorFromItemStyle(const QStyleOptionGraphicsItem *style)
Extracts the scale factor from an item style.
Definition: qgslayoututils.cpp:390
MathUtils::angle
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
QgsLayoutObject::PresetPaperSize
@ PresetPaperSize
Preset paper size for composition.
Definition: qgslayoutobject.h:138
QgsLayoutItem::pagePos
QPointF pagePos() const
Returns the item's position (in layout units) relative to the top left corner of its current page.
Definition: qgslayoutitem.cpp:553
QgsLayoutItem::createExpressionContext
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Definition: qgslayoutitem.cpp:1159
QgsLayoutItem::UpperLeft
@ UpperLeft
Upper left corner of item.
Definition: qgslayoutitem.h:203
qgslayoutmodel.h
QgsLayoutPoint::x
double x() const
Returns x coordinate of point.
Definition: qgslayoutpoint.h:72
QgsLayoutObject::writeObjectPropertiesToElement
bool writeObjectPropertiesToElement(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores object properties within an XML DOM element.
Definition: qgslayoutobject.cpp:160
QgsLayoutUtils::normalizedAngle
static double normalizedAngle(double angle, bool allowNegative=false)
Ensures that an angle (in degrees) is in the range 0 <= angle < 360.
Definition: qgslayoututils.cpp:40
QgsLayoutMeasurement
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
Definition: qgslayoutmeasurement.h:33
QgsLayoutPoint::encodePoint
QString encodePoint() const
Encodes the layout point to a string.
Definition: qgslayoutpoint.cpp:55
QgsLayoutObject::DataDefinedProperty
DataDefinedProperty
Data defined properties for different item types.
Definition: qgslayoutobject.h:132
QgsLayoutObject
Definition: qgslayoutobject.h:39
QgsLayoutItem::locked
bool locked
Definition: qgslayoutitem.h:196
QgsLayoutPoint::units
QgsUnitTypes::LayoutUnit units() const
Returns the units for the point.
Definition: qgslayoutpoint.h:99
QgsAbstractPropertyCollection::valueAsColor
QColor valueAsColor(int key, const QgsExpressionContext &context, const QColor &defaultColor=QColor(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a color.
Definition: qgspropertycollection.cpp:54
QgsRenderContext::flags
Flags flags() const
Returns combination of flags used for rendering.
Definition: qgsrendercontext.cpp:160
QgsLayoutItem::LowerMiddle
@ LowerMiddle
Lower center of item.
Definition: qgslayoutitem.h:210
QgsLayoutItem::fixedSize
virtual QgsLayoutSize fixedSize() const
Returns the fixed size of the item, if applicable, or an empty size if item can be freely resized.
Definition: qgslayoutitem.h:549
QgsLayoutItem::refreshItemRotation
void refreshItemRotation(QPointF *origin=nullptr)
Refreshes an item's rotation by rechecking it against any possible overrides such as data defined rot...
Definition: qgslayoutitem.cpp:1387
QgsLayoutObject::ItemWidth
@ ItemWidth
Width of item.
Definition: qgslayoutobject.h:147
QgsLayoutMeasurement::decodeMeasurement
static QgsLayoutMeasurement decodeMeasurement(const QString &string)
Decodes a measurement from a string.
Definition: qgslayoutmeasurement.cpp:33
QgsLayoutUtils::decodePaperOrientation
static QgsLayoutItemPage::Orientation decodePaperOrientation(const QString &string, bool &ok)
Decodes a string representing a paper orientation and returns the decoded orientation.
Definition: qgslayoututils.cpp:373