QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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  bool canceled = false;
53  for ( QgsAnnotationItem *item : qgis::as_const( mItems ) )
54  {
55  if ( mFeedback->isCanceled() )
56  {
57  canceled = true;
58  break;
59  }
60 
61  item->render( context, mFeedback.get() );
62  }
63  return !canceled;
64 }
65 
67 {
68  return renderContext()->testFlag( QgsRenderContext::UseAdvancedEffects ) && ( !qgsDoubleNear( mLayerOpacity, 1.0 ) );
69 }
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
bool forceRasterRender() const override
Returns true if the renderer must be rendered to a raster paint device (e.g.
bool render() override
Do the rendering (based on data stored in the class).
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be nullptr)
QgsAnnotationLayerRenderer(QgsAnnotationLayer *layer, QgsRenderContext &context)
Constructor for a QgsAnnotationLayerRenderer, for the specified layer.
Represents a map layer containing a set of georeferenced annotations, e.g.
QMap< QString, QgsAnnotationItem * > items() const
Returns a map of items contained in the layer, by unique item ID.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
Base class for utility classes that encapsulate information necessary for rendering of map layers.
QgsRenderContext * renderContext()
Returns the render context associated with the renderer.
Contains information about the context of a rendering operation.
@ UseAdvancedEffects
Enable layer opacity and blending effects.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
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