QGIS API Documentation 3.99.0-Master (d270888f95f)
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 <QString>
34#include <QUuid>
35
36#include "moc_qgsannotationlayer.cpp"
37
38using namespace Qt::StringLiterals;
39
41class QgsAnnotationLayerSpatialIndex : public RTree<QString, float, 2, float>
42{
43 public:
44
45 void insert( const QString &uuid, const QgsRectangle &bounds )
46 {
47 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
48 float aMin[2]
49 {
50 scaledBounds[0], scaledBounds[ 1]
51 };
52 float aMax[2]
53 {
54 scaledBounds[2], scaledBounds[ 3]
55 };
56 this->Insert(
57 aMin,
58 aMax,
59 uuid );
60 }
61
68 void remove( const QString &uuid, const QgsRectangle &bounds )
69 {
70 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
71 float aMin[2]
72 {
73 scaledBounds[0], scaledBounds[ 1]
74 };
75 float aMax[2]
76 {
77 scaledBounds[2], scaledBounds[ 3]
78 };
79 this->Remove(
80 aMin,
81 aMax,
82 uuid );
83 }
84
90 bool intersects( const QgsRectangle &bounds, const std::function< bool( const QString &uuid )> &callback ) const
91 {
92 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
93 float aMin[2]
94 {
95 scaledBounds[0], scaledBounds[ 1]
96 };
97 float aMax[2]
98 {
99 scaledBounds[2], scaledBounds[ 3]
100 };
101 this->Search(
102 aMin, aMax,
103 callback );
104 return true;
105 }
106
107 private:
108 std::array<float, 4> scaleBounds( const QgsRectangle &bounds ) const
109 {
110 return
111 {
112 static_cast< float >( bounds.xMinimum() ),
113 static_cast< float >( bounds.yMinimum() ),
114 static_cast< float >( bounds.xMaximum() ),
115 static_cast< float >( bounds.yMaximum() )
116 };
117 }
118};
120
122 : QgsMapLayer( Qgis::LayerType::Annotation, name )
123 , mTransformContext( options.transformContext )
124 , mSpatialIndex( std::make_unique< QgsAnnotationLayerSpatialIndex >() )
125{
126 mShouldValidateCrs = false;
127 mValid = true;
128
129 QgsDataProvider::ProviderOptions providerOptions;
130 providerOptions.transformContext = options.transformContext;
131 mDataProvider = std::make_unique<QgsAnnotationLayerDataProvider>( providerOptions, Qgis::DataProviderReadFlags() );
132
133 mPaintEffect.reset( QgsPaintEffectRegistry::defaultStack() );
134 mPaintEffect->setEnabled( false );
135}
136
138{
139 emit willBeDeleted();
140 qDeleteAll( mItems );
141
142}
143
156
158{
160
161 const QString uuid = QUuid::createUuid().toString();
162 mItems.insert( uuid, item );
164 mNonIndexedItems.insert( uuid );
165 else
166 mSpatialIndex->insert( uuid, item->boundingBox() );
167
169
170 return uuid;
171}
172
174{
176
177 std::unique_ptr< QgsAnnotationItem> prevItem( mItems.take( id ) );
178
179 if ( prevItem )
180 {
181 auto it = mNonIndexedItems.find( id );
182 if ( it == mNonIndexedItems.end() )
183 {
184 mSpatialIndex->remove( id, prevItem->boundingBox() );
185 }
186 else
187 {
188 mNonIndexedItems.erase( it );
189 }
190 }
191
192 mItems.insert( id, item );
194 mNonIndexedItems.insert( id );
195 else
196 mSpatialIndex->insert( id, item->boundingBox() );
197
199}
200
201bool QgsAnnotationLayer::removeItem( const QString &id )
202{
204
205 if ( !mItems.contains( id ) )
206 return false;
207
208 std::unique_ptr< QgsAnnotationItem> item( mItems.take( id ) );
209
210 auto it = mNonIndexedItems.find( id );
211 if ( it == mNonIndexedItems.end() )
212 {
213 mSpatialIndex->remove( id, item->boundingBox() );
214 }
215 else
216 {
217 mNonIndexedItems.erase( it );
218 }
219
220 item.reset();
221
223
224 return true;
225}
226
228{
230
231 qDeleteAll( mItems );
232 mItems.clear();
233 mSpatialIndex = std::make_unique< QgsAnnotationLayerSpatialIndex >();
234 mNonIndexedItems.clear();
235
237}
238
240{
242
243 return mItems.empty();
244}
245
247{
249
250 return mItems.value( id );
251}
252
253QStringList QgsAnnotationLayer::queryIndex( const QgsRectangle &bounds, QgsFeedback *feedback ) const
254{
256
257 QStringList res;
258
259 mSpatialIndex->intersects( bounds, [&res, feedback]( const QString & uuid )->bool
260 {
261 res << uuid;
262 return !feedback || !feedback->isCanceled();
263 } );
264 return res;
265}
266
267QStringList QgsAnnotationLayer::itemsInBounds( const QgsRectangle &bounds, QgsRenderContext &context, QgsFeedback *feedback ) const
268{
270
271 QStringList res = queryIndex( bounds, feedback );
272 // we also have to search through any non-indexed items
273 for ( const QString &uuid : mNonIndexedItems )
274 {
275 auto it = mItems.constFind( uuid );
276 if ( it != mItems.constEnd() && it.value()->boundingBox( context ).intersects( bounds ) )
277 res << uuid;
278 }
279
280 return res;
281}
282
289
291{
293
295 if ( QgsAnnotationItem *targetItem = item( operation->itemId() ) )
296 {
297 // remove item from index if present
298 auto it = mNonIndexedItems.find( operation->itemId() );
299 if ( it == mNonIndexedItems.end() )
300 {
301 mSpatialIndex->remove( operation->itemId(), targetItem->boundingBox() );
302 }
303 res = targetItem->applyEditV2( operation, context );
304
305 switch ( res )
306 {
309 // re-add to index if possible
310 if ( !( targetItem->flags() & Qgis::AnnotationItemFlag::ScaleDependentBoundingBox ) )
311 mSpatialIndex->insert( operation->itemId(), targetItem->boundingBox() );
312 break;
313
315 // item needs removing from layer
316 delete mItems.take( operation->itemId() );
317 mNonIndexedItems.remove( operation->itemId() );
318 break;
319 }
320 }
321
324
325 return res;
326}
327
335
337{
339
340 const QgsAnnotationLayer::LayerOptions options( mTransformContext );
341 auto layer = std::make_unique< QgsAnnotationLayer >( name(), options );
342 QgsMapLayer::clone( layer.get() );
343
344 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
345 {
346 layer->mItems.insert( it.key(), ( *it )->clone() );
348 layer->mNonIndexedItems.insert( it.key() );
349 else
350 layer->mSpatialIndex->insert( it.key(), ( *it )->boundingBox() );
351 }
352
353 if ( mPaintEffect )
354 layer->setPaintEffect( mPaintEffect->clone() );
355
356 layer->mLinkedLayer = mLinkedLayer;
357
358 return layer.release();
359}
360
367
369{
371
372 QgsRectangle rect;
373 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
374 {
375 if ( rect.isNull() )
376 {
377 rect = it.value()->boundingBox();
378 }
379 else
380 {
381 rect.combineExtentWith( it.value()->boundingBox() );
382 }
383 }
384 return rect;
385}
386
388{
390
391 if ( mDataProvider )
392 mDataProvider->setTransformContext( context );
393
394 mTransformContext = context;
396}
397
398bool QgsAnnotationLayer::readXml( const QDomNode &layerNode, QgsReadWriteContext &context )
399{
401
403 {
404 return false;
405 }
406
407 QString errorMsg;
408 readItems( layerNode, errorMsg, context );
409 readSymbology( layerNode, errorMsg, context );
410
411 {
412 const QString layerId = layerNode.toElement().attribute( u"linkedLayer"_s );
413 const QString layerName = layerNode.toElement().attribute( u"linkedLayerName"_s );
414 const QString layerSource = layerNode.toElement().attribute( u"linkedLayerSource"_s );
415 const QString layerProvider = layerNode.toElement().attribute( u"linkedLayerProvider"_s );
416 mLinkedLayer = QgsMapLayerRef( layerId, layerName, layerSource, layerProvider );
417 }
418
420
421 return mValid;
422}
423
424bool QgsAnnotationLayer::writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const
425{
427
428 // first get the layer element so that we can append the type attribute
429 QDomElement mapLayerNode = layer_node.toElement();
430
431 if ( mapLayerNode.isNull() )
432 {
433 QgsDebugMsgLevel( u"can't find maplayer node"_s, 2 );
434 return false;
435 }
436
437 mapLayerNode.setAttribute( u"type"_s, QgsMapLayerFactory::typeToString( Qgis::LayerType::Annotation ) );
438
439 if ( mLinkedLayer )
440 {
441 mapLayerNode.setAttribute( u"linkedLayer"_s, mLinkedLayer.layerId );
442 mapLayerNode.setAttribute( u"linkedLayerName"_s, mLinkedLayer.name );
443 mapLayerNode.setAttribute( u"linkedLayerSource"_s, mLinkedLayer.source );
444 mapLayerNode.setAttribute( u"linkedLayerProvider"_s, mLinkedLayer.provider );
445 }
446
447 QString errorMsg;
448 writeItems( layer_node, doc, errorMsg, context );
449
450 // renderer specific settings
451 return writeSymbology( layer_node, doc, errorMsg, context );
452}
453
454bool QgsAnnotationLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
455{
457
458 QDomElement layerElement = node.toElement();
459 writeCommonStyle( layerElement, doc, context, categories );
460
461 // add the layer opacity
462 if ( categories.testFlag( Rendering ) )
463 {
464 QDomElement layerOpacityElem = doc.createElement( u"layerOpacity"_s );
465 const QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
466 layerOpacityElem.appendChild( layerOpacityText );
467 node.appendChild( layerOpacityElem );
468 }
469
470 if ( categories.testFlag( Symbology ) )
471 {
472 // add the blend mode field
473 QDomElement blendModeElem = doc.createElement( u"blendMode"_s );
474 const QDomText blendModeText = doc.createTextNode( QString::number( static_cast< int >( QgsPainting::getBlendModeEnum( blendMode() ) ) ) );
475 blendModeElem.appendChild( blendModeText );
476 node.appendChild( blendModeElem );
477
478 QDomElement paintEffectElem = doc.createElement( u"paintEffect"_s );
479 if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect.get() ) )
480 mPaintEffect->saveProperties( doc, paintEffectElem );
481 node.appendChild( paintEffectElem );
482 }
483
484 return true;
485}
486
487bool QgsAnnotationLayer::readSymbology( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
488{
490
491 const QDomElement layerElement = node.toElement();
492 readCommonStyle( layerElement, context, categories );
493
494 if ( categories.testFlag( Rendering ) )
495 {
496 const QDomNode layerOpacityNode = node.namedItem( u"layerOpacity"_s );
497 if ( !layerOpacityNode.isNull() )
498 {
499 const QDomElement e = layerOpacityNode.toElement();
500 setOpacity( e.text().toDouble() );
501 }
502 }
503
504 if ( categories.testFlag( Symbology ) )
505 {
506 // get and set the blend mode if it exists
507 const QDomNode blendModeNode = node.namedItem( u"blendMode"_s );
508 if ( !blendModeNode.isNull() )
509 {
510 const QDomElement e = blendModeNode.toElement();
511 setBlendMode( QgsPainting::getCompositionMode( static_cast< Qgis::BlendMode >( e.text().toInt() ) ) );
512 }
513
514 //restore layer effect
515 const QDomNode paintEffectNode = node.namedItem( u"paintEffect"_s );
516 if ( !paintEffectNode.isNull() )
517 {
518 const QDomElement effectElem = paintEffectNode.firstChildElement( u"effect"_s );
519 if ( !effectElem.isNull() )
520 {
521 setPaintEffect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
522 }
523 }
524 }
525
526 return true;
527}
528
529bool QgsAnnotationLayer::writeItems( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories ) const
530{
532
533 QDomElement itemsElement = doc.createElement( u"items"_s );
534
535 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
536 {
537 QDomElement itemElement = doc.createElement( u"item"_s );
538 itemElement.setAttribute( u"type"_s, ( *it )->type() );
539 itemElement.setAttribute( u"id"_s, it.key() );
540 ( *it )->writeXml( itemElement, doc, context );
541 itemsElement.appendChild( itemElement );
542 }
543 node.appendChild( itemsElement );
544
545 return true;
546}
547
548bool QgsAnnotationLayer::readItems( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories )
549{
551
552 qDeleteAll( mItems );
553 mItems.clear();
554 mSpatialIndex = std::make_unique< QgsAnnotationLayerSpatialIndex >();
555 mNonIndexedItems.clear();
556
557 const QDomNodeList itemsElements = node.toElement().elementsByTagName( u"items"_s );
558 if ( itemsElements.size() == 0 )
559 return false;
560
561 const QDomNodeList items = itemsElements.at( 0 ).childNodes();
562 for ( int i = 0; i < items.size(); ++i )
563 {
564 const QDomElement itemElement = items.at( i ).toElement();
565 const QString id = itemElement.attribute( u"id"_s );
566 const QString type = itemElement.attribute( u"type"_s );
567 std::unique_ptr< QgsAnnotationItem > item( QgsApplication::annotationItemRegistry()->createItem( type ) );
568 if ( item )
569 {
570 item->readXml( itemElement, context );
572 mNonIndexedItems.insert( id );
573 else
574 mSpatialIndex->insert( id, item->boundingBox() );
575 mItems.insert( id, item.release() );
576 }
577 }
578
579 return true;
580}
581
582bool QgsAnnotationLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
583{
585
586 writeItems( node, doc, errorMessage, context, categories );
587
588 return writeSymbology( node, doc, errorMessage, context, categories );
589}
590
591bool QgsAnnotationLayer::readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
592{
594
595 readItems( node, errorMessage, context, categories );
596
597 return readSymbology( node, errorMessage, context, categories );
598}
599
601{
603
604 // annotation layers are always editable
605 return true;
606}
607
609{
611
612 return true;
613}
614
621
623{
625
626 return mDataProvider.get();
627}
628
630{
632
633 QString metadata = u"<html>\n<body>\n<h1>"_s + tr( "General" ) + u"</h1>\n<hr>\n"_s + u"<table class=\"list-view\">\n"_s;
634
635 metadata += u"<tr><td class=\"highlight\">"_s + tr( "Name" ) + u"</td><td>"_s + name() + u"</td></tr>\n"_s;
636
637 // Extent
638 metadata += u"<tr><td class=\"highlight\">"_s + tr( "Extent" ) + u"</td><td>"_s + extent().toString() + u"</td></tr>\n"_s;
639
640 // item count
641 QLocale locale = QLocale();
642 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
643 const int itemCount = mItems.size();
644 metadata += u"<tr><td class=\"highlight\">"_s
645 + tr( "Item count" ) + u"</td><td>"_s
646 + locale.toString( static_cast<qlonglong>( itemCount ) )
647 + u"</td></tr>\n"_s;
648 metadata += "</table>\n<br><br>"_L1;
649
650 // CRS
652
653 // items section
654 metadata += u"<h1>"_s + tr( "Items" ) + u"</h1>\n<hr>\n"_s;
655
656 metadata += "<table width=\"100%\" class=\"tabular-view\">\n"_L1;
657 metadata += "<tr><th>"_L1 + tr( "Type" ) + "</th><th>"_L1 + tr( "Count" ) + "</th></tr>\n"_L1;
658
659 QMap< QString, int > itemCounts;
660 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
661 {
662 itemCounts[ it.value()->type() ]++;
663 }
664
665 const QMap<QString, QString> itemTypes = QgsApplication::annotationItemRegistry()->itemTypes();
666 int i = 0;
667 for ( auto it = itemTypes.begin(); it != itemTypes.end(); ++it )
668 {
669 QString rowClass;
670 if ( i % 2 )
671 rowClass = u"class=\"odd-row\""_s;
672 metadata += "<tr "_L1 + rowClass + "><td>"_L1 + it.value() + "</td><td>"_L1 + locale.toString( static_cast<qlonglong>( itemCounts.value( it.key() ) ) ) + "</td></tr>\n"_L1;
673 i++;
674 }
675
676 metadata += "</table>\n<br><br>"_L1;
677
678 metadata += "\n</body>\n</html>\n"_L1;
679 return metadata;
680}
681
683{
684 mLinkedLayer.resolve( project );
685}
686
688{
690
691 return mPaintEffect.get();
692}
693
695{
697
698 mPaintEffect.reset( effect );
699}
700
707
709{
711
712 mLinkedLayer.setLayer( layer );
714}
715
716
717//
718// QgsAnnotationLayerDataProvider
719//
721QgsAnnotationLayerDataProvider::QgsAnnotationLayerDataProvider(
722 const ProviderOptions &options,
724 : QgsDataProvider( QString(), options, flags )
725{}
726
727QgsCoordinateReferenceSystem QgsAnnotationLayerDataProvider::crs() const
728{
730
732}
733
734QString QgsAnnotationLayerDataProvider::name() const
735{
737
738 return u"annotation"_s;
739}
740
741QString QgsAnnotationLayerDataProvider::description() const
742{
744
745 return QString();
746}
747
748QgsRectangle QgsAnnotationLayerDataProvider::extent() const
749{
751
752 return QgsRectangle();
753}
754
755bool QgsAnnotationLayerDataProvider::isValid() const
756{
758
759 return true;
760}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
@ UsersCannotToggleEditing
Indicates that users are not allowed to toggle editing for this layer. Note that this does not imply ...
Definition qgis.h:2338
@ ScaleDependentBoundingBox
Item's bounding box will vary depending on map scale.
Definition qgis.h:2523
AnnotationItemEditOperationResult
Results from an edit operation on an annotation item.
Definition qgis.h:2577
@ Invalid
Operation has invalid parameters for the item, no change occurred.
Definition qgis.h:2579
@ Success
Item was modified successfully.
Definition qgis.h:2578
@ ItemCleared
The operation results in the item being cleared, and the item should be removed from the layer as a r...
Definition qgis.h:2580
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Definition qgis.h:5002
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:505
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
Definition qgis.h:199
QFlags< MapLayerProperty > MapLayerProperties
Map layer properties.
Definition qgis.h:2343
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:55
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:87
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:89
QgsMapLayer(Qgis::LayerType type=Qgis::LayerType::Vector, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
Qgis::LayerType type
Definition qgsmaplayer.h:93
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:95
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:112
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:63
_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.