31 #include <QStyleOptionGraphicsItem> 34 #define CACHE_SIZE_LIMIT 5000 37 : mRenderContext( context )
38 , mViewScaleFactor( viewScaleFactor )
46 , QGraphicsRectItem( nullptr )
47 , mUuid( QUuid::createUuid().toString() )
52 setFlags( flags() | QGraphicsItem::ItemUsesExtendedStyleOption | QGraphicsItem::ItemIsSelectable );
54 setCacheMode( QGraphicsItem::DeviceCoordinateCache );
58 mItemPosition =
QgsLayoutPoint( scenePos().x(), scenePos().y(), initialUnits );
59 mItemSize =
QgsLayoutSize( rect().width(), rect().height(), initialUnits );
65 initConnectionsToLayout();
70 mLayoutManagesZValue =
true;
71 mLayout->itemsModel()->addItemAtTop(
this );
75 mLayoutManagesZValue =
false;
88 setGraphicsEffect( mEffect.get() );
98 if (
mLayout && mLayoutManagesZValue )
100 mLayout->itemsModel()->removeItem(
this );
107 if ( !
id().isEmpty() )
115 return tr(
"<%1>" ).arg( metadata->visibleName() );
118 return tr(
"<item>" );
133 if ( !shouldBlockUndoCommands() )
134 mLayout->undoStack()->beginCommand(
this, tr(
"Change Item ID" ) );
138 if ( !shouldBlockUndoCommands() )
139 mLayout->undoStack()->endCommand();
146 mLayout->itemsModel()->updateItemDisplayName(
this );
154 QGraphicsRectItem::setSelected( selected );
158 mLayout->itemsModel()->updateItemSelectStatus(
this );
164 if ( visible == isVisible() )
170 std::unique_ptr< QgsAbstractLayoutUndoCommand > command;
171 if ( !shouldBlockUndoCommands() )
173 command.reset(
createCommand( visible ? tr(
"Show Item" ) : tr(
"Hide Item" ), 0 ) );
174 command->saveBeforeState();
177 QGraphicsItem::setVisible( visible );
181 command->saveAfterState();
182 mLayout->undoStack()->push( command.release() );
188 mLayout->itemsModel()->updateItemVisibility(
this );
194 if ( locked == mIsLocked )
199 if ( !shouldBlockUndoCommands() )
200 mLayout->undoStack()->beginCommand(
this, locked ? tr(
"Lock Item" ) : tr(
"Unlock Item" ) );
204 if ( !shouldBlockUndoCommands() )
205 mLayout->undoStack()->endCommand();
210 mLayout->itemsModel()->updateItemLockStatus(
this );
219 return !mParentGroupUuid.isEmpty() &&
mLayout &&
static_cast< bool >(
mLayout->itemByUuid( mParentGroupUuid ) );
224 if ( !
mLayout || mParentGroupUuid.isEmpty() )
233 mParentGroupUuid.clear();
235 mParentGroupUuid = group->
uuid();
236 setFlag( QGraphicsItem::ItemIsSelectable, !static_cast< bool>( group ) );
248 if ( shouldDrawDebugRect() )
254 bool previewRender = !
mLayout ||
mLayout->renderContext().isPreviewRender();
256 bool useImageCache =
false;
259 if ( useImageCache || forceRasterOutput )
261 double widthInPixels = 0;
262 double heightInPixels = 0;
272 widthInPixels = boundingRect().width() * layoutUnitsToPixels;
273 heightInPixels = boundingRect().height() * layoutUnitsToPixels;
280 if ( widthInPixels > heightInPixels )
284 heightInPixels /= scale;
290 widthInPixels /= scale;
292 destinationDpi = destinationDpi / scale;
295 if ( previewRender && !mItemCachedImage.isNull() &&
qgsDoubleNear( mItemCacheDpi, destinationDpi ) )
300 preparePainter( painter );
301 double cacheScale = destinationDpi / mItemCacheDpi;
303 painter->drawImage( boundingRect().x() * context.
scaleFactor() / cacheScale,
304 boundingRect().y() * context.
scaleFactor() / cacheScale, mItemCachedImage );
310 QImage image = QImage( widthInPixels, heightInPixels, QImage::Format_ARGB32 );
311 image.fill( Qt::transparent );
312 image.setDotsPerMeterX( 1000 * destinationDpi * 25.4 );
313 image.setDotsPerMeterY( 1000 * destinationDpi * 25.4 );
314 QPainter p( &image );
316 preparePainter( &p );
325 draw( itemRenderContext );
332 painter->drawImage( boundingRect().x() * context.
scaleFactor(),
333 boundingRect().y() * context.
scaleFactor(), image );
338 mItemCacheDpi = destinationDpi;
339 mItemCachedImage = image;
347 preparePainter( painter );
356 draw( itemRenderContext );
367 if ( point == mReferencePoint )
372 mReferencePoint = point;
375 updateStoredItemPosition();
399 QSizeF targetSizeLayoutUnits =
mLayout->convertToLayoutUnits( evaluatedSize );
400 QSizeF actualSizeLayoutUnits = applyMinimumSize( targetSizeLayoutUnits );
401 actualSizeLayoutUnits = applyFixedSize( actualSizeLayoutUnits );
404 if ( actualSizeLayoutUnits == rect().size() )
410 mItemSize = actualSizeTargetUnits;
412 setRect( 0, 0, actualSizeLayoutUnits.width(), actualSizeLayoutUnits.height() );
429 point =
mLayout->pageCollection()->pagePositionToAbsolute( page, p );
436 point.
setX( point.
x() + bleed );
437 point.
setY( point.
y() + bleed );
441 if ( !useReferencePoint )
446 evaluatedPoint = applyDataDefinedPosition( evaluatedPoint );
447 QPointF evaluatedPointLayoutUnits =
mLayout->convertToLayoutUnits( evaluatedPoint );
449 if ( topLeftPointLayoutUnits == scenePos() && point.
units() == mItemPosition.
units() )
456 mItemPosition = referencePointTargetUnits;
457 setScenePos( topLeftPointLayoutUnits );
463 QPointF newPos = rect.topLeft();
465 blockSignals(
true );
473 blockSignals(
false );
481 moveBy( deltaX, deltaY );
487 itemPos.
setX( itemPos.
x() + deltaPos.
x() );
488 itemPos.
setY( itemPos.
y() + deltaPos.
y() );
497 return mLayout->pageCollection()->pageNumberForPoint( pos() );
512 p.ry() -= pageItem->pos().y();
522 return mLayout->convertFromLayoutUnits( p, mItemPosition.
units() );
525 void QgsLayoutItem::setScenePos(
const QPointF &destinationPos )
531 setPos( pos() + ( destinationPos - scenePos() ) + parentItem()->scenePos() );
533 setPos( pos() + ( destinationPos - scenePos() ) );
536 bool QgsLayoutItem::shouldBlockUndoCommands()
const 550 return !mEvaluatedExcludeFromExports;
555 return mItemRotation;
560 QDomElement element = doc.createElement( QStringLiteral(
"LayoutItem" ) );
561 element.setAttribute( QStringLiteral(
"type" ), QString::number(
type() ) );
563 element.setAttribute( QStringLiteral(
"uuid" ), mUuid );
564 element.setAttribute( QStringLiteral(
"templateUuid" ), mUuid );
565 element.setAttribute( QStringLiteral(
"id" ), mId );
566 element.setAttribute( QStringLiteral(
"referencePoint" ), QString::number( static_cast< int >( mReferencePoint ) ) );
567 element.setAttribute( QStringLiteral(
"position" ), mItemPosition.
encodePoint() );
569 element.setAttribute( QStringLiteral(
"size" ), mItemSize.
encodeSize() );
570 element.setAttribute( QStringLiteral(
"itemRotation" ), QString::number( mItemRotation ) );
571 element.setAttribute( QStringLiteral(
"groupUuid" ), mParentGroupUuid );
573 element.setAttribute(
"zValue", QString::number( zValue() ) );
574 element.setAttribute(
"visibility", isVisible() );
578 element.setAttribute(
"positionLock",
"true" );
582 element.setAttribute(
"positionLock",
"false" );
588 element.setAttribute( QStringLiteral(
"frame" ), QStringLiteral(
"true" ) );
592 element.setAttribute( QStringLiteral(
"frame" ), QStringLiteral(
"false" ) );
598 element.setAttribute( QStringLiteral(
"background" ), QStringLiteral(
"true" ) );
602 element.setAttribute( QStringLiteral(
"background" ), QStringLiteral(
"false" ) );
606 QDomElement frameColorElem = doc.createElement( QStringLiteral(
"FrameColor" ) );
607 frameColorElem.setAttribute( QStringLiteral(
"red" ), QString::number( mFrameColor.red() ) );
608 frameColorElem.setAttribute( QStringLiteral(
"green" ), QString::number( mFrameColor.green() ) );
609 frameColorElem.setAttribute( QStringLiteral(
"blue" ), QString::number( mFrameColor.blue() ) );
610 frameColorElem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mFrameColor.alpha() ) );
611 element.appendChild( frameColorElem );
612 element.setAttribute( QStringLiteral(
"outlineWidthM" ), mFrameWidth.
encodeMeasurement() );
616 QDomElement bgColorElem = doc.createElement( QStringLiteral(
"BackgroundColor" ) );
617 bgColorElem.setAttribute( QStringLiteral(
"red" ), QString::number( mBackgroundColor.red() ) );
618 bgColorElem.setAttribute( QStringLiteral(
"green" ), QString::number( mBackgroundColor.green() ) );
619 bgColorElem.setAttribute( QStringLiteral(
"blue" ), QString::number( mBackgroundColor.blue() ) );
620 bgColorElem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mBackgroundColor.alpha() ) );
621 element.appendChild( bgColorElem );
627 element.setAttribute( QStringLiteral(
"opacity" ), QString::number( mOpacity ) );
629 element.setAttribute(
"excludeFromExports", mExcludeFromExports );
634 parentElement.appendChild( element );
641 if ( element.nodeName() != QStringLiteral(
"LayoutItem" ) )
648 mBlockUndoCommands =
true;
649 mUuid = element.attribute( QStringLiteral(
"uuid" ), QUuid::createUuid().toString() );
650 setId( element.attribute( QStringLiteral(
"id" ) ) );
651 mReferencePoint =
static_cast< ReferencePoint >( element.attribute( QStringLiteral(
"referencePoint" ) ).toInt() );
652 setItemRotation( element.attribute( QStringLiteral(
"itemRotation" ), QStringLiteral(
"0" ) ).toDouble() );
656 mParentGroupUuid = element.attribute( QStringLiteral(
"groupUuid" ) );
657 if ( !mParentGroupUuid.isEmpty() )
661 group->addItem(
this );
664 mTemplateUuid = element.attribute(
"templateUuid" );
667 QString positionLock = element.attribute(
"positionLock" );
668 if ( positionLock.compare(
"true", Qt::CaseInsensitive ) == 0 )
677 setVisibility( element.attribute(
"visibility",
"1" ) !=
"0" );
678 setZValue( element.attribute(
"zValue" ).toDouble() );
681 QString frame = element.attribute( QStringLiteral(
"frame" ) );
682 if ( frame.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
692 QString background = element.attribute( QStringLiteral(
"background" ) );
693 if ( background.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
705 QDomNodeList frameColorList = element.elementsByTagName( QStringLiteral(
"FrameColor" ) );
706 if ( !frameColorList.isEmpty() )
708 QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
710 bool greenOk =
false;
712 bool alphaOk =
false;
713 int penRed, penGreen, penBlue, penAlpha;
715 penRed = frameColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
716 penGreen = frameColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
717 penBlue = frameColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
718 penAlpha = frameColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
720 if ( redOk && greenOk && blueOk && alphaOk )
722 mFrameColor = QColor( penRed, penGreen, penBlue, penAlpha );
728 QDomNodeList bgColorList = element.elementsByTagName( QStringLiteral(
"BackgroundColor" ) );
729 if ( !bgColorList.isEmpty() )
731 QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
732 bool redOk, greenOk, blueOk, alphaOk;
733 int bgRed, bgGreen, bgBlue, bgAlpha;
734 bgRed = bgColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
735 bgGreen = bgColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
736 bgBlue = bgColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
737 bgAlpha = bgColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
738 if ( redOk && greenOk && blueOk && alphaOk )
740 mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
741 setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
751 if ( element.hasAttribute( QStringLiteral(
"opacity" ) ) )
753 setItemOpacity( element.attribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1" ) ).toDouble() );
757 setItemOpacity( 1.0 - element.attribute( QStringLiteral(
"transparency" ), QStringLiteral(
"0" ) ).toInt() / 100.0 );
760 mExcludeFromExports = element.attribute( QStringLiteral(
"excludeFromExports" ), QStringLiteral(
"0" ) ).toInt();
761 mEvaluatedExcludeFromExports = mExcludeFromExports;
765 mBlockUndoCommands =
false;
778 return new QgsLayoutItemUndoCommand(
this, text,
id, parent );
783 if ( drawFrame == mFrame )
796 if ( mFrameColor == color )
809 if ( mFrameWidth == width )
821 if ( mFrameJoinStyle == style )
826 mFrameJoinStyle = style;
828 QPen itemPen = pen();
829 itemPen.setJoinStyle( mFrameJoinStyle );
842 mBackgroundColor = color;
862 return mExcludeFromExports;
867 mExcludeFromExports = exclude;
888 return pen().widthF() / 2.0;
894 return rect().adjusted( -frameBleed, -frameBleed, frameBleed, frameBleed );
917 mLayout->undoStack()->beginCommand(
this, commandText, command );
923 mLayout->undoStack()->endCommand();
929 mLayout->undoStack()->cancelCommand();
945 void QgsLayoutItem::applyDataDefinedOrientation(
double &width,
double &height,
const QgsExpressionContext &context )
949 if ( ok && !orientationString.isEmpty() )
954 double heightD = 0.0, widthD = 0.0;
955 switch ( orientation )
959 heightD = std::max( height, width );
960 widthD = std::min( height, width );
965 heightD = std::min( height, width );
966 widthD = std::max( height, width );
995 double evaluatedWidth = size.
width();
996 double evaluatedHeight = size.
height();
1000 evaluatedWidth = convertedSize.
width();
1001 evaluatedHeight = convertedSize.
height();
1009 applyDataDefinedOrientation( evaluatedWidth, evaluatedHeight, context );
1014 double QgsLayoutItem::applyDataDefinedRotation(
const double rotation )
1023 return evaluatedRotation;
1063 bool exclude = mExcludeFromExports;
1073 if ( angle >= 360.0 || angle <= -360.0 )
1075 angle = std::fmod( angle, 360.0 );
1080 double rotationRequired = angle - rotation();
1083 mItemRotation =
angle;
1086 void QgsLayoutItem::updateStoredItemPosition()
1089 mItemPosition =
mLayout->convertFromLayoutUnits( layoutPosReferencePoint, mItemPosition.
units() );
1094 double evaluatedAngle = angle + rotation();
1096 mItemRotation = evaluatedAngle;
1098 QPointF itemTransformOrigin = mapFromScene( transformOrigin );
1121 if ( !mItemCachedImage.isNull() )
1123 mItemCachedImage = QImage();
1142 painter->setRenderHint( QPainter::Antialiasing,
false );
1143 painter->setPen( Qt::NoPen );
1144 painter->setBrush( QColor( 100, 255, 100, 200 ) );
1145 painter->drawRect( rect() );
1151 if ( !mFrame || !context.
painter() )
1154 QPainter *p = context.
painter();
1157 p->setBrush( Qt::NoBrush );
1158 p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
1164 if ( !mBackground || !context.
painter() )
1167 QPainter *p = context.
painter();
1169 p->setBrush( brush() );
1170 p->setPen( Qt::NoPen );
1171 p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
1183 mMinimumSize = size;
1202 QPointF QgsLayoutItem::itemPositionAtReferencePoint(
const ReferencePoint reference,
const QSizeF &size )
const 1204 switch ( reference )
1207 return QPointF( size.width() / 2.0, 0 );
1209 return QPointF( size.width(), 0 );
1211 return QPointF( 0, size.height() / 2.0 );
1213 return QPointF( size.width() / 2.0, size.height() / 2.0 );
1215 return QPointF( size.width(), size.height() / 2.0 );
1217 return QPointF( 0, size.height() );
1219 return QPointF( size.width() / 2.0, size.height() );
1221 return QPointF( size.width(), size.height() );
1223 return QPointF( 0, 0 );
1226 return QPointF( 0, 0 );
1231 QPointF itemPosition = mapFromScene( position );
1232 QPointF adjustedPointInsideItem = itemPosition - itemPositionAtReferencePoint( reference, size );
1233 return mapToScene( adjustedPointInsideItem );
1238 QPointF pointWithinItem = itemPositionAtReferencePoint( reference, rect().size() );
1239 return mapToScene( pointWithinItem );
1244 QPointF topLeft =
mLayout->convertToLayoutUnits( point );
1245 QPointF refPoint = topLeft + itemPositionAtReferencePoint( mReferencePoint, rect().size() );
1246 return mLayout->convertFromLayoutUnits( refPoint, point.
units() );
1260 void QgsLayoutItem::initConnectionsToLayout()
1267 void QgsLayoutItem::preparePainter( QPainter *painter )
1269 if ( !painter || !painter->device() )
1274 painter->setRenderHint( QPainter::Antialiasing, shouldDrawAntialiased() );
1277 bool QgsLayoutItem::shouldDrawAntialiased()
const 1286 bool QgsLayoutItem::shouldDrawDebugRect()
const 1291 QSizeF QgsLayoutItem::applyMinimumSize(
const QSizeF &targetSize )
1298 return targetSize.expandedTo( minimumSizeLayoutUnits );
1301 QSizeF QgsLayoutItem::applyFixedSize(
const QSizeF &targetSize )
1308 QSizeF size = targetSize;
1309 QSizeF fixedSizeLayoutUnits =
mLayout->convertToLayoutUnits(
fixedSize() );
1310 if ( fixedSizeLayoutUnits.width() > 0 )
1311 size.setWidth( fixedSizeLayoutUnits.width() );
1312 if ( fixedSizeLayoutUnits.height() > 0 )
1313 size.setHeight( fixedSizeLayoutUnits.height() );
1320 double r = mItemRotation;
1332 if ( !transformPoint.isNull() )
1336 QLineF refLine = QLineF( mapToScene( transformPoint ), mapToScene( QPointF( 0, 0 ) ) );
1338 refLine.setAngle( refLine.angle() - r + rotation() );
1340 QPointF rotatedReferencePoint = refLine.p2();
1341 setPos( rotatedReferencePoint );
1344 setTransformOriginPoint( 0, 0 );
1345 QGraphicsItem::setRotation( r );
1348 updateStoredItemPosition();
1363 setOpacity( opacity / 100.0 );
1375 setPen( Qt::NoPen );
1385 itemPen = QPen( frameColor );
1389 itemPen = QPen( mFrameColor );
1391 itemPen.setJoinStyle( mFrameJoinStyle );
1394 itemPen.setWidthF(
mLayout->convertToLayoutUnits( mFrameWidth ) );
1396 itemPen.setWidthF( mFrameWidth.
length() );
1413 setBrush( QBrush( backgroundColor, Qt::SolidPattern ) );
1417 setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
1427 QPainter::CompositionMode
blendMode = mBlendMode;
1432 if ( ok && !blendStr.isEmpty() )
1434 QString blendstr = blendStr.trimmed();
1436 blendMode = blendModeD;
1440 mEffect->setCompositionMode( blendMode );
static QgsLayoutSize decodeSize(const QString &string)
Decodes a size from a string.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the item's composition blending mode.
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...
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.
void setLocked(const bool locked)
Sets whether the item is locked, preventing mouse interactions with the item.
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 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 setReferencePoint(const ReferencePoint &point)
Sets the reference point for positioning of the layout item.
virtual void setVisibility(const bool visible)
Sets whether the item is visible.
void flagsChanged(QgsLayoutRenderContext::Flags flags)
Emitted whenever the context's flags change.
virtual void setSelected(bool selected)
Sets whether the item should be selected.
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.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
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)
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
void cancelCommand()
Cancels the current item command and discards it.
virtual void rotateItem(const double angle, const QPointF &transformOrigin)
Rotates the item by a specified angle in degrees clockwise around a specified reference point...
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...
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.
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.
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 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.
virtual void setFrameStrokeWidth(const QgsLayoutMeasurement &width)
Sets the frame stroke width.
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.
QPointF toQPointF() const
Converts the layout point to a QPointF.
void setParentGroup(QgsLayoutItemGroup *group)
Sets the item's parent group.
static double normalizedAngle(const double angle, const bool allowNegative=false)
Ensures that an angle (in degrees) is in the range 0 <= angle < 360.
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
Get 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.
virtual QSizeF applyItemSizeConstraint(const QSizeF &targetSize)
Applies any item-specific size constraint handling to a given targetSize in layout units...
void setFrameJoinStyle(const Qt::PenJoinStyle style)
Sets the join style used when drawing the item's frame.
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.
QPointF adjustPointForReferencePosition(const QPointF &point, const QSizeF &size, const ReferencePoint &reference) const
Adjusts the specified point at which a reference position of the item sits and returns the top left c...
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 appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
virtual QString uuid() const
Returns the item identification string.
QPointF positionAtReferencePoint(const ReferencePoint &reference) const
Returns the current position (in layout units) of a reference point for the item. ...
Orientation
Page orientiation.
void refreshFrame(bool updateItem=true)
Refresh item's frame, considering data defined colors and frame size.
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.
virtual void refreshDataDefinedProperty(const QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
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.
void refreshBlendMode()
Refresh item's blend mode, considering data defined blend mode.
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.