QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
27 , mTransformContext( options.transformContext )
49 const QString uuid = QUuid::createUuid().toString();
50 mItems.insert( uuid, item );
59 if ( !mItems.contains(
id ) )
62 delete mItems.take(
id );
79 return mItems.empty();
91 std::unique_ptr< QgsAnnotationLayer > layer = qgis::make_unique< QgsAnnotationLayer >(
name(), options );
96 for (
auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
98 layer->mItems.insert( it.key(), ( *it )->clone() );
101 return layer.release();
112 for (
auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
116 rect = it.value()->boundingBox();
128 mTransformContext = context;
138 qDeleteAll( mItems );
141 QDomNodeList itemsElements = layerNode.toElement().elementsByTagName( QStringLiteral(
"items" ) );
142 if ( itemsElements.size() == 0 )
145 QDomNodeList
items = itemsElements.at( 0 ).childNodes();
146 for (
int i = 0; i <
items.size(); ++i )
148 QDomElement itemElement =
items.at( i ).toElement();
149 const QString
id = itemElement.attribute( QStringLiteral(
"id" ) );
150 const QString
type = itemElement.attribute( QStringLiteral(
"type" ) );
154 item->readXml( itemElement, context );
155 mItems.insert(
id, item.release() );
170 QDomElement mapLayerNode = layer_node.toElement();
172 if ( mapLayerNode.isNull() )
178 mapLayerNode.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"annotation" ) );
180 QDomElement itemsElement = doc.createElement(
"items" );
181 for (
auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
183 QDomElement itemElement = doc.createElement(
"item" );
184 itemElement.setAttribute( QStringLiteral(
"type" ), ( *it )->type() );
185 itemElement.setAttribute( QStringLiteral(
"id" ), it.key() );
186 ( *it )->writeXml( itemElement, doc, context );
187 itemsElement.appendChild( itemElement );
189 mapLayerNode.appendChild( itemsElement );
201 QDomElement layerOpacityElem = doc.createElement( QStringLiteral(
"layerOpacity" ) );
202 QDomText layerOpacityText = doc.createTextNode( QString::number(
opacity() ) );
203 layerOpacityElem.appendChild( layerOpacityText );
204 node.appendChild( layerOpacityElem );
213 QDomNode layerOpacityNode = node.namedItem( QStringLiteral(
"layerOpacity" ) );
214 if ( !layerOpacityNode.isNull() )
216 QDomElement e = layerOpacityNode.toElement();
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
QgsAnnotationLayer * clone() const override
Returns a new instance equivalent to this one except for the id which is still unique.
Contains information about the context in which a coordinate transform is executed.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
The class is used as a container of context for various read/write operations on other objects.
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.
#define QgsDebugMsgLevel(str, level)
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
QgsMapLayerType
Types of layers that can be added to a map.
void clear()
Removes all items from the layer.
Contains information about the context of a rendering operation.
Implementation of threaded rendering for annotation layers.
Setting options for loading annotation layers.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
A rectangle specified with double values.
double opacity() const
Returns the opacity for the annotation layer, where opacity is a value between 0 (totally transparent...
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
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.
@ Rendering
Rendering: scale visibility, simplify method, opacity.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
@ FlagDontResolveLayers
Don't resolve layer paths or create data providers for layers.
bool mValid
Indicates if the layer is valid and can be drawn.
bool isEmpty() const
Returns true if the annotation layer is empty and contains no annotations.
QString addItem(QgsAnnotationItem *item)
Adds an item to the layer.
bool removeItem(const QString &id)
Removes (and deletes) the item with matching id.
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.
This class represents a coordinate reference system (CRS).
bool readXml(const QDomNode &layerNode, QgsReadWriteContext &context) override
Called by readLayerXML(), used by children to read state specific to them from project files.
~QgsAnnotationLayer() override
QMap< QString, QgsAnnotationItem * > items() const
Returns a map of items contained in the layer, by unique item ID.
Base class for all map layer types.
void setOpacity(double opacity)
Sets the opacity for the annotation layer, where opacity is a value between 0 (totally transparent) a...
Represents a map layer containing a set of georeferenced annotations, e.g.
void reset()
Resets the annotation layer to a default state, and clears all items from it.
QgsRectangle extent() const override
Returns the extent of the layer.
void setTransformContext(const QgsCoordinateTransformContext &context) override
Sets the coordinate transform context to transformContext.
QgsAnnotationLayer(const QString &name, const QgsAnnotationLayer::LayerOptions &options)
Constructor for a new QgsAnnotationLayer with the specified layer name.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
static QgsAnnotationItemRegistry * annotationItemRegistry()
Returns the application's annotation item registry, used for annotation item types.