QGIS API Documentation 4.3.0-Master (767b36bf018)
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 void insert( const QString &uuid, const QgsRectangle &bounds )
45 {
46 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
47 float aMin[2] { scaledBounds[0], scaledBounds[1] };
48 float aMax[2] { scaledBounds[2], scaledBounds[3] };
49 this->Insert( aMin, aMax, uuid );
50 }
51
58 void remove( const QString &uuid, const QgsRectangle &bounds )
59 {
60 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
61 float aMin[2] { scaledBounds[0], scaledBounds[1] };
62 float aMax[2] { scaledBounds[2], scaledBounds[3] };
63 this->Remove( aMin, aMax, uuid );
64 }
65
71 bool intersects( const QgsRectangle &bounds, const std::function< bool( const QString &uuid )> &callback ) const
72 {
73 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
74 float aMin[2] { scaledBounds[0], scaledBounds[1] };
75 float aMax[2] { scaledBounds[2], scaledBounds[3] };
76 this->Search( aMin, aMax, callback );
77 return true;
78 }
79
80 private:
81 std::array<float, 4> scaleBounds( const QgsRectangle &bounds ) const
82 {
83 return { static_cast< float >( bounds.xMinimum() ), static_cast< float >( bounds.yMinimum() ), static_cast< float >( bounds.xMaximum() ), static_cast< float >( bounds.yMaximum() ) };
84 }
85};
87
89 : QgsMapLayer( Qgis::LayerType::Annotation, name )
90 , mTransformContext( options.transformContext )
91 , mSpatialIndex( std::make_unique< QgsAnnotationLayerSpatialIndex >() )
92{
93 mShouldValidateCrs = false;
94 mValid = true;
95
97 providerOptions.transformContext = options.transformContext;
98 mDataProvider = std::make_unique<QgsAnnotationLayerDataProvider>( providerOptions, Qgis::DataProviderReadFlags() );
99
100 mPaintEffect.reset( QgsPaintEffectRegistry::defaultStack() );
101 mPaintEffect->setEnabled( false );
102}
103
105{
106 emit willBeDeleted();
107 qDeleteAll( mItems );
108}
109
122
124{
126
127 const QString uuid = QUuid::createUuid().toString();
128 mItems.insert( uuid, item );
130 mNonIndexedItems.insert( uuid );
131 else
132 mSpatialIndex->insert( uuid, item->boundingBox() );
133
134 emit itemsChanged();
136
137 return uuid;
138}
139
141{
143
144 std::unique_ptr< QgsAnnotationItem> prevItem( mItems.take( id ) );
145
146 if ( prevItem )
147 {
148 auto it = mNonIndexedItems.find( id );
149 if ( it == mNonIndexedItems.end() )
150 {
151 mSpatialIndex->remove( id, prevItem->boundingBox() );
152 }
153 else
154 {
155 mNonIndexedItems.erase( it );
156 }
157 }
158
159 mItems.insert( id, item );
161 mNonIndexedItems.insert( id );
162 else
163 mSpatialIndex->insert( id, item->boundingBox() );
164
165 emit itemsChanged();
167}
168
169bool QgsAnnotationLayer::removeItem( const QString &id )
170{
172
173 if ( !mItems.contains( id ) )
174 return false;
175
176 std::unique_ptr< QgsAnnotationItem> item( mItems.take( id ) );
177
178 auto it = mNonIndexedItems.find( id );
179 if ( it == mNonIndexedItems.end() )
180 {
181 mSpatialIndex->remove( id, item->boundingBox() );
182 }
183 else
184 {
185 mNonIndexedItems.erase( it );
186 }
187
188 item.reset();
189
190 emit itemsChanged();
192
193 return true;
194}
195
197{
199
200 qDeleteAll( mItems );
201 mItems.clear();
202 mSpatialIndex = std::make_unique< QgsAnnotationLayerSpatialIndex >();
203 mNonIndexedItems.clear();
204
205 emit itemsChanged();
207}
208
210{
212
213 return mItems.empty();
214}
215
217{
219
220 return mItems.value( id );
221}
222
223QStringList QgsAnnotationLayer::queryIndex( const QgsRectangle &bounds, QgsFeedback *feedback ) const
224{
226
227 QStringList res;
228
229 mSpatialIndex->intersects( bounds, [&res, feedback]( const QString &uuid ) -> bool {
230 res << uuid;
231 return !feedback || !feedback->isCanceled();
232 } );
233 return res;
234}
235
236QStringList QgsAnnotationLayer::itemsInBounds( const QgsRectangle &bounds, QgsRenderContext &context, QgsFeedback *feedback ) const
237{
239
240 QStringList res = queryIndex( bounds, feedback );
241 // we also have to search through any non-indexed items
242 for ( const QString &uuid : mNonIndexedItems )
243 {
244 auto it = mItems.constFind( uuid );
245 if ( it != mItems.constEnd() && it.value()->boundingBox( context ).intersects( bounds ) )
246 res << uuid;
247 }
248
249 return res;
250}
251
258
260{
262
264 if ( QgsAnnotationItem *targetItem = item( operation->itemId() ) )
265 {
266 // remove item from index if present
267 auto it = mNonIndexedItems.find( operation->itemId() );
268 if ( it == mNonIndexedItems.end() )
269 {
270 mSpatialIndex->remove( operation->itemId(), targetItem->boundingBox() );
271 }
272 res = targetItem->applyEditV2( operation, context );
273
274 switch ( res )
275 {
278 // re-add to index if possible
279 if ( !( targetItem->flags() & Qgis::AnnotationItemFlag::ScaleDependentBoundingBox ) )
280 mSpatialIndex->insert( operation->itemId(), targetItem->boundingBox() );
281 break;
282
284 // item needs removing from layer
285 delete mItems.take( operation->itemId() );
286 mNonIndexedItems.remove( operation->itemId() );
287 break;
288 }
289 }
290
292 {
293 emit itemsChanged();
295 }
296
297 return res;
298}
299
307
309{
311
312 const QgsAnnotationLayer::LayerOptions options( mTransformContext );
313 auto layer = std::make_unique< QgsAnnotationLayer >( name(), options );
314 QgsMapLayer::clone( layer.get() );
315
316 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
317 {
318 layer->mItems.insert( it.key(), ( *it )->clone() );
320 layer->mNonIndexedItems.insert( it.key() );
321 else
322 layer->mSpatialIndex->insert( it.key(), ( *it )->boundingBox() );
323 }
324
325 if ( mPaintEffect )
326 layer->setPaintEffect( mPaintEffect->clone() );
327
328 layer->mLinkedLayer = mLinkedLayer;
329
330 return layer.release();
331}
332
339
341{
343
344 QgsRectangle rect;
345 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
346 {
347 if ( rect.isNull() )
348 {
349 rect = it.value()->boundingBox();
350 }
351 else
352 {
353 rect.combineExtentWith( it.value()->boundingBox() );
354 }
355 }
356 return rect;
357}
358
360{
362
363 if ( mDataProvider )
364 mDataProvider->setTransformContext( context );
365
366 mTransformContext = context;
368}
369
370bool QgsAnnotationLayer::readXml( const QDomNode &layerNode, QgsReadWriteContext &context )
371{
373
375 {
376 return false;
377 }
378
379 QString errorMsg;
380 readItems( layerNode, errorMsg, context );
381 readSymbology( layerNode, errorMsg, context );
382
383 {
384 const QString layerId = layerNode.toElement().attribute( u"linkedLayer"_s );
385 const QString layerName = layerNode.toElement().attribute( u"linkedLayerName"_s );
386 const QString layerSource = layerNode.toElement().attribute( u"linkedLayerSource"_s );
387 const QString layerProvider = layerNode.toElement().attribute( u"linkedLayerProvider"_s );
388 mLinkedLayer = QgsMapLayerRef( layerId, layerName, layerSource, layerProvider );
389 }
390
391 emit itemsChanged();
393
394 return mValid;
395}
396
397bool QgsAnnotationLayer::writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const
398{
400
401 // first get the layer element so that we can append the type attribute
402 QDomElement mapLayerNode = layer_node.toElement();
403
404 if ( mapLayerNode.isNull() )
405 {
406 QgsDebugMsgLevel( u"can't find maplayer node"_s, 2 );
407 return false;
408 }
409
410 mapLayerNode.setAttribute( u"type"_s, QgsMapLayerFactory::typeToString( Qgis::LayerType::Annotation ) );
411
412 if ( mLinkedLayer )
413 {
414 mapLayerNode.setAttribute( u"linkedLayer"_s, mLinkedLayer.layerId );
415 mapLayerNode.setAttribute( u"linkedLayerName"_s, mLinkedLayer.name );
416 mapLayerNode.setAttribute( u"linkedLayerSource"_s, mLinkedLayer.source );
417 mapLayerNode.setAttribute( u"linkedLayerProvider"_s, mLinkedLayer.provider );
418 }
419
420 QString errorMsg;
421 writeItems( layer_node, doc, errorMsg, context );
422
423 // renderer specific settings
424 return writeSymbology( layer_node, doc, errorMsg, context );
425}
426
427bool QgsAnnotationLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
428{
430
431 QDomElement layerElement = node.toElement();
432 writeCommonStyle( layerElement, doc, context, categories );
433
434 // add the layer opacity
435 if ( categories.testFlag( Rendering ) )
436 {
437 QDomElement layerOpacityElem = doc.createElement( u"layerOpacity"_s );
438 const QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
439 layerOpacityElem.appendChild( layerOpacityText );
440 node.appendChild( layerOpacityElem );
441 }
442
443 if ( categories.testFlag( Symbology ) )
444 {
445 // add the blend mode field
446 QDomElement blendModeElem = doc.createElement( u"blendMode"_s );
447 const QDomText blendModeText = doc.createTextNode( QString::number( static_cast< int >( QgsPainting::getBlendModeEnum( blendMode() ) ) ) );
448 blendModeElem.appendChild( blendModeText );
449 node.appendChild( blendModeElem );
450
451 QDomElement paintEffectElem = doc.createElement( u"paintEffect"_s );
452 if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect.get() ) )
453 mPaintEffect->saveProperties( doc, paintEffectElem );
454 node.appendChild( paintEffectElem );
455 }
456
457 return true;
458}
459
460bool QgsAnnotationLayer::readSymbology( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
461{
463
464 const QDomElement layerElement = node.toElement();
465 readCommonStyle( layerElement, context, categories );
466
467 if ( categories.testFlag( Rendering ) )
468 {
469 const QDomNode layerOpacityNode = node.namedItem( u"layerOpacity"_s );
470 if ( !layerOpacityNode.isNull() )
471 {
472 const QDomElement e = layerOpacityNode.toElement();
473 setOpacity( e.text().toDouble() );
474 }
475 }
476
477 if ( categories.testFlag( Symbology ) )
478 {
479 // get and set the blend mode if it exists
480 const QDomNode blendModeNode = node.namedItem( u"blendMode"_s );
481 if ( !blendModeNode.isNull() )
482 {
483 const QDomElement e = blendModeNode.toElement();
484 setBlendMode( QgsPainting::getCompositionMode( static_cast< Qgis::BlendMode >( e.text().toInt() ) ) );
485 }
486
487 //restore layer effect
488 const QDomNode paintEffectNode = node.namedItem( u"paintEffect"_s );
489 if ( !paintEffectNode.isNull() )
490 {
491 const QDomElement effectElem = paintEffectNode.firstChildElement( u"effect"_s );
492 if ( !effectElem.isNull() )
493 {
494 setPaintEffect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
495 }
496 }
497 }
498
499 return true;
500}
501
502bool QgsAnnotationLayer::writeItems( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories ) const
503{
505
506 QDomElement itemsElement = doc.createElement( u"items"_s );
507
508 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
509 {
510 QDomElement itemElement = doc.createElement( u"item"_s );
511 itemElement.setAttribute( u"type"_s, ( *it )->type() );
512 itemElement.setAttribute( u"id"_s, it.key() );
513 ( *it )->writeXml( itemElement, doc, context );
514 itemsElement.appendChild( itemElement );
515 }
516 node.appendChild( itemsElement );
517
518 return true;
519}
520
521bool QgsAnnotationLayer::readItems( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories )
522{
524
525 qDeleteAll( mItems );
526 mItems.clear();
527 mSpatialIndex = std::make_unique< QgsAnnotationLayerSpatialIndex >();
528 mNonIndexedItems.clear();
529
530 const QDomNodeList itemsElements = node.toElement().elementsByTagName( u"items"_s );
531 if ( itemsElements.size() == 0 )
532 return false;
533
534 const QDomNodeList items = itemsElements.at( 0 ).childNodes();
535 for ( int i = 0; i < items.size(); ++i )
536 {
537 const QDomElement itemElement = items.at( i ).toElement();
538 const QString id = itemElement.attribute( u"id"_s );
539 const QString type = itemElement.attribute( u"type"_s );
540 std::unique_ptr< QgsAnnotationItem > item( QgsApplication::annotationItemRegistry()->createItem( type ) );
541 if ( item )
542 {
543 item->readXml( itemElement, context );
545 mNonIndexedItems.insert( id );
546 else
547 mSpatialIndex->insert( id, item->boundingBox() );
548 mItems.insert( id, item.release() );
549 }
550 }
551
552 return true;
553}
554
555bool QgsAnnotationLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
556{
558
559 writeItems( node, doc, errorMessage, context, categories );
560
561 return writeSymbology( node, doc, errorMessage, context, categories );
562}
563
564bool QgsAnnotationLayer::readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
565{
567
568 readItems( node, errorMessage, context, categories );
569
570 return readSymbology( node, errorMessage, context, categories );
571}
572
574{
576
577 // annotation layers are always editable
578 return true;
579}
580
582{
584
585 return true;
586}
587
594
596{
598
599 return mDataProvider.get();
600}
601
603{
605
606 QString metadata = u"<html>\n<body>\n<h1>"_s + tr( "General" ) + u"</h1>\n<hr>\n"_s + u"<table class=\"list-view\">\n"_s;
607
608 metadata += u"<tr><td class=\"highlight\">"_s + tr( "Name" ) + u"</td><td>"_s + name() + u"</td></tr>\n"_s;
609
610 // Extent
611 metadata += u"<tr><td class=\"highlight\">"_s + tr( "Extent" ) + u"</td><td>"_s + extent().toString() + u"</td></tr>\n"_s;
612
613 // item count
614 QLocale locale = QLocale();
615 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
616 const int itemCount = mItems.size();
617 metadata += u"<tr><td class=\"highlight\">"_s + tr( "Item count" ) + u"</td><td>"_s + locale.toString( static_cast<qlonglong>( itemCount ) ) + u"</td></tr>\n"_s;
618 metadata += "</table>\n<br><br>"_L1;
619
620 // CRS
622
623 // items section
624 metadata += u"<h1>"_s + tr( "Items" ) + u"</h1>\n<hr>\n"_s;
625
626 metadata += "<table width=\"100%\" class=\"tabular-view\">\n"_L1;
627 metadata += "<tr><th>"_L1 + tr( "Type" ) + "</th><th>"_L1 + tr( "Count" ) + "</th></tr>\n"_L1;
628
629 QMap< QString, int > itemCounts;
630 for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
631 {
632 itemCounts[it.value()->type()]++;
633 }
634
635 const QMap<QString, QString> itemTypes = QgsApplication::annotationItemRegistry()->itemTypes();
636 int i = 0;
637 for ( auto it = itemTypes.begin(); it != itemTypes.end(); ++it )
638 {
639 QString rowClass;
640 if ( i % 2 )
641 rowClass = u"class=\"odd-row\""_s;
642 metadata += "<tr "_L1 + rowClass + "><td>"_L1 + it.value() + "</td><td>"_L1 + locale.toString( static_cast<qlonglong>( itemCounts.value( it.key() ) ) ) + "</td></tr>\n"_L1;
643 i++;
644 }
645
646 metadata += "</table>\n<br><br>"_L1;
647
648 metadata += "\n</body>\n</html>\n"_L1;
649 return metadata;
650}
651
653{
654 mLinkedLayer.resolve( project );
655}
656
658{
660
661 return mPaintEffect.get();
662}
663
665{
667
668 mPaintEffect.reset( effect );
669}
670
677
679{
681
682 mLinkedLayer.setLayer( layer );
684}
685
686
687//
688// QgsAnnotationLayerDataProvider
689//
691QgsAnnotationLayerDataProvider::QgsAnnotationLayerDataProvider( const ProviderOptions &options, Qgis::DataProviderReadFlags flags )
692 : QgsDataProvider( QString(), options, flags )
693{}
694
695QgsCoordinateReferenceSystem QgsAnnotationLayerDataProvider::crs() const
696{
698
700}
701
702QString QgsAnnotationLayerDataProvider::name() const
703{
705
706 return u"annotation"_s;
707}
708
709QString QgsAnnotationLayerDataProvider::description() const
710{
712
713 return QString();
714}
715
716QgsRectangle QgsAnnotationLayerDataProvider::extent() const
717{
719
720 return QgsRectangle();
721}
722
723bool QgsAnnotationLayerDataProvider::isValid() const
724{
726
727 return true;
728}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
@ UsersCannotToggleEditing
Indicates that users are not allowed to toggle editing for this layer. Note that this does not imply ...
Definition qgis.h:2445
@ ScaleDependentBoundingBox
Item's bounding box will vary depending on map scale.
Definition qgis.h:2652
AnnotationItemEditOperationResult
Results from an edit operation on an annotation item.
Definition qgis.h:2706
@ Invalid
Operation has invalid parameters for the item, no change occurred.
Definition qgis.h:2708
@ Success
Item was modified successfully.
Definition qgis.h:2707
@ ItemCleared
The operation results in the item being cleared, and the item should be removed from the layer as a r...
Definition qgis.h:2709
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Definition qgis.h:5402
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:512
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
Definition qgis.h:212
QFlags< MapLayerProperty > MapLayerProperties
Map layer properties.
Definition qgis.h:2451
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.
void itemsChanged()
Emitted when items are added, removed or modified in the layer.
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:56
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:114
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 rounded to the spec...
double xMinimum
double yMinimum
double xMaximum
double yMaximum
Contains information about the context of a rendering operation.
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:80
_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.