QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 this->Insert(
43 {
44 scaledBounds[0], scaledBounds[ 1]
45 },
46 {
47 scaledBounds[2], scaledBounds[3]
48 },
49 uuid );
50 }
51
58 void remove( const QString &uuid, const QgsRectangle &bounds )
59 {
60 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
61 this->Remove(
62 {
63 scaledBounds[0], scaledBounds[ 1]
64 },
65 {
66 scaledBounds[2], scaledBounds[3]
67 },
68 uuid );
69 }
70
76 bool intersects( const QgsRectangle &bounds, const std::function< bool( const QString &uuid )> &callback ) const
77 {
78 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
79 this->Search(
80 {
81 scaledBounds[0], scaledBounds[ 1]
82 },
83 {
84 scaledBounds[2], scaledBounds[3]
85 },
86 callback );
87 return true;
88 }
89
90 private:
91 std::array<float, 4> scaleBounds( const QgsRectangle &bounds ) const
92 {
93 return
94 {
95 static_cast< float >( bounds.xMinimum() ),
96 static_cast< float >( bounds.yMinimum() ),
97 static_cast< float >( bounds.xMaximum() ),
98 static_cast< float >( bounds.yMaximum() )
99 };
100 }
101};
103
104QgsAnnotationLayer::QgsAnnotationLayer( const QString &name, const LayerOptions &options )
105 : QgsMapLayer( Qgis::LayerType::Annotation, name )
106 , mTransformContext( options.transformContext )
107 , mSpatialIndex( std::make_unique< QgsAnnotationLayerSpatialIndex >() )
108{
109 mShouldValidateCrs = false;
110 mValid = true;
111
112 QgsDataProvider::ProviderOptions providerOptions;
113 providerOptions.transformContext = options.transformContext;
114 mDataProvider = new QgsAnnotationLayerDataProvider( providerOptions, Qgis::DataProviderReadFlags() );
115
116 mPaintEffect.reset( QgsPaintEffectRegistry::defaultStack() );
117 mPaintEffect->setEnabled( false );
118}
119
121{
122 emit willBeDeleted();
123 qDeleteAll( mItems );
124 delete mDataProvider;
125}
126
139
141{
143
144 const QString uuid = QUuid::createUuid().toString();
145 mItems.insert( uuid, item );
147 mNonIndexedItems.insert( uuid );
148 else
149 mSpatialIndex->insert( uuid, item->boundingBox() );
150
152
153 return uuid;
154}
155
157{
159
160 std::unique_ptr< QgsAnnotationItem> prevItem( mItems.take( id ) );
161
162 if ( prevItem )
163 {
164 auto it = mNonIndexedItems.find( id );
165 if ( it == mNonIndexedItems.end() )
166 {
167 mSpatialIndex->remove( id, prevItem->boundingBox() );
168 }
169 else
170 {
171 mNonIndexedItems.erase( it );
172 }
173 }
174
175 mItems.insert( id, item );
177 mNonIndexedItems.insert( id );
178 else
179 mSpatialIndex->insert( id, item->boundingBox() );
180
182}
183
184bool QgsAnnotationLayer::removeItem( const QString &id )
185{
187
188 if ( !mItems.contains( id ) )
189 return false;
190
191 std::unique_ptr< QgsAnnotationItem> item( mItems.take( id ) );
192
193 auto it = mNonIndexedItems.find( id );
194 if ( it == mNonIndexedItems.end() )
195 {
196 mSpatialIndex->remove( id, item->boundingBox() );
197 }
198 else
199 {
200 mNonIndexedItems.erase( it );
201 }
202
203 item.reset();
204
206
207 return true;
208}
209
211{
213
214 qDeleteAll( mItems );
215 mItems.clear();
216 mSpatialIndex = std::make_unique< QgsAnnotationLayerSpatialIndex >();
217 mNonIndexedItems.clear();
218
220}
221
223{
225
226 return mItems.empty();
227}
228
230{
232
233 return mItems.value( id );
234}
235
236QStringList QgsAnnotationLayer::queryIndex( const QgsRectangle &bounds, QgsFeedback *feedback ) const
237{
239
240 QStringList res;
241
242 mSpatialIndex->intersects( bounds, [&res, feedback]( const QString & uuid )->bool
243 {
244 res << uuid;
245 return !feedback || !feedback->isCanceled();
246 } );
247 return res;
248}
249
250QStringList QgsAnnotationLayer::itemsInBounds( const QgsRectangle &bounds, QgsRenderContext &context, QgsFeedback *feedback ) const
251{
253
254 QStringList res = queryIndex( bounds, feedback );
255 // we also have to search through any non-indexed items
256 for ( const QString &uuid : mNonIndexedItems )
257 {
258 if ( mItems.value( uuid )->boundingBox( context ).intersects( bounds ) )
259 res << uuid;
260 }
261
262 return res;
263}
264
271
273{
275
277 if ( QgsAnnotationItem *targetItem = item( operation->itemId() ) )
278 {
279 // remove item from index if present
280 auto it = mNonIndexedItems.find( operation->itemId() );
281 if ( it == mNonIndexedItems.end() )
282 {
283 mSpatialIndex->remove( operation->itemId(), targetItem->boundingBox() );
284 }
285 res = targetItem->applyEditV2( operation, context );
286
287 switch ( res )
288 {
291 // re-add to index if possible
292 if ( !( targetItem->flags() & Qgis::AnnotationItemFlag::ScaleDependentBoundingBox ) )
293 mSpatialIndex->insert( operation->itemId(), targetItem->boundingBox() );
294 break;
295
297 // item needs removing from layer
298 delete mItems.take( operation->itemId() );
299 mNonIndexedItems.remove( operation->itemId() );
300 break;
301 }
302 }
303
306
307 return res;
308}
309
317
319{
321
322 const QgsAnnotationLayer::LayerOptions options( mTransformContext );
323 std::unique_ptr< QgsAnnotationLayer > layer = std::make_unique< QgsAnnotationLayer >( name(), options );
324 QgsMapLayer::clone( layer.get() );
325
326 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
327 {
328 layer->mItems.insert( it.key(), ( *it )->clone() );
330 layer->mNonIndexedItems.insert( it.key() );
331 else
332 layer->mSpatialIndex->insert( it.key(), ( *it )->boundingBox() );
333 }
334
335 if ( mPaintEffect )
336 layer->setPaintEffect( mPaintEffect->clone() );
337
338 layer->mLinkedLayer = mLinkedLayer;
339
340 return layer.release();
341}
342
349
351{
353
354 QgsRectangle rect;
355 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
356 {
357 if ( rect.isNull() )
358 {
359 rect = it.value()->boundingBox();
360 }
361 else
362 {
363 rect.combineExtentWith( it.value()->boundingBox() );
364 }
365 }
366 return rect;
367}
368
370{
372
373 if ( mDataProvider )
374 mDataProvider->setTransformContext( context );
375
376 mTransformContext = context;
378}
379
380bool QgsAnnotationLayer::readXml( const QDomNode &layerNode, QgsReadWriteContext &context )
381{
383
385 {
386 return false;
387 }
388
389 QString errorMsg;
390 readItems( layerNode, errorMsg, context );
391 readSymbology( layerNode, errorMsg, context );
392
393 {
394 const QString layerId = layerNode.toElement().attribute( QStringLiteral( "linkedLayer" ) );
395 const QString layerName = layerNode.toElement().attribute( QStringLiteral( "linkedLayerName" ) );
396 const QString layerSource = layerNode.toElement().attribute( QStringLiteral( "linkedLayerSource" ) );
397 const QString layerProvider = layerNode.toElement().attribute( QStringLiteral( "linkedLayerProvider" ) );
398 mLinkedLayer = QgsMapLayerRef( layerId, layerName, layerSource, layerProvider );
399 }
400
402
403 return mValid;
404}
405
406bool QgsAnnotationLayer::writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const
407{
409
410 // first get the layer element so that we can append the type attribute
411 QDomElement mapLayerNode = layer_node.toElement();
412
413 if ( mapLayerNode.isNull() )
414 {
415 QgsDebugMsgLevel( QStringLiteral( "can't find maplayer node" ), 2 );
416 return false;
417 }
418
419 mapLayerNode.setAttribute( QStringLiteral( "type" ), QgsMapLayerFactory::typeToString( Qgis::LayerType::Annotation ) );
420
421 if ( mLinkedLayer )
422 {
423 mapLayerNode.setAttribute( QStringLiteral( "linkedLayer" ), mLinkedLayer.layerId );
424 mapLayerNode.setAttribute( QStringLiteral( "linkedLayerName" ), mLinkedLayer.name );
425 mapLayerNode.setAttribute( QStringLiteral( "linkedLayerSource" ), mLinkedLayer.source );
426 mapLayerNode.setAttribute( QStringLiteral( "linkedLayerProvider" ), mLinkedLayer.provider );
427 }
428
429 QString errorMsg;
430 writeItems( layer_node, doc, errorMsg, context );
431
432 // renderer specific settings
433 return writeSymbology( layer_node, doc, errorMsg, context );
434}
435
436bool QgsAnnotationLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
437{
439
440 QDomElement layerElement = node.toElement();
441 writeCommonStyle( layerElement, doc, context, categories );
442
443 // add the layer opacity
444 if ( categories.testFlag( Rendering ) )
445 {
446 QDomElement layerOpacityElem = doc.createElement( QStringLiteral( "layerOpacity" ) );
447 const QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
448 layerOpacityElem.appendChild( layerOpacityText );
449 node.appendChild( layerOpacityElem );
450 }
451
452 if ( categories.testFlag( Symbology ) )
453 {
454 // add the blend mode field
455 QDomElement blendModeElem = doc.createElement( QStringLiteral( "blendMode" ) );
456 const QDomText blendModeText = doc.createTextNode( QString::number( static_cast< int >( QgsPainting::getBlendModeEnum( blendMode() ) ) ) );
457 blendModeElem.appendChild( blendModeText );
458 node.appendChild( blendModeElem );
459
460 QDomElement paintEffectElem = doc.createElement( QStringLiteral( "paintEffect" ) );
461 if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect.get() ) )
462 mPaintEffect->saveProperties( doc, paintEffectElem );
463 node.appendChild( paintEffectElem );
464 }
465
466 return true;
467}
468
469bool QgsAnnotationLayer::readSymbology( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
470{
472
473 const QDomElement layerElement = node.toElement();
474 readCommonStyle( layerElement, context, categories );
475
476 if ( categories.testFlag( Rendering ) )
477 {
478 const QDomNode layerOpacityNode = node.namedItem( QStringLiteral( "layerOpacity" ) );
479 if ( !layerOpacityNode.isNull() )
480 {
481 const QDomElement e = layerOpacityNode.toElement();
482 setOpacity( e.text().toDouble() );
483 }
484 }
485
486 if ( categories.testFlag( Symbology ) )
487 {
488 // get and set the blend mode if it exists
489 const QDomNode blendModeNode = node.namedItem( QStringLiteral( "blendMode" ) );
490 if ( !blendModeNode.isNull() )
491 {
492 const QDomElement e = blendModeNode.toElement();
493 setBlendMode( QgsPainting::getCompositionMode( static_cast< Qgis::BlendMode >( e.text().toInt() ) ) );
494 }
495
496 //restore layer effect
497 const QDomNode paintEffectNode = node.namedItem( QStringLiteral( "paintEffect" ) );
498 if ( !paintEffectNode.isNull() )
499 {
500 const QDomElement effectElem = paintEffectNode.firstChildElement( QStringLiteral( "effect" ) );
501 if ( !effectElem.isNull() )
502 {
503 setPaintEffect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
504 }
505 }
506 }
507
508 return true;
509}
510
511bool QgsAnnotationLayer::writeItems( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories ) const
512{
514
515 QDomElement itemsElement = doc.createElement( QStringLiteral( "items" ) );
516
517 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
518 {
519 QDomElement itemElement = doc.createElement( QStringLiteral( "item" ) );
520 itemElement.setAttribute( QStringLiteral( "type" ), ( *it )->type() );
521 itemElement.setAttribute( QStringLiteral( "id" ), it.key() );
522 ( *it )->writeXml( itemElement, doc, context );
523 itemsElement.appendChild( itemElement );
524 }
525 node.appendChild( itemsElement );
526
527 return true;
528}
529
530bool QgsAnnotationLayer::readItems( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories )
531{
533
534 qDeleteAll( mItems );
535 mItems.clear();
536 mSpatialIndex = std::make_unique< QgsAnnotationLayerSpatialIndex >();
537 mNonIndexedItems.clear();
538
539 const QDomNodeList itemsElements = node.toElement().elementsByTagName( QStringLiteral( "items" ) );
540 if ( itemsElements.size() == 0 )
541 return false;
542
543 const QDomNodeList items = itemsElements.at( 0 ).childNodes();
544 for ( int i = 0; i < items.size(); ++i )
545 {
546 const QDomElement itemElement = items.at( i ).toElement();
547 const QString id = itemElement.attribute( QStringLiteral( "id" ) );
548 const QString type = itemElement.attribute( QStringLiteral( "type" ) );
549 std::unique_ptr< QgsAnnotationItem > item( QgsApplication::annotationItemRegistry()->createItem( type ) );
550 if ( item )
551 {
552 item->readXml( itemElement, context );
554 mNonIndexedItems.insert( id );
555 else
556 mSpatialIndex->insert( id, item->boundingBox() );
557 mItems.insert( id, item.release() );
558 }
559 }
560
561 return true;
562}
563
564bool QgsAnnotationLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
565{
567
568 writeItems( node, doc, errorMessage, context, categories );
569
570 return writeSymbology( node, doc, errorMessage, context, categories );
571}
572
573bool QgsAnnotationLayer::readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
574{
576
577 readItems( node, errorMessage, context, categories );
578
579 return readSymbology( node, errorMessage, context, categories );
580}
581
583{
585
586 // annotation layers are always editable
587 return true;
588}
589
591{
593
594 return true;
595}
596
603
605{
607
608 return mDataProvider;
609}
610
612{
614
615 QString metadata = QStringLiteral( "<html>\n<body>\n<h1>" ) + tr( "General" ) + QStringLiteral( "</h1>\n<hr>\n" ) + QStringLiteral( "<table class=\"list-view\">\n" );
616
617 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Name" ) + QStringLiteral( "</td><td>" ) + name() + QStringLiteral( "</td></tr>\n" );
618
619 // Extent
620 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Extent" ) + QStringLiteral( "</td><td>" ) + extent().toString() + QStringLiteral( "</td></tr>\n" );
621
622 // item count
623 QLocale locale = QLocale();
624 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
625 const int itemCount = mItems.size();
626 metadata += QStringLiteral( "<tr><td class=\"highlight\">" )
627 + tr( "Item count" ) + QStringLiteral( "</td><td>" )
628 + locale.toString( static_cast<qlonglong>( itemCount ) )
629 + QStringLiteral( "</td></tr>\n" );
630 metadata += QLatin1String( "</table>\n<br><br>" );
631
632 // CRS
634
635 // items section
636 metadata += QStringLiteral( "<h1>" ) + tr( "Items" ) + QStringLiteral( "</h1>\n<hr>\n" );
637
638 metadata += QLatin1String( "<table width=\"100%\" class=\"tabular-view\">\n" );
639 metadata += QLatin1String( "<tr><th>" ) + tr( "Type" ) + QLatin1String( "</th><th>" ) + tr( "Count" ) + QLatin1String( "</th></tr>\n" );
640
641 QMap< QString, int > itemCounts;
642 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
643 {
644 itemCounts[ it.value()->type() ]++;
645 }
646
647 const QMap<QString, QString> itemTypes = QgsApplication::annotationItemRegistry()->itemTypes();
648 int i = 0;
649 for ( auto it = itemTypes.begin(); it != itemTypes.end(); ++it )
650 {
651 QString rowClass;
652 if ( i % 2 )
653 rowClass = QStringLiteral( "class=\"odd-row\"" );
654 metadata += QLatin1String( "<tr " ) + rowClass + QLatin1String( "><td>" ) + it.value() + QLatin1String( "</td><td>" ) + locale.toString( static_cast<qlonglong>( itemCounts.value( it.key() ) ) ) + QLatin1String( "</td></tr>\n" );
655 i++;
656 }
657
658 metadata += QLatin1String( "</table>\n<br><br>" );
659
660 metadata += QLatin1String( "\n</body>\n</html>\n" );
661 return metadata;
662}
663
665{
666 mLinkedLayer.resolve( project );
667}
668
670{
672
673 return mPaintEffect.get();
674}
675
677{
679
680 mPaintEffect.reset( effect );
681}
682
689
697
698
699//
700// QgsAnnotationLayerDataProvider
701//
703QgsAnnotationLayerDataProvider::QgsAnnotationLayerDataProvider(
704 const ProviderOptions &options,
706 : QgsDataProvider( QString(), options, flags )
707{}
708
709QgsCoordinateReferenceSystem QgsAnnotationLayerDataProvider::crs() const
710{
712
714}
715
716QString QgsAnnotationLayerDataProvider::name() const
717{
719
720 return QStringLiteral( "annotation" );
721}
722
723QString QgsAnnotationLayerDataProvider::description() const
724{
726
727 return QString();
728}
729
730QgsRectangle QgsAnnotationLayerDataProvider::extent() const
731{
733
734 return QgsRectangle();
735}
736
737bool QgsAnnotationLayerDataProvider::isValid() const
738{
740
741 return true;
742}
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:2414
@ 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:4657
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:2181
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:39
_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.