QGIS API Documentation 3.41.0-Master (3291e9ff48b)
|
A layout item subclass for text labels. More...
#include <qgslayoutitemlabel.h>
Public Slots | |
void | convertToStaticText () |
Converts the label's text() to a static string, by evaluating any expressions included in the text and replacing them with their current values. | |
void | refresh () override |
Public Slots inherited from QgsLayoutItem | |
virtual void | invalidateCache () |
Forces a deferred update of any cached image the item uses. | |
virtual void | redraw () |
Triggers a redraw (update) of the item. | |
void | refresh () override |
Refreshes the item, causing a recalculation of any property overrides and recalculation of its position and size. | |
virtual void | refreshDataDefinedProperty (QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::DataDefinedProperty::AllProperties) |
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the item with this new value. | |
virtual void | rotateItem (double angle, QPointF transformOrigin) |
Rotates the item by a specified angle in degrees clockwise around a specified reference point. | |
virtual void | setItemRotation (double rotation, bool adjustPosition=true) |
Sets the layout item's rotation, in degrees clockwise. | |
Public Slots inherited from QgsLayoutObject | |
virtual void | refresh () |
Refreshes the object, causing a recalculation of any property overrides. | |
Public Member Functions | |
QgsLayoutItemLabel (QgsLayout *layout) | |
Constructor for QgsLayoutItemLabel, with the specified parent layout. | |
void | adjustSizeToText () |
Resizes the item so that the label's text fits to the item. | |
QRectF | boundingRect () const override |
QString | currentText () const |
Returns the text as it appears on the label (with evaluated expressions and other dynamic content). | |
QString | displayName () const override |
Gets item display name. | |
Q_DECL_DEPRECATED QFont | font () const |
Returns the label's current font. | |
Q_DECL_DEPRECATED QColor | fontColor () const |
Returns the label font color. | |
Qt::AlignmentFlag | hAlign () const |
Returns the horizontal alignment of the label. | |
QIcon | icon () const override |
Returns the item's icon. | |
double | marginX () const |
Returns the horizontal margin between the edge of the frame and the label contents, in layout units. | |
double | marginY () const |
Returns the vertical margin between the edge of the frame and the label contents, in layout units. | |
Mode | mode () const |
Returns the label's current mode. | |
Q_DECL_DEPRECATED void | setFont (const QFont &font) |
Sets the label's current font. | |
Q_DECL_DEPRECATED void | setFontColor (const QColor &color) |
Sets the label font color. | |
void | setFrameEnabled (bool drawFrame) override |
Sets whether this item has a frame drawn around it or not. | |
void | setFrameStrokeWidth (QgsLayoutMeasurement strokeWidth) override |
Sets the frame stroke width. | |
void | setHAlign (Qt::AlignmentFlag alignment) |
Sets the horizontal alignment of the label. | |
void | setMargin (double margin) |
Sets the margin between the edge of the frame and the label contents. | |
void | setMarginX (double margin) |
Sets the horizontal margin between the edge of the frame and the label contents, in layout units. | |
void | setMarginY (double margin) |
Sets the vertical margin between the edge of the frame and the label contents, in layout units. | |
void | setMode (Mode mode) |
Sets the label's current mode, allowing the label to switch between font based and HTML based rendering. | |
void | setText (const QString &text) |
Sets the label's preset text. | |
void | setTextFormat (const QgsTextFormat &format) |
Sets the text format used for drawing text in the label. | |
void | setVAlign (Qt::AlignmentFlag alignment) |
Sets for the vertical alignment of the label. | |
QSizeF | sizeForText () const |
Returns the required item size (in layout units) for the label's text to fill the item. | |
QString | text () const |
Returns the label's preset text. | |
QgsTextFormat | textFormat () const |
Returns the text format used for drawing text in the label. | |
int | type () const override |
Qt::AlignmentFlag | vAlign () const |
Returns for the vertical alignment of the label. | |
Public Member Functions inherited from QgsLayoutItem | |
QgsLayoutItem (QgsLayout *layout, bool manageZValue=true) | |
Constructor for QgsLayoutItem, with the specified parent layout. | |
~QgsLayoutItem () override | |
virtual bool | accept (QgsStyleEntityVisitorInterface *visitor) const |
Accepts the specified style entity visitor, causing it to visit all style entities associated with the layout item. | |
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 | attemptMoveBy (double deltaX, double deltaY) |
Attempts to shift the item's position by a specified deltaX and deltaY, in layout units. | |
virtual void | attemptResize (const QgsLayoutSize &size, bool includesFrame=false) |
Attempts to resize the item to a specified target size. | |
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 (bool useDataDefined=true) const |
Returns the background color for this item. | |
void | beginCommand (const QString &commandText, UndoCommand command=UndoNone) |
Starts new undo command for this item. | |
QPainter::CompositionMode | blendMode () const |
Returns the item's composition blending mode. | |
void | cancelCommand () |
Cancels the current item command and discards it. | |
virtual void | cleanup () |
Called just before a batch of items are deleted, allowing them to run cleanup tasks. | |
virtual QgsGeometry | clipPath () const |
Returns the clipping path generated by this item, in layout coordinates. | |
virtual bool | containsAdvancedEffects () const |
Returns true if the item contains contents with blend modes or transparency effects which can only be reproduced by rastering the item. | |
QgsAbstractLayoutUndoCommand * | createCommand (const QString &text, int id, QUndoCommand *parent=nullptr) override |
Creates a new layout undo command with the specified text and parent. | |
QgsExpressionContext | createExpressionContext () const override |
This method needs to be reimplemented in all classes which implement this interface and return an expression context. | |
void | endCommand () |
Completes the current item command and push it onto the layout's undo stack. | |
virtual double | estimatedFrameBleed () const |
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle. | |
bool | excludeFromExports () const |
Returns whether the item should be excluded from layout exports and prints. | |
virtual ExportLayerBehavior | exportLayerBehavior () const |
Returns the behavior of this item during exporting to layered exports (e.g. | |
virtual QgsLayoutItem::ExportLayerDetail | exportLayerDetails () const |
Returns the details for the specified current export layer. | |
virtual void | finalizeRestoreFromXml () |
Called after all pending items have been restored from XML. | |
virtual QgsLayoutSize | fixedSize () const |
Returns the fixed size of the item, if applicable, or an empty size if item can be freely resized. | |
bool | frameEnabled () const |
Returns true if the item includes a frame. | |
Qt::PenJoinStyle | frameJoinStyle () const |
Returns the join style used for drawing the item's frame. | |
QColor | frameStrokeColor () const |
Returns the frame's stroke color. | |
QgsLayoutMeasurement | frameStrokeWidth () const |
Returns the frame's stroke width. | |
bool | hasBackground () const |
Returns true if the item has a background. | |
QString | id () const |
Returns the item's ID name. | |
bool | isGroupMember () const |
Returns true if the item is part of a QgsLayoutItemGroup group. | |
bool | isLocked () const |
Returns true if the item is locked, and cannot be interacted with using the mouse. | |
virtual bool | isRefreshing () const |
Returns true if the item is currently refreshing content in the background. | |
virtual Flags | itemFlags () const |
Returns the item's flags, which indicate how the item behaves. | |
double | itemOpacity () const |
Returns the item's opacity. | |
double | itemRotation () const |
Returns the current rotation for the item, in degrees clockwise. | |
virtual QgsLayoutSize | minimumSize () const |
Returns the minimum allowed size of the item, if applicable, or an empty size if item can be freely resized. | |
virtual void | moveContent (double dx, double dy) |
Moves the content of the item, by a specified dx and dy in layout units. | |
virtual bool | nextExportPart () |
Moves to the next export part for a multi-layered export item, during a multi-layered export. | |
virtual Q_DECL_DEPRECATED int | numberExportLayers () const |
Returns the number of layers that this item requires for exporting during layered exports (e.g. | |
int | page () const |
Returns the page the item is currently on, with the first page returning 0. | |
QPointF | pagePos () const |
Returns the item's position (in layout units) relative to the top left corner of its current page. | |
QgsLayoutPoint | pagePositionWithUnits () const |
Returns the item's position (in item units) relative to the top left corner of its current page. | |
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. | |
QgsLayoutItemGroup * | parentGroup () const |
Returns the item's parent group, if the item is part of a QgsLayoutItemGroup group. | |
QgsLayoutPoint | positionWithUnits () const |
Returns the item's current position, including units. | |
bool | readXml (const QDomElement &itemElement, const QDomDocument &document, const QgsReadWriteContext &context) |
Sets the item state from a DOM element. | |
virtual QRectF | rectWithFrame () const |
Returns the item's rectangular bounds, including any bleed caused by the item's frame. | |
ReferencePoint | referencePoint () const |
Returns the reference point for positioning of the layout item. | |
virtual bool | requiresRasterization () const |
Returns true if the item is drawn in such a way that forces the whole layout to be rasterized when exporting to vector formats. | |
void | setBackgroundColor (const QColor &color) |
Sets the background color for this item. | |
void | setBackgroundEnabled (bool drawBackground) |
Sets whether this item has a background drawn under it or not. | |
void | setBlendMode (QPainter::CompositionMode mode) |
Sets the item's composition blending mode. | |
void | setExcludeFromExports (bool exclude) |
Sets whether the item should be excluded from layout exports and prints. | |
void | setFrameJoinStyle (Qt::PenJoinStyle style) |
Sets the join style used when drawing the item's frame. | |
void | setFrameStrokeColor (const QColor &color) |
Sets the frame stroke color. | |
virtual void | setId (const QString &id) |
Set the item's id name. | |
void | setItemOpacity (double opacity) |
Sets the item's opacity. | |
void | setLocked (bool locked) |
Sets whether the item is locked, preventing mouse interactions with the item. | |
virtual void | setMoveContentPreviewOffset (double dx, double dy) |
Sets temporary offset for the item, by a specified dx and dy in layout units. | |
void | setParentGroup (QgsLayoutItemGroup *group) |
Sets the item's parent group. | |
void | setReferencePoint (ReferencePoint point) |
Sets the reference point for positioning of the layout item. | |
virtual void | setSelected (bool selected) |
Sets whether the item should be selected. | |
virtual void | setVisibility (bool visible) |
Sets whether the item is visible. | |
bool | shouldDrawItem () const |
Returns whether the item should be drawn in the current context. | |
QgsLayoutSize | sizeWithUnits () const |
Returns the item's current size, including units. | |
virtual void | startLayeredExport () |
Starts a multi-layer export operation. | |
virtual void | stopLayeredExport () |
Stops a multi-layer export operation. | |
int | type () const override |
Returns a unique graphics item type identifier. | |
virtual QString | uuid () const |
Returns the item identification string. | |
bool | writeXml (QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const |
Stores the item state in a DOM element. | |
virtual void | zoomContent (double factor, QPointF point) |
Zooms content of item. | |
Public Member Functions inherited from QgsLayoutObject | |
QgsLayoutObject (QgsLayout *layout) | |
Constructor for QgsLayoutObject, with the specified parent layout. | |
QgsExpressionContext | createExpressionContext () const override |
Creates an expression context relating to the objects' current state. | |
QStringList | customProperties () const |
Returns list of keys stored in custom properties for the object. | |
QVariant | customProperty (const QString &key, const QVariant &defaultValue=QVariant()) const |
Read a custom property from the object. | |
QgsPropertyCollection & | dataDefinedProperties () |
Returns a reference to the object's property collection, used for data defined overrides. | |
const QgsPropertyCollection & | dataDefinedProperties () const |
Returns a reference to the object's property collection, used for data defined overrides. | |
QgsLayout * | layout () |
Returns the layout the object is attached to. | |
const QgsLayout * | layout () const |
Returns the layout the object is attached to. | |
void | removeCustomProperty (const QString &key) |
Remove a custom property from the object. | |
void | setCustomProperty (const QString &key, const QVariant &value) |
Set a custom property for the object. | |
void | setDataDefinedProperties (const QgsPropertyCollection &collection) |
Sets the objects's property collection, used for data defined overrides. | |
Public Member Functions inherited from QgsExpressionContextGenerator | |
virtual | ~QgsExpressionContextGenerator ()=default |
Public Member Functions inherited from QgsLayoutUndoObjectInterface | |
virtual | ~QgsLayoutUndoObjectInterface ()=default |
Static Public Member Functions | |
static QgsLayoutItemLabel * | create (QgsLayout *layout) |
Returns a new label item for the specified layout. | |
Static Public Member Functions inherited from QgsLayoutObject | |
static bool | propertyAssociatesWithParentMultiframe (DataDefinedProperty property) |
Returns true if the specified property key is normally associated with the parent QgsLayoutMultiFrame object instead of a child QgsLayoutFrame object. | |
static const QgsPropertiesDefinition & | propertyDefinitions () |
Returns the layout object property definitions. | |
Protected Member Functions | |
void | draw (QgsLayoutItemRenderContext &context) override |
Draws the item's contents using the specified item render context. | |
bool | readPropertiesFromElement (const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override |
Sets item state from a DOM element. | |
bool | writePropertiesToElement (QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override |
Stores item state within an XML DOM element. | |
Protected Member Functions inherited from QgsLayoutItem | |
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 corner of the item, if reference point were placed at the specified position. | |
QgsLayoutSize | applyDataDefinedSize (const QgsLayoutSize &size) |
Applies any present data defined size overrides to the specified layout size. | |
virtual QSizeF | applyItemSizeConstraint (QSizeF targetSize) |
Applies any item-specific size constraint handling to a given targetSize in layout units. | |
virtual void | drawBackground (QgsRenderContext &context) |
Draws the background for the item. | |
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. | |
void | drawRefreshingOverlay (QPainter *painter, const QStyleOptionGraphicsItem *itemStyle) |
Draws a "refreshing" overlay icon on the item. | |
virtual QPainterPath | framePath () const |
Returns the path to use when drawing the item's frame or background. | |
QPointF | positionAtReferencePoint (ReferencePoint reference) const |
Returns the current position (in layout units) of a reference point for the item. | |
void | refreshBackgroundColor (bool updateItem=true) |
Refresh item's background color, considering data defined colors. | |
void | refreshBlendMode () |
Refresh item's blend mode, considering data defined blend mode. | |
void | refreshFrame (bool updateItem=true) |
Refresh item's frame, considering data defined colors and frame size. | |
void | refreshItemPosition () |
Refreshes an item's position by rechecking it against any possible overrides such as data defined positioning. | |
void | refreshItemRotation (QPointF *origin=nullptr) |
Refreshes an item's rotation by rechecking it against any possible overrides such as data defined rotation. | |
void | refreshItemSize () |
Refreshes an item's size by rechecking it against any possible item fixed or minimum sizes. | |
void | refreshOpacity (bool updateItem=true) |
Refresh item's opacity, considering data defined opacity. | |
virtual void | setFixedSize (const QgsLayoutSize &size) |
Sets a fixed size for the layout item, which prevents it from being freely resized. | |
virtual void | setMinimumSize (const QgsLayoutSize &size) |
Sets the minimum allowed size for the layout item. | |
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 the specified point. | |
Protected Member Functions inherited from QgsLayoutObject | |
bool | readObjectPropertiesFromElement (const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context) |
Sets object properties from a DOM element. | |
bool | writeObjectPropertiesToElement (QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const |
Stores object properties within an XML DOM element. | |
Friends | |
class | QgsLayoutItemHtml |
Additional Inherited Members | |
Signals inherited from QgsLayoutItem | |
void | backgroundTaskCountChanged (int count) |
Emitted whenever the number of background tasks an item is executing changes. | |
void | clipPathChanged () |
Emitted when the item's clipping path has changed. | |
void | frameChanged () |
Emitted if the item's frame style changes. | |
void | lockChanged () |
Emitted if the item's lock status changes. | |
void | rotationChanged (double newRotation) |
Emitted on item rotation change. | |
void | sizePositionChanged () |
Emitted when the item's size or position changes. | |
Signals inherited from QgsLayoutObject | |
void | changed () |
Emitted when the object's properties change. | |
Protected Attributes inherited from QgsLayoutObject | |
QgsObjectCustomProperties | mCustomProperties |
Custom properties for object. | |
QgsPropertyCollection | mDataDefinedProperties |
QPointer< QgsLayout > | mLayout |
Properties inherited from QgsLayoutItem | |
bool | locked |
A layout item subclass for text labels.
Definition at line 34 of file qgslayoutitemlabel.h.
Label modes.
Enumerator | |
---|---|
ModeFont | Label displays text rendered using a single font. |
ModeHtml | Label displays rendered HTML content. |
Definition at line 41 of file qgslayoutitemlabel.h.
QgsLayoutItemLabel::QgsLayoutItemLabel | ( | QgsLayout * | layout | ) |
Constructor for QgsLayoutItemLabel, with the specified parent layout.
Definition at line 42 of file qgslayoutitemlabel.cpp.
void QgsLayoutItemLabel::adjustSizeToText | ( | ) |
Resizes the item so that the label's text fits to the item.
Keeps the top left point stationary.
Definition at line 324 of file qgslayoutitemlabel.cpp.
|
override |
Definition at line 486 of file qgslayoutitemlabel.cpp.
|
slot |
Converts the label's text() to a static string, by evaluating any expressions included in the text and replacing them with their current values.
Definition at line 510 of file qgslayoutitemlabel.cpp.
|
static |
Returns a new label item for the specified layout.
The caller takes responsibility for deleting the returned object.
Definition at line 75 of file qgslayoutitemlabel.cpp.
QString QgsLayoutItemLabel::currentText | ( | ) | const |
Returns the text as it appears on the label (with evaluated expressions and other dynamic content).
Definition at line 251 of file qgslayoutitemlabel.cpp.
|
overridevirtual |
Gets item display name.
This is the item's id if set, and if not, a user-friendly string identifying item type.
Reimplemented from QgsLayoutItem.
Definition at line 452 of file qgslayoutitemlabel.cpp.
|
overrideprotectedvirtual |
Draws the item's contents using the specified item render context.
Note that the context's painter has been scaled so that painter units are pixels. Use the QgsRenderContext methods to convert from millimeters or other units to the painter's units.
Implements QgsLayoutItem.
Definition at line 90 of file qgslayoutitemlabel.cpp.
QFont QgsLayoutItemLabel::font | ( | ) | const |
Returns the label's current font.
Definition at line 354 of file qgslayoutitemlabel.cpp.
|
inline |
Returns the label font color.
Definition at line 208 of file qgslayoutitemlabel.h.
|
inline |
Returns the horizontal alignment of the label.
Definition at line 135 of file qgslayoutitemlabel.h.
|
overridevirtual |
Returns the item's icon.
Reimplemented from QgsLayoutItem.
Definition at line 85 of file qgslayoutitemlabel.cpp.
|
inline |
Returns the horizontal margin between the edge of the frame and the label contents, in layout units.
Definition at line 157 of file qgslayoutitemlabel.h.
|
inline |
Returns the vertical margin between the edge of the frame and the label contents, in layout units.
Definition at line 165 of file qgslayoutitemlabel.h.
|
inline |
Returns the label's current mode.
Definition at line 100 of file qgslayoutitemlabel.h.
|
overrideprotectedvirtual |
Sets item state from a DOM element.
element | is the DOM element for the item |
document | DOM document |
context | read write context |
Note that item subclasses should not rely on all other items being present in the layout at the time this method is called. Instead, any connections and links to other items must be made in the finalizeRestoreFromXml() method. E.g. when restoring a scalebar, the connection to the linked map's signals should be implemented in finalizeRestoreFromXml(), not readPropertiesFromElement().
Reimplemented from QgsLayoutItem.
Definition at line 375 of file qgslayoutitemlabel.cpp.
|
overrideslot |
Definition at line 503 of file qgslayoutitemlabel.cpp.
void QgsLayoutItemLabel::setFont | ( | const QFont & | font | ) |
Sets the label's current font.
Definition at line 286 of file qgslayoutitemlabel.cpp.
|
inline |
Sets the label font color.
Definition at line 201 of file qgslayoutitemlabel.h.
|
overridevirtual |
Sets whether this item has a frame drawn around it or not.
Reimplemented from QgsLayoutItem.
Definition at line 491 of file qgslayoutitemlabel.cpp.
|
overridevirtual |
Sets the frame stroke width.
Reimplemented from QgsLayoutItem.
Definition at line 497 of file qgslayoutitemlabel.cpp.
|
inline |
Sets the horizontal alignment of the label.
Definition at line 142 of file qgslayoutitemlabel.h.
void QgsLayoutItemLabel::setMargin | ( | double | margin | ) |
Sets the margin between the edge of the frame and the label contents.
This method sets both the horizontal and vertical margins to the same value. The margins can be individually controlled using the setMarginX() and setMarginY() methods.
Margins are set using the current layout units.
Definition at line 305 of file qgslayoutitemlabel.cpp.
void QgsLayoutItemLabel::setMarginX | ( | double | margin | ) |
Sets the horizontal margin between the edge of the frame and the label contents, in layout units.
Definition at line 312 of file qgslayoutitemlabel.cpp.
void QgsLayoutItemLabel::setMarginY | ( | double | margin | ) |
Sets the vertical margin between the edge of the frame and the label contents, in layout units.
Definition at line 318 of file qgslayoutitemlabel.cpp.
void QgsLayoutItemLabel::setMode | ( | Mode | mode | ) |
Sets the label's current mode, allowing the label to switch between font based and HTML based rendering.
Definition at line 186 of file qgslayoutitemlabel.cpp.
void QgsLayoutItemLabel::setText | ( | const QString & | text | ) |
void QgsLayoutItemLabel::setTextFormat | ( | const QgsTextFormat & | format | ) |
Sets the text format used for drawing text in the label.
Definition at line 299 of file qgslayoutitemlabel.cpp.
|
inline |
Sets for the vertical alignment of the label.
Definition at line 149 of file qgslayoutitemlabel.h.
QSizeF QgsLayoutItemLabel::sizeForText | ( | ) | const |
Returns the required item size (in layout units) for the label's text to fill the item.
Definition at line 338 of file qgslayoutitemlabel.cpp.
|
inline |
Returns the label's preset text.
Definition at line 81 of file qgslayoutitemlabel.h.
QgsTextFormat QgsLayoutItemLabel::textFormat | ( | ) | const |
Returns the text format used for drawing text in the label.
Definition at line 294 of file qgslayoutitemlabel.cpp.
|
override |
Definition at line 80 of file qgslayoutitemlabel.cpp.
|
inline |
Returns for the vertical alignment of the label.
Definition at line 128 of file qgslayoutitemlabel.h.
|
overrideprotectedvirtual |
Stores item state within an XML DOM element.
element | is the DOM element to store the item's properties in |
document | DOM document |
context | read write context |
Reimplemented from QgsLayoutItem.
Definition at line 359 of file qgslayoutitemlabel.cpp.
|
friend |
Definition at line 298 of file qgslayoutitemlabel.h.