Class: QgsAnnotationLayer¶
Represents a map layer containing a set of georeferenced annotations, e.g. markers, lines, polygons or text items.
Annotation layers store a set of QgsAnnotationItem
items,
which are rendered according to the item’s z-order.
Added in version 3.16.
Class Hierarchy¶
Base classes¶
Base class for all map layer types. |
|
Methods
Adds an item to the layer. |
|
Applies an edit operation to the layer. |
|
Applies an edit operation to the layer. |
|
Removes all items from the layer. |
|
Returns |
|
Returns the item with the specified id, or |
|
Returns a map of items contained in the layer, by unique item ID. |
|
Returns a list of the IDs of all annotation items within the specified bounds (in layer CRS), when rendered using the given render context. |
|
Returns a linked layer, where the items in this annotation layer will only be visible when the linked layer is also visible. |
|
Returns the current paint effect for the layer. |
|
Removes (and deletes) the item with matching id. |
|
Replaces the existing item with matching id with a new item. |
|
Resets the annotation layer to a default state, and clears all items from it. |
|
Sets a linked layer, where the items in this annotation layer will only be visible when the linked layer is also visible. |
|
Sets the current paint effect for the layer. |
- class qgis.core.QgsAnnotationLayer[source]¶
Bases:
QgsMapLayer
- __init__(name: str | None, options: QgsAnnotationLayer.LayerOptions)
Constructor for a new QgsAnnotationLayer with the specified layer
name
.The
options
argument specifies load-time layer options.- Parameters:
name (Optional[str])
options (QgsAnnotationLayer.LayerOptions)
- class LayerOptions¶
Bases:
object
Setting options for loading annotation layers.
Added in version 3.16.
- addItem(self, item: QgsAnnotationItem | None) str [source]¶
Adds an
item
to the layer.Ownership of
item
is transferred to the layer.Returns the unique ID assigned to the item.
- Parameters:
item (Optional[QgsAnnotationItem])
- Return type:
str
- applyEdit(self, operation: QgsAbstractAnnotationItemEditOperation | None) Qgis.AnnotationItemEditOperationResult [source]¶
Applies an edit
operation
to the layer.Returns
True
if the operation was successfully applied.Deprecated since version 3.40: Use
applyEditV2()
instead.- Parameters:
operation (Optional[QgsAbstractAnnotationItemEditOperation])
- Return type:
- applyEditV2(self, operation: QgsAbstractAnnotationItemEditOperation | None, context: QgsAnnotationItemEditContext) Qgis.AnnotationItemEditOperationResult [source]¶
Applies an edit
operation
to the layer.Returns
True
if the operation was successfully applied.Added in version 3.40.
- Parameters:
operation (Optional[QgsAbstractAnnotationItemEditOperation])
context (QgsAnnotationItemEditContext)
- Return type:
- isEmpty(self) bool [source]¶
Returns
True
if the annotation layer is empty and contains no annotations.- Return type:
bool
- item(self, id: str | None) QgsAnnotationItem | None [source]¶
Returns the item with the specified
id
, orNone
if no matching item was found.Added in version 3.22.
- Parameters:
id (Optional[str])
- Return type:
Optional[QgsAnnotationItem]
- items(self) Any ¶
Returns a map of items contained in the layer, by unique item ID.
This map contains references to items owned by the layer, and ownership of these remains with the layer.
- Return type:
Any
- itemsInBounds(self, bounds: QgsRectangle, context: QgsRenderContext, feedback: QgsFeedback | None = None) List[str] [source]¶
Returns a list of the IDs of all annotation items within the specified
bounds
(in layer CRS), when rendered using the given rendercontext
.The optional
feedback
argument can be used to cancel the search early.Added in version 3.22.
- Parameters:
bounds (QgsRectangle)
context (QgsRenderContext)
feedback (Optional[QgsFeedback] = None)
- Return type:
List[str]
- linkedVisibilityLayer(self) QgsMapLayer | None [source]¶
Returns a linked layer, where the items in this annotation layer will only be visible when the linked layer is also visible.
See also
Added in version 3.40.
- Return type:
Optional[QgsMapLayer]
- paintEffect(self) QgsPaintEffect | None [source]¶
Returns the current paint effect for the layer.
See also
Added in version 3.22.
- Return type:
Optional[QgsPaintEffect]
- removeItem(self, id: str | None) bool [source]¶
Removes (and deletes) the item with matching
id
.- Parameters:
id (Optional[str])
- Return type:
bool
- replaceItem(self, id: str | None, item: QgsAnnotationItem | None)[source]¶
Replaces the existing item with matching
id
with a newitem
.Ownership of
item
is transferred to the layer.Added in version 3.22.
- Parameters:
id (Optional[str])
item (Optional[QgsAnnotationItem])
- setLinkedVisibilityLayer(self, layer: QgsMapLayer | None)[source]¶
Sets a linked
layer
, where the items in this annotation layer will only be visible when the linked layer is also visible.See also
Added in version 3.40.
- Parameters:
layer (Optional[QgsMapLayer])
- setPaintEffect(self, effect: QgsPaintEffect | None)[source]¶
Sets the current paint
effect
for the layer.Ownership is transferred to the renderer.
See also
Added in version 3.22.
- Parameters:
effect (Optional[QgsPaintEffect])