QGIS API Documentation  3.17.0-Master (a84647cf30)
qgsannotationlayerrenderer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsannotationlayerrenderer.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 
18 #include "qgsannotationlayer.h"
19 #include "qgsfeedback.h"
20 
22  : QgsMapLayerRenderer( layer->id(), &context )
23  , mFeedback( qgis::make_unique< QgsFeedback >() )
24  , mLayerOpacity( layer->opacity() )
25 {
26  // clone items from layer
27  const QMap< QString, QgsAnnotationItem * > items = layer->items();
28  mItems.reserve( items.size() );
29  for ( auto it = items.constBegin(); it != items.constEnd(); ++it )
30  {
31  if ( it.value() )
32  mItems << ( *it )->clone();
33  }
34 
35  std::sort( mItems.begin(), mItems.end(), []( QgsAnnotationItem * a, QgsAnnotationItem * b ) { return a->zIndex() < b->zIndex(); } ); //clazy:exclude=detaching-member
36 }
37 
39 {
40  qDeleteAll( mItems );
41 }
42 
44 {
45  return mFeedback.get();
46 }
47 
49 {
50  QgsRenderContext &context = *renderContext();
51 
52  for ( QgsAnnotationItem *item : qgis::as_const( mItems ) )
53  {
54  if ( mFeedback->isCanceled() )
55  break;
56 
57  item->render( context, mFeedback.get() );
58  }
59  return true;
60 }
61 
63 {
64  return renderContext()->testFlag( QgsRenderContext::UseAdvancedEffects ) && ( !qgsDoubleNear( mLayerOpacity, 1.0 ) );
65 }
Enable layer opacity and blending effects.
bool forceRasterRender() const override
Returns true if the renderer must be rendered to a raster paint device (e.g.
QMap< QString, QgsAnnotationItem * > items() const
Returns a map of items contained in the layer, by unique item ID.
bool render() override
Do the rendering (based on data stored in the class)
Represents a map layer containing a set of georeferenced annotations, e.g.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:316
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be nullptr)
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Definition: qgsfeedback.h:43
int zIndex() const
Returns the item&#39;s z index, which controls the order in which annotation items are rendered in the la...
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
Contains information about the context of a rendering operation.
QgsAnnotationLayerRenderer(QgsAnnotationLayer *layer, QgsRenderContext &context)
Constructor for a QgsAnnotationLayerRenderer, for the specified layer.
Base class for utility classes that encapsulate information necessary for rendering of map layers...
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
QgsRenderContext * renderContext()
Returns the render context associated with the renderer.