Class: QgsAnnotationLayer¶
- class qgis.core.QgsAnnotationLayer¶
Bases:
QgsMapLayer
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.New in version 3.16.
QgsAnnotationLayer(name: str, options: QgsAnnotationLayer.LayerOptions) Constructor for a new
QgsAnnotationLayer
with the specified layername
.The
options
argument specifies load-time layer options.Methods
Adds an
item
to the layer.Add error message
Applies an edit
operation
to the layer.Removes all items from the layer.
- rtype:
QgsAnnotationLayer
- param rendererContext:
- rtype:
QgsDataProvider
Called by
readLayerXML()
, used by derived classes to decode provider's specific data source from project files.Called by
writeLayerXML()
, used by derived classes to encode provider's specific data source to project files.- rtype:
QgsRectangle
Checks whether a new set of dependencies will introduce a cycle this method is now deprecated and always return
False
, because circular dependencies are now correctly managed.- rtype:
str
Invalidates the WGS84 extent.
- rtype:
bool
Returns
True
if the annotation layer is empty and contains no annotations.Returns the item with the specified
id
, orNone
if no matching item was found.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 rendercontext
.Returns the current paint effect for the layer.
- rtype:
Qgis.MapLayerProperties
Read style data common to all layer types
Read custom properties from project file.
- param node:
Read style manager's configuration (if any).
- param node:
- param layerNode:
Removes (and deletes) the item with matching
id
.Replaces the existing item with matching
id
with a newitem
.Resets the annotation layer to a default state, and clears all items from it.
Sets error message
Sets the extent
Sets the extent
Sets the current paint
effect
for the layer.Sets the
providerType
(provider key)- param context:
Sets whether layer is valid or not
- rtype:
bool
Write style data common to all layer types
Write custom properties to project file.
- param node:
Write style manager's configuration (if exists).
- param node:
- param layer_node:
- class LayerOptions(transformContext: QgsCoordinateTransformContext)¶
Bases:
sip.wrapper
Constructor for LayerOptions.
QgsAnnotationLayer.LayerOptions(QgsAnnotationLayer.LayerOptions)
- transformContext¶
- addItem(self, item: QgsAnnotationItem) str ¶
Adds an
item
to the layer.Ownership of
item
is transferred to the layer.Returns the unique ID assigned to the item.
- Parameters:
item (QgsAnnotationItem) –
- Return type:
str
- appendError(self, error: QgsErrorMessage)¶
Add error message
- applyEdit(self, operation: QgsAbstractAnnotationItemEditOperation) Qgis.AnnotationItemEditOperationResult ¶
Applies an edit
operation
to the layer.Returns
True
if the operation was successfully applied.New in version 3.22.
- Parameters:
operation (QgsAbstractAnnotationItemEditOperation) –
- Return type:
- childEvent(self, QChildEvent)¶
- clear(self)¶
Removes all items from the layer.
- clone(self) QgsAnnotationLayer ¶
- Return type:
- connectNotify(self, QMetaMethod)¶
- createMapRenderer(self, rendererContext: QgsRenderContext) QgsMapLayerRenderer ¶
- Parameters:
rendererContext (QgsRenderContext) –
- Return type:
- customEvent(self, QEvent)¶
- dataProvider(self) QgsDataProvider ¶
- Return type:
- decodedSource(self, source: str, dataProvider: str, context: QgsReadWriteContext) str ¶
Called by
readLayerXML()
, used by derived classes to decode provider’s specific data source from project files. Typically resolving absolute or relative paths, usernames and passwords or drivers prefixes (“HDF5:”)- Parameters:
source – data source to decode, typically read from layer’s DOM element “datasource”
dataProvider – string identification of data provider (e.g. “ogr”), typically read from layer’s DOM element
context – reading context (e.g. for conversion between relative and absolute paths)
- Returns:
decoded source, typically to be used as the layer’s datasource
New in version 3.2.
- disconnectNotify(self, QMetaMethod)¶
- encodedSource(self, source: str, context: QgsReadWriteContext) str ¶
Called by
writeLayerXML()
, used by derived classes to encode provider’s specific data source to project files. Typically resolving absolute or relative paths, usernames and passwords or drivers prefixes (“HDF5:”)- Parameters:
source – data source to encode, typically
QgsMapLayer.source()
context – writing context (e.g. for conversion between relative and absolute paths)
- Returns:
encoded source, typically to be written in the DOM element “datasource”
New in version 3.2.
- extent(self) QgsRectangle ¶
- Return type:
- hasDependencyCycle(self, Iterable[QgsMapLayerDependency]) bool ¶
Checks whether a new set of dependencies will introduce a cycle this method is now deprecated and always return
False
, because circular dependencies are now correctly managed.Deprecated since version QGIS: 3.10
- htmlMetadata(self) str ¶
- Return type:
str
- invalidateWgs84Extent(self)¶
Invalidates the WGS84 extent. If FlagTrustLayerMetadata is enabled, the extent is not invalidated because we want to trust metadata whatever happens.
New in version 3.20.
- isEditable(self) bool ¶
- Return type:
bool
- isEmpty(self) bool ¶
Returns
True
if the annotation layer is empty and contains no annotations.- Return type:
bool
- isSignalConnected(self, QMetaMethod) bool ¶
- item(self, id: str) QgsAnnotationItem ¶
Returns the item with the specified
id
, orNone
if no matching item was found.New in version 3.22.
- Parameters:
id (str) –
- Return type:
- items(self) object ¶
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:
object
- itemsInBounds(self, bounds: QgsRectangle, context: QgsRenderContext, feedback: QgsFeedback = None) List[str] ¶
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.New in version 3.22.
- Parameters:
bounds (QgsRectangle) –
context (QgsRenderContext) –
feedback (
QgsFeedback
= None) –
- Return type:
List[str]
- paintEffect(self) QgsPaintEffect ¶
Returns the current paint effect for the layer.
See also
New in version 3.22.
- Return type:
- properties(self) Qgis.MapLayerProperties ¶
- Return type:
- readCommonStyle(self, layerElement: QDomElement, context: QgsReadWriteContext, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories)¶
Read style data common to all layer types
- readCustomProperties(self, layerNode: QDomNode, keyStartsWith: str = '')¶
Read custom properties from project file.
- Parameters:
layerNode – note to read from
keyStartsWith – reads only properties starting with the specified string (or all if the string is empty)
- readStyle(self, node: QDomNode, errorMessage: str, context: QgsReadWriteContext, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory) bool ¶
- Parameters:
node (QDomNode) –
errorMessage (str) –
context (QgsReadWriteContext) –
categories (Union[QgsMapLayer.StyleCategories) –
- Return type:
bool
- readStyleManager(self, layerNode: QDomNode)¶
Read style manager’s configuration (if any). To be called by subclasses.
- readSymbology(self, node: QDomNode, errorMessage: str, context: QgsReadWriteContext, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories) bool ¶
- Parameters:
node (QDomNode) –
errorMessage (str) –
context (QgsReadWriteContext) –
categories (Union[QgsMapLayer.StyleCategories) –
- Return type:
bool
- readXml(self, layerNode: QDomNode, context: QgsReadWriteContext) bool ¶
- Parameters:
layerNode (QDomNode) –
context (QgsReadWriteContext) –
- Return type:
bool
- receivers(self, PYQT_SIGNAL) int ¶
- removeItem(self, id: str) bool ¶
Removes (and deletes) the item with matching
id
.- Parameters:
id (str) –
- Return type:
bool
- replaceItem(self, id: str, item: QgsAnnotationItem)¶
Replaces the existing item with matching
id
with a newitem
.Ownership of
item
is transferred to the layer.New in version 3.22.
- Parameters:
id (str) –
item (QgsAnnotationItem) –
- reset(self)¶
Resets the annotation layer to a default state, and clears all items from it.
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setExtent(self, rect: QgsRectangle)¶
Sets the extent
- setPaintEffect(self, effect: QgsPaintEffect)¶
Sets the current paint
effect
for the layer.Ownership is transferred to the renderer.
See also
New in version 3.22.
- Parameters:
effect (QgsPaintEffect) –
- setProviderType(self, providerType: str)¶
Sets the
providerType
(provider key)
- setTransformContext(self, context: QgsCoordinateTransformContext)¶
- Parameters:
context (QgsCoordinateTransformContext) –
- setValid(self, valid: bool)¶
Sets whether layer is valid or not
- supportsEditing(self) bool ¶
- Return type:
bool
- timerEvent(self, QTimerEvent)¶
- writeCommonStyle(self, layerElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories)¶
Write style data common to all layer types
- writeCustomProperties(self, layerNode: QDomNode, doc: QDomDocument)¶
Write custom properties to project file.
- writeStyle(self, node: QDomNode, doc: QDomDocument, errorMessage: str, context: QgsReadWriteContext, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory) bool ¶
- Parameters:
node (QDomNode) –
doc (QDomDocument) –
errorMessage (str) –
context (QgsReadWriteContext) –
categories (Union[QgsMapLayer.StyleCategories) –
- Return type:
bool
- writeStyleManager(self, layerNode: QDomNode, doc: QDomDocument)¶
Write style manager’s configuration (if exists). To be called by subclasses.
- writeSymbology(self, node: QDomNode, doc: QDomDocument, errorMessage: str, a3: QgsReadWriteContext, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories) bool ¶
- Parameters:
node (QDomNode) –
doc (QDomDocument) –
errorMessage (str) –
a3 (QgsReadWriteContext) –
categories (Union[QgsMapLayer.StyleCategories) –
- Return type:
bool
- writeXml(self, layer_node: QDomNode, doc: QDomDocument, context: QgsReadWriteContext) bool ¶
- Parameters:
layer_node (QDomNode) –
doc (QDomDocument) –
context (QgsReadWriteContext) –
- Return type:
bool