17 #ifndef QGSLAYOUTITEM_H 18 #define QGSLAYOUTITEM_H 20 #include "qgis_core.h" 27 #include <QGraphicsRectItem> 102 double mViewScaleFactor = 1.0;
137 switch ( sipCpp->type() )
140 case QGraphicsItem::UserType + 101:
141 sipType = sipType_QgsLayoutItemGroup;
144 case QGraphicsItem::UserType + 102:
145 sipType = sipType_QgsLayoutItemPage;
148 case QGraphicsItem::UserType + 103:
149 sipType = sipType_QgsLayoutItemMap;
152 case QGraphicsItem::UserType + 104:
153 sipType = sipType_QgsLayoutItemPicture;
156 case QGraphicsItem::UserType + 105:
157 sipType = sipType_QgsLayoutItemLabel;
160 case QGraphicsItem::UserType + 106:
161 sipType = sipType_QgsLayoutItemLegend;
164 case QGraphicsItem::UserType + 107:
165 sipType = sipType_QgsLayoutItemShape;
168 case QGraphicsItem::UserType + 108:
169 sipType = sipType_QgsLayoutItemPolygon;
172 case QGraphicsItem::UserType + 109:
173 sipType = sipType_QgsLayoutItemPolyline;
176 case QGraphicsItem::UserType + 110:
177 sipType = sipType_QgsLayoutItemScaleBar;
180 case QGraphicsItem::UserType + 111:
181 sipType = sipType_QgsLayoutFrame;
195 Q_PROPERTY(
bool locked READ isLocked WRITE setLocked NOTIFY lockChanged )
217 UndoIncrementalMove = 1,
296 FlagOverridesPaint = 1 << 1,
298 Q_DECLARE_FLAGS( Flags,
Flag )
314 virtual
void cleanup();
321 int type() const override;
335 virtual QString
uuid()
const {
return mUuid; }
341 virtual Flags itemFlags()
const;
349 QString
id()
const {
return mId; }
357 virtual void setId(
const QString &
id );
365 virtual QString displayName()
const;
370 virtual void setSelected(
bool selected );
378 virtual void setVisibility(
bool visible );
385 void setLocked(
bool locked );
399 bool isGroupMember()
const;
430 void paint( QPainter *painter,
const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget )
override;
478 virtual void attemptResize(
const QgsLayoutSize &size,
bool includesFrame =
false );
505 virtual void attemptMove(
const QgsLayoutPoint &point,
bool useReferencePoint =
true,
bool includesFrame =
false,
int page = -1 );
522 void attemptSetSceneRect(
const QRectF &rect,
bool includesFrame =
false );
536 void attemptMoveBy(
double deltaX,
double deltaY );
559 QPointF pagePos()
const;
585 double itemRotation()
const;
594 bool writeXml( QDomElement &parentElement, QDomDocument &document,
const QgsReadWriteContext &context )
const;
611 bool readXml(
const QDomElement &itemElement,
const QDomDocument &document,
const QgsReadWriteContext &context );
621 virtual void finalizeRestoreFromXml();
641 virtual void setFrameEnabled(
bool drawFrame );
650 void setFrameStrokeColor(
const QColor &color );
695 void setFrameJoinStyle( Qt::PenJoinStyle style );
709 void setBackgroundEnabled(
bool drawBackground );
724 void setBackgroundColor(
const QColor &color );
730 QPainter::CompositionMode
blendMode()
const {
return mBlendMode; }
736 void setBlendMode( QPainter::CompositionMode mode );
754 void setItemOpacity(
double opacity );
760 bool excludeFromExports()
const;
766 void setExcludeFromExports(
bool exclude );
777 virtual bool containsAdvancedEffects()
const;
784 virtual bool requiresRasterization()
const;
796 virtual double estimatedFrameBleed()
const;
807 virtual QRectF rectWithFrame()
const;
815 virtual void moveContent(
double dx,
double dy );
823 virtual void setMoveContentPreviewOffset(
double dx,
double dy );
831 virtual void zoomContent(
double factor, QPointF point );
841 void beginCommand(
const QString &commandText,
UndoCommand command = UndoNone );
855 void cancelCommand();
860 bool shouldDrawItem()
const;
875 virtual void invalidateCache();
880 virtual void redraw();
899 virtual void setItemRotation(
double rotation,
bool adjustPosition =
true );
906 virtual void rotateItem(
double angle, QPointF transformOrigin );
925 void rotationChanged(
double newRotation );
930 void sizePositionChanged();
939 virtual void drawDebugRect( QPainter *painter );
983 virtual QSizeF applyItemSizeConstraint( QSizeF targetSize );
992 void refreshItemSize();
999 void refreshItemPosition();
1011 void refreshItemRotation( QPointF *origin =
nullptr );
1018 void refreshOpacity(
bool updateItem =
true );
1025 void refreshFrame(
bool updateItem =
true );
1032 void refreshBackgroundColor(
bool updateItem =
true );
1037 void refreshBlendMode();
1043 QPointF adjustPointForReferencePosition( QPointF point, QSizeF size,
ReferencePoint reference )
const;
1048 QPointF positionAtReferencePoint(
ReferencePoint reference )
const;
1064 virtual bool writePropertiesToElement( QDomElement &element, QDomDocument &document,
const QgsReadWriteContext &context )
const;
1081 virtual bool readPropertiesFromElement(
const QDomElement &element,
const QDomDocument &document,
const QgsReadWriteContext &context );
1091 bool mLayoutManagesZValue =
false;
1100 QString mTemplateUuid;
1103 QString mParentGroupUuid;
1111 double mItemRotation = 0.0;
1114 bool mExcludeFromExports =
false;
1120 bool mEvaluatedExcludeFromExports =
false;
1123 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
1124 std::unique_ptr< QgsLayoutEffect > mEffect;
1127 double mOpacity = 1.0;
1128 double mEvaluatedOpacity = 1.0;
1130 QImage mItemCachedImage;
1131 double mItemCacheDpi = -1;
1133 bool mIsLocked =
false;
1136 bool mFrame =
false;
1138 QColor mFrameColor = QColor( 0, 0, 0 );
1142 Qt::PenJoinStyle mFrameJoinStyle = Qt::MiterJoin;
1145 bool mBackground =
true;
1147 QColor mBackgroundColor = QColor( 255, 255, 255 );
1149 bool mBlockUndoCommands =
false;
1151 void initConnectionsToLayout();
1154 void preparePainter( QPainter *painter );
1155 bool shouldDrawAntialiased()
const;
1156 bool shouldDrawDebugRect()
const;
1157 QSizeF applyMinimumSize( QSizeF targetSize );
1158 QSizeF applyFixedSize( QSizeF targetSize );
1161 double applyDataDefinedRotation(
double rotation );
1162 void updateStoredItemPosition();
1163 QPointF itemPositionAtReferencePoint(
ReferencePoint reference, QSizeF size )
const;
1164 void setScenePos( QPointF destinationPos );
1165 bool shouldBlockUndoCommands()
const;
1167 void applyDataDefinedOrientation(
double &width,
double &height,
const QgsExpressionContext &context );
1169 friend class TestQgsLayoutItem;
1170 friend class TestQgsLayoutView;
1176 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLayoutItem::Flags )
1178 #endif //QGSLAYOUTITEM_H
The class is used as a container of context for various read/write operations on other objects...
Map grid frame pen color.
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the objects' current state.
ReferencePoint referencePoint() const
Returns the reference point for positioning of the layout item.
Base class for graphical items within a QgsLayout.
Lower left corner of item.
Base class for commands to undo/redo layout and layout object changes.
A layout item subclass for text labels.
UndoCommand
Layout item undo commands, used for collapsing undo commands.
virtual int numberExportLayers() const
Returns the number of layers that this item requires for exporting during layered exports (e...
A container for grouping several QgsLayoutItems.
A layout item subclass that displays SVG files or raster format images (jpg, png, ...
Scalebar secondary fill color.
virtual QgsLayoutSize minimumSize() const
Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely r...
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
virtual QgsLayoutSize fixedSize() const
Returns the fixed size of the item, if applicable, or an empty size if item can be freely resized...
Layout item for node based polygon shapes.
Lower right corner of item.
double itemOpacity() const
Returns the item's opacity.
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)
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
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.
A QGraphicsEffect subclass used for rendering layout items onto a scene with custom composition modes...
QgsLayoutMeasurement frameStrokeWidth() const
Returns the frame's stroke width.
Layout graphical items for displaying a map.
Layout item for node based polyline shapes.
Map grid frame fill color 1.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
Upper right corner of item.
Legend raster stroke color.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Layout item for basic filled shapes (e.g.
Map grid frame fill color 2.
Qt::PenJoinStyle frameJoinStyle() const
Returns the join style used for drawing the item's frame.
bool hasBackground() const
Returns true if the item has a background.
virtual QString uuid() const
Returns the item identification string.
Scalebar map units per segment.
const QgsRenderContext & renderContext() const
Returns a reference to the context's render context.
Base id for plugin based item undo commands.
Upper left corner of item.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Flag
Flags for controlling how an item behaves.
Map frame annotation color.
Contains settings and helpers relating to a render of a QgsLayoutItem.
virtual QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id=0, QUndoCommand *parent=nullptr)=0
Creates a new layout undo command with the specified text and parent.
Legend raster stroke width.
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
Contains information about the context of a rendering operation.
Map frame annotation distance.
double viewScaleFactor() const
Returns the current view zoom (scale factor).
Scalebar box context space.
QColor backgroundColor() const
Returns the background color for this item.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Interface for layout objects which support undo/redo commands.
QPainter::CompositionMode blendMode() const
Returns the item's composition blending mode.
Background color adjustment.
A layout item subclass for scale bars.
A base class for objects which belong to a layout.
QString id() const
Returns the item's ID name.
A layout item subclass for map legends.
virtual void refresh()
Refreshes the object, causing a recalculation of any property overrides.
bool isLocked() const
Returns true if the item is locked, and cannot be interacted with using the mouse.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Scalebar number of segments.
DataDefinedProperty
Data defined properties for different item types.
Base class for frame items, which form a layout multiframe item.
Legend icon symbol space.
bool frameEnabled() const
Returns true if the item includes a frame.
Item representing the paper in a layout.
Map atlas margin changed.
QColor frameStrokeColor() const
Returns the frame's stroke color.