17 #ifndef QGSLAYOUTITEM_H
18 #define QGSLAYOUTITEM_H
20 #include "qgis_core.h"
28 #include <QGraphicsRectItem>
103 double mViewScaleFactor = 1.0;
138 switch ( sipCpp->type() )
141 case QGraphicsItem::UserType + 101:
142 sipType = sipType_QgsLayoutItemGroup;
145 case QGraphicsItem::UserType + 102:
146 sipType = sipType_QgsLayoutItemPage;
149 case QGraphicsItem::UserType + 103:
150 sipType = sipType_QgsLayoutItemMap;
153 case QGraphicsItem::UserType + 104:
154 sipType = sipType_QgsLayoutItemPicture;
157 case QGraphicsItem::UserType + 105:
158 sipType = sipType_QgsLayoutItemLabel;
161 case QGraphicsItem::UserType + 106:
162 sipType = sipType_QgsLayoutItemLegend;
165 case QGraphicsItem::UserType + 107:
166 sipType = sipType_QgsLayoutItemShape;
169 case QGraphicsItem::UserType + 108:
170 sipType = sipType_QgsLayoutItemPolygon;
173 case QGraphicsItem::UserType + 109:
174 sipType = sipType_QgsLayoutItemPolyline;
177 case QGraphicsItem::UserType + 110:
178 sipType = sipType_QgsLayoutItemScaleBar;
181 case QGraphicsItem::UserType + 111:
182 sipType = sipType_QgsLayoutFrame;
196 Q_PROPERTY(
bool locked READ isLocked WRITE setLocked NOTIFY lockChanged )
218 UndoIncrementalMove = 1,
303 FlagOverridesPaint = 1 << 1,
304 FlagProvidesClipPath = 1 << 2,
306 Q_DECLARE_FLAGS( Flags, Flag )
322 virtual void cleanup();
329 int type()
const override;
343 virtual QString
uuid()
const {
return mUuid; }
349 virtual Flags itemFlags()
const;
357 QString
id()
const {
return mId; }
365 virtual void setId(
const QString &
id );
373 virtual QString displayName()
const;
378 virtual void setSelected(
bool selected );
386 virtual void setVisibility(
bool visible );
393 void setLocked(
bool locked );
407 bool isGroupMember()
const;
441 virtual ExportLayerBehavior exportLayerBehavior()
const;
456 Q_DECL_DEPRECATED
virtual int numberExportLayers() const
SIP_DEPRECATED;
465 virtual
void startLayeredExport();
474 virtual
void stopLayeredExport();
483 virtual
bool nextExportPart();
502 QPainter::CompositionMode compositionMode = QPainter::CompositionMode_SourceOver;
508 double opacity = 1.0;
528 void paint( QPainter *painter,
const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget )
override;
576 virtual void attemptResize(
const QgsLayoutSize &size,
bool includesFrame =
false );
603 virtual void attemptMove(
const QgsLayoutPoint &point,
bool useReferencePoint =
true,
bool includesFrame =
false,
int page = -1 );
620 void attemptSetSceneRect(
const QRectF &rect,
bool includesFrame =
false );
634 void attemptMoveBy(
double deltaX,
double deltaY );
657 QPointF pagePos()
const;
683 double itemRotation()
const;
692 bool writeXml( QDomElement &parentElement, QDomDocument &document,
const QgsReadWriteContext &context )
const;
709 bool readXml(
const QDomElement &itemElement,
const QDomDocument &document,
const QgsReadWriteContext &context );
719 virtual void finalizeRestoreFromXml();
730 bool frameEnabled()
const {
return mFrame; }
739 virtual void setFrameEnabled(
bool drawFrame );
748 void setFrameStrokeColor(
const QColor &color );
793 void setFrameJoinStyle( Qt::PenJoinStyle style );
807 void setBackgroundEnabled(
bool drawBackground );
822 void setBackgroundColor(
const QColor &color );
828 QPainter::CompositionMode
blendMode()
const {
return mBlendMode; }
834 void setBlendMode( QPainter::CompositionMode mode );
852 void setItemOpacity(
double opacity );
858 bool excludeFromExports()
const;
864 void setExcludeFromExports(
bool exclude );
875 virtual bool containsAdvancedEffects()
const;
882 virtual bool requiresRasterization()
const;
894 virtual double estimatedFrameBleed()
const;
905 virtual QRectF rectWithFrame()
const;
913 virtual void moveContent(
double dx,
double dy );
921 virtual void setMoveContentPreviewOffset(
double dx,
double dy );
929 virtual void zoomContent(
double factor, QPointF point );
939 void beginCommand(
const QString &commandText, UndoCommand command = UndoNone );
953 void cancelCommand();
958 bool shouldDrawItem()
const;
989 void refresh()
override;
994 virtual void invalidateCache();
999 virtual void redraw();
1018 virtual void setItemRotation(
double rotation,
bool adjustPosition =
true );
1025 virtual void rotateItem(
double angle, QPointF transformOrigin );
1074 virtual void drawDebugRect( QPainter *painter );
1091 virtual QPainterPath framePath()
const;
1131 virtual QSizeF applyItemSizeConstraint( QSizeF targetSize );
1140 void refreshItemSize();
1147 void refreshItemPosition();
1159 void refreshItemRotation( QPointF *origin =
nullptr );
1166 void refreshOpacity(
bool updateItem =
true );
1173 void refreshFrame(
bool updateItem =
true );
1180 void refreshBackgroundColor(
bool updateItem =
true );
1185 void refreshBlendMode();
1191 QPointF adjustPointForReferencePosition( QPointF point, QSizeF size,
ReferencePoint reference )
const;
1196 QPointF positionAtReferencePoint(
ReferencePoint reference )
const;
1212 virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document,
const QgsReadWriteContext &context )
const;
1229 virtual bool readPropertiesFromElement(
const QDomElement &element,
const QDomDocument &document,
const QgsReadWriteContext &context );
1239 bool mLayoutManagesZValue =
false;
1248 QString mTemplateUuid;
1251 QString mParentGroupUuid;
1259 double mItemRotation = 0.0;
1262 bool mExcludeFromExports =
false;
1268 bool mEvaluatedExcludeFromExports =
false;
1271 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
1272 std::unique_ptr< QgsLayoutEffect > mEffect;
1275 double mOpacity = 1.0;
1276 double mEvaluatedOpacity = 1.0;
1278 QImage mItemCachedImage;
1279 double mItemCacheDpi = -1;
1281 bool mIsLocked =
false;
1284 bool mFrame =
false;
1286 QColor mFrameColor = QColor( 0, 0, 0 );
1290 Qt::PenJoinStyle mFrameJoinStyle = Qt::MiterJoin;
1293 bool mBackground =
true;
1295 QColor mBackgroundColor = QColor( 255, 255, 255 );
1297 bool mBlockUndoCommands =
false;
1299 void initConnectionsToLayout();
1302 void preparePainter( QPainter *painter );
1303 bool shouldDrawAntialiased()
const;
1304 bool shouldDrawDebugRect()
const;
1305 QSizeF applyMinimumSize( QSizeF targetSize );
1306 QSizeF applyFixedSize( QSizeF targetSize );
1309 double applyDataDefinedRotation(
double rotation );
1310 void updateStoredItemPosition();
1311 QPointF itemPositionAtReferencePoint(
ReferencePoint reference, QSizeF size )
const;
1312 void setScenePos( QPointF destinationPos );
1313 bool shouldBlockUndoCommands()
const;
1315 void applyDataDefinedOrientation(
double &width,
double &height,
const QgsExpressionContext &context );
1317 friend class TestQgsLayoutItem;
1318 friend class TestQgsLayoutView;
Base class for commands to undo/redo layout and layout object changes.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
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 container for grouping several QgsLayoutItems.
A layout item subclass for text labels.
A layout item subclass for map legends.
Layout graphical items for displaying a map.
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.
double viewScaleFactor() const
Returns the current view zoom (scale factor).
QgsLayoutItemRenderContext & operator=(const QgsLayoutItemRenderContext &other)=delete
QgsLayoutItemRenderContext cannot be copied.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
QgsLayoutItemRenderContext(const QgsLayoutItemRenderContext &other)=delete
QgsLayoutItemRenderContext cannot be copied.
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.
Base class for graphical items within a QgsLayout.
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.
@ UndoLegendBoxSpace
Legend box space.
@ UndoScaleBarFillColor
Scalebar fill color.
@ UndoArrowHeadFillColor
Arrow head fill color.
@ UndoLegendRasterStrokeColor
Legend raster stroke color.
@ UndoLabelFontColor
Label color.
@ UndoScaleBarMapUnitsSegment
Scalebar map units per segment.
@ UndoLegendTitleFont
Legend title font.
@ UndoBackgroundColor
Background color adjustment.
@ UndoLegendFontColor
Legend font color.
@ UndoScaleBarBoxContentSpace
Scalebar box context space.
@ UndoOverviewStyle
Map overview style.
@ UndoGridFramePenColor
Map grid frame pen color.
@ UndoMapRotation
Map rotation changed.
@ UndoOpacity
Opacity adjustment.
@ UndoIncrementalResize
Incremental resize.
@ UndoArrowHeadWidth
Arrow head width.
@ UndoScaleBarSegmentSize
Scalebar segment size.
@ 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.
@ UndoMapGridLineSymbol
Grid line symbol.
@ UndoZoomContent
Item content zoomed.
@ UndoScaleBarFontColor
Scalebar font color.
@ UndoMapGridMarkerSymbol
Grid marker symbol.
@ UndoAtlasMargin
Map atlas margin changed.
@ UndoPictureFillColor
Picture fill color.
@ UndoLegendSymbolSpace
Legend symbol spacing.
@ UndoMapGridFrameFill1Color
Map grid frame fill color 1.
@ UndoLegendSymbolWidth
Legend symbol width.
@ UndoLegendColumnCount
Legend column count.
@ UndoScaleBarSegments
Scalebar number of segments.
@ UndoLegendSymbolHeight
Legend symbol height.
@ UndoLegendGroupSpace
Legend group spacing.
@ UndoScaleBarSubdivisions
Scalebar number of subdivisions.
@ UndoSetId
Change item ID.
@ UndoScaleBarLineWidth
Scalebar line width.
@ UndoLegendRasterStrokeWidth
Legend raster stroke width.
@ UndoMapGridAnnotationFontColor
Map frame annotation color.
@ UndoPictureNorthOffset
Picture north offset.
@ UndoCustomCommand
Base id for plugin based item undo commands.
@ UndoLabelFont
Label font.
@ UndoPictureStrokeColor
Picture stroke color.
@ UndoMapAnnotationDistance
Map frame annotation distance.
@ UndoScaleBarStrokeColor
Scalebar stroke color.
@ UndoShapeStyle
Shape symbol style.
@ UndoStrokeColor
Stroke color adjustment.
@ UndoScaleBarSegmentsLeft
Scalebar segments left.
@ 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.
@ UndoLabelText
Label text.
@ UndoLegendGroupFont
Legend group font.
void rotationChanged(double newRotation)
Emitted on item rotation change.
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.
ReferencePoint referencePoint() const
Returns the reference point for positioning of the layout item.
QgsLayoutPoint positionWithUnits() const
Returns the item's current position, including units.
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.
QColor backgroundColor() const
Returns the background color for this 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.
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 QString uuid() const
Returns the item identification string.
QString id() const
Returns the item's ID name.
virtual QIcon icon() const
Returns the item's icon.
void frameChanged()
Emitted if the item's frame style changes.
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 clipPathChanged()
Emitted when the item's clipping path has changed.
bool hasBackground() const
Returns true if the item has a background.
QColor frameStrokeColor() const
Returns the frame's stroke color.
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.
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.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
A base class for objects which belong to a layout.
DataDefinedProperty
Data defined properties for different item types.
@ AllProperties
All properties for item.
This class provides a method of storing points, consisting of an x and y coordinate,...
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Interface for layout objects which support undo/redo commands.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g.
@ LayoutMillimeters
Millimeters.
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)
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
Contains details of a particular export layer relating to a layout item.
QString mapLayerId
Associated map layer ID, or an empty string if this export layer is not associated with a map layer.
QString name
User-friendly name for the export layer.
QString mapTheme
Associated map theme, or an empty string if this export layer does not need to be associated with a m...