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 = qgis::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;
132 qDeleteAll( mItems );
135 QDomNodeList itemsElements = layerNode.toElement().elementsByTagName( QStringLiteral(
"items" ) );
136 if ( itemsElements.size() == 0 )
139 QDomNodeList
items = itemsElements.at( 0 ).childNodes();
140 for (
int i = 0; i <
items.size(); ++i )
142 QDomElement itemElement =
items.at( i ).toElement();
143 const QString
id = itemElement.attribute( QStringLiteral(
"id" ) );
144 const QString
type = itemElement.attribute( QStringLiteral(
"type" ) );
148 item->readXml( itemElement, context );
149 mItems.insert(
id, item.release() );
164 QDomElement mapLayerNode = layer_node.toElement();
166 if ( mapLayerNode.isNull() )
174 QDomElement itemsElement = doc.createElement(
"items" );
175 for (
auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
177 QDomElement itemElement = doc.createElement(
"item" );
178 itemElement.setAttribute( QStringLiteral(
"type" ), ( *it )->type() );
179 itemElement.setAttribute( QStringLiteral(
"id" ), it.key() );
180 ( *it )->writeXml( itemElement, doc, context );
181 itemsElement.appendChild( itemElement );
183 mapLayerNode.appendChild( itemsElement );
195 QDomElement layerOpacityElem = doc.createElement( QStringLiteral(
"layerOpacity" ) );
196 QDomText layerOpacityText = doc.createTextNode( QString::number(
opacity() ) );
197 layerOpacityElem.appendChild( layerOpacityText );
198 node.appendChild( layerOpacityElem );
204 QDomElement blendModeElem = doc.createElement( QStringLiteral(
"blendMode" ) );
206 blendModeElem.appendChild( blendModeText );
207 node.appendChild( blendModeElem );
217 QDomNode layerOpacityNode = node.namedItem( QStringLiteral(
"layerOpacity" ) );
218 if ( !layerOpacityNode.isNull() )
220 QDomElement e = layerOpacityNode.toElement();
228 QDomNode blendModeNode = node.namedItem( QStringLiteral(
"blendMode" ) );
229 if ( !blendModeNode.isNull() )
231 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.
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.