34 #include <QStyleOptionGraphicsItem> 37 #define CACHE_SIZE_LIMIT 5000 40 : mRenderContext( context )
41 , mViewScaleFactor( viewScaleFactor )
49 , QGraphicsRectItem( nullptr )
50 , mUuid( QUuid::createUuid().toString() )
55 setFlags( flags() | QGraphicsItem::ItemUsesExtendedStyleOption | QGraphicsItem::ItemIsSelectable );
57 setCacheMode( QGraphicsItem::DeviceCoordinateCache );
61 mItemPosition =
QgsLayoutPoint( scenePos().x(), scenePos().y(), initialUnits );
62 mItemSize =
QgsLayoutSize( rect().width(), rect().height(), initialUnits );
68 initConnectionsToLayout();
73 mLayoutManagesZValue =
true;
74 mLayout->itemsModel()->addItemAtTop(
this );
78 mLayoutManagesZValue =
false;
91 setGraphicsEffect( mEffect.get() );
101 if (
mLayout && mLayoutManagesZValue )
103 mLayout->itemsModel()->removeItem(
this );
110 if ( !
id().isEmpty() )
118 return tr(
"<%1>" ).arg( metadata->visibleName() );
121 return tr(
"<item>" );
141 if ( !shouldBlockUndoCommands() )
142 mLayout->undoStack()->beginCommand(
this, tr(
"Change Item ID" ) );
146 if ( !shouldBlockUndoCommands() )
147 mLayout->undoStack()->endCommand();
154 mLayout->itemsModel()->updateItemDisplayName(
this );
162 QGraphicsRectItem::setSelected( selected );
166 mLayout->itemsModel()->updateItemSelectStatus(
this );
172 if ( visible == isVisible() )
178 std::unique_ptr< QgsAbstractLayoutUndoCommand > command;
179 if ( !shouldBlockUndoCommands() )
181 command.reset(
createCommand( visible ? tr(
"Show Item" ) : tr(
"Hide Item" ), 0 ) );
182 command->saveBeforeState();
185 QGraphicsItem::setVisible( visible );
189 command->saveAfterState();
190 mLayout->undoStack()->push( command.release() );
196 mLayout->itemsModel()->updateItemVisibility(
this );
202 if ( locked == mIsLocked )
207 if ( !shouldBlockUndoCommands() )
208 mLayout->undoStack()->beginCommand(
this, locked ? tr(
"Lock Item" ) : tr(
"Unlock Item" ) );
212 if ( !shouldBlockUndoCommands() )
213 mLayout->undoStack()->endCommand();
218 mLayout->itemsModel()->updateItemLockStatus(
this );
227 return !mParentGroupUuid.isEmpty() &&
mLayout &&
static_cast< bool >(
mLayout->itemByUuid( mParentGroupUuid ) );
232 if ( !
mLayout || mParentGroupUuid.isEmpty() )
241 mParentGroupUuid.clear();
243 mParentGroupUuid = group->
uuid();
244 setFlag( QGraphicsItem::ItemIsSelectable, !static_cast< bool>( group ) );
256 if ( shouldDrawDebugRect() )
262 bool previewRender = !
mLayout ||
mLayout->renderContext().isPreviewRender();
264 bool useImageCache =
false;
267 if ( useImageCache || forceRasterOutput )
269 double widthInPixels = 0;
270 double heightInPixels = 0;
280 widthInPixels = boundingRect().width() * layoutUnitsToPixels;
281 heightInPixels = boundingRect().height() * layoutUnitsToPixels;
288 if ( widthInPixels > heightInPixels )
292 heightInPixels /= scale;
298 widthInPixels /= scale;
300 destinationDpi = destinationDpi / scale;
303 if ( previewRender && !mItemCachedImage.isNull() &&
qgsDoubleNear( mItemCacheDpi, destinationDpi ) )
308 preparePainter( painter );
309 double cacheScale = destinationDpi / mItemCacheDpi;
311 painter->drawImage( boundingRect().x() * context.
scaleFactor() / cacheScale,
312 boundingRect().y() * context.
scaleFactor() / cacheScale, mItemCachedImage );
318 QImage image = QImage( widthInPixels, heightInPixels, QImage::Format_ARGB32 );
319 image.fill( Qt::transparent );
320 image.setDotsPerMeterX( 1000 * destinationDpi * 25.4 );
321 image.setDotsPerMeterY( 1000 * destinationDpi * 25.4 );
322 QPainter p( &image );
324 preparePainter( &p );
336 draw( itemRenderContext );
347 painter->drawImage( boundingRect().x() * context.
scaleFactor(),
348 boundingRect().y() * context.
scaleFactor(), image );
353 mItemCacheDpi = destinationDpi;
354 mItemCachedImage = image;
362 preparePainter( painter );
371 draw( itemRenderContext );
382 if ( point == mReferencePoint )
387 mReferencePoint = point;
390 updateStoredItemPosition();
414 QSizeF targetSizeLayoutUnits =
mLayout->convertToLayoutUnits( evaluatedSize );
415 QSizeF actualSizeLayoutUnits = applyMinimumSize( targetSizeLayoutUnits );
416 actualSizeLayoutUnits = applyFixedSize( actualSizeLayoutUnits );
419 if ( actualSizeLayoutUnits == rect().size() )
425 mItemSize = actualSizeTargetUnits;
427 setRect( 0, 0, actualSizeLayoutUnits.width(), actualSizeLayoutUnits.height() );
444 point =
mLayout->pageCollection()->pagePositionToAbsolute( page, p );
451 point.
setX( point.
x() + bleed );
452 point.
setY( point.
y() + bleed );
456 if ( !useReferencePoint )
461 evaluatedPoint = applyDataDefinedPosition( evaluatedPoint );
462 QPointF evaluatedPointLayoutUnits =
mLayout->convertToLayoutUnits( evaluatedPoint );
464 if ( topLeftPointLayoutUnits == scenePos() && point.
units() == mItemPosition.
units() )
471 mItemPosition = referencePointTargetUnits;
472 setScenePos( topLeftPointLayoutUnits );
478 QPointF newPos = rect.topLeft();
480 blockSignals(
true );
488 blockSignals(
false );
496 moveBy( deltaX, deltaY );
502 itemPos.
setX( itemPos.
x() + deltaPos.
x() );
503 itemPos.
setY( itemPos.
y() + deltaPos.
y() );
512 return mLayout->pageCollection()->pageNumberForPoint( pos() );
527 p.ry() -= pageItem->pos().y();
537 return mLayout->convertFromLayoutUnits( p, mItemPosition.
units() );
540 void QgsLayoutItem::setScenePos(
const QPointF destinationPos )
546 setPos( pos() + ( destinationPos - scenePos() ) + parentItem()->scenePos() );
548 setPos( pos() + ( destinationPos - scenePos() ) );
551 bool QgsLayoutItem::shouldBlockUndoCommands()
const 565 return !mEvaluatedExcludeFromExports;
570 return mItemRotation;
575 QDomElement element = doc.createElement( QStringLiteral(
"LayoutItem" ) );
576 element.setAttribute( QStringLiteral(
"type" ), QString::number(
type() ) );
578 element.setAttribute( QStringLiteral(
"uuid" ), mUuid );
579 element.setAttribute( QStringLiteral(
"templateUuid" ), mUuid );
580 element.setAttribute( QStringLiteral(
"id" ), mId );
581 element.setAttribute( QStringLiteral(
"referencePoint" ), QString::number( static_cast< int >( mReferencePoint ) ) );
582 element.setAttribute( QStringLiteral(
"position" ), mItemPosition.
encodePoint() );
584 element.setAttribute( QStringLiteral(
"size" ), mItemSize.
encodeSize() );
585 element.setAttribute( QStringLiteral(
"itemRotation" ), QString::number( mItemRotation ) );
586 element.setAttribute( QStringLiteral(
"groupUuid" ), mParentGroupUuid );
588 element.setAttribute( QStringLiteral(
"zValue" ), QString::number( zValue() ) );
589 element.setAttribute( QStringLiteral(
"visibility" ), isVisible() );
593 element.setAttribute( QStringLiteral(
"positionLock" ), QStringLiteral(
"true" ) );
597 element.setAttribute( QStringLiteral(
"positionLock" ), QStringLiteral(
"false" ) );
603 element.setAttribute( QStringLiteral(
"frame" ), QStringLiteral(
"true" ) );
607 element.setAttribute( QStringLiteral(
"frame" ), QStringLiteral(
"false" ) );
613 element.setAttribute( QStringLiteral(
"background" ), QStringLiteral(
"true" ) );
617 element.setAttribute( QStringLiteral(
"background" ), QStringLiteral(
"false" ) );
621 QDomElement frameColorElem = doc.createElement( QStringLiteral(
"FrameColor" ) );
622 frameColorElem.setAttribute( QStringLiteral(
"red" ), QString::number( mFrameColor.red() ) );
623 frameColorElem.setAttribute( QStringLiteral(
"green" ), QString::number( mFrameColor.green() ) );
624 frameColorElem.setAttribute( QStringLiteral(
"blue" ), QString::number( mFrameColor.blue() ) );
625 frameColorElem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mFrameColor.alpha() ) );
626 element.appendChild( frameColorElem );
627 element.setAttribute( QStringLiteral(
"outlineWidthM" ), mFrameWidth.
encodeMeasurement() );
631 QDomElement bgColorElem = doc.createElement( QStringLiteral(
"BackgroundColor" ) );
632 bgColorElem.setAttribute( QStringLiteral(
"red" ), QString::number( mBackgroundColor.red() ) );
633 bgColorElem.setAttribute( QStringLiteral(
"green" ), QString::number( mBackgroundColor.green() ) );
634 bgColorElem.setAttribute( QStringLiteral(
"blue" ), QString::number( mBackgroundColor.blue() ) );
635 bgColorElem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mBackgroundColor.alpha() ) );
636 element.appendChild( bgColorElem );
642 element.setAttribute( QStringLiteral(
"opacity" ), QString::number( mOpacity ) );
644 element.setAttribute( QStringLiteral(
"excludeFromExports" ), mExcludeFromExports );
649 parentElement.appendChild( element );
656 if ( element.nodeName() != QStringLiteral(
"LayoutItem" ) )
663 mBlockUndoCommands =
true;
664 mUuid = element.attribute( QStringLiteral(
"uuid" ), QUuid::createUuid().toString() );
665 setId( element.attribute( QStringLiteral(
"id" ) ) );
666 mReferencePoint =
static_cast< ReferencePoint >( element.attribute( QStringLiteral(
"referencePoint" ) ).toInt() );
667 setItemRotation( element.attribute( QStringLiteral(
"itemRotation" ), QStringLiteral(
"0" ) ).toDouble() );
671 mParentGroupUuid = element.attribute( QStringLiteral(
"groupUuid" ) );
672 if ( !mParentGroupUuid.isEmpty() )
676 group->addItem(
this );
679 mTemplateUuid = element.attribute( QStringLiteral(
"templateUuid" ) );
682 QString positionLock = element.attribute( QStringLiteral(
"positionLock" ) );
683 if ( positionLock.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
692 setVisibility( element.attribute( QStringLiteral(
"visibility" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
693 setZValue( element.attribute( QStringLiteral(
"zValue" ) ).toDouble() );
696 QString frame = element.attribute( QStringLiteral(
"frame" ) );
697 if ( frame.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
707 QString background = element.attribute( QStringLiteral(
"background" ) );
708 if ( background.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
720 QDomNodeList frameColorList = element.elementsByTagName( QStringLiteral(
"FrameColor" ) );
721 if ( !frameColorList.isEmpty() )
723 QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
725 bool greenOk =
false;
727 bool alphaOk =
false;
728 int penRed, penGreen, penBlue, penAlpha;
730 penRed = frameColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
731 penGreen = frameColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
732 penBlue = frameColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
733 penAlpha = frameColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
735 if ( redOk && greenOk && blueOk && alphaOk )
737 mFrameColor = QColor( penRed, penGreen, penBlue, penAlpha );
743 QDomNodeList bgColorList = element.elementsByTagName( QStringLiteral(
"BackgroundColor" ) );
744 if ( !bgColorList.isEmpty() )
746 QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
747 bool redOk, greenOk, blueOk, alphaOk;
748 int bgRed, bgGreen, bgBlue, bgAlpha;
749 bgRed = bgColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
750 bgGreen = bgColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
751 bgBlue = bgColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
752 bgAlpha = bgColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
753 if ( redOk && greenOk && blueOk && alphaOk )
755 mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
756 setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
766 if ( element.hasAttribute( QStringLiteral(
"opacity" ) ) )
768 setItemOpacity( element.attribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1" ) ).toDouble() );
772 setItemOpacity( 1.0 - element.attribute( QStringLiteral(
"transparency" ), QStringLiteral(
"0" ) ).toInt() / 100.0 );
775 mExcludeFromExports = element.attribute( QStringLiteral(
"excludeFromExports" ), QStringLiteral(
"0" ) ).toInt();
776 mEvaluatedExcludeFromExports = mExcludeFromExports;
780 mBlockUndoCommands =
false;
793 return new QgsLayoutItemUndoCommand(
this, text,
id, parent );
798 if ( drawFrame == mFrame )
811 if ( mFrameColor == color )
824 if ( mFrameWidth == width )
836 if ( mFrameJoinStyle == style )
841 mFrameJoinStyle = style;
843 QPen itemPen = pen();
844 itemPen.setJoinStyle( mFrameJoinStyle );
857 mBackgroundColor = color;
873 if ( !mItemCachedImage.isNull() )
879 return mExcludeFromExports;
884 mExcludeFromExports = exclude;
890 return itemFlags() & Flag::FlagOverridesPaint ? false : mEvaluatedOpacity < 1.0;
896 blendMode() != QPainter::CompositionMode_SourceOver;
906 return pen().widthF() / 2.0;
912 return rect().adjusted( -frameBleed, -frameBleed, frameBleed, frameBleed );
935 mLayout->undoStack()->beginCommand(
this, commandText, command );
941 mLayout->undoStack()->endCommand();
947 mLayout->undoStack()->cancelCommand();
963 void QgsLayoutItem::applyDataDefinedOrientation(
double &width,
double &height,
const QgsExpressionContext &context )
967 if ( ok && !orientationString.isEmpty() )
972 double heightD = 0.0, widthD = 0.0;
973 switch ( orientation )
977 heightD = std::max( height, width );
978 widthD = std::min( height, width );
983 heightD = std::min( height, width );
984 widthD = std::max( height, width );
1013 double evaluatedWidth = size.
width();
1014 double evaluatedHeight = size.
height();
1018 evaluatedWidth = convertedSize.
width();
1019 evaluatedHeight = convertedSize.
height();
1027 applyDataDefinedOrientation( evaluatedWidth, evaluatedHeight, context );
1032 double QgsLayoutItem::applyDataDefinedRotation(
const double rotation )
1041 return evaluatedRotation;
1081 bool exclude = mExcludeFromExports;
1091 if ( angle >= 360.0 || angle <= -360.0 )
1093 angle = std::fmod( angle, 360.0 );
1098 double rotationRequired = angle - rotation();
1101 mItemRotation =
angle;
1104 void QgsLayoutItem::updateStoredItemPosition()
1107 mItemPosition =
mLayout->convertFromLayoutUnits( layoutPosReferencePoint, mItemPosition.
units() );
1112 double evaluatedAngle = angle + rotation();
1114 mItemRotation = evaluatedAngle;
1116 QPointF itemTransformOrigin = mapFromScene( transformOrigin );
1139 if ( !mItemCachedImage.isNull() )
1141 mItemCachedImage = QImage();
1160 painter->setRenderHint( QPainter::Antialiasing,
false );
1161 painter->setPen( Qt::NoPen );
1162 painter->setBrush( QColor( 100, 255, 100, 200 ) );
1163 painter->drawRect( rect() );
1169 if ( !mFrame || !context.
painter() )
1172 QPainter *p = context.
painter();
1175 p->setBrush( Qt::NoBrush );
1176 p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
1182 if ( !mBackground || !context.
painter() )
1185 QPainter *p = context.
painter();
1187 p->setBrush( brush() );
1188 p->setPen( Qt::NoPen );
1189 p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
1201 mMinimumSize = size;
1220 QPointF QgsLayoutItem::itemPositionAtReferencePoint(
const ReferencePoint reference,
const QSizeF size )
const 1222 switch ( reference )
1225 return QPointF( size.width() / 2.0, 0 );
1227 return QPointF( size.width(), 0 );
1229 return QPointF( 0, size.height() / 2.0 );
1231 return QPointF( size.width() / 2.0, size.height() / 2.0 );
1233 return QPointF( size.width(), size.height() / 2.0 );
1235 return QPointF( 0, size.height() );
1237 return QPointF( size.width() / 2.0, size.height() );
1239 return QPointF( size.width(), size.height() );
1241 return QPointF( 0, 0 );
1244 return QPointF( 0, 0 );
1249 QPointF itemPosition = mapFromScene( position );
1250 QPointF adjustedPointInsideItem = itemPosition - itemPositionAtReferencePoint( reference, size );
1251 return mapToScene( adjustedPointInsideItem );
1256 QPointF pointWithinItem = itemPositionAtReferencePoint( reference, rect().size() );
1257 return mapToScene( pointWithinItem );
1262 QPointF topLeft =
mLayout->convertToLayoutUnits( point );
1263 QPointF refPoint = topLeft + itemPositionAtReferencePoint( mReferencePoint, rect().size() );
1264 return mLayout->convertFromLayoutUnits( refPoint, point.
units() );
1278 void QgsLayoutItem::initConnectionsToLayout()
1285 void QgsLayoutItem::preparePainter( QPainter *painter )
1287 if ( !painter || !painter->device() )
1292 painter->setRenderHint( QPainter::Antialiasing, shouldDrawAntialiased() );
1295 bool QgsLayoutItem::shouldDrawAntialiased()
const 1304 bool QgsLayoutItem::shouldDrawDebugRect()
const 1309 QSizeF QgsLayoutItem::applyMinimumSize(
const QSizeF targetSize )
1316 return targetSize.expandedTo( minimumSizeLayoutUnits );
1319 QSizeF QgsLayoutItem::applyFixedSize(
const QSizeF targetSize )
1326 QSizeF size = targetSize;
1327 QSizeF fixedSizeLayoutUnits =
mLayout->convertToLayoutUnits(
fixedSize() );
1328 if ( fixedSizeLayoutUnits.width() > 0 )
1329 size.setWidth( fixedSizeLayoutUnits.width() );
1330 if ( fixedSizeLayoutUnits.height() > 0 )
1331 size.setHeight( fixedSizeLayoutUnits.height() );
1338 double r = mItemRotation;
1350 if ( !transformPoint.isNull() )
1354 QLineF refLine = QLineF( mapToScene( transformPoint ), mapToScene( QPointF( 0, 0 ) ) );
1356 refLine.setAngle( refLine.angle() - r + rotation() );
1358 QPointF rotatedReferencePoint = refLine.p2();
1359 setPos( rotatedReferencePoint );
1362 setTransformOriginPoint( 0, 0 );
1363 QGraphicsItem::setRotation( r );
1366 updateStoredItemPosition();
1381 mEvaluatedOpacity = opacity / 100.0;
1387 setOpacity( mEvaluatedOpacity );
1400 setPen( Qt::NoPen );
1410 itemPen = QPen( frameColor );
1414 itemPen = QPen( mFrameColor );
1416 itemPen.setJoinStyle( mFrameJoinStyle );
1419 itemPen.setWidthF(
mLayout->convertToLayoutUnits( mFrameWidth ) );
1421 itemPen.setWidthF( mFrameWidth.
length() );
1438 setBrush( QBrush( backgroundColor, Qt::SolidPattern ) );
1442 setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
1452 QPainter::CompositionMode
blendMode = mBlendMode;
1457 if ( ok && !blendStr.isEmpty() )
1459 QString blendstr = blendStr.trimmed();
1461 blendMode = blendModeD;
1465 mEffect->setCompositionMode( blendMode );
static QgsLayoutSize decodeSize(const QString &string)
Decodes a size from a string.
The class is used as a container of context for various read/write operations on other objects...
QgsLayoutPoint positionWithUnits() const
Returns the item's current position, including units.
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...
static double scaleFactorFromItemStyle(const QStyleOptionGraphicsItem *style)
Extracts the scale factor from an item style.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
static void multiplyOpacity(QImage &image, double factor)
Multiplies opacity of image pixel values by a factor.
QString encodePoint() const
Encodes the layout point to a string.
QgsLayoutItemRenderContext(QgsRenderContext &context, double viewScaleFactor=1.0)
Constructor for QgsLayoutItemRenderContext.
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the objects' current state.
void beginCommand(const QString &commandText, UndoCommand command=UndoNone)
Starts new undo command for this item.
QgsLayoutSize applyDataDefinedSize(const QgsLayoutSize &size)
Applies any present data defined size overrides to the specified layout size.
int type() const override
Returns a unique graphics item type identifier.
virtual bool containsAdvancedEffects() const
Returns true if the item contains contents with blend modes or transparency effects which can only be...
Lower left corner of item.
bool readObjectPropertiesFromElement(const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets object properties from a DOM element.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double...
void refreshBackgroundColor(bool updateItem=true)
Refresh item's background color, considering data defined colors.
Base class for commands to undo/redo layout and layout object changes.
void setY(const double y)
Sets y coordinate of point.
virtual QRectF rectWithFrame() const
Returns the item's rectangular bounds, including any bleed caused by the item's frame.
UndoCommand
Layout item undo commands, used for collapsing undo commands.
virtual double estimatedFrameBleed() const
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.
void refreshItemPosition()
Refreshes an item's position by rechecking it against any possible overrides such as data defined pos...
QgsUnitTypes::LayoutUnit units() const
Returns the native units for the layout.
virtual void setMinimumSize(const QgsLayoutSize &size)
Sets the minimum allowed size for the layout item.
Exclude item from exports.
QgsLayoutItem(QgsLayout *layout, bool manageZValue=true)
Constructor for QgsLayoutItem, with the specified parent layout.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QPointF positionAtReferencePoint(ReferencePoint reference) const
Returns the current position (in layout units) of a reference point for the item. ...
bool isGroupMember() const
Returns true if the item is part of a QgsLayoutItemGroup group.
bool frameEnabled() const
Returns true if the item includes a frame.
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
A container for grouping several QgsLayoutItems.
void flagsChanged(QgsLayoutRenderContext::Flags flags)
Emitted whenever the context's flags change.
virtual void setSelected(bool selected)
Sets whether the item should be selected.
virtual void setFrameStrokeWidth(QgsLayoutMeasurement width)
Sets the frame stroke width.
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
QgsLayoutPoint pagePositionWithUnits() const
Returns the item's position (in item units) relative to the top left corner of its current page...
virtual QgsLayoutSize fixedSize() const
Returns the fixed size of the item, if applicable, or an empty size if item can be freely resized...
void attemptMoveBy(double deltaX, double deltaY)
Attempts to shift the item's position by a specified deltaX and deltaY, in layout units...
void setFrameStrokeColor(const QColor &color)
Sets the frame stroke color.
Lower right corner of item.
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...
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)
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...
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
void cancelCommand()
Cancels the current item command and discards it.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
This class provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
ReferencePoint
Fixed position reference point.
static QgsExpressionContextScope * layoutItemScope(const QgsLayoutItem *item)
Creates a new scope which contains variables and functions relating to a QgsLayoutItem.
void refreshItemSize()
Refreshes an item's size by rechecking it against any possible item fixed or minimum sizes...
void frameChanged()
Emitted if the item's frame style changes.
void sizePositionChanged()
Emitted when the item's size or position changes.
bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores the item state in a DOM element.
void setX(const double x)
Sets the x coordinate of point.
virtual void drawFrame(QgsRenderContext &context)
Draws the frame around the item.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the point.
A QGraphicsEffect subclass used for rendering layout items onto a scene with custom composition modes...
virtual void invalidateCache()
Forces a deferred update of any cached image the item uses.
static QgsLayoutItemRegistry * layoutItemRegistry()
Returns the application's layout item registry, used for layout item types.
virtual void setId(const QString &id)
Set the item's id name.
void setExcludeFromExports(bool exclude)
Sets whether the item should be excluded from layout exports and prints.
QgsPropertyCollection mDataDefinedProperties
virtual QgsLayoutSize minimumSize() const
Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely r...
void setLocked(bool locked)
Sets whether the item is locked, preventing mouse interactions with the item.
virtual void setFixedSize(const QgsLayoutSize &size)
Sets a fixed size for the layout item, which prevents it from being freely resized.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets item state from a DOM element.
Upper right corner of item.
void endCommand()
Completes the current item command and push it onto the layout's undo stack.
void setFrameJoinStyle(Qt::PenJoinStyle style)
Sets the join style used when drawing the item's frame.
virtual void drawBackground(QgsRenderContext &context)
Draws the background for the item.
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.
double itemRotation() const
Returns the current rotation for the item, in degrees clockwise.
void setBlendMode(QPainter::CompositionMode mode)
Sets the item's composition blending mode.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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...
QColor backgroundColor() const
Returns the background color for this item.
double y() const
Returns y coordinate of point.
virtual void rotateItem(double angle, QPointF transformOrigin)
Rotates the item by a specified angle in degrees clockwise around a specified reference point...
virtual void cleanup()
Called just before a batch of items are deleted, allowing them to run cleanup tasks.
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
QPointer< QgsLayout > mLayout
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
Minimum z value for items.
virtual void setItemRotation(double rotation, bool adjustPosition=true)
Sets the layout item's rotation, in degrees clockwise.
double x() const
Returns x coordinate of point.
int page() const
Returns the page the item is currently on, with the first page returning 0.
double itemOpacity() const
Returns the item's opacity.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the size.
QString id() const
Returns the item's ID name.
static QPainter::CompositionMode decodeBlendMode(const QString &s)
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...
Upper left corner of item.
QPainter::CompositionMode blendMode() const
Returns the item's composition blending mode.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
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...
void setHeight(const double height)
Sets the height for the size.
virtual Flags itemFlags() const
Returns the item's flags, which indicate how the item behaves.
virtual void setVisibility(bool visible)
Sets whether the item is visible.
QPointF toQPointF() const
Converts the layout point to a QPointF.
void setParentGroup(QgsLayoutItemGroup *group)
Sets the item's parent group.
virtual void drawDebugRect(QPainter *painter)
Draws a debugging rectangle of the item's current bounds within the specified painter.
virtual void redraw()
Triggers a redraw (update) of the item.
Use antialiasing when drawing items.
bool readXml(const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets the item state from a DOM element.
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
Contains settings and helpers relating to a render of a QgsLayoutItem.
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
static QgsLayoutMeasurement decodeMeasurement(const QString &string)
Decodes a measurement from a string.
QPointF pagePos() const
Returns the item's position (in layout units) relative to the top left corner of its current page...
virtual QString displayName() const
Gets item display name.
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an boolean...
bool writeObjectPropertiesToElement(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores object properties within an XML DOM element.
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...
void lockChanged()
Emitted if the item's lock status changes.
Contains information about the context of a rendering operation.
Force output in vector format where possible, even if items require rasterization to keep their corre...
double length() const
Returns the length of the measurement.
QPainter * painter()
Returns the destination QPainter for the render operation.
static QgsPageSizeRegistry * pageSizeRegistry()
Returns the application's page size registry, used for managing layout page sizes.
~QgsLayoutItem() override
A named page size for layouts.
Enable advanced effects such as blend modes.
virtual void setMoveContentPreviewOffset(double dx, double dy)
Sets temporary offset for the item, by a specified dx and dy in layout units.
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
virtual void moveContent(double dx, double dy)
Moves the content of the item, by a specified dx and dy in layout units.
Preset paper size for composition.
virtual void attemptMove(const QgsLayoutPoint &point, bool useReferencePoint=true, bool includesFrame=false, int page=-1)
Attempts to move the item to a specified point.
void setReferencePoint(ReferencePoint point)
Sets the reference point for positioning of the layout item.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
virtual QString uuid() const
Returns the item identification string.
Orientation
Page orientiation.
void refreshFrame(bool updateItem=true)
Refresh item's frame, considering data defined colors and frame size.
virtual QSizeF applyItemSizeConstraint(QSizeF targetSize)
Applies any item-specific size constraint handling to a given targetSize in layout units...
void refreshOpacity(bool updateItem=true)
Refresh item's opacity, considering data defined opacity.
virtual void zoomContent(double factor, QPointF point)
Zooms content of item.
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
bool excludeFromExports() const
Returns whether the item should be excluded from layout exports and prints.
virtual void setFrameEnabled(bool drawFrame)
Sets whether this item has a frame drawn around it or not.
A base class for objects which belong to a layout.
Debug/testing mode, items are drawn as solid rectangles.
LayoutUnit
Layout measurement units.
virtual void draw(QgsLayoutItemRenderContext &context)=0
Draws the item's contents using the specified item render context.
Item overrides the default layout item painting method.
void refreshBlendMode()
Refresh item's blend mode, considering data defined blend mode.
static double normalizedAngle(double angle, bool allowNegative=false)
Ensures that an angle (in degrees) is in the range 0 <= angle < 360.
virtual void refresh()
Refreshes the object, causing a recalculation of any property overrides.
QString encodeMeasurement() const
Encodes the layout measurement to a string.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
void refreshItemRotation(QPointF *origin=nullptr)
Refreshes an item's rotation by rechecking it against any possible overrides such as data defined rot...
void rotationChanged(double newRotation)
Emitted on item rotation change.
void changed()
Emitted when the object's properties change.
QgsLayoutSize size
Page size.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
double height() const
Returns the height of the size.
QgsLayoutItemGroup * parentGroup() const
Returns the item's parent group, if the item is part of a QgsLayoutItemGroup group.
DataDefinedProperty
Data defined properties for different item types.
static QgsLayoutItemPage::Orientation decodePaperOrientation(const QString &string, bool &ok)
Decodes a string representing a paper orientation and returns the decoded orientation.
void refresh() override
Refreshes the item, causing a recalculation of any property overrides and recalculation of its positi...
QString encodeSize() const
Encodes the layout size to a string.
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
void setItemOpacity(double opacity)
Sets the item's opacity.
static QgsLayoutPoint decodePoint(const QString &string)
Decodes a point from a string.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id, QUndoCommand *parent=nullptr) override
Creates a new layout undo command with the specified text and parent.
void setWidth(const double width)
Sets the width for the size.
void setBackgroundColor(const QColor &color)
Sets the background color for this item.
Item representing the paper in a layout.
double width() const
Returns the width of the size.