39 if ( mAnnotations.contains( annotation ) )
42 mAnnotations << annotation;
53 if ( !mAnnotations.contains( annotation ) )
57 mAnnotations.removeAll( annotation );
66 for (
auto *a : qgis::as_const( mAnnotations ) )
79 QList<QgsAnnotation *> results;
80 for (
const auto *a : qgis::as_const( mAnnotations ) )
82 results << a->clone();
93 QDomElement annotationsElem = element.firstChildElement( QStringLiteral(
"Annotations" ) );
95 QDomNodeList annotationNodes = annotationsElem.elementsByTagName( QStringLiteral(
"Annotation" ) );
96 for (
int i = 0; i < annotationNodes.size(); ++i )
98 createAnnotationFromXml( annotationNodes.at( i ).toElement(), context );
102 QDomNodeList oldItemList = element.elementsByTagName( QStringLiteral(
"TextAnnotationItem" ) );
103 for (
int i = 0; i < oldItemList.size(); ++i )
105 createAnnotationFromXml( oldItemList.at( i ).toElement(), context );
107 oldItemList = element.elementsByTagName( QStringLiteral(
"FormAnnotationItem" ) );
108 for (
int i = 0; i < oldItemList.size(); ++i )
110 createAnnotationFromXml( oldItemList.at( i ).toElement(), context );
112 oldItemList = element.elementsByTagName( QStringLiteral(
"HtmlAnnotationItem" ) );
113 for (
int i = 0; i < oldItemList.size(); ++i )
115 createAnnotationFromXml( oldItemList.at( i ).toElement(), context );
117 oldItemList = element.elementsByTagName( QStringLiteral(
"SVGAnnotationItem" ) );
118 for (
int i = 0; i < oldItemList.size(); ++i )
120 createAnnotationFromXml( oldItemList.at( i ).toElement(), context );
128 QDomElement annotationsElem = doc.createElement( QStringLiteral(
"Annotations" ) );
129 QListIterator<QgsAnnotation *> i( mAnnotations );
132 while ( i.hasPrevious() )
141 annotation->
writeXml( annotationsElem, doc, context );
143 return annotationsElem;
146 void QgsAnnotationManager::createAnnotationFromXml(
const QDomElement &element,
const QgsReadWriteContext &context )
148 QString type = element.tagName();
153 annotation->
readXml( element, context );
void clear()
Removes and deletes all annotations from the manager.
void setDirty(bool b=true)
Flag the project as dirty (modified).
The class is used as a container of context for various read/write operations on other objects...
~QgsAnnotationManager() override
static QgsAnnotationRegistry * annotationRegistry()
Returns the application's annotation registry, used for managing annotation types.
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.
virtual void writeXml(QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context) const =0
Writes the annotation state to a DOM element.
Abstract base class for annotation items which are drawn over a map.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Returns a DOM element representing the state of the manager.
bool addAnnotation(QgsAnnotation *annotation)
Adds an annotation to the manager.
QgsCoordinateReferenceSystem crs
void annotationAboutToBeRemoved(QgsAnnotation *annotation)
Emitted when an annotation is about to be removed from the manager.
virtual void readXml(const QDomElement &itemElem, const QgsReadWriteContext &context)=0
Restores the annotation's state from a DOM element.
Reads and writes project states.
QgsCoordinateReferenceSystem mapPositionCrs() const
Returns the CRS of the map position, or an invalid CRS if the annotation does not have a fixed map po...
QList< QgsAnnotation *> annotations() const
Returns a list of all annotations contained in the manager.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads the manager's state from a DOM element, restoring all annotations present in the XML document...
QList< QgsAnnotation *> cloneAnnotations() const
Returns a list containing clones of all annotations contained in the manager.
bool removeAnnotation(QgsAnnotation *annotation)
Removes an annotation from the manager.
void setMapPositionCrs(const QgsCoordinateReferenceSystem &crs)
Sets the CRS of the map position.
QgsAnnotationManager(QgsProject *project=nullptr)
Constructor for QgsAnnotationManager.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.