17#ifndef QGSLAYOUTITEM_H
18#define QGSLAYOUTITEM_H
28#include <QGraphicsRectItem>
97 double mViewScaleFactor = 1.0;
132 switch ( sipCpp->type() )
135 case QGraphicsItem::UserType + 101:
136 sipType = sipType_QgsLayoutItemGroup;
139 case QGraphicsItem::UserType + 102:
140 sipType = sipType_QgsLayoutItemPage;
143 case QGraphicsItem::UserType + 103:
144 sipType = sipType_QgsLayoutItemMap;
147 case QGraphicsItem::UserType + 104:
148 sipType = sipType_QgsLayoutItemPicture;
151 case QGraphicsItem::UserType + 105:
152 sipType = sipType_QgsLayoutItemLabel;
155 case QGraphicsItem::UserType + 106:
156 sipType = sipType_QgsLayoutItemLegend;
159 case QGraphicsItem::UserType + 107:
160 sipType = sipType_QgsLayoutItemShape;
163 case QGraphicsItem::UserType + 108:
164 sipType = sipType_QgsLayoutItemPolygon;
167 case QGraphicsItem::UserType + 109:
168 sipType = sipType_QgsLayoutItemPolyline;
171 case QGraphicsItem::UserType + 110:
172 sipType = sipType_QgsLayoutItemScaleBar;
175 case QGraphicsItem::UserType + 111:
176 sipType = sipType_QgsLayoutFrame;
179 case QGraphicsItem::UserType + 117:
180 sipType = sipType_QgsLayoutItemMarker;
183 case QGraphicsItem::UserType + 118:
184 sipType = sipType_QgsLayoutItemElevationProfile;
187 case QGraphicsItem::UserType + 119:
188 sipType = sipType_QgsLayoutItemChart;
363 int type()
const override;
368 virtual QIcon
icon()
const;
377 virtual QString
uuid()
const {
return mUuid; }
383 virtual Flags itemFlags()
const;
391 QString
id()
const {
return mId; }
399 virtual void setId(
const QString &
id );
407 virtual QString displayName()
const;
412 virtual void setSelected(
bool selected );
420 virtual void setVisibility(
bool visible );
427 void setLocked(
bool locked );
441 bool isGroupMember()
const;
477 virtual ExportLayerBehavior exportLayerBehavior()
const;
492 Q_DECL_DEPRECATED
virtual int numberExportLayers() const
SIP_DEPRECATED;
501 virtual
void startLayeredExport();
510 virtual
void stopLayeredExport();
519 virtual
bool nextExportPart();
571 void paint( QPainter *painter,
const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget )
override;
619 virtual void attemptResize(
const QgsLayoutSize &size,
bool includesFrame =
false );
646 virtual void attemptMove(
const QgsLayoutPoint &point,
bool useReferencePoint =
true,
bool includesFrame =
false,
int page = -1 );
663 void attemptSetSceneRect(
const QRectF &rect,
bool includesFrame =
false );
677 void attemptMoveBy(
double deltaX,
double deltaY );
700 QPointF pagePos()
const;
726 double itemRotation()
const;
735 bool writeXml( QDomElement &parentElement, QDomDocument &document,
const QgsReadWriteContext &context )
const;
752 bool readXml(
const QDomElement &itemElement,
const QDomDocument &document,
const QgsReadWriteContext &context );
762 virtual void finalizeRestoreFromXml();
782 virtual void setFrameEnabled(
bool drawFrame );
791 void setFrameStrokeColor(
const QColor &color );
836 void setFrameJoinStyle( Qt::PenJoinStyle style );
850 void setBackgroundEnabled(
bool drawBackground );
859 QColor backgroundColor(
bool useDataDefined =
true )
const;
866 void setBackgroundColor(
const QColor &color );
872 QPainter::CompositionMode
blendMode()
const {
return mBlendMode; }
878 void setBlendMode( QPainter::CompositionMode mode );
896 void setItemOpacity(
double opacity );
902 bool excludeFromExports()
const;
908 void setExcludeFromExports(
bool exclude );
919 virtual bool containsAdvancedEffects()
const;
926 virtual bool requiresRasterization()
const;
938 virtual double estimatedFrameBleed()
const;
949 virtual QRectF rectWithFrame()
const;
957 virtual void moveContent(
double dx,
double dy );
965 virtual void setMoveContentPreviewOffset(
double dx,
double dy );
973 virtual void zoomContent(
double factor, QPointF point );
983 void beginCommand(
const QString &commandText, UndoCommand command = UndoNone );
997 void cancelCommand();
1002 bool shouldDrawItem()
const;
1032 virtual bool isRefreshing()
const;
1040 void refresh()
override;
1045 virtual void invalidateCache();
1050 virtual void redraw();
1069 virtual void setItemRotation(
double rotation,
bool adjustPosition =
true );
1076 virtual void rotateItem(
double angle, QPointF transformOrigin );
1295 bool mLayoutManagesZValue =
false;
1304 QString mTemplateUuid;
1307 QString mParentGroupUuid;
1315 double mItemRotation = 0.0;
1318 bool mExcludeFromExports =
false;
1324 bool mEvaluatedExcludeFromExports =
false;
1327 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
1329 QPainter::CompositionMode mEvaluatedBlendMode = QPainter::CompositionMode_SourceOver;
1331 QPainter::CompositionMode blendModeForRender()
const;
1334 double mOpacity = 1.0;
1335 double mEvaluatedOpacity = 1.0;
1337 QImage mItemCachedImage;
1338 double mItemCacheDpi = -1;
1340 bool mIsLocked =
false;
1343 bool mFrame =
false;
1345 QColor mFrameColor = QColor( 0, 0, 0 );
1349 Qt::PenJoinStyle mFrameJoinStyle = Qt::MiterJoin;
1352 bool mBackground =
true;
1354 QColor mBackgroundColor = QColor( 255, 255, 255 );
1356 bool mBlockUndoCommands =
false;
1358 void initConnectionsToLayout();
1361 void preparePainter( QPainter *painter );
1362 bool shouldDrawAntialiased()
const;
1363 bool shouldDrawDebugRect()
const;
1364 QSizeF applyMinimumSize( QSizeF targetSize );
1365 QSizeF applyFixedSize( QSizeF targetSize );
1368 double applyDataDefinedRotation(
double rotation );
1369 void updateStoredItemPosition();
1370 QPointF itemPositionAtReferencePoint(
ReferencePoint reference, QSizeF size )
const;
1371 void setScenePos( QPointF destinationPos );
1372 bool shouldBlockUndoCommands()
const;
1374 void applyDataDefinedOrientation(
double &width,
double &height,
const QgsExpressionContext &context );
@ Millimeters
Millimeters.
Base class for commands to undo/redo layout and layout object changes.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A geometry is the spatial representation of a feature.
A QGraphicsEffect subclass used for rendering layout items onto a scene with custom composition modes...
Base class for frame items, which form a layout multiframe item.
A layout item subclass that renders chart plots.
A container for grouping several QgsLayoutItems.
A layout item subclass for text labels.
A layout item for showing marker symbols.
Item representing the paper in a layout.
A layout item subclass that displays SVG files or raster format images (jpg, png, ....
Layout item for node based polygon shapes.
Layout item for node based polyline shapes.
Contains settings and helpers relating to a render of a QgsLayoutItem.
QgsLayoutItemRenderContext & operator=(const QgsLayoutItemRenderContext &other)=delete
QgsLayoutItemRenderContext(QgsRenderContext &context, double viewScaleFactor=1.0)
Constructor for QgsLayoutItemRenderContext.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
double viewScaleFactor() const
Returns the current view zoom (scale factor).
QgsLayoutItemRenderContext(const QgsLayoutItemRenderContext &other)=delete
const QgsRenderContext & renderContext() const
Returns a reference to the context's render context.
A layout item subclass for scale bars.
Layout item for basic filled shapes (e.g.
virtual void drawDebugRect(QPainter *painter)
Draws a debugging rectangle of the item's current bounds within the specified painter.
virtual void drawFrame(QgsRenderContext &context)
Draws the frame around the item.
friend class QgsLayoutItemGroup
virtual QPainterPath framePath() const
Returns the path to use when drawing the item's frame or background.
virtual void cleanup()
Called just before a batch of items are deleted, allowing them to run cleanup tasks.
void drawRefreshingOverlay(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle)
Draws a "refreshing" overlay icon on the item.
void refreshItemRotation(QPointF *origin=nullptr)
Refreshes an item's rotation by rechecking it against any possible overrides such as data defined rot...
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
UndoCommand
Layout item undo commands, used for collapsing undo commands.
@ UndoScaleBarSubdivisionsHeight
Scalebar subdivisions height.
@ UndoPictureStrokeWidth
Picture stroke width.
@ UndoLegendMinSymbolSize
Legend minimum symbol size.
@ UndoArrowHeadStrokeColor
Arrow head stroke color.
@ UndoLegendTitleSpaceBottom
Legend title space.
@ UndoScaleBarLabelBarSize
Scalebar label bar size.
@ UndoLegendIconSymbolSpace
Legend icon symbol space.
@ UndoLegendLayerFont
Legend layer font.
@ UndoShapeCornerRadius
Shape corner radius.
@ UndoLegendLineSpacing
Legend line spacing.
@ UndoNone
No command suppression.
@ UndoLegendBoxSpace
Legend box space.
@ UndoScaleBarFillColor
Scalebar fill color.
@ UndoArrowHeadFillColor
Arrow head fill color.
@ UndoLegendRasterStrokeColor
Legend raster stroke color.
@ UndoLabelFontColor
Label color.
@ UndoIncrementalMove
Layout item incremental movement, e.g. as a result of a keypress.
@ UndoScaleBarMapUnitsSegment
Scalebar map units per segment.
@ UndoElevationProfileElevationMajorGridlines
Change elevation profile elevation axis major gridlines.
@ UndoLegendTitleFont
Legend title font.
@ UndoBackgroundColor
Background color adjustment.
@ UndoLegendFontColor
Legend font color.
@ UndoElevationProfileMaximumDistance
Change elevation profile maximum distance.
@ UndoScaleBarBoxContentSpace
Scalebar box context space.
@ UndoOverviewStyle
Map overview style.
@ UndoElevationProfileChartBackground
Change elevation profile chart background.
@ UndoGridFramePenColor
Map grid frame pen color.
@ UndoMapRotation
Map rotation changed.
@ UndoOpacity
Opacity adjustment.
@ UndoIncrementalResize
Incremental resize.
@ UndoArrowHeadWidth
Arrow head width.
@ UndoElevationProfileDistanceMinorGridlines
Change elevation profile distance axis minor gridlines.
@ UndoScaleBarSegmentSize
Scalebar segment size.
@ UndoMarginTop
Top margin.
@ UndoLegendItemFont
Legend item font.
@ UndoLegendWmsLegendWidth
Legend WMS width.
@ UndoMapGridIntervalRange
Grid interval range.
@ UndoLegendLayerSpace
Legend layer spacing.
@ UndoLabelMargin
Label margin.
@ UndoRotation
Rotation adjustment.
@ UndoLegendColumnSpace
Legend column space.
@ UndoPictureRotation
Picture rotation.
@ UndoStrokeWidth
Stroke width adjustment.
@ UndoScaleBarFillColor2
Scalebar secondary fill color.
@ UndoScaleBarHeight
Scalebar height.
@ UndoLegendMaxSymbolSize
Legend maximum symbol size.
@ UndoArrowStrokeWidth
Arrow stroke width.
@ UndoElevationProfileChartBorder
Change elevation profile chart border.
@ UndoMapGridLineSymbol
Grid line symbol.
@ UndoExportLayerName
Export layer name.
@ UndoZoomContent
Item content zoomed.
@ UndoScaleBarFontColor
Scalebar font color.
@ UndoElevationProfileMaximumElevation
Change elevation profile maximum elevation.
@ UndoMarginLeft
Left margin.
@ UndoLegendAutoWrapAfter
Legend auto wrap lines after distance.
@ UndoMarginRight
Right margin.
@ UndoMapGridMarkerSymbol
Grid marker symbol.
@ UndoAtlasMargin
Map atlas margin changed.
@ UndoPictureFillColor
Picture fill color.
@ UndoLegendSymbolSpace
Legend symbol spacing.
@ UndoMapGridFrameFill1Color
Map grid frame fill color 1.
@ UndoElevationProfileTolerance
Change elevation profile distance tolerance.
@ UndoElevationProfileElevationFormat
Change elevation profile elevation axis number format.
@ UndoLegendSymbolWidth
Legend symbol width.
@ UndoLegendColumnCount
Legend column count.
@ UndoScaleBarSegments
Scalebar number of segments.
@ UndoLegendSymbolHeight
Legend symbol height.
@ UndoElevationProfileMinimumElevation
Change elevation profile minimum elevation.
@ UndoElevationProfileDistanceLabels
Change elevation profile distance axis label interval.
@ UndoLegendGroupSpace
Legend group spacing.
@ UndoScaleBarSubdivisions
Scalebar number of subdivisions.
@ UndoMarginBottom
Bottom margin.
@ UndoSetId
Change item ID.
@ UndoLegendSubgroupIndent
Legend subgroup indent.
@ UndoScaleBarLineWidth
Scalebar line width.
@ UndoElevationProfileElevationFont
Change elevation profile elevation axis number font.
@ UndoLegendRasterStrokeWidth
Legend raster stroke width.
@ UndoLegendGroupIndent
Legend group indent.
@ UndoElevationProfileDistanceFormat
Change elevation profile distance axis number format.
@ UndoMapGridAnnotationFontColor
Map frame annotation color.
@ UndoPictureNorthOffset
Picture north offset.
@ UndoElevationProfileElevationMinorGridlines
Change elevation profile elevation axis minor gridlines.
@ UndoCustomCommand
Base id for plugin based item undo commands.
@ UndoLabelFont
Label font.
@ UndoPictureStrokeColor
Picture stroke color.
@ UndoElevationProfileDistanceFont
Change elevation profile distance axis number font.
@ UndoMapAnnotationDistance
Map frame annotation distance.
@ UndoScaleBarStrokeColor
Scalebar stroke color.
@ UndoShapeStyle
Shape symbol style.
@ UndoStrokeColor
Stroke color adjustment.
@ UndoElevationProfileElevationLabels
Change elevation profile elevation axis label interval.
@ UndoScaleBarSegmentsLeft
Scalebar segments left.
@ UndoElevationProfileDistanceMajorGridlines
Change elevation profile distance axis major gridlines.
@ UndoLegendText
Legend text.
@ UndoMapGridFrameFill2Color
Map grid frame fill color 2.
@ UndoScaleBarUnitText
Scalebar unit text.
@ UndoMapLabelMargin
Margin for labels from edge of map.
@ UndoLegendWmsLegendHeight
Legend WMS height.
@ UndoElevationProfileMinimumDistance
Change elevation profile minimum distance.
@ UndoLabelText
Label text.
@ UndoLegendGroupFont
Legend group font.
@ UndoElevationProfileSubsectionLines
Change elevation profile subsection indicator symbol.
QgsLayoutItem(QgsLayout *layout, bool manageZValue=true)
Constructor for QgsLayoutItem, with the specified parent layout.
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...
void rotationChanged(double newRotation)
Emitted on item rotation change.
virtual QgsLayoutItem::ExportLayerDetail exportLayerDetails() const
Returns the details for the specified current export layer.
virtual QIcon icon() const
Returns the item's icon.
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.
QgsLayoutMeasurement frameStrokeWidth() const
Returns the frame's stroke width.
bool isLocked() const
Returns true if the item is locked, and cannot be interacted with using the mouse.
double itemOpacity() const
Returns the item's opacity.
friend class TestQgsLayoutView
ReferencePoint referencePoint() const
Returns the reference point for positioning of the layout item.
QgsLayoutPoint positionWithUnits() const
Returns the item's current position, including units.
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...
ReferencePoint
Fixed position reference point.
@ LowerMiddle
Lower center of item.
@ MiddleLeft
Middle left of item.
@ UpperRight
Upper right corner of item.
@ LowerLeft
Lower left corner of item.
@ UpperLeft
Upper left corner of item.
@ UpperMiddle
Upper center of item.
@ MiddleRight
Middle right of item.
@ LowerRight
Lower right corner of item.
friend class QgsLayoutItemMap
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
void refreshItemSize()
Refreshes an item's size by rechecking it against any possible item fixed or minimum sizes.
void refreshBackgroundColor(bool updateItem=true)
Refresh item's background color, considering data defined colors.
void setLocked(bool locked)
Sets whether the item is locked, preventing mouse interactions with the item.
int type() const override
Returns a unique graphics item type identifier.
virtual void drawBackground(QgsRenderContext &context)
Draws the background for the item.
virtual QgsLayoutSize minimumSize() const
Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely r...
Flag
Flags for controlling how an item behaves.
@ FlagOverridesPaint
Item overrides the default layout item painting method.
@ FlagDisableSceneCaching
Item should not have QGraphicsItem caching enabled.
@ FlagProvidesClipPath
Item can act as a clipping path provider (see clipPath()).
virtual QgsLayoutSize fixedSize() const
Returns the fixed size of the item, if applicable, or an empty size if item can be freely resized.
void sizePositionChanged()
Emitted when the item's size or position changes.
void lockChanged()
Emitted if the item's lock status changes.
virtual QSizeF applyItemSizeConstraint(QSizeF targetSize)
Applies any item-specific size constraint handling to a given targetSize in layout units.
void refreshFrame(bool updateItem=true)
Refresh item's frame, considering data defined colors and frame size.
virtual QString uuid() const
Returns the item identification string.
QString id() const
Returns the item's ID name.
bool frameEnabled() const
Returns true if the item includes a frame.
friend class QgsCompositionConverter
void frameChanged()
Emitted if the item's frame style changes.
void setReferencePoint(ReferencePoint point)
Sets the reference point for positioning of the layout item.
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets item state from a DOM element.
ExportLayerBehavior
Behavior of item when exporting to layered outputs.
@ ItemContainsSubLayers
Item contains multiple sublayers which must be individually exported.
@ MustPlaceInOwnLayer
Item must be placed in its own individual layer.
@ CanGroupWithItemsOfSameType
Item can only be placed on layers with other items of the same type, but multiple items of this type ...
@ CanGroupWithAnyOtherItem
Item can be placed on a layer with any other item (default behavior).
void refreshBlendMode()
Refresh item's blend mode, considering data defined blend mode.
void clipPathChanged()
Emitted when the item's clipping path has changed.
QPointF positionAtReferencePoint(ReferencePoint reference) const
Returns the current position (in layout units) of a reference point for the item.
void refreshOpacity(bool updateItem=true)
Refresh item's opacity, considering data defined opacity.
bool hasBackground() const
Returns true if the item has a background.
friend class QgsLayoutItemLegend
QgsLayoutSize applyDataDefinedSize(const QgsLayoutSize &size)
Applies any present data defined size overrides to the specified layout size.
virtual void setMinimumSize(const QgsLayoutSize &size)
Sets the minimum allowed size for the layout item.
friend class QgsLayoutItemElevationProfile
QColor frameStrokeColor() const
Returns the frame's stroke color.
void refreshItemPosition()
Refreshes an item's position by rechecking it against any possible overrides such as data defined pos...
virtual void setFixedSize(const QgsLayoutSize &size)
Sets a fixed size for the layout item, which prevents it from being freely resized.
QPainter::CompositionMode blendMode() const
Returns the item's composition blending mode.
virtual void draw(QgsLayoutItemRenderContext &context)=0
Draws the item's contents using the specified item render context.
friend class TestQgsLayoutItem
void backgroundTaskCountChanged(int count)
Emitted whenever the number of background tasks an item is executing changes.
Qt::PenJoinStyle frameJoinStyle() const
Returns the join style used for drawing the item's frame.
Provides a method of storing measurements for use in QGIS layouts using a variety of different measur...
const QgsLayout * layout() const
Returns the layout the object is attached to.
DataDefinedProperty
Data defined properties for different item types.
@ AllProperties
All properties for item.
QgsLayoutObject(QgsLayout *layout)
Constructor for QgsLayoutObject, with the specified parent layout.
Provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
Provides a method of storing sizes, consisting of a width and height, for use in QGIS layouts.
Interface for layout objects which support undo/redo commands.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
#define SIP_ENUM_BASETYPE(type)
Contains details of a particular export layer relating to a layout item.
QPainter::CompositionMode compositionMode
Associated composition mode if this layer is associated with a map layer.
QString mapLayerId
Associated map layer ID, or an empty string if this export layer is not associated with a map layer.
double opacity
Associated opacity, if this layer is associated with a map layer.
QString name
User-friendly name for the export layer.
QString groupName
Associated group name, if this layer is associated with an export group.
QString mapTheme
Associated map theme, or an empty string if this export layer does not need to be associated with a m...