QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
19#include "RTree.h"
20#include "qgsannotationitem.h"
24#include "qgsapplication.h"
25#include "qgsfeedback.h"
26#include "qgslogger.h"
27#include "qgsmaplayerfactory.h"
28#include "qgspainteffect.h"
30#include "qgspainting.h"
31#include "qgsthreadingutils.h"
32
33#include <QUuid>
34
35#include "moc_qgsannotationlayer.cpp"
36
38class QgsAnnotationLayerSpatialIndex : public RTree<QString, float, 2, float>
39{
40 public:
41
42 void insert( const QString &uuid, const QgsRectangle &bounds )
43 {
44 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
45 float aMin[2]
46 {
47 scaledBounds[0], scaledBounds[ 1]
48 };
49 float aMax[2]
50 {
51 scaledBounds[2], scaledBounds[ 3]
52 };
53 this->Insert(
54 aMin,
55 aMax,
56 uuid );
57 }
58
65 void remove( const QString &uuid, const QgsRectangle &bounds )
66 {
67 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
68 float aMin[2]
69 {
70 scaledBounds[0], scaledBounds[ 1]
71 };
72 float aMax[2]
73 {
74 scaledBounds[2], scaledBounds[ 3]
75 };
76 this->Remove(
77 aMin,
78 aMax,
79 uuid );
80 }
81
87 bool intersects( const QgsRectangle &bounds, const std::function< bool( const QString &uuid )> &callback ) const
88 {
89 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
90 float aMin[2]
91 {
92 scaledBounds[0], scaledBounds[ 1]
93 };
94 float aMax[2]
95 {
96 scaledBounds[2], scaledBounds[ 3]
97 };
98 this->Search(
99 aMin, aMax,
100 callback );
101 return true;
102 }
103
104 private:
105 std::array<float, 4> scaleBounds( const QgsRectangle &bounds ) const
106 {
107 return
108 {
109 static_cast< float >( bounds.xMinimum() ),
110 static_cast< float >( bounds.yMinimum() ),
111 static_cast< float >( bounds.xMaximum() ),
112 static_cast< float >( bounds.yMaximum() )
113 };
114 }
115};
117
119 : QgsMapLayer( Qgis::LayerType::Annotation, name )
120 , mTransformContext( options.transformContext )
121 , mSpatialIndex( std::make_unique< QgsAnnotationLayerSpatialIndex >() )
122{
123 mShouldValidateCrs = false;
124 mValid = true;
125
126 QgsDataProvider::ProviderOptions providerOptions;
127 providerOptions.transformContext = options.transformContext;
128 mDataProvider = std::make_unique<QgsAnnotationLayerDataProvider>( providerOptions, Qgis::DataProviderReadFlags() );
129
130 mPaintEffect.reset( QgsPaintEffectRegistry::defaultStack() );
131 mPaintEffect->setEnabled( false );
132}
133
135{
136 emit willBeDeleted();
137 qDeleteAll( mItems );
138
139}
140
153
155{
157
158 const QString uuid = QUuid::createUuid().toString();
159 mItems.insert( uuid, item );
161 mNonIndexedItems.insert( uuid );
162 else
163 mSpatialIndex->insert( uuid, item->boundingBox() );
164
166
167 return uuid;
168}
169
171{
173
174 std::unique_ptr< QgsAnnotationItem> prevItem( mItems.take( id ) );
175
176 if ( prevItem )
177 {
178 auto it = mNonIndexedItems.find( id );
179 if ( it == mNonIndexedItems.end() )
180 {
181 mSpatialIndex->remove( id, prevItem->boundingBox() );
182 }
183 else
184 {
185 mNonIndexedItems.erase( it );
186 }
187 }
188
189 mItems.insert( id, item );
191 mNonIndexedItems.insert( id );
192 else
193 mSpatialIndex->insert( id, item->boundingBox() );
194
196}
197
198bool QgsAnnotationLayer::removeItem( const QString &id )
199{
201
202 if ( !mItems.contains( id ) )
203 return false;
204
205 std::unique_ptr< QgsAnnotationItem> item( mItems.take( id ) );
206
207 auto it = mNonIndexedItems.find( id );
208 if ( it == mNonIndexedItems.end() )
209 {
210 mSpatialIndex->remove( id, item->boundingBox() );
211 }
212 else
213 {
214 mNonIndexedItems.erase( it );
215 }
216
217 item.reset();
218
220
221 return true;
222}
223
225{
227
228 qDeleteAll( mItems );
229 mItems.clear();
230 mSpatialIndex = std::make_unique< QgsAnnotationLayerSpatialIndex >();
231 mNonIndexedItems.clear();
232
234}
235
237{
239
240 return mItems.empty();
241}
242
244{
246
247 return mItems.value( id );
248}
249
250QStringList QgsAnnotationLayer::queryIndex( const QgsRectangle &bounds, QgsFeedback *feedback ) const
251{
253
254 QStringList res;
255
256 mSpatialIndex->intersects( bounds, [&res, feedback]( const QString & uuid )->bool
257 {
258 res << uuid;
259 return !feedback || !feedback->isCanceled();
260 } );
261 return res;
262}
263
264QStringList QgsAnnotationLayer::itemsInBounds( const QgsRectangle &bounds, QgsRenderContext &context, QgsFeedback *feedback ) const
265{
267
268 QStringList res = queryIndex( bounds, feedback );
269 // we also have to search through any non-indexed items
270 for ( const QString &uuid : mNonIndexedItems )
271 {
272 auto it = mItems.constFind( uuid );
273 if ( it != mItems.constEnd() && it.value()->boundingBox( context ).intersects( bounds ) )
274 res << uuid;
275 }
276
277 return res;
278}
279
286
288{
290
292 if ( QgsAnnotationItem *targetItem = item( operation->itemId() ) )
293 {
294 // remove item from index if present
295 auto it = mNonIndexedItems.find( operation->itemId() );
296 if ( it == mNonIndexedItems.end() )
297 {
298 mSpatialIndex->remove( operation->itemId(), targetItem->boundingBox() );
299 }
300 res = targetItem->applyEditV2( operation, context );
301
302 switch ( res )
303 {
306 // re-add to index if possible
307 if ( !( targetItem->flags() & Qgis::AnnotationItemFlag::ScaleDependentBoundingBox ) )
308 mSpatialIndex->insert( operation->itemId(), targetItem->boundingBox() );
309 break;
310
312 // item needs removing from layer
313 delete mItems.take( operation->itemId() );
314 mNonIndexedItems.remove( operation->itemId() );
315 break;
316 }
317 }
318
321
322 return res;
323}
324
332
334{
336
337 const QgsAnnotationLayer::LayerOptions options( mTransformContext );
338 auto layer = std::make_unique< QgsAnnotationLayer >( name(), options );
339 QgsMapLayer::clone( layer.get() );
340
341 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
342 {
343 layer->mItems.insert( it.key(), ( *it )->clone() );
345 layer->mNonIndexedItems.insert( it.key() );
346 else
347 layer->mSpatialIndex->insert( it.key(), ( *it )->boundingBox() );
348 }
349
350 if ( mPaintEffect )
351 layer->setPaintEffect( mPaintEffect->clone() );
352
353 layer->mLinkedLayer = mLinkedLayer;
354
355 return layer.release();
356}
357
364
366{
368
369 QgsRectangle rect;
370 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
371 {
372 if ( rect.isNull() )
373 {
374 rect = it.value()->boundingBox();
375 }
376 else
377 {
378 rect.combineExtentWith( it.value()->boundingBox() );
379 }
380 }
381 return rect;
382}
383
385{
387
388 if ( mDataProvider )
389 mDataProvider->setTransformContext( context );
390
391 mTransformContext = context;
393}
394
395bool QgsAnnotationLayer::readXml( const QDomNode &layerNode, QgsReadWriteContext &context )
396{
398
400 {
401 return false;
402 }
403
404 QString errorMsg;
405 readItems( layerNode, errorMsg, context );
406 readSymbology( layerNode, errorMsg, context );
407
408 {
409 const QString layerId = layerNode.toElement().attribute( QStringLiteral( "linkedLayer" ) );
410 const QString layerName = layerNode.toElement().attribute( QStringLiteral( "linkedLayerName" ) );
411 const QString layerSource = layerNode.toElement().attribute( QStringLiteral( "linkedLayerSource" ) );
412 const QString layerProvider = layerNode.toElement().attribute( QStringLiteral( "linkedLayerProvider" ) );
413 mLinkedLayer = QgsMapLayerRef( layerId, layerName, layerSource, layerProvider );
414 }
415
417
418 return mValid;
419}
420
421bool QgsAnnotationLayer::writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const
422{
424
425 // first get the layer element so that we can append the type attribute
426 QDomElement mapLayerNode = layer_node.toElement();
427
428 if ( mapLayerNode.isNull() )
429 {
430 QgsDebugMsgLevel( QStringLiteral( "can't find maplayer node" ), 2 );
431 return false;
432 }
433
434 mapLayerNode.setAttribute( QStringLiteral( "type" ), QgsMapLayerFactory::typeToString( Qgis::LayerType::Annotation ) );
435
436 if ( mLinkedLayer )
437 {
438 mapLayerNode.setAttribute( QStringLiteral( "linkedLayer" ), mLinkedLayer.layerId );
439 mapLayerNode.setAttribute( QStringLiteral( "linkedLayerName" ), mLinkedLayer.name );
440 mapLayerNode.setAttribute( QStringLiteral( "linkedLayerSource" ), mLinkedLayer.source );
441 mapLayerNode.setAttribute( QStringLiteral( "linkedLayerProvider" ), mLinkedLayer.provider );
442 }
443
444 QString errorMsg;
445 writeItems( layer_node, doc, errorMsg, context );
446
447 // renderer specific settings
448 return writeSymbology( layer_node, doc, errorMsg, context );
449}
450
451bool QgsAnnotationLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
452{
454
455 QDomElement layerElement = node.toElement();
456 writeCommonStyle( layerElement, doc, context, categories );
457
458 // add the layer opacity
459 if ( categories.testFlag( Rendering ) )
460 {
461 QDomElement layerOpacityElem = doc.createElement( QStringLiteral( "layerOpacity" ) );
462 const QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
463 layerOpacityElem.appendChild( layerOpacityText );
464 node.appendChild( layerOpacityElem );
465 }
466
467 if ( categories.testFlag( Symbology ) )
468 {
469 // add the blend mode field
470 QDomElement blendModeElem = doc.createElement( QStringLiteral( "blendMode" ) );
471 const QDomText blendModeText = doc.createTextNode( QString::number( static_cast< int >( QgsPainting::getBlendModeEnum( blendMode() ) ) ) );
472 blendModeElem.appendChild( blendModeText );
473 node.appendChild( blendModeElem );
474
475 QDomElement paintEffectElem = doc.createElement( QStringLiteral( "paintEffect" ) );
476 if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect.get() ) )
477 mPaintEffect->saveProperties( doc, paintEffectElem );
478 node.appendChild( paintEffectElem );
479 }
480
481 return true;
482}
483
484bool QgsAnnotationLayer::readSymbology( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
485{
487
488 const QDomElement layerElement = node.toElement();
489 readCommonStyle( layerElement, context, categories );
490
491 if ( categories.testFlag( Rendering ) )
492 {
493 const QDomNode layerOpacityNode = node.namedItem( QStringLiteral( "layerOpacity" ) );
494 if ( !layerOpacityNode.isNull() )
495 {
496 const QDomElement e = layerOpacityNode.toElement();
497 setOpacity( e.text().toDouble() );
498 }
499 }
500
501 if ( categories.testFlag( Symbology ) )
502 {
503 // get and set the blend mode if it exists
504 const QDomNode blendModeNode = node.namedItem( QStringLiteral( "blendMode" ) );
505 if ( !blendModeNode.isNull() )
506 {
507 const QDomElement e = blendModeNode.toElement();
508 setBlendMode( QgsPainting::getCompositionMode( static_cast< Qgis::BlendMode >( e.text().toInt() ) ) );
509 }
510
511 //restore layer effect
512 const QDomNode paintEffectNode = node.namedItem( QStringLiteral( "paintEffect" ) );
513 if ( !paintEffectNode.isNull() )
514 {
515 const QDomElement effectElem = paintEffectNode.firstChildElement( QStringLiteral( "effect" ) );
516 if ( !effectElem.isNull() )
517 {
518 setPaintEffect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
519 }
520 }
521 }
522
523 return true;
524}
525
526bool QgsAnnotationLayer::writeItems( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories ) const
527{
529
530 QDomElement itemsElement = doc.createElement( QStringLiteral( "items" ) );
531
532 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
533 {
534 QDomElement itemElement = doc.createElement( QStringLiteral( "item" ) );
535 itemElement.setAttribute( QStringLiteral( "type" ), ( *it )->type() );
536 itemElement.setAttribute( QStringLiteral( "id" ), it.key() );
537 ( *it )->writeXml( itemElement, doc, context );
538 itemsElement.appendChild( itemElement );
539 }
540 node.appendChild( itemsElement );
541
542 return true;
543}
544
545bool QgsAnnotationLayer::readItems( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories )
546{
548
549 qDeleteAll( mItems );
550 mItems.clear();
551 mSpatialIndex = std::make_unique< QgsAnnotationLayerSpatialIndex >();
552 mNonIndexedItems.clear();
553
554 const QDomNodeList itemsElements = node.toElement().elementsByTagName( QStringLiteral( "items" ) );
555 if ( itemsElements.size() == 0 )
556 return false;
557
558 const QDomNodeList items = itemsElements.at( 0 ).childNodes();
559 for ( int i = 0; i < items.size(); ++i )
560 {
561 const QDomElement itemElement = items.at( i ).toElement();
562 const QString id = itemElement.attribute( QStringLiteral( "id" ) );
563 const QString type = itemElement.attribute( QStringLiteral( "type" ) );
564 std::unique_ptr< QgsAnnotationItem > item( QgsApplication::annotationItemRegistry()->createItem( type ) );
565 if ( item )
566 {
567 item->readXml( itemElement, context );
569 mNonIndexedItems.insert( id );
570 else
571 mSpatialIndex->insert( id, item->boundingBox() );
572 mItems.insert( id, item.release() );
573 }
574 }
575
576 return true;
577}
578
579bool QgsAnnotationLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
580{
582
583 writeItems( node, doc, errorMessage, context, categories );
584
585 return writeSymbology( node, doc, errorMessage, context, categories );
586}
587
588bool QgsAnnotationLayer::readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
589{
591
592 readItems( node, errorMessage, context, categories );
593
594 return readSymbology( node, errorMessage, context, categories );
595}
596
598{
600
601 // annotation layers are always editable
602 return true;
603}
604
606{
608
609 return true;
610}
611
618
620{
622
623 return mDataProvider.get();
624}
625
627{
629
630 QString metadata = QStringLiteral( "<html>\n<body>\n<h1>" ) + tr( "General" ) + QStringLiteral( "</h1>\n<hr>\n" ) + QStringLiteral( "<table class=\"list-view\">\n" );
631
632 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Name" ) + QStringLiteral( "</td><td>" ) + name() + QStringLiteral( "</td></tr>\n" );
633
634 // Extent
635 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Extent" ) + QStringLiteral( "</td><td>" ) + extent().toString() + QStringLiteral( "</td></tr>\n" );
636
637 // item count
638 QLocale locale = QLocale();
639 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
640 const int itemCount = mItems.size();
641 metadata += QStringLiteral( "<tr><td class=\"highlight\">" )
642 + tr( "Item count" ) + QStringLiteral( "</td><td>" )
643 + locale.toString( static_cast<qlonglong>( itemCount ) )
644 + QStringLiteral( "</td></tr>\n" );
645 metadata += QLatin1String( "</table>\n<br><br>" );
646
647 // CRS
649
650 // items section
651 metadata += QStringLiteral( "<h1>" ) + tr( "Items" ) + QStringLiteral( "</h1>\n<hr>\n" );
652
653 metadata += QLatin1String( "<table width=\"100%\" class=\"tabular-view\">\n" );
654 metadata += QLatin1String( "<tr><th>" ) + tr( "Type" ) + QLatin1String( "</th><th>" ) + tr( "Count" ) + QLatin1String( "</th></tr>\n" );
655
656 QMap< QString, int > itemCounts;
657 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
658 {
659 itemCounts[ it.value()->type() ]++;
660 }
661
662 const QMap<QString, QString> itemTypes = QgsApplication::annotationItemRegistry()->itemTypes();
663 int i = 0;
664 for ( auto it = itemTypes.begin(); it != itemTypes.end(); ++it )
665 {
666 QString rowClass;
667 if ( i % 2 )
668 rowClass = QStringLiteral( "class=\"odd-row\"" );
669 metadata += QLatin1String( "<tr " ) + rowClass + QLatin1String( "><td>" ) + it.value() + QLatin1String( "</td><td>" ) + locale.toString( static_cast<qlonglong>( itemCounts.value( it.key() ) ) ) + QLatin1String( "</td></tr>\n" );
670 i++;
671 }
672
673 metadata += QLatin1String( "</table>\n<br><br>" );
674
675 metadata += QLatin1String( "\n</body>\n</html>\n" );
676 return metadata;
677}
678
680{
681 mLinkedLayer.resolve( project );
682}
683
685{
687
688 return mPaintEffect.get();
689}
690
692{
694
695 mPaintEffect.reset( effect );
696}
697
704
706{
708
709 mLinkedLayer.setLayer( layer );
711}
712
713
714//
715// QgsAnnotationLayerDataProvider
716//
718QgsAnnotationLayerDataProvider::QgsAnnotationLayerDataProvider(
719 const ProviderOptions &options,
721 : QgsDataProvider( QString(), options, flags )
722{}
723
724QgsCoordinateReferenceSystem QgsAnnotationLayerDataProvider::crs() const
725{
727
729}
730
731QString QgsAnnotationLayerDataProvider::name() const
732{
734
735 return QStringLiteral( "annotation" );
736}
737
738QString QgsAnnotationLayerDataProvider::description() const
739{
741
742 return QString();
743}
744
745QgsRectangle QgsAnnotationLayerDataProvider::extent() const
746{
748
749 return QgsRectangle();
750}
751
752bool QgsAnnotationLayerDataProvider::isValid() const
753{
755
756 return true;
757}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
@ UsersCannotToggleEditing
Indicates that users are not allowed to toggle editing for this layer. Note that this does not imply ...
Definition qgis.h:2280
@ ScaleDependentBoundingBox
Item's bounding box will vary depending on map scale.
Definition qgis.h:2465
AnnotationItemEditOperationResult
Results from an edit operation on an annotation item.
Definition qgis.h:2519
@ Invalid
Operation has invalid parameters for the item, no change occurred.
Definition qgis.h:2521
@ Success
Item was modified successfully.
Definition qgis.h:2520
@ ItemCleared
The operation results in the item being cleared, and the item should be removed from the layer as a r...
Definition qgis.h:2522
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Definition qgis.h:4930
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:486
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
Definition qgis.h:196
QFlags< MapLayerProperty > MapLayerProperties
Map layer properties.
Definition qgis.h:2285
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.
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.
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.
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.
QString name
Definition qgsmaplayer.h:84
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:86
QgsMapLayer(Qgis::LayerType type=Qgis::LayerType::Vector, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
Qgis::LayerType type
Definition qgsmaplayer.h:90
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
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
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:92
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:109
A container for the context for various read/write operations on 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
Contains information about the context of a rendering operation.
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:61
_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.