QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
31 QString expression =
properties.value( QStringLiteral(
"geometryModifier" ) ).toString();
32 if ( expression.isEmpty() )
34 expression = QStringLiteral(
"$geometry" );
38 if (
properties.value( QStringLiteral(
"SymbolType" ) ) == QLatin1String(
"Marker" ) )
42 else if (
properties.value( QStringLiteral(
"SymbolType" ) ) == QLatin1String(
"Line" ) )
57 QgsGeometryGeneratorSymbolLayer::QgsGeometryGeneratorSymbolLayer(
const QString &expression )
60 , mSymbolType(
Qgis::SymbolType::Marker )
67 return QStringLiteral(
"GeometryGenerator" );
76 mSymbol = mFillSymbol.get();
82 mSymbol = mLineSymbol.get();
88 mSymbol = mMarkerSymbol.get();
114 mRenderingFeature =
true;
115 mHasRenderedFeature =
false;
120 mRenderingFeature =
false;
126 return mFillSymbol->usesMapUnits();
127 else if ( mLineSymbol )
128 return mLineSymbol->usesMapUnits();
129 else if ( mMarkerSymbol )
130 return mMarkerSymbol->usesMapUnits();
137 return mFillSymbol->color();
138 else if ( mLineSymbol )
139 return mLineSymbol->color();
140 else if ( mMarkerSymbol )
141 return mMarkerSymbol->color();
148 return mFillSymbol->outputUnit();
149 else if ( mLineSymbol )
150 return mLineSymbol->outputUnit();
151 else if ( mMarkerSymbol )
152 return mMarkerSymbol->outputUnit();
159 mFillSymbol->setOutputUnit( unit );
160 else if ( mLineSymbol )
161 mLineSymbol->setOutputUnit( unit );
162 else if ( mMarkerSymbol )
163 mMarkerSymbol->setOutputUnit( unit );
169 return mFillSymbol->mapUnitScale();
170 else if ( mLineSymbol )
171 return mLineSymbol->mapUnitScale();
172 else if ( mMarkerSymbol )
173 return mMarkerSymbol->mapUnitScale();
182 clone->mFillSymbol.reset( mFillSymbol->clone() );
184 clone->mLineSymbol.reset( mLineSymbol->clone() );
186 clone->mMarkerSymbol.reset( mMarkerSymbol->clone() );
188 clone->setSymbolType( mSymbolType );
189 clone->setUnits( mUnits );
200 props.insert( QStringLiteral(
"geometryModifier" ), mExpression->expression() );
201 switch ( mSymbolType )
204 props.insert( QStringLiteral(
"SymbolType" ), QStringLiteral(
"Marker" ) );
207 props.insert( QStringLiteral(
"SymbolType" ), QStringLiteral(
"Line" ) );
210 props.insert( QStringLiteral(
"SymbolType" ), QStringLiteral(
"Fill" ) );
229 if ( patchShapeGeometry.
isEmpty() )
245 originalSymbolType = mSymbol->
type();
274 switch ( symbol->
type() )
301 + mExpression->referencedColumns();
323 const QTransform painterToTargetUnits = QTransform::fromScale( scale, scale );
324 drawGeometry.transform( painterToTargetUnits );
335 geom.
transform( painterToTargetUnits.inverted( ) );
342 switch ( mSymbolType )
348 if ( !geoms.empty() )
349 return geoms.at( 0 );
356 if ( !geoms.empty() )
357 return geoms.at( 0 );
364 if ( !geoms.empty() )
365 return geoms.at( 0 );
376 if ( mRenderingFeature && mHasRenderedFeature )
391 switch ( geometryType )
395 Q_ASSERT( points->size() == 1 );
409 std::unique_ptr< QgsPolygon > polygon = std::make_unique< QgsPolygon >();
410 polygon->setExteriorRing( exterior.release() );
413 for (
const QPolygonF &ring : *rings )
418 drawGeometry =
QgsGeometry( std::move( polygon ) );
434 result.
transform( mapToPixel.inverted() );
442 QgsDebugMsg( QStringLiteral(
"Could no transform generated geometry to layer CRS" ) );
477 result.
transform( mapToPixel.inverted() );
485 QgsDebugMsg( QStringLiteral(
"Could no transform generated geometry to layer CRS" ) );
504 if ( mRenderingFeature )
505 mHasRenderedFeature =
true;
QVariantMap properties() const override
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns the set of attributes referenced by the layer.
RAII class to pop scope from an expression context on destruction.
QString layerType() const override
Returns a string that represents this layer type.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
void setGeometry(const QgsGeometry &geometry)
Convenience function for setting a geometry for the scope.
RenderUnit
Rendering size units.
QgsExpressionContext & expressionContext()
Gets the expression context.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
const QgsFeature * feature() const
Returns the current feature being rendered.
QgsSymbol * subSymbol() override
Returns the symbol's sub symbol, if present.
@ RenderPoints
Points (e.g., for font sizes)
static QgsGeometry fromPointXY(const QgsPointXY &point) SIP_HOLDGIL
Creates a new geometry from a QgsPointXY object.
void setOutputUnit(QgsUnitTypes::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
Qgis::RenderContextFlags flags() const
Returns combination of flags used for rendering.
QColor color() const override
Returns the "representative" color of the symbol layer.
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
Contains information about the context of a rendering operation.
bool usesMapUnits() const override
Returns true if the symbol layer has any components which use map unit based sizes.
void setSymbolType(Qgis::SymbolType symbolType)
Set the type of symbol which should be created.
@ RenderMillimeters
Millimeters.
void setColor(const QColor &color) override
Sets the "representative" color for the symbol layer.
Abstract base class for all rendered symbols.
void setScaleToOutputSize(bool scale)
Sets whether the patch shape should by resized to the desired target size when rendering.
const QgsLegendPatchShape * patchShape() const
Returns the symbol patch shape, to use if rendering symbol preview icons.
static QgsLineSymbol * createSimple(const QVariantMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties.
Represents a patch shape for use in map legends.
void startFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called before the layer will be rendered for a particular feature.
static QgsStyle * defaultStyle()
Returns default application-wide style.
bool selected() const
Returns true if symbols should be rendered using the selected symbol coloring and style.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
QgsExpressionContextScope * expressionContextScope()
This scope is always available when a symbol of this type is being rendered.
QgsWkbTypes::GeometryType originalGeometryType() const
Returns the geometry type for the original feature geometry being rendered.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
Custom exception class for Coordinate Reference System related exceptions.
QgsUnitTypes::RenderUnit outputUnit() const override
Returns the units to use for sizes and widths within the symbol layer.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
void stopRender(QgsRenderContext &context)
Ends the rendering process.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
QgsSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
Qgis::SymbolType type() const
Returns the symbol's type.
A marker symbol type, for rendering Point and MultiPoint geometries.
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
static QgsLineString * fromQPolygonF(const QPolygonF &polygon)
Returns a new linestring from a QPolygonF polygon input.
static QgsSymbolLayer * create(const QVariantMap &properties)
Creates the symbol layer.
QgsGeometry scaledGeometry(QSizeF size) const
Returns the patch shape's geometry, scaled to the given size.
void copyPaintEffect(QgsSymbolLayer *destLayer) const
Copies paint effect of this layer to another symbol layer.
~QgsGeometryGeneratorSymbolLayer() override
QgsMapUnitScale mapUnitScale() const override
A line symbol type, for rendering LineString and MultiLineString geometries.
void renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false, Qgis::VertexMarkerType currentVertexMarkerType=Qgis::VertexMarkerType::SemiTransparentCircle, double currentVertexMarkerSize=0.0) SIP_THROW(QgsCsException)
Render a feature.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
void restoreOldDataDefinedProperties(const QVariantMap &stringMap)
Restores older data defined properties from string map.
Struct for storing maximum and minimum scales for measurements in map units.
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
bool hasDataDefinedProperties() const override
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
Qgis::SymbolType symbolType() const
Access the symbol type.
void setUnits(QgsUnitTypes::RenderUnit units)
Sets the units for the geometry expression.
static QgsFillSymbol * createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
QgsSymbolRenderContext * symbolRenderContext()
Returns the symbol render context.
bool isCompatibleWithSymbol(QgsSymbol *symbol) const override
Will always return true.
void render(QgsSymbolRenderContext &context, QgsWkbTypes::GeometryType geometryType=QgsWkbTypes::GeometryType::UnknownGeometry, const QPolygonF *points=nullptr, const QVector< QPolygonF > *rings=nullptr)
Will render this symbol layer using the context.
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
Single scope for storing variables and functions for use within a QgsExpressionContext....
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns the set of attributes referenced by the layer.
void setGeometryExpression(const QString &exp)
Set the expression to generate this geometry.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
void startRender(QgsSymbolRenderContext &context) override
Called before a set of rendering operations commences on the supplied render context.
void stopFeatureRender(const QgsFeature &feature, QgsRenderContext &context) override
Called after the layer has been rendered for a particular feature.
QVector< QgsGeometry > coerceToType(QgsWkbTypes::Type type, double defaultZ=0, double defaultM=0) const
Attempts to coerce this geometry into the specified destination type.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
A geometry is the spatial representation of a feature.
void drawPreviewIcon(QPainter *painter, QSize size, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr, const QgsLegendPatchShape *patchShape=nullptr)
Draws an icon of the symbol that occupies an area given by size using the specified painter.
void stopRender(QgsSymbolRenderContext &context) override
Called after a set of rendering operations has finished on the supplied render context.
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns a list of attributes required to render this feature.
void drawPreviewIcon(QgsSymbolRenderContext &context, QSize size) override
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
@ RenderMetersInMapUnits
Meters value as Map units.
@ RenderUnknownUnit
Mixed or unknown units.
QgsLegendPatchShape defaultPatch(Qgis::SymbolType type, QSizeF size) const
Returns the default legend patch shape for the given symbol type.
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
The Qgis class provides global constants for use throughout the application.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
@ RenderingSubSymbol
Set whenever a sub-symbol of a parent symbol is currently being rendered. Can be used during symbol a...
QPainter * painter()
Returns the destination QPainter for the render operation.
Class for parsing and evaluation of expressions (formerly called "search strings")....
QgsWkbTypes::GeometryType type
static QgsMarkerSymbol * createSimple(const QVariantMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
void copyDataDefinedProperties(QgsSymbolLayer *destLayer) const
Copies all data defined properties of this layer to another symbol layer.
void setColor(const QColor &color) const
Sets the color for the symbol.
@ RenderMapUnits
Map units.
bool isNull() const
Returns true if the patch shape is a null QgsLegendPatchShape, which indicates that the default legen...