QGIS API Documentation  3.21.0-Master (5b68dc587e)
qgsmergedfeaturerenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmergedfeaturerenderer.h
3  ---------------------
4  begin : December 2020
5  copyright : (C) 2020 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSMERGEDFEATURERENDERER_H
16 #define QGSMERGEDFEATURERENDERER_H
17 
18 #include "qgis_core.h"
19 #include "qgis_sip.h"
20 #include "qgis.h"
21 #include "qgsrenderer.h"
22 #include "qgsexpression.h"
23 #include "qgsfeature.h"
24 #include "qgsgeometry.h"
25 #include "qgsrendercontext.h"
26 
40 class CORE_EXPORT QgsMergedFeatureRenderer : public QgsFeatureRenderer
41 {
42  public:
43 
49 
54 
56  static QgsFeatureRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
57 
58  QgsMergedFeatureRenderer *clone() const override SIP_FACTORY;
59  void startRender( QgsRenderContext &context, const QgsFields &fields ) override;
60 
71  bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) override SIP_THROW( QgsCsException );
72 
77  void stopRender( QgsRenderContext &context ) override;
78 
79  QString dump() const override;
80  QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
81  bool filterNeedsGeometry() const override;
82  QgsFeatureRenderer::Capabilities capabilities() override;
83  QgsSymbolList symbols( QgsRenderContext &context ) const override;
84  QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
85  QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
86  QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
87  QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
88  QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
89  QgsLegendSymbolList legendSymbolItems() const override;
90  bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
91  QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) override;
92  void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER ) override;
93  const QgsFeatureRenderer *embeddedRenderer() const override;
94  void setLegendSymbolItem( const QString &key, QgsSymbol *symbol ) override;
95  bool legendSymbolItemsCheckable() const override;
96  bool legendSymbolItemChecked( const QString &key ) override;
97  void checkLegendSymbolItem( const QString &key, bool state = true ) override;
98  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
99 
104  static QgsMergedFeatureRenderer *convertFromRenderer( const QgsFeatureRenderer *renderer ) SIP_FACTORY;
105 
106  protected:
107 
113  QgsMergedFeatureRenderer( const QString &type, QgsFeatureRenderer *embeddedRenderer SIP_TRANSFER );
114 
119  {
123  };
124 
126  GeometryOperation mOperation = Merge;
127 
129  std::unique_ptr<QgsFeatureRenderer> mSubRenderer;
130 
131  private:
132 
134  struct CombinedFeature
135  {
136  QVector<QgsGeometry> geometries; //< list of geometries
137  QgsFeature feature; //< one feature (for attriute-based rendering)
138  };
139  typedef QVector<CombinedFeature> FeatureCategoryVector;
141  FeatureCategoryVector mFeaturesCategories;
142 
144  QMap<QByteArray, int> mSymbolCategories;
145 
147  QgsPolygonXY mExtentPolygon;
148 
150  QgsRenderContext mContext;
151 
153  QgsFields mFields;
154 
159  struct FeatureDecoration
160  {
161  QgsFeature feature;
162  bool selected;
163  bool drawMarkers;
164  int layer;
165  FeatureDecoration( const QgsFeature &a_feature, bool a_selected, bool a_drawMarkers, int a_layer )
166  : feature( a_feature )
167  , selected( a_selected )
168  , drawMarkers( a_drawMarkers )
169  , layer( a_layer )
170  {}
171  };
172  QList<FeatureDecoration> mFeatureDecorations;
173 
174 };
175 
176 
177 #endif // QGSMERGEDFEATURERENDERER_H
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:66
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
Container of fields for a vector layer.
Definition: qgsfields.h:45
QgsMergedFeatureRenderer is a polygon or line-only feature renderer used to renderer a set of feature...
GeometryOperation
Operations to apply to collected geometries prior to rendering.
@ Merge
Merge features (union/dissolve)
@ InvertOnly
Invert features only (polygons only)
@ MergeAndInvert
Merge and invert features (polygons only)
QgsMergedFeatureRenderer(const QgsMergedFeatureRenderer &)=delete
Direct copies are forbidden. Use clone() instead.
std::unique_ptr< QgsFeatureRenderer > mSubRenderer
Embedded renderer.
QgsMergedFeatureRenderer & operator=(const QgsMergedFeatureRenderer &)=delete
Direct copies are forbidden. Use clone() instead.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:38
#define SIP_THROW(name)
Definition: qgis_sip.h:189
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
Definition: qgsgeometry.h:75
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:44