29 , mTransformContext( options.transformContext )
51 const QString uuid = QUuid::createUuid().toString();
52 mItems.insert( uuid, item );
61 if ( !mItems.contains(
id ) )
64 delete mItems.take(
id );
81 return mItems.empty();
87 std::unique_ptr< QgsAnnotationLayer > layer = std::make_unique< QgsAnnotationLayer >(
name(), options );
90 for (
auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
92 layer->mItems.insert( it.key(), ( *it )->clone() );
95 return layer.release();
106 for (
auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
110 rect = it.value()->boundingBox();
122 mTransformContext = context;
133 qDeleteAll( mItems );
136 QDomNodeList itemsElements = layerNode.toElement().elementsByTagName( QStringLiteral(
"items" ) );
137 if ( itemsElements.size() == 0 )
140 QDomNodeList
items = itemsElements.at( 0 ).childNodes();
141 for (
int i = 0; i <
items.size(); ++i )
143 QDomElement itemElement =
items.at( i ).toElement();
144 const QString
id = itemElement.attribute( QStringLiteral(
"id" ) );
145 const QString
type = itemElement.attribute( QStringLiteral(
"type" ) );
149 item->readXml( itemElement, context );
150 mItems.insert(
id, item.release() );
165 QDomElement mapLayerNode = layer_node.toElement();
167 if ( mapLayerNode.isNull() )
175 QDomElement itemsElement = doc.createElement(
"items" );
176 for (
auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
178 QDomElement itemElement = doc.createElement(
"item" );
179 itemElement.setAttribute( QStringLiteral(
"type" ), ( *it )->type() );
180 itemElement.setAttribute( QStringLiteral(
"id" ), it.key() );
181 ( *it )->writeXml( itemElement, doc, context );
182 itemsElement.appendChild( itemElement );
184 mapLayerNode.appendChild( itemsElement );
196 QDomElement layerOpacityElem = doc.createElement( QStringLiteral(
"layerOpacity" ) );
197 QDomText layerOpacityText = doc.createTextNode( QString::number(
opacity() ) );
198 layerOpacityElem.appendChild( layerOpacityText );
199 node.appendChild( layerOpacityElem );
205 QDomElement blendModeElem = doc.createElement( QStringLiteral(
"blendMode" ) );
207 blendModeElem.appendChild( blendModeText );
208 node.appendChild( blendModeElem );
218 QDomNode layerOpacityNode = node.namedItem( QStringLiteral(
"layerOpacity" ) );
219 if ( !layerOpacityNode.isNull() )
221 QDomElement e = layerOpacityNode.toElement();
229 QDomNode blendModeNode = node.namedItem( QStringLiteral(
"blendMode" ) );
230 if ( !blendModeNode.isNull() )
232 QDomElement e = blendModeNode.toElement();
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
Implementation of threaded rendering for annotation layers.
Represents a map layer containing a set of georeferenced annotations, e.g.
QgsRectangle extent() const override
Returns the extent of the layer.
bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &, StyleCategories categories=AllStyleCategories) const override
Write the style for the layer into the docment provided.
bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) override
Read the symbology for the current layer from the DOM node supplied.
void clear()
Removes all items from the layer.
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
QMap< QString, QgsAnnotationItem * > items() const
Returns a map of items contained in the layer, by unique item ID.
bool removeItem(const QString &id)
Removes (and deletes) the item with matching id.
void setTransformContext(const QgsCoordinateTransformContext &context) override
Sets the coordinate transform context to transformContext.
QgsAnnotationLayer * clone() const override
Returns a new instance equivalent to this one except for the id which is still unique.
void reset()
Resets the annotation layer to a default state, and clears all items from it.
QString addItem(QgsAnnotationItem *item)
Adds an item to the layer.
bool isEmpty() const
Returns true if the annotation layer is empty and contains no annotations.
~QgsAnnotationLayer() override
bool writeXml(QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by children to write state specific to them to project files.
bool readXml(const QDomNode &layerNode, QgsReadWriteContext &context) override
Called by readLayerXML(), used by children to read state specific to them from project files.
QgsAnnotationLayer(const QString &name, const QgsAnnotationLayer::LayerOptions &options)
Constructor for a new QgsAnnotationLayer with the specified layer name.
static QgsAnnotationItemRegistry * annotationItemRegistry()
Returns the application's annotation item registry, used for annotation item types.
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
static QString typeToString(QgsMapLayerType type)
Converts a map layer type to a string value.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Base class for all map layer types.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
@ FlagDontResolveLayers
Don't resolve layer paths or create data providers for layers.
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
bool mValid
Indicates if the layer is valid and can be drawn.
@ Rendering
Rendering: scale visibility, simplify method, opacity.
void invalidateWgs84Extent()
Invalidates the WGS84 extent.
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
Contains information about the context of a rendering operation.
QgsMapLayerType
Types of layers that can be added to a map.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
#define QgsDebugMsgLevel(str, level)
Setting options for loading annotation layers.