Class: QgsAnnotationItem¶
Abstract base class for annotation items which are drawn with
QgsAnnotationLayers
.
Added in version 3.16.
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: boundingBox()
, clone()
, readXml()
, render()
, type()
, writeXml()
Class Hierarchy¶
Subclasses¶
An annotation item which renders a line symbol along a line geometry. |
|
An annotation item which renders text along a line geometry. |
|
An annotation item which renders a marker symbol at a point location. |
|
Abstract base class for annotation items which render annotations in a rectangular shape. |
|
An annotation item which renders a text string at a point location. |
|
An annotation item which renders a fill symbol for a polygon geometry. |
Abstract Methods
Returns the bounding box of the item's geographic location, in the parent layer's coordinate reference system. |
|
Returns a clone of the item. |
|
Reads the item's state from the given DOM element. |
|
Renders the item to the specified render context. |
|
Returns a unique (untranslated) string identifying the type of item. |
|
Writes the item's state into an XML element. |
Methods
Returns the item's callout renderer, responsible for drawing item callouts. |
|
Returns the callout's anchor geometry. |
|
Returns |
|
Returns the (optional) offset of the annotation item from the |
|
Returns the units for the |
|
Renders the item's callout. |
|
Sets the item's callout renderer, responsible for drawing item callouts. |
|
Sets the callout's anchor geometry. |
|
Sets if the item will be rendered or not in the layer. |
|
Sets the offset of the annotation item from the |
|
Sets the unit for the |
|
Sets the annotation's symbology reference scale. |
|
Sets whether the annotation item uses a symbology reference scale. |
|
Sets the item's z index, which controls the order in which annotation items are rendered in the layer. |
|
Returns the annotation's symbology reference scale. |
|
Returns |
|
Returns the item's z index, which controls the order in which annotation items are rendered in the layer. |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsAnnotationItem. See the FAQ for more details.
Applies an edit operation to the item. |
|
Applies an edit operation to the item. |
|
Copies common properties from the base class from an other item. |
|
Returns item flags. |
|
Returns the nodes for the item, used for editing the item. |
|
Returns the nodes for the item, used for editing the item. |
|
Reads common properties from the base class from the given DOM element. |
|
Retrieves the results of a transient (in progress) edit operation on the item. |
|
Retrieves the results of a transient (in progress) edit operation on the item. |
|
Writes common properties from the base class into an XML element. |
- class qgis.core.QgsAnnotationItem[source]¶
Bases:
object
- virtual applyEdit(self, operation: QgsAbstractAnnotationItemEditOperation | None) Qgis.AnnotationItemEditOperationResult [source]¶
Applies an edit
operation
to the item.Deprecated since version 3.40: Use
applyEditV2()
instead.- Parameters:
operation (Optional[QgsAbstractAnnotationItemEditOperation])
- Return type:
- virtual applyEditV2(self, operation: QgsAbstractAnnotationItemEditOperation | None, context: QgsAnnotationItemEditContext) Qgis.AnnotationItemEditOperationResult [source]¶
Applies an edit
operation
to the item.Added in version 3.40.
- Parameters:
operation (Optional[QgsAbstractAnnotationItemEditOperation])
context (QgsAnnotationItemEditContext)
- Return type:
- abstract boundingBox(self) QgsRectangle [source]¶
Returns the bounding box of the item’s geographic location, in the parent layer’s coordinate reference system.
- Return type:
- abstract boundingBox(self, context: QgsRenderContext) QgsRectangle [source]
Returns the bounding box of the item’s geographic location, in the parent layer’s coordinate reference system.
- Parameters:
context (
QgsRenderContext
)- Return type:
- callout(self) QgsCallout | None [source]¶
Returns the item’s callout renderer, responsible for drawing item callouts.
Ownership is not transferred.
By default items do not have a callout, and it is necessary to be explicitly set a callout style (via
setCallout()
) and set the callout anchor geometry (via setsetCalloutAnchor()
).Note
Callouts are only supported by items which return
Qgis
.AnnotationItemFlag.SupportsCallouts fromflags()
.See also
See also
Added in version 3.40.
- Return type:
Optional[QgsCallout]
- calloutAnchor(self) QgsGeometry [source]¶
Returns the callout’s anchor geometry.
The anchor dictates the geometry which the option item
callout()
should connect to. Depending on the callout subclass and anchor geometry type, the actual shape of the rendered callout may vary.The callout anchor geometry is in the parent layer’s coordinate reference system.
See also
See also
Added in version 3.40.
- Return type:
- abstract clone(self) QgsAnnotationItem | None [source]¶
Returns a clone of the item. Ownership is transferred to the caller.
Implementations should include a call to
copyCommonProperties()
to copy the base class properties.See also
- Return type:
Optional[QgsAnnotationItem]
- virtual copyCommonProperties(self, other: QgsAnnotationItem | None)[source]¶
Copies common properties from the base class from an
other
item.Added in version 3.22.
- Parameters:
other (Optional[QgsAnnotationItem])
- enabled(self) bool [source]¶
Returns
True
if the item is enabled and will be rendered in the layer.See also
Added in version 3.36.
- Return type:
bool
- virtual flags(self) Qgis.AnnotationItemFlags [source]¶
Returns item flags.
Added in version 3.22.
- Return type:
- virtual nodes(self) List[QgsAnnotationItemNode] ¶
Returns the nodes for the item, used for editing the item.
Deprecated since version 3.40: Use
nodesV2()
instead.- Return type:
List[QgsAnnotationItemNode]
- virtual nodesV2(self, context: QgsAnnotationItemEditContext) List[QgsAnnotationItemNode] ¶
Returns the nodes for the item, used for editing the item.
Added in version 3.40.
- Parameters:
context (QgsAnnotationItemEditContext)
- Return type:
List[QgsAnnotationItemNode]
- offsetFromCallout(self) QSizeF [source]¶
Returns the (optional) offset of the annotation item from the
calloutAnchor()
.Some annotation item subclasses support placement relative to the callout anchor. For these items, the offset from callout defines how far (in screen/page units) the item should be placed from the anchor point.
Units are defined by
offsetFromCalloutUnit()
See also
Added in version 3.40.
- Return type:
QSizeF
- offsetFromCalloutUnit(self) Qgis.RenderUnit [source]¶
Returns the units for the
offsetFromCallout()
.See also
See also
Added in version 3.40.
- Return type:
- virtual readCommonProperties(self, element: QDomElement, context: QgsReadWriteContext) bool [source]¶
Reads common properties from the base class from the given DOM
element
.See also
Added in version 3.22.
- Parameters:
element (QDomElement)
context (QgsReadWriteContext)
- Return type:
bool
- abstract readXml(self, element: QDomElement, context: QgsReadWriteContext) bool [source]¶
Reads the item’s state from the given DOM
element
.Implementations should include a call to
readCommonProperties()
to read the base class properties.See also
See also
- Parameters:
element (QDomElement)
context (QgsReadWriteContext)
- Return type:
bool
- abstract render(self, context: QgsRenderContext, feedback: QgsFeedback | None)[source]¶
Renders the item to the specified render
context
.The
feedback
argument can be used to detect render cancellations during expensive render operations.- Parameters:
context (QgsRenderContext)
feedback (Optional[QgsFeedback])
- renderCallout(self, context: QgsRenderContext, rect: QRectF, angle: float, calloutContext: QgsCallout.QgsCalloutContext, feedback: QgsFeedback | None)[source]¶
Renders the item’s callout.
The item must have valid
callout()
set.Added in version 3.40.
- Parameters:
context (QgsRenderContext)
rect (QRectF)
angle (float)
calloutContext (QgsCallout.QgsCalloutContext)
feedback (Optional[QgsFeedback])
- setCallout(self, callout: QgsCallout | None)[source]¶
Sets the item’s
callout
renderer, responsible for drawing item callouts.Ownership of
callout
is transferred to the item.Note
Callouts are only supported by items which return
Qgis
.AnnotationItemFlag.SupportsCallouts fromflags()
.See also
See also
Added in version 3.40.
- Parameters:
callout (Optional[QgsCallout])
- setCalloutAnchor(self, anchor: QgsGeometry)[source]¶
Sets the callout’s
anchor
geometry.The anchor dictates the geometry which the option item
callout()
should connect to. Depending on the callout subclass and anchor geometry type, the actual shape of the rendered callout may vary.The callout
anchor
geometry must be specified in the parent layer’s coordinate reference system.See also
See also
Added in version 3.40.
- Parameters:
anchor (QgsGeometry)
- setEnabled(self, enabled: bool)[source]¶
Sets if the item will be rendered or not in the layer.
See also
Added in version 3.36.
- Parameters:
enabled (bool)
- setOffsetFromCallout(self, offset: QSizeF)[source]¶
Sets the offset of the annotation item from the
calloutAnchor()
.Some annotation item subclasses support placement relative to the callout anchor. For these items, the offset from callout defines how far (in screen/page units) the item should be placed from the anchor point.
Units are defined by
offsetFromCalloutUnit()
See also
Added in version 3.40.
- Parameters:
offset (QSizeF)
- setOffsetFromCalloutUnit(self, unit: Qgis.RenderUnit)[source]¶
Sets the
unit
for theoffsetFromCallout()
.See also
See also
Added in version 3.40.
- Parameters:
unit (Qgis.RenderUnit)
- setSymbologyReferenceScale(self, scale: float)[source]¶
Sets the annotation’s symbology reference
scale
.The reference scale will only be used if
useSymbologyReferenceScale()
returnsTrue
.This represents the desired scale denominator for the rendered map, eg 1000.0 for a 1:1000 map render.
The symbology reference scale is an optional property which specifies the reference scale at which symbology in paper units (such a millimeters or points) is fixed to. For instance, if the scale is 1000 then a 2mm thick line will be rendered at exactly 2mm thick when a map is rendered at 1:1000, or 1mm thick when rendered at 1:2000, or 4mm thick at 1:500.
See also
See also
- Parameters:
scale (float)
- setUseSymbologyReferenceScale(self, enabled: bool)[source]¶
Sets whether the annotation item uses a symbology reference scale.
See also
See also
- Parameters:
enabled (bool)
- setZIndex(self, index: int)[source]¶
Sets the item’s z
index
, which controls the order in which annotation items are rendered in the layer.See also
- Parameters:
index (int)
- symbologyReferenceScale(self) float [source]¶
Returns the annotation’s symbology reference scale.
The reference scale will only be used if
useSymbologyReferenceScale()
returnsTrue
.This represents the desired scale denominator for the rendered map, eg 1000.0 for a 1:1000 map render.
The symbology reference scale is an optional property which specifies the reference scale at which symbology in paper units (such a millimeters or points) is fixed to. For instance, if the scale is 1000 then a 2mm thick line will be rendered at exactly 2mm thick when a map is rendered at 1:1000, or 1mm thick when rendered at 1:2000, or 4mm thick at 1:500.
See also
See also
- Return type:
float
- virtual transientEditResults(self, operation: QgsAbstractAnnotationItemEditOperation | None) QgsAnnotationItemEditOperationTransientResults | None [source]¶
Retrieves the results of a transient (in progress) edit
operation
on the item.Deprecated since version 3.40: Use
transientEditResultsV2()
instead.- Parameters:
operation (Optional[QgsAbstractAnnotationItemEditOperation])
- Return type:
- virtual transientEditResultsV2(self, operation: QgsAbstractAnnotationItemEditOperation | None, context: QgsAnnotationItemEditContext) QgsAnnotationItemEditOperationTransientResults | None [source]¶
Retrieves the results of a transient (in progress) edit
operation
on the item.Added in version 3.40.
- Parameters:
operation (Optional[QgsAbstractAnnotationItemEditOperation])
context (QgsAnnotationItemEditContext)
- Return type:
- abstract type(self) str [source]¶
Returns a unique (untranslated) string identifying the type of item.
- Return type:
str
- useSymbologyReferenceScale(self) bool [source]¶
Returns
True
if the annotation item uses a symbology reference scale.See also
See also
- Return type:
bool
- virtual writeCommonProperties(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool [source]¶
Writes common properties from the base class into an XML
element
.See also
Added in version 3.22.
- Parameters:
element (QDomElement)
document (QDomDocument)
context (QgsReadWriteContext)
- Return type:
bool
- abstract writeXml(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool [source]¶
Writes the item’s state into an XML
element
.Implementations should include a call to
writeCommonProperties()
to store the base class properties.See also
See also
- Parameters:
element (QDomElement)
document (QDomDocument)
context (QgsReadWriteContext)
- Return type:
bool