QGIS API Documentation 3.43.0-Master (ebb4087afc0)
Loading...
Searching...
No Matches
qgsannotationlayer.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsannotationlayer.cpp
3 ------------------
4 copyright : (C) 2019 by Sandro Mani
5 email : smani at sourcepole dot ch
6 ***************************************************************************/
7
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#include "qgsannotationlayer.h"
18#include "moc_qgsannotationlayer.cpp"
20#include "qgsannotationitem.h"
22#include "qgsapplication.h"
23#include "qgslogger.h"
24#include "qgspainting.h"
25#include "qgsmaplayerfactory.h"
26#include "qgsfeedback.h"
28#include "qgspainteffect.h"
30#include "qgsthreadingutils.h"
31#include <QUuid>
32#include "RTree.h"
33
35class QgsAnnotationLayerSpatialIndex : public RTree<QString, float, 2, float>
36{
37 public:
38
39 void insert( const QString &uuid, const QgsRectangle &bounds )
40 {
41 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
42 float aMin[2]
43 {
44 scaledBounds[0], scaledBounds[ 1]
45 };
46 float aMax[2]
47 {
48 scaledBounds[2], scaledBounds[ 3]
49 };
50 this->Insert(
51 aMin,
52 aMax,
53 uuid );
54 }
55
62 void remove( const QString &uuid, const QgsRectangle &bounds )
63 {
64 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
65 float aMin[2]
66 {
67 scaledBounds[0], scaledBounds[ 1]
68 };
69 float aMax[2]
70 {
71 scaledBounds[2], scaledBounds[ 3]
72 };
73 this->Remove(
74 aMin,
75 aMax,
76 uuid );
77 }
78
84 bool intersects( const QgsRectangle &bounds, const std::function< bool( const QString &uuid )> &callback ) const
85 {
86 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
87 float aMin[2]
88 {
89 scaledBounds[0], scaledBounds[ 1]
90 };
91 float aMax[2]
92 {
93 scaledBounds[2], scaledBounds[ 3]
94 };
95 this->Search(
96 aMin, aMax,
97 callback );
98 return true;
99 }
100
101 private:
102 std::array<float, 4> scaleBounds( const QgsRectangle &bounds ) const
103 {
104 return
105 {
106 static_cast< float >( bounds.xMinimum() ),
107 static_cast< float >( bounds.yMinimum() ),
108 static_cast< float >( bounds.xMaximum() ),
109 static_cast< float >( bounds.yMaximum() )
110 };
111 }
112};
114
115QgsAnnotationLayer::QgsAnnotationLayer( const QString &name, const LayerOptions &options )
116 : QgsMapLayer( Qgis::LayerType::Annotation, name )
117 , mTransformContext( options.transformContext )
118 , mSpatialIndex( std::make_unique< QgsAnnotationLayerSpatialIndex >() )
119{
120 mShouldValidateCrs = false;
121 mValid = true;
122
123 QgsDataProvider::ProviderOptions providerOptions;
124 providerOptions.transformContext = options.transformContext;
125 mDataProvider = new QgsAnnotationLayerDataProvider( providerOptions, Qgis::DataProviderReadFlags() );
126
127 mPaintEffect.reset( QgsPaintEffectRegistry::defaultStack() );
128 mPaintEffect->setEnabled( false );
129}
130
132{
133 emit willBeDeleted();
134 qDeleteAll( mItems );
135 delete mDataProvider;
136}
137
150
152{
154
155 const QString uuid = QUuid::createUuid().toString();
156 mItems.insert( uuid, item );
158 mNonIndexedItems.insert( uuid );
159 else
160 mSpatialIndex->insert( uuid, item->boundingBox() );
161
163
164 return uuid;
165}
166
168{
170
171 std::unique_ptr< QgsAnnotationItem> prevItem( mItems.take( id ) );
172
173 if ( prevItem )
174 {
175 auto it = mNonIndexedItems.find( id );
176 if ( it == mNonIndexedItems.end() )
177 {
178 mSpatialIndex->remove( id, prevItem->boundingBox() );
179 }
180 else
181 {
182 mNonIndexedItems.erase( it );
183 }
184 }
185
186 mItems.insert( id, item );
188 mNonIndexedItems.insert( id );
189 else
190 mSpatialIndex->insert( id, item->boundingBox() );
191
193}
194
195bool QgsAnnotationLayer::removeItem( const QString &id )
196{
198
199 if ( !mItems.contains( id ) )
200 return false;
201
202 std::unique_ptr< QgsAnnotationItem> item( mItems.take( id ) );
203
204 auto it = mNonIndexedItems.find( id );
205 if ( it == mNonIndexedItems.end() )
206 {
207 mSpatialIndex->remove( id, item->boundingBox() );
208 }
209 else
210 {
211 mNonIndexedItems.erase( it );
212 }
213
214 item.reset();
215
217
218 return true;
219}
220
222{
224
225 qDeleteAll( mItems );
226 mItems.clear();
227 mSpatialIndex = std::make_unique< QgsAnnotationLayerSpatialIndex >();
228 mNonIndexedItems.clear();
229
231}
232
234{
236
237 return mItems.empty();
238}
239
241{
243
244 return mItems.value( id );
245}
246
247QStringList QgsAnnotationLayer::queryIndex( const QgsRectangle &bounds, QgsFeedback *feedback ) const
248{
250
251 QStringList res;
252
253 mSpatialIndex->intersects( bounds, [&res, feedback]( const QString & uuid )->bool
254 {
255 res << uuid;
256 return !feedback || !feedback->isCanceled();
257 } );
258 return res;
259}
260
261QStringList QgsAnnotationLayer::itemsInBounds( const QgsRectangle &bounds, QgsRenderContext &context, QgsFeedback *feedback ) const
262{
264
265 QStringList res = queryIndex( bounds, feedback );
266 // we also have to search through any non-indexed items
267 for ( const QString &uuid : mNonIndexedItems )
268 {
269 if ( mItems.value( uuid )->boundingBox( context ).intersects( bounds ) )
270 res << uuid;
271 }
272
273 return res;
274}
275
282
284{
286
288 if ( QgsAnnotationItem *targetItem = item( operation->itemId() ) )
289 {
290 // remove item from index if present
291 auto it = mNonIndexedItems.find( operation->itemId() );
292 if ( it == mNonIndexedItems.end() )
293 {
294 mSpatialIndex->remove( operation->itemId(), targetItem->boundingBox() );
295 }
296 res = targetItem->applyEditV2( operation, context );
297
298 switch ( res )
299 {
302 // re-add to index if possible
303 if ( !( targetItem->flags() & Qgis::AnnotationItemFlag::ScaleDependentBoundingBox ) )
304 mSpatialIndex->insert( operation->itemId(), targetItem->boundingBox() );
305 break;
306
308 // item needs removing from layer
309 delete mItems.take( operation->itemId() );
310 mNonIndexedItems.remove( operation->itemId() );
311 break;
312 }
313 }
314
317
318 return res;
319}
320
328
330{
332
333 const QgsAnnotationLayer::LayerOptions options( mTransformContext );
334 auto layer = std::make_unique< QgsAnnotationLayer >( name(), options );
335 QgsMapLayer::clone( layer.get() );
336
337 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
338 {
339 layer->mItems.insert( it.key(), ( *it )->clone() );
341 layer->mNonIndexedItems.insert( it.key() );
342 else
343 layer->mSpatialIndex->insert( it.key(), ( *it )->boundingBox() );
344 }
345
346 if ( mPaintEffect )
347 layer->setPaintEffect( mPaintEffect->clone() );
348
349 layer->mLinkedLayer = mLinkedLayer;
350
351 return layer.release();
352}
353
360
362{
364
365 QgsRectangle rect;
366 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
367 {
368 if ( rect.isNull() )
369 {
370 rect = it.value()->boundingBox();
371 }
372 else
373 {
374 rect.combineExtentWith( it.value()->boundingBox() );
375 }
376 }
377 return rect;
378}
379
381{
383
384 if ( mDataProvider )
385 mDataProvider->setTransformContext( context );
386
387 mTransformContext = context;
389}
390
391bool QgsAnnotationLayer::readXml( const QDomNode &layerNode, QgsReadWriteContext &context )
392{
394
396 {
397 return false;
398 }
399
400 QString errorMsg;
401 readItems( layerNode, errorMsg, context );
402 readSymbology( layerNode, errorMsg, context );
403
404 {
405 const QString layerId = layerNode.toElement().attribute( QStringLiteral( "linkedLayer" ) );
406 const QString layerName = layerNode.toElement().attribute( QStringLiteral( "linkedLayerName" ) );
407 const QString layerSource = layerNode.toElement().attribute( QStringLiteral( "linkedLayerSource" ) );
408 const QString layerProvider = layerNode.toElement().attribute( QStringLiteral( "linkedLayerProvider" ) );
409 mLinkedLayer = QgsMapLayerRef( layerId, layerName, layerSource, layerProvider );
410 }
411
413
414 return mValid;
415}
416
417bool QgsAnnotationLayer::writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const
418{
420
421 // first get the layer element so that we can append the type attribute
422 QDomElement mapLayerNode = layer_node.toElement();
423
424 if ( mapLayerNode.isNull() )
425 {
426 QgsDebugMsgLevel( QStringLiteral( "can't find maplayer node" ), 2 );
427 return false;
428 }
429
430 mapLayerNode.setAttribute( QStringLiteral( "type" ), QgsMapLayerFactory::typeToString( Qgis::LayerType::Annotation ) );
431
432 if ( mLinkedLayer )
433 {
434 mapLayerNode.setAttribute( QStringLiteral( "linkedLayer" ), mLinkedLayer.layerId );
435 mapLayerNode.setAttribute( QStringLiteral( "linkedLayerName" ), mLinkedLayer.name );
436 mapLayerNode.setAttribute( QStringLiteral( "linkedLayerSource" ), mLinkedLayer.source );
437 mapLayerNode.setAttribute( QStringLiteral( "linkedLayerProvider" ), mLinkedLayer.provider );
438 }
439
440 QString errorMsg;
441 writeItems( layer_node, doc, errorMsg, context );
442
443 // renderer specific settings
444 return writeSymbology( layer_node, doc, errorMsg, context );
445}
446
447bool QgsAnnotationLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
448{
450
451 QDomElement layerElement = node.toElement();
452 writeCommonStyle( layerElement, doc, context, categories );
453
454 // add the layer opacity
455 if ( categories.testFlag( Rendering ) )
456 {
457 QDomElement layerOpacityElem = doc.createElement( QStringLiteral( "layerOpacity" ) );
458 const QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
459 layerOpacityElem.appendChild( layerOpacityText );
460 node.appendChild( layerOpacityElem );
461 }
462
463 if ( categories.testFlag( Symbology ) )
464 {
465 // add the blend mode field
466 QDomElement blendModeElem = doc.createElement( QStringLiteral( "blendMode" ) );
467 const QDomText blendModeText = doc.createTextNode( QString::number( static_cast< int >( QgsPainting::getBlendModeEnum( blendMode() ) ) ) );
468 blendModeElem.appendChild( blendModeText );
469 node.appendChild( blendModeElem );
470
471 QDomElement paintEffectElem = doc.createElement( QStringLiteral( "paintEffect" ) );
472 if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect.get() ) )
473 mPaintEffect->saveProperties( doc, paintEffectElem );
474 node.appendChild( paintEffectElem );
475 }
476
477 return true;
478}
479
480bool QgsAnnotationLayer::readSymbology( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
481{
483
484 const QDomElement layerElement = node.toElement();
485 readCommonStyle( layerElement, context, categories );
486
487 if ( categories.testFlag( Rendering ) )
488 {
489 const QDomNode layerOpacityNode = node.namedItem( QStringLiteral( "layerOpacity" ) );
490 if ( !layerOpacityNode.isNull() )
491 {
492 const QDomElement e = layerOpacityNode.toElement();
493 setOpacity( e.text().toDouble() );
494 }
495 }
496
497 if ( categories.testFlag( Symbology ) )
498 {
499 // get and set the blend mode if it exists
500 const QDomNode blendModeNode = node.namedItem( QStringLiteral( "blendMode" ) );
501 if ( !blendModeNode.isNull() )
502 {
503 const QDomElement e = blendModeNode.toElement();
504 setBlendMode( QgsPainting::getCompositionMode( static_cast< Qgis::BlendMode >( e.text().toInt() ) ) );
505 }
506
507 //restore layer effect
508 const QDomNode paintEffectNode = node.namedItem( QStringLiteral( "paintEffect" ) );
509 if ( !paintEffectNode.isNull() )
510 {
511 const QDomElement effectElem = paintEffectNode.firstChildElement( QStringLiteral( "effect" ) );
512 if ( !effectElem.isNull() )
513 {
514 setPaintEffect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
515 }
516 }
517 }
518
519 return true;
520}
521
522bool QgsAnnotationLayer::writeItems( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories ) const
523{
525
526 QDomElement itemsElement = doc.createElement( QStringLiteral( "items" ) );
527
528 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
529 {
530 QDomElement itemElement = doc.createElement( QStringLiteral( "item" ) );
531 itemElement.setAttribute( QStringLiteral( "type" ), ( *it )->type() );
532 itemElement.setAttribute( QStringLiteral( "id" ), it.key() );
533 ( *it )->writeXml( itemElement, doc, context );
534 itemsElement.appendChild( itemElement );
535 }
536 node.appendChild( itemsElement );
537
538 return true;
539}
540
541bool QgsAnnotationLayer::readItems( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories )
542{
544
545 qDeleteAll( mItems );
546 mItems.clear();
547 mSpatialIndex = std::make_unique< QgsAnnotationLayerSpatialIndex >();
548 mNonIndexedItems.clear();
549
550 const QDomNodeList itemsElements = node.toElement().elementsByTagName( QStringLiteral( "items" ) );
551 if ( itemsElements.size() == 0 )
552 return false;
553
554 const QDomNodeList items = itemsElements.at( 0 ).childNodes();
555 for ( int i = 0; i < items.size(); ++i )
556 {
557 const QDomElement itemElement = items.at( i ).toElement();
558 const QString id = itemElement.attribute( QStringLiteral( "id" ) );
559 const QString type = itemElement.attribute( QStringLiteral( "type" ) );
560 std::unique_ptr< QgsAnnotationItem > item( QgsApplication::annotationItemRegistry()->createItem( type ) );
561 if ( item )
562 {
563 item->readXml( itemElement, context );
565 mNonIndexedItems.insert( id );
566 else
567 mSpatialIndex->insert( id, item->boundingBox() );
568 mItems.insert( id, item.release() );
569 }
570 }
571
572 return true;
573}
574
575bool QgsAnnotationLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
576{
578
579 writeItems( node, doc, errorMessage, context, categories );
580
581 return writeSymbology( node, doc, errorMessage, context, categories );
582}
583
584bool QgsAnnotationLayer::readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
585{
587
588 readItems( node, errorMessage, context, categories );
589
590 return readSymbology( node, errorMessage, context, categories );
591}
592
594{
596
597 // annotation layers are always editable
598 return true;
599}
600
602{
604
605 return true;
606}
607
614
616{
618
619 return mDataProvider;
620}
621
623{
625
626 QString metadata = QStringLiteral( "<html>\n<body>\n<h1>" ) + tr( "General" ) + QStringLiteral( "</h1>\n<hr>\n" ) + QStringLiteral( "<table class=\"list-view\">\n" );
627
628 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Name" ) + QStringLiteral( "</td><td>" ) + name() + QStringLiteral( "</td></tr>\n" );
629
630 // Extent
631 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Extent" ) + QStringLiteral( "</td><td>" ) + extent().toString() + QStringLiteral( "</td></tr>\n" );
632
633 // item count
634 QLocale locale = QLocale();
635 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
636 const int itemCount = mItems.size();
637 metadata += QStringLiteral( "<tr><td class=\"highlight\">" )
638 + tr( "Item count" ) + QStringLiteral( "</td><td>" )
639 + locale.toString( static_cast<qlonglong>( itemCount ) )
640 + QStringLiteral( "</td></tr>\n" );
641 metadata += QLatin1String( "</table>\n<br><br>" );
642
643 // CRS
645
646 // items section
647 metadata += QStringLiteral( "<h1>" ) + tr( "Items" ) + QStringLiteral( "</h1>\n<hr>\n" );
648
649 metadata += QLatin1String( "<table width=\"100%\" class=\"tabular-view\">\n" );
650 metadata += QLatin1String( "<tr><th>" ) + tr( "Type" ) + QLatin1String( "</th><th>" ) + tr( "Count" ) + QLatin1String( "</th></tr>\n" );
651
652 QMap< QString, int > itemCounts;
653 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
654 {
655 itemCounts[ it.value()->type() ]++;
656 }
657
658 const QMap<QString, QString> itemTypes = QgsApplication::annotationItemRegistry()->itemTypes();
659 int i = 0;
660 for ( auto it = itemTypes.begin(); it != itemTypes.end(); ++it )
661 {
662 QString rowClass;
663 if ( i % 2 )
664 rowClass = QStringLiteral( "class=\"odd-row\"" );
665 metadata += QLatin1String( "<tr " ) + rowClass + QLatin1String( "><td>" ) + it.value() + QLatin1String( "</td><td>" ) + locale.toString( static_cast<qlonglong>( itemCounts.value( it.key() ) ) ) + QLatin1String( "</td></tr>\n" );
666 i++;
667 }
668
669 metadata += QLatin1String( "</table>\n<br><br>" );
670
671 metadata += QLatin1String( "\n</body>\n</html>\n" );
672 return metadata;
673}
674
676{
677 mLinkedLayer.resolve( project );
678}
679
681{
683
684 return mPaintEffect.get();
685}
686
688{
690
691 mPaintEffect.reset( effect );
692}
693
700
708
709
710//
711// QgsAnnotationLayerDataProvider
712//
714QgsAnnotationLayerDataProvider::QgsAnnotationLayerDataProvider(
715 const ProviderOptions &options,
717 : QgsDataProvider( QString(), options, flags )
718{}
719
720QgsCoordinateReferenceSystem QgsAnnotationLayerDataProvider::crs() const
721{
723
725}
726
727QString QgsAnnotationLayerDataProvider::name() const
728{
730
731 return QStringLiteral( "annotation" );
732}
733
734QString QgsAnnotationLayerDataProvider::description() const
735{
737
738 return QString();
739}
740
741QgsRectangle QgsAnnotationLayerDataProvider::extent() const
742{
744
745 return QgsRectangle();
746}
747
748bool QgsAnnotationLayerDataProvider::isValid() const
749{
751
752 return true;
753}
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
@ UsersCannotToggleEditing
Indicates that users are not allowed to toggle editing for this layer. Note that this does not imply ...
@ ScaleDependentBoundingBox
Item's bounding box will vary depending on map scale.
AnnotationItemEditOperationResult
Results from an edit operation on an annotation item.
Definition qgis.h:2464
@ Invalid
Operation has invalid parameters for the item, no change occurred.
@ Success
Item was modified successfully.
@ ItemCleared
The operation results in the item being cleared, and the item should be removed from the layer as a r...
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Definition qgis.h:4738
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:450
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
QFlags< MapLayerProperty > MapLayerProperties
Map layer properties.
Definition qgis.h:2231
Abstract base class for annotation item edit operations.
QString itemId() const
Returns the associated item ID.
Encapsulates the context for an annotation item edit operation.
QMap< QString, QString > itemTypes() const
Returns a map of available item types to translated name.
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
virtual QgsRectangle boundingBox() const =0
Returns the bounding box of the item's geographic location, in the parent layer's coordinate referenc...
virtual bool readXml(const QDomElement &element, const QgsReadWriteContext &context)=0
Reads the item's state from the given DOM element.
virtual Qgis::AnnotationItemFlags flags() const
Returns item flags.
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 document provided.
void resolveReferences(QgsProject *project) override
Resolve references to other layers (kept as layer IDs after reading XML) into layer objects.
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.
bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories) override
Read the style for the current layer from the DOM node supplied.
void clear()
Removes all items from the layer.
QgsDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
bool isEditable() const override
Returns true if the layer can be edited.
bool removeItem(const QString &id)
Removes (and deletes) the item with matching id.
QStringList itemsInBounds(const QgsRectangle &bounds, QgsRenderContext &context, QgsFeedback *feedback=nullptr) const
Returns a list of the IDs of all annotation items within the specified bounds (in layer CRS),...
void setTransformContext(const QgsCoordinateTransformContext &context) override
Sets the coordinate transform context to transformContext.
Q_DECL_DEPRECATED Qgis::AnnotationItemEditOperationResult applyEdit(QgsAbstractAnnotationItemEditOperation *operation)
Applies an edit operation to the layer.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the layer.
void setLinkedVisibilityLayer(QgsMapLayer *layer)
Sets a linked layer, where the items in this annotation layer will only be visible when the linked la...
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the layer.
void replaceItem(const QString &id, QgsAnnotationItem *item)
Replaces the existing item with matching id with a new item.
Qgis::AnnotationItemEditOperationResult applyEditV2(QgsAbstractAnnotationItemEditOperation *operation, const QgsAnnotationItemEditContext &context)
Applies an edit operation to the layer.
QgsAnnotationLayer * clone() const override
Returns a new instance equivalent to this one except for the id which is still unique.
friend class QgsAnnotationLayerRenderer
bool supportsEditing() const override
Returns whether the layer supports editing or not.
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.
QgsMapLayer * linkedVisibilityLayer()
Returns a linked layer, where the items in this annotation layer will only be visible when the linked...
QString htmlMetadata() const override
Obtain a formatted HTML string containing assorted metadata for this layer.
Qgis::MapLayerProperties properties() const override
Returns the map layer properties of this layer.
bool isEmpty() const
Returns true if the annotation layer is empty and contains no annotations.
QgsAnnotationItem * item(const QString &id) const
Returns the item with the specified id, or nullptr if no matching item was found.
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.
QMap< QString, QgsAnnotationItem * > items() const
Returns a map of items contained in the layer, by unique item ID.
bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories) const override
Write just the symbology information for the layer into the document.
static QgsAnnotationItemRegistry * annotationItemRegistry()
Returns the application's annotation item registry, used for annotation item types.
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects.
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Abstract base class for spatial data provider implementations.
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets data coordinate transform context to transformContext.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:53
static QString typeToString(Qgis::LayerType 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.
Definition qgsmaplayer.h:76
QString name
Definition qgsmaplayer.h:80
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.
QString crsHtmlMetadata() const
Returns a HTML fragment containing the layer's CRS metadata, for use in the htmlMetadata() method.
QgsLayerMetadata metadata
Definition qgsmaplayer.h:82
Qgis::LayerType type
Definition qgsmaplayer.h:86
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....
QFlags< StyleCategory > StyleCategories
QUndoStack * undoStackStyles()
Returns pointer to layer's style undo stack.
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
@ FlagDontResolveLayers
Don't resolve layer paths or create data providers for layers.
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
QgsProject * project() const
Returns the parent project if this map layer is added to a project.
double opacity
Definition qgsmaplayer.h:88
bool mValid
Indicates if the layer is valid and can be drawn.
@ Symbology
Symbology.
@ Rendering
Rendering: scale visibility, simplify method, opacity.
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
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 QgsPaintEffect * defaultStack()
Returns a new effect stack consisting of a sensible selection of default effects.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
Base class for visual effects which can be applied to QPicture drawings.
static Qgis::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a Qgis::BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode(Qgis::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a Qgis::BlendMode.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Q_INVOKABLE QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
double xMinimum
double yMinimum
double xMaximum
double yMaximum
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.
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:41
_LayerRef< QgsMapLayer > QgsMapLayerRef
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Setting options for loading annotation layers.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Setting options for creating vector data providers.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
QString source
Weak reference to layer public source.
QString name
Weak reference to layer name.
TYPE * get() const
Returns a pointer to the layer, or nullptr if the reference has not yet been matched to a layer.
QString provider
Weak reference to layer provider.
TYPE * resolve(const QgsProject *project)
Resolves the map layer by attempting to find a layer with matching ID within a project.
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
QString layerId
Original layer ID.