QGIS API Documentation 3.39.0-Master (d85f3c2a281)
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"
19#include "qgsannotationitem.h"
21#include "qgsapplication.h"
22#include "qgslogger.h"
23#include "qgspainting.h"
24#include "qgsmaplayerfactory.h"
25#include "qgsfeedback.h"
27#include "qgspainteffect.h"
29#include "qgsthreadingutils.h"
30#include <QUuid>
31#include "RTree.h"
32
34class QgsAnnotationLayerSpatialIndex : public RTree<QString, float, 2, float>
35{
36 public:
37
38 void insert( const QString &uuid, const QgsRectangle &bounds )
39 {
40 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
41 this->Insert(
42 {
43 scaledBounds[0], scaledBounds[ 1]
44 },
45 {
46 scaledBounds[2], scaledBounds[3]
47 },
48 uuid );
49 }
50
57 void remove( const QString &uuid, const QgsRectangle &bounds )
58 {
59 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
60 this->Remove(
61 {
62 scaledBounds[0], scaledBounds[ 1]
63 },
64 {
65 scaledBounds[2], scaledBounds[3]
66 },
67 uuid );
68 }
69
75 bool intersects( const QgsRectangle &bounds, const std::function< bool( const QString &uuid )> &callback ) const
76 {
77 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
78 this->Search(
79 {
80 scaledBounds[0], scaledBounds[ 1]
81 },
82 {
83 scaledBounds[2], scaledBounds[3]
84 },
85 callback );
86 return true;
87 }
88
89 private:
90 std::array<float, 4> scaleBounds( const QgsRectangle &bounds ) const
91 {
92 return
93 {
94 static_cast< float >( bounds.xMinimum() ),
95 static_cast< float >( bounds.yMinimum() ),
96 static_cast< float >( bounds.xMaximum() ),
97 static_cast< float >( bounds.yMaximum() )
98 };
99 }
100};
102
103QgsAnnotationLayer::QgsAnnotationLayer( const QString &name, const LayerOptions &options )
104 : QgsMapLayer( Qgis::LayerType::Annotation, name )
105 , mTransformContext( options.transformContext )
106 , mSpatialIndex( std::make_unique< QgsAnnotationLayerSpatialIndex >() )
107{
108 mShouldValidateCrs = false;
109 mValid = true;
110
111 QgsDataProvider::ProviderOptions providerOptions;
112 providerOptions.transformContext = options.transformContext;
113 mDataProvider = new QgsAnnotationLayerDataProvider( providerOptions, Qgis::DataProviderReadFlags() );
114
115 mPaintEffect.reset( QgsPaintEffectRegistry::defaultStack() );
116 mPaintEffect->setEnabled( false );
117}
118
120{
121 emit willBeDeleted();
122 qDeleteAll( mItems );
123 delete mDataProvider;
124}
125
138
140{
142
143 const QString uuid = QUuid::createUuid().toString();
144 mItems.insert( uuid, item );
146 mNonIndexedItems.insert( uuid );
147 else
148 mSpatialIndex->insert( uuid, item->boundingBox() );
149
151
152 return uuid;
153}
154
156{
158
159 std::unique_ptr< QgsAnnotationItem> prevItem( mItems.take( id ) );
160
161 if ( prevItem )
162 {
163 auto it = mNonIndexedItems.find( id );
164 if ( it == mNonIndexedItems.end() )
165 {
166 mSpatialIndex->remove( id, prevItem->boundingBox() );
167 }
168 else
169 {
170 mNonIndexedItems.erase( it );
171 }
172 }
173
174 mItems.insert( id, item );
176 mNonIndexedItems.insert( id );
177 else
178 mSpatialIndex->insert( id, item->boundingBox() );
179
181}
182
183bool QgsAnnotationLayer::removeItem( const QString &id )
184{
186
187 if ( !mItems.contains( id ) )
188 return false;
189
190 std::unique_ptr< QgsAnnotationItem> item( mItems.take( id ) );
191
192 auto it = mNonIndexedItems.find( id );
193 if ( it == mNonIndexedItems.end() )
194 {
195 mSpatialIndex->remove( id, item->boundingBox() );
196 }
197 else
198 {
199 mNonIndexedItems.erase( it );
200 }
201
202 item.reset();
203
205
206 return true;
207}
208
210{
212
213 qDeleteAll( mItems );
214 mItems.clear();
215 mSpatialIndex = std::make_unique< QgsAnnotationLayerSpatialIndex >();
216 mNonIndexedItems.clear();
217
219}
220
222{
224
225 return mItems.empty();
226}
227
229{
231
232 return mItems.value( id );
233}
234
235QStringList QgsAnnotationLayer::queryIndex( const QgsRectangle &bounds, QgsFeedback *feedback ) const
236{
238
239 QStringList res;
240
241 mSpatialIndex->intersects( bounds, [&res, feedback]( const QString & uuid )->bool
242 {
243 res << uuid;
244 return !feedback || !feedback->isCanceled();
245 } );
246 return res;
247}
248
249QStringList QgsAnnotationLayer::itemsInBounds( const QgsRectangle &bounds, QgsRenderContext &context, QgsFeedback *feedback ) const
250{
252
253 QStringList res = queryIndex( bounds, feedback );
254 // we also have to search through any non-indexed items
255 for ( const QString &uuid : mNonIndexedItems )
256 {
257 if ( mItems.value( uuid )->boundingBox( context ).intersects( bounds ) )
258 res << uuid;
259 }
260
261 return res;
262}
263
270
272{
274
276 if ( QgsAnnotationItem *targetItem = item( operation->itemId() ) )
277 {
278 // remove item from index if present
279 auto it = mNonIndexedItems.find( operation->itemId() );
280 if ( it == mNonIndexedItems.end() )
281 {
282 mSpatialIndex->remove( operation->itemId(), targetItem->boundingBox() );
283 }
284 res = targetItem->applyEditV2( operation, context );
285
286 switch ( res )
287 {
290 // re-add to index if possible
291 if ( !( targetItem->flags() & Qgis::AnnotationItemFlag::ScaleDependentBoundingBox ) )
292 mSpatialIndex->insert( operation->itemId(), targetItem->boundingBox() );
293 break;
294
296 // item needs removing from layer
297 delete mItems.take( operation->itemId() );
298 mNonIndexedItems.remove( operation->itemId() );
299 break;
300 }
301 }
302
305
306 return res;
307}
308
316
318{
320
321 const QgsAnnotationLayer::LayerOptions options( mTransformContext );
322 std::unique_ptr< QgsAnnotationLayer > layer = std::make_unique< QgsAnnotationLayer >( name(), options );
323 QgsMapLayer::clone( layer.get() );
324
325 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
326 {
327 layer->mItems.insert( it.key(), ( *it )->clone() );
329 layer->mNonIndexedItems.insert( it.key() );
330 else
331 layer->mSpatialIndex->insert( it.key(), ( *it )->boundingBox() );
332 }
333
334 if ( mPaintEffect )
335 layer->setPaintEffect( mPaintEffect->clone() );
336
337 layer->mLinkedLayer = mLinkedLayer;
338
339 return layer.release();
340}
341
348
350{
352
353 QgsRectangle rect;
354 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
355 {
356 if ( rect.isNull() )
357 {
358 rect = it.value()->boundingBox();
359 }
360 else
361 {
362 rect.combineExtentWith( it.value()->boundingBox() );
363 }
364 }
365 return rect;
366}
367
369{
371
372 if ( mDataProvider )
373 mDataProvider->setTransformContext( context );
374
375 mTransformContext = context;
377}
378
379bool QgsAnnotationLayer::readXml( const QDomNode &layerNode, QgsReadWriteContext &context )
380{
382
384 {
385 return false;
386 }
387
388 QString errorMsg;
389 readItems( layerNode, errorMsg, context );
390 readSymbology( layerNode, errorMsg, context );
391
392 {
393 const QString layerId = layerNode.toElement().attribute( QStringLiteral( "linkedLayer" ) );
394 const QString layerName = layerNode.toElement().attribute( QStringLiteral( "linkedLayerName" ) );
395 const QString layerSource = layerNode.toElement().attribute( QStringLiteral( "linkedLayerSource" ) );
396 const QString layerProvider = layerNode.toElement().attribute( QStringLiteral( "linkedLayerProvider" ) );
397 mLinkedLayer = QgsMapLayerRef( layerId, layerName, layerSource, layerProvider );
398 }
399
401
402 return mValid;
403}
404
405bool QgsAnnotationLayer::writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const
406{
408
409 // first get the layer element so that we can append the type attribute
410 QDomElement mapLayerNode = layer_node.toElement();
411
412 if ( mapLayerNode.isNull() )
413 {
414 QgsDebugMsgLevel( QStringLiteral( "can't find maplayer node" ), 2 );
415 return false;
416 }
417
418 mapLayerNode.setAttribute( QStringLiteral( "type" ), QgsMapLayerFactory::typeToString( Qgis::LayerType::Annotation ) );
419
420 if ( mLinkedLayer )
421 {
422 mapLayerNode.setAttribute( QStringLiteral( "linkedLayer" ), mLinkedLayer.layerId );
423 mapLayerNode.setAttribute( QStringLiteral( "linkedLayerName" ), mLinkedLayer.name );
424 mapLayerNode.setAttribute( QStringLiteral( "linkedLayerSource" ), mLinkedLayer.source );
425 mapLayerNode.setAttribute( QStringLiteral( "linkedLayerProvider" ), mLinkedLayer.provider );
426 }
427
428 QString errorMsg;
429 writeItems( layer_node, doc, errorMsg, context );
430
431 // renderer specific settings
432 return writeSymbology( layer_node, doc, errorMsg, context );
433}
434
435bool QgsAnnotationLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
436{
438
439 QDomElement layerElement = node.toElement();
440 writeCommonStyle( layerElement, doc, context, categories );
441
442 // add the layer opacity
443 if ( categories.testFlag( Rendering ) )
444 {
445 QDomElement layerOpacityElem = doc.createElement( QStringLiteral( "layerOpacity" ) );
446 const QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
447 layerOpacityElem.appendChild( layerOpacityText );
448 node.appendChild( layerOpacityElem );
449 }
450
451 if ( categories.testFlag( Symbology ) )
452 {
453 // add the blend mode field
454 QDomElement blendModeElem = doc.createElement( QStringLiteral( "blendMode" ) );
455 const QDomText blendModeText = doc.createTextNode( QString::number( static_cast< int >( QgsPainting::getBlendModeEnum( blendMode() ) ) ) );
456 blendModeElem.appendChild( blendModeText );
457 node.appendChild( blendModeElem );
458
459 QDomElement paintEffectElem = doc.createElement( QStringLiteral( "paintEffect" ) );
460 if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect.get() ) )
461 mPaintEffect->saveProperties( doc, paintEffectElem );
462 node.appendChild( paintEffectElem );
463 }
464
465 return true;
466}
467
468bool QgsAnnotationLayer::readSymbology( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
469{
471
472 const QDomElement layerElement = node.toElement();
473 readCommonStyle( layerElement, context, categories );
474
475 if ( categories.testFlag( Rendering ) )
476 {
477 const QDomNode layerOpacityNode = node.namedItem( QStringLiteral( "layerOpacity" ) );
478 if ( !layerOpacityNode.isNull() )
479 {
480 const QDomElement e = layerOpacityNode.toElement();
481 setOpacity( e.text().toDouble() );
482 }
483 }
484
485 if ( categories.testFlag( Symbology ) )
486 {
487 // get and set the blend mode if it exists
488 const QDomNode blendModeNode = node.namedItem( QStringLiteral( "blendMode" ) );
489 if ( !blendModeNode.isNull() )
490 {
491 const QDomElement e = blendModeNode.toElement();
492 setBlendMode( QgsPainting::getCompositionMode( static_cast< Qgis::BlendMode >( e.text().toInt() ) ) );
493 }
494
495 //restore layer effect
496 const QDomNode paintEffectNode = node.namedItem( QStringLiteral( "paintEffect" ) );
497 if ( !paintEffectNode.isNull() )
498 {
499 const QDomElement effectElem = paintEffectNode.firstChildElement( QStringLiteral( "effect" ) );
500 if ( !effectElem.isNull() )
501 {
502 setPaintEffect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
503 }
504 }
505 }
506
507 return true;
508}
509
510bool QgsAnnotationLayer::writeItems( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories ) const
511{
513
514 QDomElement itemsElement = doc.createElement( QStringLiteral( "items" ) );
515
516 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
517 {
518 QDomElement itemElement = doc.createElement( QStringLiteral( "item" ) );
519 itemElement.setAttribute( QStringLiteral( "type" ), ( *it )->type() );
520 itemElement.setAttribute( QStringLiteral( "id" ), it.key() );
521 ( *it )->writeXml( itemElement, doc, context );
522 itemsElement.appendChild( itemElement );
523 }
524 node.appendChild( itemsElement );
525
526 return true;
527}
528
529bool QgsAnnotationLayer::readItems( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories )
530{
532
533 qDeleteAll( mItems );
534 mItems.clear();
535 mSpatialIndex = std::make_unique< QgsAnnotationLayerSpatialIndex >();
536 mNonIndexedItems.clear();
537
538 const QDomNodeList itemsElements = node.toElement().elementsByTagName( QStringLiteral( "items" ) );
539 if ( itemsElements.size() == 0 )
540 return false;
541
542 const QDomNodeList items = itemsElements.at( 0 ).childNodes();
543 for ( int i = 0; i < items.size(); ++i )
544 {
545 const QDomElement itemElement = items.at( i ).toElement();
546 const QString id = itemElement.attribute( QStringLiteral( "id" ) );
547 const QString type = itemElement.attribute( QStringLiteral( "type" ) );
548 std::unique_ptr< QgsAnnotationItem > item( QgsApplication::annotationItemRegistry()->createItem( type ) );
549 if ( item )
550 {
551 item->readXml( itemElement, context );
553 mNonIndexedItems.insert( id );
554 else
555 mSpatialIndex->insert( id, item->boundingBox() );
556 mItems.insert( id, item.release() );
557 }
558 }
559
560 return true;
561}
562
563bool QgsAnnotationLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
564{
566
567 writeItems( node, doc, errorMessage, context, categories );
568
569 return writeSymbology( node, doc, errorMessage, context, categories );
570}
571
572bool QgsAnnotationLayer::readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
573{
575
576 readItems( node, errorMessage, context, categories );
577
578 return readSymbology( node, errorMessage, context, categories );
579}
580
582{
584
585 // annotation layers are always editable
586 return true;
587}
588
590{
592
593 return true;
594}
595
602
604{
606
607 return mDataProvider;
608}
609
611{
613
614 QString metadata = QStringLiteral( "<html>\n<body>\n<h1>" ) + tr( "General" ) + QStringLiteral( "</h1>\n<hr>\n" ) + QStringLiteral( "<table class=\"list-view\">\n" );
615
616 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Name" ) + QStringLiteral( "</td><td>" ) + name() + QStringLiteral( "</td></tr>\n" );
617
618 // Extent
619 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Extent" ) + QStringLiteral( "</td><td>" ) + extent().toString() + QStringLiteral( "</td></tr>\n" );
620
621 // item count
622 QLocale locale = QLocale();
623 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
624 const int itemCount = mItems.size();
625 metadata += QStringLiteral( "<tr><td class=\"highlight\">" )
626 + tr( "Item count" ) + QStringLiteral( "</td><td>" )
627 + locale.toString( static_cast<qlonglong>( itemCount ) )
628 + QStringLiteral( "</td></tr>\n" );
629 metadata += QLatin1String( "</table>\n<br><br>" );
630
631 // CRS
633
634 // items section
635 metadata += QStringLiteral( "<h1>" ) + tr( "Items" ) + QStringLiteral( "</h1>\n<hr>\n" );
636
637 metadata += QLatin1String( "<table width=\"100%\" class=\"tabular-view\">\n" );
638 metadata += QLatin1String( "<tr><th>" ) + tr( "Type" ) + QLatin1String( "</th><th>" ) + tr( "Count" ) + QLatin1String( "</th></tr>\n" );
639
640 QMap< QString, int > itemCounts;
641 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
642 {
643 itemCounts[ it.value()->type() ]++;
644 }
645
646 const QMap<QString, QString> itemTypes = QgsApplication::annotationItemRegistry()->itemTypes();
647 int i = 0;
648 for ( auto it = itemTypes.begin(); it != itemTypes.end(); ++it )
649 {
650 QString rowClass;
651 if ( i % 2 )
652 rowClass = QStringLiteral( "class=\"odd-row\"" );
653 metadata += QLatin1String( "<tr " ) + rowClass + QLatin1String( "><td>" ) + it.value() + QLatin1String( "</td><td>" ) + locale.toString( static_cast<qlonglong>( itemCounts.value( it.key() ) ) ) + QLatin1String( "</td></tr>\n" );
654 i++;
655 }
656
657 metadata += QLatin1String( "</table>\n<br><br>" );
658
659 metadata += QLatin1String( "\n</body>\n</html>\n" );
660 return metadata;
661}
662
664{
665 mLinkedLayer.resolve( project );
666}
667
669{
671
672 return mPaintEffect.get();
673}
674
676{
678
679 mPaintEffect.reset( effect );
680}
681
688
696
697
698//
699// QgsAnnotationLayerDataProvider
700//
702QgsAnnotationLayerDataProvider::QgsAnnotationLayerDataProvider(
703 const ProviderOptions &options,
705 : QgsDataProvider( QString(), options, flags )
706{}
707
708QgsCoordinateReferenceSystem QgsAnnotationLayerDataProvider::crs() const
709{
711
713}
714
715QString QgsAnnotationLayerDataProvider::name() const
716{
718
719 return QStringLiteral( "annotation" );
720}
721
722QString QgsAnnotationLayerDataProvider::description() const
723{
725
726 return QString();
727}
728
729QgsRectangle QgsAnnotationLayerDataProvider::extent() const
730{
732
733 return QgsRectangle();
734}
735
736bool QgsAnnotationLayerDataProvider::isValid() const
737{
739
740 return true;
741}
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:2351
@ 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:4542
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:2118
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.
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() const
Returns the x minimum value (left side of rectangle).
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
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.