QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
39 class CORE_EXPORT QgsMergedFeatureRenderer : public QgsFeatureRenderer
40 {
41  public:
42 
48 
53 
55  static QgsFeatureRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
56 
57  QgsMergedFeatureRenderer *clone() const override SIP_FACTORY;
58  void startRender( QgsRenderContext &context, const QgsFields &fields ) override;
59 
70  bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) override SIP_THROW( QgsCsException );
71 
76  void stopRender( QgsRenderContext &context ) override;
77 
78  QString dump() const override;
79  QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
80  bool filterNeedsGeometry() const override;
81  QgsFeatureRenderer::Capabilities capabilities() override;
82  QgsSymbolList symbols( QgsRenderContext &context ) const override;
83  QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
84  QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
85  QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
86  QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
87  QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
88  QgsLegendSymbolList legendSymbolItems() const override;
89  bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
90  QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) override;
91  void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER ) override;
92  const QgsFeatureRenderer *embeddedRenderer() const override;
93  void setLegendSymbolItem( const QString &key, QgsSymbol *symbol ) override;
94  bool legendSymbolItemsCheckable() const override;
95  bool legendSymbolItemChecked( const QString &key ) override;
96  void checkLegendSymbolItem( const QString &key, bool state = true ) override;
97  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
98 
103  static QgsMergedFeatureRenderer *convertFromRenderer( const QgsFeatureRenderer *renderer ) SIP_FACTORY;
104 
105  protected:
106 
112  QgsMergedFeatureRenderer( const QString &type, QgsFeatureRenderer *embeddedRenderer SIP_TRANSFER );
113 
118  {
122  };
123 
125  GeometryOperation mOperation = Merge;
126 
128  std::unique_ptr<QgsFeatureRenderer> mSubRenderer;
129 
130  private:
131 
133  struct CombinedFeature
134  {
135  QVector<QgsGeometry> geometries; //< list of geometries
136  QgsFeature feature; //< one feature (for attriute-based rendering)
137  };
138  typedef QVector<CombinedFeature> FeatureCategoryVector;
140  FeatureCategoryVector mFeaturesCategories;
141 
143  QMap<QByteArray, int> mSymbolCategories;
144 
146  QgsPolygonXY mExtentPolygon;
147 
149  QgsRenderContext mContext;
150 
152  QgsFields mFields;
153 
158  struct FeatureDecoration
159  {
160  QgsFeature feature;
161  bool selected;
162  bool drawMarkers;
163  int layer;
164  FeatureDecoration( const QgsFeature &a_feature, bool a_selected, bool a_drawMarkers, int a_layer )
165  : feature( a_feature )
166  , selected( a_selected )
167  , drawMarkers( a_drawMarkers )
168  , layer( a_layer )
169  {}
170  };
171  QList<FeatureDecoration> mFeatureDecorations;
172 
173 };
174 
175 
176 #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:43