QgsAnnotationManager class

Manages storage of a set of QgsAnnotation annotation objects.

QgsAnnotationManager handles the storage, serializing and deserializing of QgsAnnotations. Usually this class is not constructed directly, but rather accessed through a QgsProject via QgsProject::annotationManager().

QgsAnnotationManager retains ownership of all the annotations contained in the manager.

Constructors, destructors, conversion operators

QgsAnnotationManager(QgsProject* project = nullptr) explicit
Constructor for QgsAnnotationManager.

Public functions

auto addAnnotation(QgsAnnotation* annotation) -> bool
Adds an annotation to the manager.
auto annotations() const -> QList<QgsAnnotation*>
Returns a list of all annotations contained in the manager.
void clear()
Removes and deletes all annotations from the manager.
auto cloneAnnotations() const -> QList<QgsAnnotation*>
Returns a list containing clones of all annotations contained in the manager.
auto readXml(const QDomElement& element, const QgsReadWriteContext& context) -> bool
Reads the manager's state from a DOM element, restoring all annotations present in the XML document.
auto removeAnnotation(QgsAnnotation* annotation) -> bool
Removes an annotation from the manager.
auto writeXml(QDomDocument& doc, const QgsReadWriteContext& context) const -> QDomElement
Returns a DOM element representing the state of the manager.

Signals

void annotationAboutToBeRemoved(QgsAnnotation* annotation)
Emitted when an annotation is about to be removed from the manager.
void annotationAdded(QgsAnnotation* annotation)
Emitted when a annotation has been added to the manager.
void annotationRemoved()
Emitted when an annotation was removed from the manager.

Function documentation

QgsAnnotationManager::QgsAnnotationManager(QgsProject* project = nullptr) explicit

Constructor for QgsAnnotationManager.

The project will become the parent object for this manager.

bool QgsAnnotationManager::addAnnotation(QgsAnnotation* annotation)

Adds an annotation to the manager.

Ownership of the annotation is transferred to the manager. Returns true if the addition was successful, or false if the annotation could not be added.

QList<QgsAnnotation*> QgsAnnotationManager::annotations() const

Returns a list of all annotations contained in the manager.

void QgsAnnotationManager::clear()

Removes and deletes all annotations from the manager.

QList<QgsAnnotation*> QgsAnnotationManager::cloneAnnotations() const

Returns a list containing clones of all annotations contained in the manager.

The caller takes responsibility for deleting all returned annotations.

bool QgsAnnotationManager::readXml(const QDomElement& element, const QgsReadWriteContext& context)

Reads the manager's state from a DOM element, restoring all annotations present in the XML document.

bool QgsAnnotationManager::removeAnnotation(QgsAnnotation* annotation)

Removes an annotation from the manager.

The annotation is deleted. Returns true if the removal was successful, or false if the removal failed (eg as a result of removing an annotation which is not contained in the manager).

QDomElement QgsAnnotationManager::writeXml(QDomDocument& doc, const QgsReadWriteContext& context) const

Returns a DOM element representing the state of the manager.