QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsgeometrygeneratorsymbollayer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgeometrygeneratorsymbollayer.h
3  ---------------------
4  begin : November 2015
5  copyright : (C) 2015 by Matthias Kuhn
6  email : matthias at opengis dot ch
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 
16 #ifndef QGSGEOMETRYGENERATORSYMBOLLAYER_H
17 #define QGSGEOMETRYGENERATORSYMBOLLAYER_H
18 
19 #include "qgis_core.h"
20 #include "qgis.h"
21 #include "qgssymbollayer.h"
22 
23 class QgsFillSymbol;
24 class QgsLineSymbol;
25 class QgsMarkerSymbol;
26 
32 {
33  public:
35 
37  static QgsSymbolLayer *create( const QVariantMap &properties ) SIP_FACTORY;
38 
39  QString layerType() const override;
40 
47  void setSymbolType( Qgis::SymbolType symbolType );
48 
55  Qgis::SymbolType symbolType() const { return mSymbolType; }
56 
57  void startRender( QgsSymbolRenderContext &context ) override;
58  void stopRender( QgsSymbolRenderContext &context ) override;
59  void startFeatureRender( const QgsFeature &feature, QgsRenderContext &context ) override;
60  void stopFeatureRender( const QgsFeature &feature, QgsRenderContext &context ) override;
61  bool usesMapUnits() const override;
62  QColor color() const override;
63  QgsUnitTypes::RenderUnit outputUnit() const override;
64  void setOutputUnit( QgsUnitTypes::RenderUnit unit ) override;
65  QgsMapUnitScale mapUnitScale() const override;
66 
67  QgsSymbolLayer *clone() const override SIP_FACTORY;
68 
69  QVariantMap properties() const override;
70 
71  void drawPreviewIcon( QgsSymbolRenderContext &context, QSize size ) override;
72 
76  void setGeometryExpression( const QString &exp );
77 
81  QString geometryExpression() const { return mExpression->expression(); }
82 
92  QgsUnitTypes::RenderUnit units() const { return mUnits; }
93 
103  void setUnits( QgsUnitTypes::RenderUnit units ) { mUnits = units;}
104 
105  QgsSymbol *subSymbol() override { return mSymbol; }
106 
107  bool setSubSymbol( QgsSymbol *symbol SIP_TRANSFER ) override;
108 
109  QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
110  bool hasDataDefinedProperties() const override;
111 
117  bool isCompatibleWithSymbol( QgsSymbol *symbol ) const override;
118 
131  void render( QgsSymbolRenderContext &context, QgsWkbTypes::GeometryType geometryType = QgsWkbTypes::GeometryType::UnknownGeometry, const QPolygonF *points = nullptr, const QVector<QPolygonF> *rings = nullptr );
132 
133  void setColor( const QColor &color ) override;
134 
135  private:
136  QgsGeometryGeneratorSymbolLayer( const QString &expression );
137 
138 #ifdef SIP_RUN
140 #endif
141 
145  QgsGeometry evaluateGeometryInPainterUnits( const QgsGeometry &input, const QgsFeature &feature, const QgsRenderContext &renderContext, QgsExpressionContext &expressionContext ) const;
146 
151  QgsGeometry coerceToExpectedType( const QgsGeometry &geometry ) const;
152 
153  std::unique_ptr<QgsExpression> mExpression;
154  std::unique_ptr<QgsFillSymbol> mFillSymbol;
155  std::unique_ptr<QgsLineSymbol> mLineSymbol;
156  std::unique_ptr<QgsMarkerSymbol> mMarkerSymbol;
157  QgsSymbol *mSymbol = nullptr;
158 
162  Qgis::SymbolType mSymbolType;
163 
165 
166  bool mRenderingFeature = false;
167  bool mHasRenderedFeature = false;
168 };
169 
170 #endif // QGSGEOMETRYGENERATORSYMBOLLAYER_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsSymbolLayer::mapUnitScale
virtual QgsMapUnitScale mapUnitScale() const
Definition: qgssymbollayer.h:505
QgsGeometryGeneratorSymbolLayer::units
QgsUnitTypes::RenderUnit units() const
Returns the unit for the geometry expression.
Definition: qgsgeometrygeneratorsymbollayer.h:92
QgsSymbolLayer::startFeatureRender
virtual void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called before the layer will be rendered for a particular feature.
Definition: qgssymbollayer.cpp:131
QgsSymbolLayer::setColor
virtual void setColor(const QColor &color)
Sets the "representative" color for the symbol layer.
Definition: qgssymbollayer.cpp:252
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
QgsSymbolLayer::isCompatibleWithSymbol
virtual bool isCompatibleWithSymbol(QgsSymbol *symbol) const
Returns if the layer can be used below the specified symbol.
Definition: qgssymbollayer.cpp:300
QgsGeometryGeneratorSymbolLayer::subSymbol
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
Definition: qgsgeometrygeneratorsymbollayer.h:105
QgsSymbolLayer::hasDataDefinedProperties
virtual bool hasDataDefinedProperties() const
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
Definition: qgssymbollayer.cpp:287
qgis.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
QgsSymbolLayer::usesMapUnits
virtual bool usesMapUnits() const
Returns true if the symbol layer has any components which use map unit based sizes.
Definition: qgssymbollayer.cpp:313
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsSymbolRenderContext
Definition: qgssymbolrendercontext.h:35
QgsSymbolLayer::clone
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsSymbolLayer
Definition: qgssymbollayer.h:54
Qgis::SymbolType
SymbolType
Symbol types.
Definition: qgis.h:205
QgsSymbolLayer::setSubSymbol
virtual bool setSubSymbol(QgsSymbol *symbol)
Sets layer's subsymbol. takes ownership of the passed symbol.
Definition: qgssymbollayer.cpp:159
QgsMarkerSymbol
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgsmarkersymbol.h:30
QgsSymbolLayer::stopFeatureRender
virtual void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context)
Called after the layer has been rendered for a particular feature.
Definition: qgssymbollayer.cpp:143
QgsSymbolLayer::setOutputUnit
virtual void setOutputUnit(QgsUnitTypes::RenderUnit unit)
Sets the units to use for sizes and widths within the symbol layer.
Definition: qgssymbollayer.h:485
QgsGeometryGeneratorSymbolLayer
Definition: qgsgeometrygeneratorsymbollayer.h:31
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:29
qgssymbollayer.h
QgsMapUnitScale
Struct for storing maximum and minimum scales for measurements in map units.
Definition: qgsmapunitscale.h:36
QgsGeometryGeneratorSymbolLayer::symbolType
Qgis::SymbolType symbolType() const
Access the symbol type.
Definition: qgsgeometrygeneratorsymbollayer.h:55
QgsGeometryGeneratorSymbolLayer::setUnits
void setUnits(QgsUnitTypes::RenderUnit units)
Sets the units for the geometry expression.
Definition: qgsgeometrygeneratorsymbollayer.h:103
QgsSymbolLayer::usedAttributes
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns the set of attributes referenced by the layer.
Definition: qgssymbollayer.cpp:328
QgsSymbolLayer::outputUnit
virtual QgsUnitTypes::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol layer.
Definition: qgssymbollayer.h:495
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:29
QgsSymbolLayer::stopRender
virtual void stopRender(QgsSymbolRenderContext &context)=0
Called after a set of rendering operations has finished on the supplied render context.
QgsSymbolLayer::layerType
virtual QString layerType() const =0
Returns a string that represents this layer type.
QgsSymbolLayer::color
virtual QColor color() const
Returns the "representative" color of the symbol layer.
Definition: qgssymbollayer.cpp:247
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsSymbolLayer::startRender
virtual void startRender(QgsSymbolRenderContext &context)=0
Called before a set of rendering operations commences on the supplied render context.
QgsUnitTypes::RenderMapUnits
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:170