QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsrenderer.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsrenderer.cpp
3 ---------------------
4 begin : November 2009
5 copyright : (C) 2009 by Martin Dobias
6 email : wonder dot sk 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
16#include "qgsrenderer.h"
17#include "qgssymbol.h"
18#include "qgssymbollayerutils.h"
19
20#include "qgssinglesymbolrenderer.h" // for default renderer
21
22#include "qgsrendererregistry.h"
23
24#include "qgsrendercontext.h"
25#include "qgsfeature.h"
26#include "qgslogger.h"
27#include "qgsvectorlayer.h"
28#include "qgspainteffect.h"
30#include "qgspoint.h"
31#include "qgsproperty.h"
32#include "qgsapplication.h"
33#include "qgsmarkersymbol.h"
34#include "qgslinesymbol.h"
36
37#include <QDomElement>
38#include <QDomDocument>
39#include <QPolygonF>
40#include <QThread>
41#include <algorithm>
42
43QgsPropertiesDefinition QgsFeatureRenderer::sPropertyDefinitions;
44
46{
47 return QgsSymbol::_getPoint( context, point );
48}
49
51{
52 if ( !destRenderer )
53 return;
54
55 if ( mPaintEffect )
56 destRenderer->setPaintEffect( mPaintEffect->clone() );
57
58 destRenderer->setForceRasterRender( mForceRaster );
60 destRenderer->mOrderBy = mOrderBy;
61 destRenderer->mOrderByEnabled = mOrderByEnabled;
62 destRenderer->mReferenceScale = mReferenceScale;
63 destRenderer->mDataDefinedProperties = mDataDefinedProperties;
64}
65
67 : mType( type )
68{
70 mPaintEffect->setEnabled( false );
71}
72
77
79{
80 QgsFeatureRenderer::initPropertyDefinitions();
81 return sPropertyDefinitions;
82}
83
88
90{
91 return symbolForFeature( feature, context );
92}
93
94QSet< QString > QgsFeatureRenderer::legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const
95{
96 Q_UNUSED( feature )
97 Q_UNUSED( context )
98 return QSet< QString >();
99}
100
102{
103#ifdef QGISDEBUG
104 if ( !mThread )
105 {
106 mThread = QThread::currentThread();
107 }
108 else
109 {
110 Q_ASSERT_X( mThread == QThread::currentThread(), "QgsFeatureRenderer::startRender", "startRender called in a different thread - use a cloned renderer instead" );
111 }
112#endif
113
114 mDataDefinedProperties.prepare( context.expressionContext() );
115}
116
118{
119 return false;
120}
121
123{
124#ifdef QGISDEBUG
125 Q_ASSERT_X( mThread == QThread::currentThread(), "QgsFeatureRenderer::stopRender", "stopRender called in a different thread - use a cloned renderer instead" );
126#endif
127}
128
130{
131 return false;
132}
133
135{
136 return false;
137}
138
139bool QgsFeatureRenderer::renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker )
140{
141#ifdef QGISDEBUG
142 Q_ASSERT_X( mThread == QThread::currentThread(), "QgsFeatureRenderer::renderFeature", "renderFeature called in a different thread - use a cloned renderer instead" );
143#endif
144
145 QgsSymbol *symbol = symbolForFeature( feature, context );
146 if ( !symbol )
147 return false;
148
149 renderFeatureWithSymbol( feature, symbol, context, layer, selected, drawVertexMarker );
150 return true;
151}
152
153void QgsFeatureRenderer::renderFeatureWithSymbol( const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker )
154{
155 symbol->renderFeature( feature, context, layer, selected, drawVertexMarker, mCurrentVertexMarkerType, mCurrentVertexMarkerSize );
156}
157
159{
160 return QStringLiteral( "UNKNOWN RENDERER\n" );
161}
162
167
169{
170 Q_UNUSED( context )
171 return QgsSymbolList();
172}
173
175{
176 // <renderer-v2 type=""> ... </renderer-v2>
177
178 if ( element.isNull() )
179 return nullptr;
180
181 // load renderer
182 const QString rendererType = element.attribute( QStringLiteral( "type" ) );
183
185 if ( !m )
186 return nullptr;
187
188 QgsFeatureRenderer *r = m->createRenderer( element, context );
189 if ( r )
190 {
191 r->setUsingSymbolLevels( element.attribute( QStringLiteral( "symbollevels" ), QStringLiteral( "0" ) ).toInt() );
192 r->setForceRasterRender( element.attribute( QStringLiteral( "forceraster" ), QStringLiteral( "0" ) ).toInt() );
193 r->setReferenceScale( element.attribute( QStringLiteral( "referencescale" ), QStringLiteral( "-1" ) ).toDouble() );
194
195 //restore layer effect
196 const QDomElement effectElem = element.firstChildElement( QStringLiteral( "effect" ) );
197 if ( !effectElem.isNull() )
198 {
199 r->setPaintEffect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
200 }
201
202 // restore order by
203 const QDomElement orderByElem = element.firstChildElement( QStringLiteral( "orderby" ) );
204 r->mOrderBy.load( orderByElem );
205 r->setOrderByEnabled( element.attribute( QStringLiteral( "enableorderby" ), QStringLiteral( "0" ) ).toInt() );
206
207 const QDomElement elemDataDefinedProperties = element.firstChildElement( QStringLiteral( "data-defined-properties" ) );
208 if ( !elemDataDefinedProperties.isNull() )
209 r->mDataDefinedProperties.readXml( elemDataDefinedProperties, propertyDefinitions() );
210 }
211 return r;
212}
213
214QDomElement QgsFeatureRenderer::save( QDomDocument &doc, const QgsReadWriteContext &context )
215{
216 Q_UNUSED( context )
217 // create empty renderer element
218 QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
219
220 saveRendererData( doc, rendererElem, context );
221
222 return rendererElem;
223}
224
225void QgsFeatureRenderer::saveRendererData( QDomDocument &doc, QDomElement &rendererElem, const QgsReadWriteContext & )
226{
227 rendererElem.setAttribute( QStringLiteral( "forceraster" ), ( mForceRaster ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ) );
228 rendererElem.setAttribute( QStringLiteral( "symbollevels" ), ( mUsingSymbolLevels ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ) );
229 rendererElem.setAttribute( QStringLiteral( "referencescale" ), mReferenceScale );
230
231 QDomElement elemDataDefinedProperties = doc.createElement( QStringLiteral( "data-defined-properties" ) );
232 mDataDefinedProperties.writeXml( elemDataDefinedProperties, propertyDefinitions() );
233 rendererElem.appendChild( elemDataDefinedProperties );
234
236 mPaintEffect->saveProperties( doc, rendererElem );
237
238 if ( !mOrderBy.isEmpty() )
239 {
240 QDomElement orderBy = doc.createElement( QStringLiteral( "orderby" ) );
242 rendererElem.appendChild( orderBy );
243 }
244 rendererElem.setAttribute( QStringLiteral( "enableorderby" ), ( mOrderByEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ) );
245}
246
247QgsFeatureRenderer *QgsFeatureRenderer::loadSld( const QDomNode &node, Qgis::GeometryType geomType, QString &errorMessage )
248{
249 const QDomElement element = node.toElement();
250 if ( element.isNull() )
251 return nullptr;
252
253 // get the UserStyle element
254 const QDomElement userStyleElem = element.firstChildElement( QStringLiteral( "UserStyle" ) );
255 if ( userStyleElem.isNull() )
256 {
257 // UserStyle element not found, nothing will be rendered
258 errorMessage = QStringLiteral( "Info: UserStyle element not found." );
259 return nullptr;
260 }
261
262 // get the FeatureTypeStyle element
263 QDomElement featTypeStyleElem = userStyleElem.firstChildElement( QStringLiteral( "FeatureTypeStyle" ) );
264 if ( featTypeStyleElem.isNull() )
265 {
266 errorMessage = QStringLiteral( "Info: FeatureTypeStyle element not found." );
267 return nullptr;
268 }
269
270 // create empty FeatureTypeStyle element to merge Rule's from all FeatureTypeStyle's
271 QDomElement mergedFeatTypeStyle = featTypeStyleElem.cloneNode( false ).toElement();
272
273 // use the RuleRenderer when more rules are present or the rule
274 // has filters or min/max scale denominators set,
275 // otherwise use the SingleSymbol renderer
276 bool needRuleRenderer = false;
277 int ruleCount = 0;
278
279 while ( !featTypeStyleElem.isNull() )
280 {
281 QDomElement ruleElem = featTypeStyleElem.firstChildElement( QStringLiteral( "Rule" ) );
282 while ( !ruleElem.isNull() )
283 {
284 // test rule children element to check if we need to create RuleRenderer
285 // and if the rule has a symbolizer
286 bool hasRendererSymbolizer = false;
287 bool hasRuleRenderer = false;
288 QDomElement ruleChildElem = ruleElem.firstChildElement();
289 while ( !ruleChildElem.isNull() )
290 {
291 // rule has filter or min/max scale denominator, use the RuleRenderer
292 if ( ruleChildElem.localName() == QLatin1String( "Filter" ) ||
293 ruleChildElem.localName() == QLatin1String( "ElseFilter" ) ||
294 ruleChildElem.localName() == QLatin1String( "MinScaleDenominator" ) ||
295 ruleChildElem.localName() == QLatin1String( "MaxScaleDenominator" ) )
296 {
297 hasRuleRenderer = true;
298 }
299 // rule has a renderer symbolizer, not a text symbolizer
300 else if ( ruleChildElem.localName().endsWith( QLatin1String( "Symbolizer" ) ) &&
301 ruleChildElem.localName() != QLatin1String( "TextSymbolizer" ) )
302 {
303 QgsDebugMsgLevel( QStringLiteral( "Symbolizer element found and not a TextSymbolizer" ), 2 );
304 hasRendererSymbolizer = true;
305 }
306
307 ruleChildElem = ruleChildElem.nextSiblingElement();
308 }
309
310 if ( hasRendererSymbolizer )
311 {
312 ruleCount++;
313
314 // append a clone of all Rules to the merged FeatureTypeStyle element
315 mergedFeatTypeStyle.appendChild( ruleElem.cloneNode().toElement() );
316
317 if ( hasRuleRenderer )
318 {
319 QgsDebugMsgLevel( QStringLiteral( "Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" ), 2 );
320 needRuleRenderer = true;
321 }
322 }
323
324 // more rules present, use the RuleRenderer
325 if ( ruleCount > 1 )
326 {
327 QgsDebugMsgLevel( QStringLiteral( "more Rule elements found: need a RuleRenderer" ), 2 );
328 needRuleRenderer = true;
329 }
330
331 ruleElem = ruleElem.nextSiblingElement( QStringLiteral( "Rule" ) );
332 }
333 featTypeStyleElem = featTypeStyleElem.nextSiblingElement( QStringLiteral( "FeatureTypeStyle" ) );
334 }
335
336 QString rendererType;
337 if ( needRuleRenderer )
338 {
339 rendererType = QStringLiteral( "RuleRenderer" );
340 }
341 else
342 {
343 rendererType = QStringLiteral( "singleSymbol" );
344 }
345 QgsDebugMsgLevel( QStringLiteral( "Instantiating a '%1' renderer..." ).arg( rendererType ), 2 );
346
347 // create the renderer and return it
349 if ( !m )
350 {
351 errorMessage = QStringLiteral( "Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
352 return nullptr;
353 }
354
355 QgsFeatureRenderer *r = m->createRendererFromSld( mergedFeatTypeStyle, geomType );
356 return r;
357}
358
360{
361 // build up a list of unique legend keys
362 const QgsLegendSymbolList allLegendSymbols = legendSymbolItems();
363 QSet< QString > keys;
364 keys.reserve( allLegendSymbols.size() );
365 for ( const QgsLegendSymbolItem &symbol : allLegendSymbols )
366 {
367 keys.insert( symbol.ruleKey() );
368 }
369 return keys;
370}
371
372QDomElement QgsFeatureRenderer::writeSld( QDomDocument &doc, const QString &styleName, const QVariantMap &props ) const
373{
374 QDomElement userStyleElem = doc.createElement( QStringLiteral( "UserStyle" ) );
375
376 QDomElement nameElem = doc.createElement( QStringLiteral( "se:Name" ) );
377 nameElem.appendChild( doc.createTextNode( styleName ) );
378 userStyleElem.appendChild( nameElem );
379
380 QDomElement featureTypeStyleElem = doc.createElement( QStringLiteral( "se:FeatureTypeStyle" ) );
381 toSld( doc, featureTypeStyleElem, props );
382 userStyleElem.appendChild( featureTypeStyleElem );
383
384 return userStyleElem;
385}
386
388{
389 return false;
390}
391
393{
394 Q_UNUSED( key )
395 return false;
396}
397
398void QgsFeatureRenderer::checkLegendSymbolItem( const QString &key, bool state )
399{
400 Q_UNUSED( key )
401 Q_UNUSED( state )
402}
403
404void QgsFeatureRenderer::setLegendSymbolItem( const QString &key, QgsSymbol *symbol )
405{
406 Q_UNUSED( key )
407 delete symbol;
408}
409
410QString QgsFeatureRenderer::legendKeyToExpression( const QString &, QgsVectorLayer *, bool &ok ) const
411{
412 ok = false;
413 return QString();
414}
415
420
422{
423 const QgsSymbolList symbolList = symbols( context );
424
425 if ( symbolList.empty() )
426 return 0;
427
428 QgsExpressionContext &expContext = context.expressionContext();
429
430 auto getValueFromSymbol = [ &expContext, &context ]( const QgsSymbol * sym ) -> double
431 {
432 const QgsProperty property = sym->dataDefinedProperties().property( QgsSymbol::Property::ExtentBuffer );
433
434 double value = 0.0;
435
436 if ( property.isActive() )
437 {
438 expContext.setOriginalValueVariable( sym->extentBuffer() );
439
440 value = sym->dataDefinedProperties().valueAsDouble( QgsSymbol::Property::ExtentBuffer, expContext, sym->extentBuffer() );
441 if ( value < 0 )
442 value = 0;
443 }
444 else
445 {
446 value = sym->extentBuffer();
447 }
448
449 if ( sym->extentBufferSizeUnit() != Qgis::RenderUnit::MapUnits )
450 {
451 value = context.convertToMapUnits( value, sym->extentBufferSizeUnit(), sym->mapUnitScale() );
452 }
453
454 return value;
455 };
456
457 if ( symbolList.size() == 1 )
458 return getValueFromSymbol( symbolList[0] );
459
460 auto it = std::max_element( symbolList.constBegin(), symbolList.constEnd(), [ &getValueFromSymbol ]( const QgsSymbol * a, const QgsSymbol * b ) -> bool
461 {
462 return getValueFromSymbol( a ) < getValueFromSymbol( b );
463 } );
464
465 return getValueFromSymbol( *it );
466}
467
468QList<QgsLayerTreeModelLegendNode *> QgsFeatureRenderer::createLegendNodes( QgsLayerTreeLayer *nodeLayer ) const
469{
470 QList<QgsLayerTreeModelLegendNode *> nodes;
471
472 const QgsLegendSymbolList symbolItems = legendSymbolItems();
473 nodes.reserve( symbolItems.size() );
474
475 for ( const QgsLegendSymbolItem &item : symbolItems )
476 {
477 if ( const QgsDataDefinedSizeLegend *dataDefinedSizeLegendSettings = item.dataDefinedSizeLegendSettings() )
478 {
479 nodes << new QgsDataDefinedSizeLegendNode( nodeLayer, *dataDefinedSizeLegendSettings );
480 }
481 else
482 {
483 nodes << new QgsSymbolLegendNode( nodeLayer, item );
484 }
485 }
486 return nodes;
487}
488
494
496{
497 return nullptr != symbolForFeature( feature, context );
498}
499
501{
503 QgsSymbolLayerUtils::drawVertexMarker( pt.x(), pt.y(), *context.painter(),
505 markerSize );
506}
507
509{
510 const auto constPts = pts;
511 for ( const QPointF pt : constPts )
512 renderVertexMarker( pt, context );
513}
514
515void QgsFeatureRenderer::renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context )
516{
517 const auto constPts = pts;
518 for ( const QPointF pt : constPts )
519 renderVertexMarker( pt, context );
520
521 if ( rings )
522 {
523 const auto constRings = *rings;
524 for ( const QPolygonF &ring : constRings )
525 {
526 const auto constRing = ring;
527 for ( const QPointF pt : constRing )
528 renderVertexMarker( pt, context );
529 }
530 }
531}
532
534{
535 QgsSymbolList lst;
536 QgsSymbol *s = symbolForFeature( feature, context );
537 if ( s ) lst.append( s );
538 return lst;
539}
540
542{
543 double extentBuffer = maximumExtentBuffer( context );
544
545 extent.grow( extentBuffer );
546}
547
549{
550 QgsSymbolList lst;
551 QgsSymbol *s = originalSymbolForFeature( feature, context );
552 if ( s ) lst.append( s );
553 return lst;
554}
555
560
562{
563 delete mPaintEffect;
564 mPaintEffect = effect;
565}
566
568{
569 mDataDefinedProperties.setProperty( key, property );
570}
571
576
581
583{
584 return mOrderByEnabled;
585}
586
588{
589 mOrderByEnabled = enabled;
590}
591
593{
594 delete subRenderer;
595}
596
598{
599 return nullptr;
600}
601
603{
604 return true;
605}
606
607void QgsFeatureRenderer::convertSymbolSizeScale( QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field )
608{
609 if ( symbol->type() == Qgis:: SymbolType::Marker )
610 {
611 QgsMarkerSymbol *s = static_cast<QgsMarkerSymbol *>( symbol );
612 if ( Qgis::ScaleMethod::ScaleArea == method )
613 {
614 s->setDataDefinedSize( QgsProperty::fromExpression( "coalesce(sqrt(" + QString::number( s->size() ) + " * (" + field + ")),0)" ) );
615 }
616 else
617 {
618 s->setDataDefinedSize( QgsProperty::fromExpression( "coalesce(" + QString::number( s->size() ) + " * (" + field + "),0)" ) );
619 }
621 }
622 else if ( symbol->type() == Qgis::SymbolType::Line )
623 {
624 QgsLineSymbol *s = static_cast<QgsLineSymbol *>( symbol );
625 s->setDataDefinedWidth( QgsProperty::fromExpression( "coalesce(" + QString::number( s->width() ) + " * (" + field + "),0)" ) );
626 }
627}
628
629void QgsFeatureRenderer::convertSymbolRotation( QgsSymbol *symbol, const QString &field )
630{
631 if ( symbol->type() == Qgis::SymbolType::Marker )
632 {
633 QgsMarkerSymbol *s = static_cast<QgsMarkerSymbol *>( symbol );
635 ? QString::number( s->angle() ) + " + "
636 : QString() ) + field );
637 s->setDataDefinedAngle( dd );
638 }
639}
640
641void QgsFeatureRenderer::initPropertyDefinitions()
642{
643 if ( !sPropertyDefinitions.isEmpty() )
644 return;
645
646 QString origin = QStringLiteral( "renderer" );
647
648 sPropertyDefinitions = QgsPropertiesDefinition
649 {
650 { static_cast< int >( QgsFeatureRenderer::Property::HeatmapRadius ), QgsPropertyDefinition( "heatmapRadius", QObject::tr( "Radius" ), QgsPropertyDefinition::DoublePositive, origin )},
651 { static_cast< int >( QgsFeatureRenderer::Property::HeatmapMaximum ), QgsPropertyDefinition( "heatmapMaximum", QObject::tr( "Maximum" ), QgsPropertyDefinition::DoublePositive, origin )},
652 };
653}
654
656{
657 return mSymbol;
658}
659
661{
662 return mLayer;
663}
ScaleMethod
Scale methods.
Definition qgis.h:588
@ ScaleDiameter
Calculate scale by the diameter.
@ ScaleArea
Calculate scale by the area.
QFlags< FeatureRendererFlag > FeatureRendererFlags
Flags controlling behavior of vector feature renderers.
Definition qgis.h:772
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:337
@ Millimeters
Millimeters.
@ MapUnits
Map units.
VertexMarkerType
Editing vertex markers, used for showing vertices during a edit operation.
Definition qgis.h:1725
@ Marker
Marker symbol.
@ Line
Line symbol.
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into 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.
Produces 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.
Abstract base class for all 2D vector feature renderers.
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 void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
virtual QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns legend keys matching a specified feature.
QgsPaintEffect * mPaintEffect
QString type() const
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.
static void convertSymbolRotation(QgsSymbol *symbol, const QString &field)
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.
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)
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.
void CORE_EXPORT save(QDomElement &elem) const
Serialize to XML.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Container of fields for a vector layer.
Definition qgsfields.h:46
Layer tree node points to a map layer.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
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.
void setEnabled(bool enabled)
Sets whether the effect is enabled.
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const final
Prepares the collection against a specified expression context.
Definition for a property.
Definition qgsproperty.h:45
@ DoublePositive
Positive double value (including 0)
Definition qgsproperty.h:56
A store for object properties.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
The class is used as a container of context for various read/write operations on other 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.
Stores metadata about one renderer class.
virtual QgsFeatureRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context)=0
Returns new instance of the renderer given the DOM element.
virtual QgsFeatureRenderer * createRendererFromSld(QDomElement &elem, Qgis::GeometryType geomType)
Returns a new instance of the renderer, converted from an SLD XML element.
QgsRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
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 * mSymbol
Definition qgsrenderer.h:82
QgsSymbol * symbol() const
The symbol of this symbol level.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
@ 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.
Definition qgssymbol.h:920
Qgis::SymbolType type() const
Returns the symbol's type.
Definition qgssymbol.h:294
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 data sets.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
#define RENDERER_TAG_NAME
Definition qgsrenderer.h:53
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:47