32 #include <QStyleOptionGraphicsItem> 35 #define CACHE_SIZE_LIMIT 5000 38 : mRenderContext( context )
39 , mViewScaleFactor( viewScaleFactor )
47 , QGraphicsRectItem( nullptr )
48 , mUuid( QUuid::createUuid().toString() )
53 setFlags( flags() | QGraphicsItem::ItemUsesExtendedStyleOption | QGraphicsItem::ItemIsSelectable );
55 setCacheMode( QGraphicsItem::DeviceCoordinateCache );
59 mItemPosition =
QgsLayoutPoint( scenePos().x(), scenePos().y(), initialUnits );
60 mItemSize =
QgsLayoutSize( rect().width(), rect().height(), initialUnits );
66 initConnectionsToLayout();
71 mLayoutManagesZValue =
true;
72 mLayout->itemsModel()->addItemAtTop(
this );
76 mLayoutManagesZValue =
false;
89 setGraphicsEffect( mEffect.get() );
99 if (
mLayout && mLayoutManagesZValue )
101 mLayout->itemsModel()->removeItem(
this );
108 if ( !
id().isEmpty() )
116 return tr(
"<%1>" ).arg( metadata->visibleName() );
119 return tr(
"<item>" );
139 if ( !shouldBlockUndoCommands() )
140 mLayout->undoStack()->beginCommand(
this, tr(
"Change Item ID" ) );
144 if ( !shouldBlockUndoCommands() )
145 mLayout->undoStack()->endCommand();
152 mLayout->itemsModel()->updateItemDisplayName(
this );
160 QGraphicsRectItem::setSelected( selected );
164 mLayout->itemsModel()->updateItemSelectStatus(
this );
170 if ( visible == isVisible() )
176 std::unique_ptr< QgsAbstractLayoutUndoCommand > command;
177 if ( !shouldBlockUndoCommands() )
179 command.reset(
createCommand( visible ? tr(
"Show Item" ) : tr(
"Hide Item" ), 0 ) );
180 command->saveBeforeState();
183 QGraphicsItem::setVisible( visible );
187 command->saveAfterState();
188 mLayout->undoStack()->push( command.release() );
194 mLayout->itemsModel()->updateItemVisibility(
this );
200 if ( locked == mIsLocked )
205 if ( !shouldBlockUndoCommands() )
206 mLayout->undoStack()->beginCommand(
this, locked ? tr(
"Lock Item" ) : tr(
"Unlock Item" ) );
210 if ( !shouldBlockUndoCommands() )
211 mLayout->undoStack()->endCommand();
216 mLayout->itemsModel()->updateItemLockStatus(
this );
225 return !mParentGroupUuid.isEmpty() &&
mLayout &&
static_cast< bool >(
mLayout->itemByUuid( mParentGroupUuid ) );
230 if ( !
mLayout || mParentGroupUuid.isEmpty() )
239 mParentGroupUuid.clear();
241 mParentGroupUuid = group->
uuid();
242 setFlag( QGraphicsItem::ItemIsSelectable, !static_cast< bool>( group ) );
254 if ( shouldDrawDebugRect() )
260 bool previewRender = !
mLayout ||
mLayout->renderContext().isPreviewRender();
262 bool useImageCache =
false;
265 if ( useImageCache || forceRasterOutput )
267 double widthInPixels = 0;
268 double heightInPixels = 0;
278 widthInPixels = boundingRect().width() * layoutUnitsToPixels;
279 heightInPixels = boundingRect().height() * layoutUnitsToPixels;
286 if ( widthInPixels > heightInPixels )
290 heightInPixels /= scale;
296 widthInPixels /= scale;
298 destinationDpi = destinationDpi / scale;
301 if ( previewRender && !mItemCachedImage.isNull() &&
qgsDoubleNear( mItemCacheDpi, destinationDpi ) )
306 preparePainter( painter );
307 double cacheScale = destinationDpi / mItemCacheDpi;
309 painter->drawImage( boundingRect().x() * context.
scaleFactor() / cacheScale,
310 boundingRect().y() * context.
scaleFactor() / cacheScale, mItemCachedImage );
316 QImage image = QImage( widthInPixels, heightInPixels, QImage::Format_ARGB32 );
317 image.fill( Qt::transparent );
318 image.setDotsPerMeterX( 1000 * destinationDpi * 25.4 );
319 image.setDotsPerMeterY( 1000 * destinationDpi * 25.4 );
320 QPainter p( &image );
322 preparePainter( &p );
334 draw( itemRenderContext );
345 painter->drawImage( boundingRect().x() * context.
scaleFactor(),
346 boundingRect().y() * context.
scaleFactor(), image );
351 mItemCacheDpi = destinationDpi;
352 mItemCachedImage = image;
360 preparePainter( painter );
369 draw( itemRenderContext );
380 if ( point == mReferencePoint )
385 mReferencePoint = point;
388 updateStoredItemPosition();
412 QSizeF targetSizeLayoutUnits =
mLayout->convertToLayoutUnits( evaluatedSize );
413 QSizeF actualSizeLayoutUnits = applyMinimumSize( targetSizeLayoutUnits );
414 actualSizeLayoutUnits = applyFixedSize( actualSizeLayoutUnits );
417 if ( actualSizeLayoutUnits == rect().size() )
423 mItemSize = actualSizeTargetUnits;
425 setRect( 0, 0, actualSizeLayoutUnits.width(), actualSizeLayoutUnits.height() );
442 point =
mLayout->pageCollection()->pagePositionToAbsolute( page, p );
449 point.
setX( point.
x() + bleed );
450 point.
setY( point.
y() + bleed );
454 if ( !useReferencePoint )
459 evaluatedPoint = applyDataDefinedPosition( evaluatedPoint );
460 QPointF evaluatedPointLayoutUnits =
mLayout->convertToLayoutUnits( evaluatedPoint );
462 if ( topLeftPointLayoutUnits == scenePos() && point.
units() == mItemPosition.
units() )
469 mItemPosition = referencePointTargetUnits;
470 setScenePos( topLeftPointLayoutUnits );
476 QPointF newPos = rect.topLeft();
478 blockSignals(
true );
486 blockSignals(
false );
494 moveBy( deltaX, deltaY );
500 itemPos.
setX( itemPos.
x() + deltaPos.
x() );
501 itemPos.
setY( itemPos.
y() + deltaPos.
y() );
510 return mLayout->pageCollection()->pageNumberForPoint( pos() );
525 p.ry() -= pageItem->pos().y();
535 return mLayout->convertFromLayoutUnits( p, mItemPosition.
units() );
538 void QgsLayoutItem::setScenePos(
const QPointF destinationPos )
544 setPos( pos() + ( destinationPos - scenePos() ) + parentItem()->scenePos() );
546 setPos( pos() + ( destinationPos - scenePos() ) );
549 bool QgsLayoutItem::shouldBlockUndoCommands()
const 563 return !mEvaluatedExcludeFromExports;
568 return mItemRotation;
573 QDomElement element = doc.createElement( QStringLiteral(
"LayoutItem" ) );
574 element.setAttribute( QStringLiteral(
"type" ), QString::number(
type() ) );
576 element.setAttribute( QStringLiteral(
"uuid" ), mUuid );
577 element.setAttribute( QStringLiteral(
"templateUuid" ), mUuid );
578 element.setAttribute( QStringLiteral(
"id" ), mId );
579 element.setAttribute( QStringLiteral(
"referencePoint" ), QString::number( static_cast< int >( mReferencePoint ) ) );
580 element.setAttribute( QStringLiteral(
"position" ), mItemPosition.
encodePoint() );
582 element.setAttribute( QStringLiteral(
"size" ), mItemSize.
encodeSize() );
583 element.setAttribute( QStringLiteral(
"itemRotation" ), QString::number( mItemRotation ) );
584 element.setAttribute( QStringLiteral(
"groupUuid" ), mParentGroupUuid );
586 element.setAttribute( QStringLiteral(
"zValue" ), QString::number( zValue() ) );
587 element.setAttribute( QStringLiteral(
"visibility" ), isVisible() );
591 element.setAttribute( QStringLiteral(
"positionLock" ), QStringLiteral(
"true" ) );
595 element.setAttribute( QStringLiteral(
"positionLock" ), QStringLiteral(
"false" ) );
601 element.setAttribute( QStringLiteral(
"frame" ), QStringLiteral(
"true" ) );
605 element.setAttribute( QStringLiteral(
"frame" ), QStringLiteral(
"false" ) );
611 element.setAttribute( QStringLiteral(
"background" ), QStringLiteral(
"true" ) );
615 element.setAttribute( QStringLiteral(
"background" ), QStringLiteral(
"false" ) );
619 QDomElement frameColorElem = doc.createElement( QStringLiteral(
"FrameColor" ) );
620 frameColorElem.setAttribute( QStringLiteral(
"red" ), QString::number( mFrameColor.red() ) );
621 frameColorElem.setAttribute( QStringLiteral(
"green" ), QString::number( mFrameColor.green() ) );
622 frameColorElem.setAttribute( QStringLiteral(
"blue" ), QString::number( mFrameColor.blue() ) );
623 frameColorElem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mFrameColor.alpha() ) );
624 element.appendChild( frameColorElem );
625 element.setAttribute( QStringLiteral(
"outlineWidthM" ), mFrameWidth.
encodeMeasurement() );
629 QDomElement bgColorElem = doc.createElement( QStringLiteral(
"BackgroundColor" ) );
630 bgColorElem.setAttribute( QStringLiteral(
"red" ), QString::number( mBackgroundColor.red() ) );
631 bgColorElem.setAttribute( QStringLiteral(
"green" ), QString::number( mBackgroundColor.green() ) );
632 bgColorElem.setAttribute( QStringLiteral(
"blue" ), QString::number( mBackgroundColor.blue() ) );
633 bgColorElem.setAttribute( QStringLiteral(
"alpha" ), QString::number( mBackgroundColor.alpha() ) );
634 element.appendChild( bgColorElem );
640 element.setAttribute( QStringLiteral(
"opacity" ), QString::number( mOpacity ) );
642 element.setAttribute( QStringLiteral(
"excludeFromExports" ), mExcludeFromExports );
647 parentElement.appendChild( element );
654 if ( element.nodeName() != QStringLiteral(
"LayoutItem" ) )
661 mBlockUndoCommands =
true;
662 mUuid = element.attribute( QStringLiteral(
"uuid" ), QUuid::createUuid().toString() );
663 setId( element.attribute( QStringLiteral(
"id" ) ) );
664 mReferencePoint =
static_cast< ReferencePoint >( element.attribute( QStringLiteral(
"referencePoint" ) ).toInt() );
665 setItemRotation( element.attribute( QStringLiteral(
"itemRotation" ), QStringLiteral(
"0" ) ).toDouble() );
669 mParentGroupUuid = element.attribute( QStringLiteral(
"groupUuid" ) );
670 if ( !mParentGroupUuid.isEmpty() )
674 group->addItem(
this );
677 mTemplateUuid = element.attribute( QStringLiteral(
"templateUuid" ) );
680 QString positionLock = element.attribute( QStringLiteral(
"positionLock" ) );
681 if ( positionLock.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
690 setVisibility( element.attribute( QStringLiteral(
"visibility" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
691 setZValue( element.attribute( QStringLiteral(
"zValue" ) ).toDouble() );
694 QString frame = element.attribute( QStringLiteral(
"frame" ) );
695 if ( frame.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
705 QString background = element.attribute( QStringLiteral(
"background" ) );
706 if ( background.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
718 QDomNodeList frameColorList = element.elementsByTagName( QStringLiteral(
"FrameColor" ) );
719 if ( !frameColorList.isEmpty() )
721 QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
723 bool greenOk =
false;
725 bool alphaOk =
false;
726 int penRed, penGreen, penBlue, penAlpha;
728 penRed = frameColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
729 penGreen = frameColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
730 penBlue = frameColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
731 penAlpha = frameColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
733 if ( redOk && greenOk && blueOk && alphaOk )
735 mFrameColor = QColor( penRed, penGreen, penBlue, penAlpha );
741 QDomNodeList bgColorList = element.elementsByTagName( QStringLiteral(
"BackgroundColor" ) );
742 if ( !bgColorList.isEmpty() )
744 QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
745 bool redOk, greenOk, blueOk, alphaOk;
746 int bgRed, bgGreen, bgBlue, bgAlpha;
747 bgRed = bgColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
748 bgGreen = bgColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
749 bgBlue = bgColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
750 bgAlpha = bgColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
751 if ( redOk && greenOk && blueOk && alphaOk )
753 mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
754 setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
764 if ( element.hasAttribute( QStringLiteral(
"opacity" ) ) )
766 setItemOpacity( element.attribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1" ) ).toDouble() );
770 setItemOpacity( 1.0 - element.attribute( QStringLiteral(
"transparency" ), QStringLiteral(
"0" ) ).toInt() / 100.0 );
773 mExcludeFromExports = element.attribute( QStringLiteral(
"excludeFromExports" ), QStringLiteral(
"0" ) ).toInt();
774 mEvaluatedExcludeFromExports = mExcludeFromExports;
778 mBlockUndoCommands =
false;
791 return new QgsLayoutItemUndoCommand(
this, text,
id, parent );
796 if ( drawFrame == mFrame )
809 if ( mFrameColor == color )
822 if ( mFrameWidth == width )
834 if ( mFrameJoinStyle == style )
839 mFrameJoinStyle = style;
841 QPen itemPen = pen();
842 itemPen.setJoinStyle( mFrameJoinStyle );
855 mBackgroundColor = color;
871 if ( !mItemCachedImage.isNull() )
877 return mExcludeFromExports;
882 mExcludeFromExports = exclude;
888 return itemFlags() & Flag::FlagOverridesPaint ?
false : mEvaluatedOpacity < 1.0;
894 blendMode() != QPainter::CompositionMode_SourceOver;
904 return pen().widthF() / 2.0;
910 return rect().adjusted( -frameBleed, -frameBleed, frameBleed, frameBleed );
933 mLayout->undoStack()->beginCommand(
this, commandText, command );
939 mLayout->undoStack()->endCommand();
945 mLayout->undoStack()->cancelCommand();
961 void QgsLayoutItem::applyDataDefinedOrientation(
double &width,
double &height,
const QgsExpressionContext &context )
965 if ( ok && !orientationString.isEmpty() )
970 double heightD = 0.0, widthD = 0.0;
971 switch ( orientation )
975 heightD = std::max( height, width );
976 widthD = std::min( height, width );
981 heightD = std::min( height, width );
982 widthD = std::max( height, width );
1011 double evaluatedWidth = size.
width();
1012 double evaluatedHeight = size.
height();
1016 evaluatedWidth = convertedSize.
width();
1017 evaluatedHeight = convertedSize.
height();
1025 applyDataDefinedOrientation( evaluatedWidth, evaluatedHeight, context );
1030 double QgsLayoutItem::applyDataDefinedRotation(
const double rotation )
1039 return evaluatedRotation;
1079 bool exclude = mExcludeFromExports;
1089 if ( angle >= 360.0 || angle <= -360.0 )
1091 angle = std::fmod( angle, 360.0 );
1096 double rotationRequired = angle - rotation();
1099 mItemRotation =
angle;
1102 void QgsLayoutItem::updateStoredItemPosition()
1105 mItemPosition =
mLayout->convertFromLayoutUnits( layoutPosReferencePoint, mItemPosition.
units() );
1110 double evaluatedAngle = angle + rotation();
1112 mItemRotation = evaluatedAngle;
1114 QPointF itemTransformOrigin = mapFromScene( transformOrigin );
1137 if ( !mItemCachedImage.isNull() )
1139 mItemCachedImage = QImage();
1158 painter->setRenderHint( QPainter::Antialiasing,
false );
1159 painter->setPen( Qt::NoPen );
1160 painter->setBrush( QColor( 100, 255, 100, 200 ) );
1161 painter->drawRect( rect() );
1167 if ( !mFrame || !context.
painter() )
1170 QPainter *p = context.
painter();
1173 p->setBrush( Qt::NoBrush );
1174 p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
1180 if ( !mBackground || !context.
painter() )
1183 QPainter *p = context.
painter();
1185 p->setBrush( brush() );
1186 p->setPen( Qt::NoPen );
1187 p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
1199 mMinimumSize = size;
1218 QPointF QgsLayoutItem::itemPositionAtReferencePoint(
const ReferencePoint reference,
const QSizeF size )
const 1220 switch ( reference )
1223 return QPointF( size.width() / 2.0, 0 );
1225 return QPointF( size.width(), 0 );
1227 return QPointF( 0, size.height() / 2.0 );
1229 return QPointF( size.width() / 2.0, size.height() / 2.0 );
1231 return QPointF( size.width(), size.height() / 2.0 );
1233 return QPointF( 0, size.height() );
1235 return QPointF( size.width() / 2.0, size.height() );
1237 return QPointF( size.width(), size.height() );
1239 return QPointF( 0, 0 );
1242 return QPointF( 0, 0 );
1247 QPointF itemPosition = mapFromScene( position );
1248 QPointF adjustedPointInsideItem = itemPosition - itemPositionAtReferencePoint( reference, size );
1249 return mapToScene( adjustedPointInsideItem );
1254 QPointF pointWithinItem = itemPositionAtReferencePoint( reference, rect().size() );
1255 return mapToScene( pointWithinItem );
1260 QPointF topLeft =
mLayout->convertToLayoutUnits( point );
1261 QPointF refPoint = topLeft + itemPositionAtReferencePoint( mReferencePoint, rect().size() );
1262 return mLayout->convertFromLayoutUnits( refPoint, point.
units() );
1276 void QgsLayoutItem::initConnectionsToLayout()
1283 void QgsLayoutItem::preparePainter( QPainter *painter )
1285 if ( !painter || !painter->device() )
1290 painter->setRenderHint( QPainter::Antialiasing, shouldDrawAntialiased() );
1293 bool QgsLayoutItem::shouldDrawAntialiased()
const 1302 bool QgsLayoutItem::shouldDrawDebugRect()
const 1307 QSizeF QgsLayoutItem::applyMinimumSize(
const QSizeF targetSize )
1314 return targetSize.expandedTo( minimumSizeLayoutUnits );
1317 QSizeF QgsLayoutItem::applyFixedSize(
const QSizeF targetSize )
1324 QSizeF size = targetSize;
1325 QSizeF fixedSizeLayoutUnits =
mLayout->convertToLayoutUnits(
fixedSize() );
1326 if ( fixedSizeLayoutUnits.width() > 0 )
1327 size.setWidth( fixedSizeLayoutUnits.width() );
1328 if ( fixedSizeLayoutUnits.height() > 0 )
1329 size.setHeight( fixedSizeLayoutUnits.height() );
1336 double r = mItemRotation;
1348 if ( !transformPoint.isNull() )
1352 QLineF refLine = QLineF( mapToScene( transformPoint ), mapToScene( QPointF( 0, 0 ) ) );
1354 refLine.setAngle( refLine.angle() - r + rotation() );
1356 QPointF rotatedReferencePoint = refLine.p2();
1357 setPos( rotatedReferencePoint );
1360 setTransformOriginPoint( 0, 0 );
1361 QGraphicsItem::setRotation( r );
1364 updateStoredItemPosition();
1379 mEvaluatedOpacity = opacity / 100.0;
1385 setOpacity( mEvaluatedOpacity );
1398 setPen( Qt::NoPen );
1408 itemPen = QPen( frameColor );
1412 itemPen = QPen( mFrameColor );
1414 itemPen.setJoinStyle( mFrameJoinStyle );
1417 itemPen.setWidthF(
mLayout->convertToLayoutUnits( mFrameWidth ) );
1419 itemPen.setWidthF( mFrameWidth.
length() );
1436 setBrush( QBrush( backgroundColor, Qt::SolidPattern ) );
1440 setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
1450 QPainter::CompositionMode
blendMode = mBlendMode;
1455 if ( ok && !blendStr.isEmpty() )
1457 QString blendstr = blendStr.trimmed();
1459 blendMode = blendModeD;
1463 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...
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...
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.
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.
bool excludeFromExports() const
Returns whether the item should be excluded from layout exports and prints.
QgsLayoutSize applyDataDefinedSize(const QgsLayoutSize &size)
Applies any present data defined size overrides to the specified layout size.
QPointF toQPointF() const
Converts the layout point to a QPointF.
int type() const override
Returns a unique graphics item type identifier.
Lower left corner of item.
bool readObjectPropertiesFromElement(const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets object properties from a DOM element.
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.
bool isGroupMember() const
Returns true if the item is part of a QgsLayoutItemGroup group.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the size.
UndoCommand
Layout item undo commands, used for collapsing undo commands.
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 refreshItemPosition()
Refreshes an item's position by rechecking it against any possible overrides such as data defined pos...
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.
QString encodeMeasurement() const
Encodes the layout measurement to a string.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
double length() const
Returns the length of the measurement.
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 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 setFrameStrokeWidth(QgsLayoutMeasurement width)
Sets the frame stroke width.
virtual QgsLayoutSize fixedSize() const
Returns the fixed size of the item, if applicable, or an empty size if item can be freely resized...
double x() const
Returns x coordinate of point.
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
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.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores the item state in a DOM element.
Lower right corner of item.
double itemOpacity() const
Returns the item's opacity.
QPointF pagePos() const
Returns the item's position (in layout units) relative to the top left corner of its current page...
double height() const
Returns the height of the size.
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.
QgsLayoutPoint positionWithUnits() const
Returns the item's current position, including units.
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.
void setX(const double x)
Sets the x coordinate of point.
virtual void drawFrame(QgsRenderContext &context)
Draws the frame around the item.
A QGraphicsEffect subclass used for rendering layout items onto a scene with custom composition modes...
double width() const
Returns the width of the size.
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
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 Flags itemFlags() const
Returns the item's flags, which indicate how the item behaves.
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.
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...
virtual void rotateItem(double angle, QPointF transformOrigin)
Rotates the item by a specified angle in degrees clockwise around a specified reference point...
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...
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.
QString encodeSize() const
Encodes the layout size to a string.
virtual QString uuid() const
Returns the item identification string.
static QPainter::CompositionMode decodeBlendMode(const QString &s)
Upper left corner of item.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
void setHeight(const double height)
Sets the height for the size.
virtual void setVisibility(bool visible)
Sets whether the item is visible.
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.
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...
Use antialiasing when drawing items.
bool readXml(const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets the item state from a DOM element.
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...
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.
QString encodePoint() const
Encodes the layout point to a string.
virtual QRectF rectWithFrame() const
Returns the item's rectangular bounds, including any bleed caused by the item's frame.
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...
int page() const
Returns the page the item is currently on, with the first page returning 0.
void lockChanged()
Emitted if the item's lock status changes.
QgsLayoutPoint pagePositionWithUnits() const
Returns the item's position (in item units) relative to the top left corner of its current page...
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...
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
QPainter * painter()
Returns the destination QPainter for the render operation.
QPointF positionAtReferencePoint(ReferencePoint reference) const
Returns the current position (in layout units) of a reference point for the item. ...
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 bool containsAdvancedEffects() const
Returns true if the item contains contents with blend modes or transparency effects which can only be...
virtual void setMoveContentPreviewOffset(double dx, double dy)
Sets temporary offset for the item, by a specified dx and dy in layout units.
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.
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...
QColor backgroundColor() const
Returns the background color for this item.
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.
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 double estimatedFrameBleed() const
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.
QPainter::CompositionMode blendMode() const
Returns the item's composition blending mode.
virtual void setFrameEnabled(bool drawFrame)
Sets whether this item has a frame drawn around it or not.
virtual QString displayName() const
Gets item display name.
double itemRotation() const
Returns the current rotation for the item, in degrees clockwise.
A base class for objects which belong to a layout.
Debug/testing mode, items are drawn as solid rectangles.
LayoutUnit
Layout measurement units.
QgsUnitTypes::LayoutUnit units() const
Returns the native units for the layout.
QgsLayoutItemGroup * parentGroup() const
Returns the item's parent group, if the item is part of a QgsLayoutItemGroup group.
QString id() const
Returns the item's ID name.
virtual void draw(QgsLayoutItemRenderContext &context)=0
Draws the item's contents using the specified item render context.
bool writeObjectPropertiesToElement(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores object properties within an XML DOM element.
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.
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.
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...
QgsUnitTypes::LayoutUnit units() const
Returns the units for the point.
bool frameEnabled() const
Returns true if the item includes a frame.
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
void setItemOpacity(double opacity)
Sets the item's opacity.
double y() const
Returns y coordinate of point.
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.