38#include <QDomDocument>
44using namespace Qt::StringLiterals;
66 destRenderer->mDataDefinedProperties = mDataDefinedProperties;
83 QgsFeatureRenderer::initPropertyDefinitions();
84 return sPropertyDefinitions;
101 return QSet< QString >();
109 mThread = QThread::currentThread();
113 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsFeatureRenderer::startRender",
"startRender called in a different thread - use a cloned renderer instead" );
128 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsFeatureRenderer::stopRender",
"stopRender called in a different thread - use a cloned renderer instead" );
145 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsFeatureRenderer::renderFeature",
"renderFeature called in a different thread - use a cloned renderer instead" );
163 return u
"UNKNOWN RENDERER\n"_s;
181 if ( element.isNull() )
185 const QString rendererType = element.attribute( u
"type"_s );
196 r->
setReferenceScale( element.attribute( u
"referencescale"_s, u
"-1"_s ).toDouble() );
199 const QDomElement effectElem = element.firstChildElement( u
"effect"_s );
200 if ( !effectElem.isNull() )
206 const QDomElement orderByElem = element.firstChildElement( u
"orderby"_s );
210 const QDomElement elemDataDefinedProperties = element.firstChildElement( u
"data-defined-properties"_s );
211 if ( !elemDataDefinedProperties.isNull() )
230 rendererElem.setAttribute( u
"forceraster"_s, (
mForceRaster ? u
"1"_s : u
"0"_s ) );
231 rendererElem.setAttribute( u
"symbollevels"_s, (
mUsingSymbolLevels ? u
"1"_s : u
"0"_s ) );
234 QDomElement elemDataDefinedProperties = doc.createElement( u
"data-defined-properties"_s );
236 rendererElem.appendChild( elemDataDefinedProperties );
243 QDomElement
orderBy = doc.createElement( u
"orderby"_s );
245 rendererElem.appendChild(
orderBy );
247 rendererElem.setAttribute( u
"enableorderby"_s, (
mOrderByEnabled ? u
"1"_s : u
"0"_s ) );
252 const QDomElement element = node.toElement();
253 if ( element.isNull() )
257 const QDomElement userStyleElem = element.firstChildElement( u
"UserStyle"_s );
258 if ( userStyleElem.isNull() )
261 errorMessage = u
"Info: UserStyle element not found."_s;
266 QDomElement featTypeStyleElem = userStyleElem.firstChildElement( u
"FeatureTypeStyle"_s );
267 if ( featTypeStyleElem.isNull() )
269 errorMessage = u
"Info: FeatureTypeStyle element not found."_s;
274 QDomElement mergedFeatTypeStyle = featTypeStyleElem.cloneNode(
false ).toElement();
279 bool needRuleRenderer =
false;
282 while ( !featTypeStyleElem.isNull() )
284 QDomElement ruleElem = featTypeStyleElem.firstChildElement( u
"Rule"_s );
285 while ( !ruleElem.isNull() )
289 bool hasRendererSymbolizer =
false;
290 bool hasRuleRenderer =
false;
291 QDomElement ruleChildElem = ruleElem.firstChildElement();
292 while ( !ruleChildElem.isNull() )
295 if ( ruleChildElem.localName() ==
"Filter"_L1 ||
296 ruleChildElem.localName() ==
"ElseFilter"_L1 ||
297 ruleChildElem.localName() ==
"MinScaleDenominator"_L1 ||
298 ruleChildElem.localName() ==
"MaxScaleDenominator"_L1 )
300 hasRuleRenderer =
true;
303 else if ( ruleChildElem.localName().endsWith(
"Symbolizer"_L1 ) &&
304 ruleChildElem.localName() !=
"TextSymbolizer"_L1 )
306 QgsDebugMsgLevel( u
"Symbolizer element found and not a TextSymbolizer"_s, 2 );
307 hasRendererSymbolizer =
true;
310 ruleChildElem = ruleChildElem.nextSiblingElement();
313 if ( hasRendererSymbolizer )
318 mergedFeatTypeStyle.appendChild( ruleElem.cloneNode().toElement() );
320 if ( hasRuleRenderer )
322 QgsDebugMsgLevel( u
"Filter or Min/MaxScaleDenominator element found: need a RuleRenderer"_s, 2 );
323 needRuleRenderer =
true;
331 needRuleRenderer =
true;
334 ruleElem = ruleElem.nextSiblingElement( u
"Rule"_s );
336 featTypeStyleElem = featTypeStyleElem.nextSiblingElement( u
"FeatureTypeStyle"_s );
339 QString rendererType;
340 if ( needRuleRenderer )
342 rendererType = u
"RuleRenderer"_s;
346 rendererType = u
"singleSymbol"_s;
348 QgsDebugMsgLevel( u
"Instantiating a '%1' renderer..."_s.arg( rendererType ), 2 );
354 errorMessage = u
"Error: Unable to get metadata for '%1' renderer."_s.arg( rendererType );
366 toSld( doc, element, context );
371 context.
pushError( QObject::tr(
"Vector %1 renderer cannot be converted to SLD" ).arg(
type() ) );
379 QSet< QString > keys;
380 keys.reserve( allLegendSymbols.size() );
383 keys.insert( symbol.ruleKey() );
390 QDomElement userStyleElem = doc.createElement( u
"UserStyle"_s );
392 QDomElement nameElem = doc.createElement( u
"se:Name"_s );
393 nameElem.appendChild( doc.createTextNode( styleName ) );
394 userStyleElem.appendChild( nameElem );
396 QDomElement featureTypeStyleElem = doc.createElement( u
"se:FeatureTypeStyle"_s );
400 toSld( doc, featureTypeStyleElem, context );
401 userStyleElem.appendChild( featureTypeStyleElem );
403 return userStyleElem;
444 if ( symbolList.empty() )
449 auto getValueFromSymbol = [ &expContext, &context ](
const QgsSymbol * sym ) ->
double
455 if ( property.isActive() )
465 value = sym->extentBuffer();
470 value = context.
convertToMapUnits( value, sym->extentBufferSizeUnit(), sym->mapUnitScale() );
476 if ( symbolList.size() == 1 )
477 return getValueFromSymbol( symbolList[0] );
479 auto it = std::max_element( symbolList.constBegin(), symbolList.constEnd(), [ &getValueFromSymbol ](
const QgsSymbol * a,
const QgsSymbol * b ) ->
bool
481 return getValueFromSymbol( a ) < getValueFromSymbol( b );
484 return getValueFromSymbol( *it );
489 QList<QgsLayerTreeModelLegendNode *> nodes;
492 nodes.reserve( symbolItems.size() );
529 const auto constPts = pts;
530 for (
const QPointF pt : constPts )
536 const auto constPts = pts;
537 for (
const QPointF pt : constPts )
542 const auto constRings = *rings;
543 for (
const QPolygonF &ring : constRings )
545 const auto constRing = ring;
546 for (
const QPointF pt : constRing )
556 if ( s ) lst.append( s );
564 extent.
grow( extentBuffer );
571 if ( s ) lst.append( s );
588 mDataDefinedProperties.setProperty( key, property );
654 ? QString::number( s->
angle() ) +
" + "
655 : QString() ) + field );
660void QgsFeatureRenderer::initPropertyDefinitions()
662 if ( !sPropertyDefinitions.isEmpty() )
665 QString origin = u
"renderer"_s;
ScaleMethod
Scale methods.
@ ScaleDiameter
Calculate scale by the diameter.
@ ScaleArea
Calculate scale by the area.
QFlags< FeatureRendererFlag > FeatureRendererFlags
Flags controlling behavior of vector feature renderers.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
@ Millimeters
Millimeters.
VertexMarkerType
Editing vertex markers, used for showing vertices during a edit operation.
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects.
static QgsRendererRegistry * rendererRegistry()
Returns the application's renderer registry, used for managing vector layer renderers.
A legend node with a marker symbol.
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
void setOrderBy(const QgsFeatureRequest::OrderBy &orderBy)
Define the order in which features shall be processed by this renderer.
void renderVertexMarkerPolyline(QPolygonF &pts, QgsRenderContext &context)
render editing vertex marker for a polyline
virtual bool canSkipRender()
Returns true if the renderer can be entirely skipped, i.e.
static QPointF _getPoint(QgsRenderContext &context, const QgsPoint &point)
Creates a point in screen coordinates from a wkb string in map coordinates.
virtual QDomElement writeSld(QDomDocument &doc, const QString &styleName, const QVariantMap &props=QVariantMap()) const
create the SLD UserStyle element following the SLD v1.1 specs with the given name
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
void setOrderByEnabled(bool enabled)
Sets whether custom ordering should be applied before features are processed by this renderer.
virtual bool legendSymbolItemsCheckable() const
Returns true if symbology items in legend are checkable.
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
virtual bool legendSymbolItemChecked(const QString &key)
Returns true if the legend symbology item with the specified key is checked.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the renderer.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the renderer.
virtual void setLegendSymbolItem(const QString &key, QgsSymbol *symbol)
Sets the symbol to be used for a legend symbol item.
virtual void setEmbeddedRenderer(QgsFeatureRenderer *subRenderer)
Sets an embedded renderer (subrenderer) for this feature renderer.
virtual QList< QgsLayerTreeModelLegendNode * > createLegendNodes(QgsLayerTreeLayer *nodeLayer) const
Returns a list of legend nodes to be used for the legend for the renderer.
QgsFeatureRenderer(const QString &type)
static QgsFeatureRenderer * defaultRenderer(Qgis::GeometryType geomType)
Returns a new renderer - used by default in vector layers.
virtual QgsSymbolList symbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns list of symbols used for rendering the feature.
void setForceRasterRender(bool forceRaster)
Sets whether the renderer should be rendered to a raster destination.
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
virtual Qgis::FeatureRendererFlags flags() const
Returns flags associated with the renderer.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
Property
Data definable properties for renderers.
@ HeatmapRadius
Heatmap renderer radius.
@ HeatmapMaximum
Heatmap maximum value.
virtual QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns legend keys matching a specified feature.
double maximumExtentBuffer(QgsRenderContext &context) const
Returns the maximum extent buffer found in this renderer's symbols.
virtual bool usesEmbeddedSymbols() const
Returns true if the renderer uses embedded symbols for features.
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
virtual bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
Render a feature using this renderer in the given context.
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context)
Stores renderer properties to an XML element.
void setReferenceScale(double scale)
Sets the symbology reference scale.
virtual QString dump() const
Returns debug information about this renderer.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol property definitions.
void setUsingSymbolLevels(bool usingSymbolLevels)
virtual ~QgsFeatureRenderer()
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
virtual void checkLegendSymbolItem(const QString &key, bool state=true)
Sets whether the legend symbology item with the specified ley should be checked.
virtual QString legendKeyToExpression(const QString &key, QgsVectorLayer *layer, bool &ok) const
Attempts to convert the specified legend rule key to a QGIS expression matching the features displaye...
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer.
virtual bool filterNeedsGeometry() const
Returns true if this renderer requires the geometry to apply the filter.
virtual Q_DECL_DEPRECATED void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const
Used from subclasses to create SLD Rule elements following SLD v1.1 specs.
static void convertSymbolRotation(QgsSymbol *symbol, const QString &field)
Converts old rotation expressions to symbol level data defined angles.
static QgsFeatureRenderer * load(QDomElement &symbologyElem, const QgsReadWriteContext &context)
create a renderer from XML element
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
QgsFeatureRequest::OrderBy mOrderBy
virtual QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns symbol for feature.
Qgis::VertexMarkerType mCurrentVertexMarkerType
The current type of editing marker.
QSet< QString > legendKeys() const
Returns the set of all legend keys used by the renderer.
virtual bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns whether the renderer will render a feature or not.
void saveRendererData(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context)
Saves generic renderer data into the specified element.
void renderFeatureWithSymbol(const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker)
Render the feature with the symbol using context.
void renderVertexMarker(QPointF pt, QgsRenderContext &context)
render editing vertex marker at specified point
void renderVertexMarkerPolygon(QPolygonF &pts, QList< QPolygonF > *rings, QgsRenderContext &context)
render editing vertex marker for a polygon
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
double mCurrentVertexMarkerSize
The current size of editing marker.
std::unique_ptr< QgsPaintEffect > mPaintEffect
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the renderer.
static void convertSymbolSizeScale(QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field)
Converts old sizeScale expressions to symbol level data defined sizes.
void setVertexMarkerAppearance(Qgis::VertexMarkerType type, double size)
Sets type and size of editing vertex markers for subsequent rendering.
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
static QgsFeatureRenderer * loadSld(const QDomNode &node, Qgis::GeometryType geomType, QString &errorMessage)
Create a new renderer according to the information contained in the UserStyle element of a SLD style ...
virtual QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
Represents a list of OrderByClauses, with the most important first and the least important last.
void CORE_EXPORT load(const QDomElement &elem)
Deserialize from XML.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Container of fields for a vector layer.
Layer tree node points to a map layer.
Stores information about one class/rule of a vector layer renderer in a unified way that can be used ...
A line symbol type, for rendering LineString and MultiLineString geometries.
void setDataDefinedWidth(const QgsProperty &property) const
Set data defined width for whole symbol (including all symbol layers).
double width() const
Returns the estimated width for the whole symbol, which is the maximum width of all marker symbol lay...
A marker symbol type, for rendering Point and MultiPoint geometries.
void setScaleMethod(Qgis::ScaleMethod scaleMethod) const
Sets the method to use for scaling the marker's size.
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
double angle() const
Returns the marker angle for the whole symbol.
void setDataDefinedSize(const QgsProperty &property) const
Set data defined size for whole symbol (including all symbol layers).
void setDataDefinedAngle(const QgsProperty &property)
Set data defined angle for whole symbol (including all symbol layers).
static QgsPaintEffect * defaultStack()
Returns a new effect stack consisting of a sensible selection of default effects.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
Base class for visual effects which can be applied to QPicture drawings.
Point geometry type, with support for z-dimension and m-values.
Definition for a property.
@ DoublePositive
Positive double value (including 0).
A store for object properties.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
void grow(double delta)
Grows the rectangle in place by the specified amount.
Contains information about the context of a rendering operation.
double convertToMapUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
A feature renderer which renders all features with the same symbol.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
void setExtraProperties(const QVariantMap &properties)
Sets the open ended set of properties that can drive/inform the SLD encoding.
void pushError(const QString &error)
Pushes a error message generated during the conversion.
An interface for classes which can visit style entity (e.g.
static void drawVertexMarker(double x, double y, QPainter &p, Qgis::VertexMarkerType type, int markerSize)
Draws a vertex symbol at (painter) coordinates x, y.
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
int layer() const
The layer of this symbol level.
QgsSymbol * symbol() const
The symbol of this symbol level.
Abstract base class for all rendered symbols.
@ ExtentBuffer
Extent buffer.
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)
Render a feature.
static QPointF _getPoint(QgsRenderContext &context, const QgsPoint &point)
Creates a point in screen coordinates from a QgsPoint in map coordinates.
Qgis::SymbolType type() const
Returns the symbol's type.
static QgsSymbol * defaultSymbol(Qgis::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
Represents a vector layer which manages a vector based dataset.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
#define QgsDebugMsgLevel(str, level)
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
#define RENDERER_TAG_NAME
QList< QgsSymbol * > QgsSymbolList