QGIS API Documentation 3.41.0-Master (d5b93354e9c)
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
42QgsPropertiesDefinition QgsFeatureRenderer::sPropertyDefinitions;
43
45{
46 return QgsSymbol::_getPoint( context, point );
47}
48
50{
51 if ( !destRenderer )
52 return;
53
54 if ( mPaintEffect )
55 destRenderer->setPaintEffect( mPaintEffect->clone() );
56
57 destRenderer->setForceRasterRender( mForceRaster );
59 destRenderer->mOrderBy = mOrderBy;
60 destRenderer->mOrderByEnabled = mOrderByEnabled;
61 destRenderer->mReferenceScale = mReferenceScale;
62 destRenderer->mDataDefinedProperties = mDataDefinedProperties;
63}
64
66 : mType( type )
67{
69 mPaintEffect->setEnabled( false );
70}
71
76
78{
79 QgsFeatureRenderer::initPropertyDefinitions();
80 return sPropertyDefinitions;
81}
82
87
89{
90 return symbolForFeature( feature, context );
91}
92
93QSet< QString > QgsFeatureRenderer::legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const
94{
95 Q_UNUSED( feature )
96 Q_UNUSED( context )
97 return QSet< QString >();
98}
99
101{
102#ifdef QGISDEBUG
103 if ( !mThread )
104 {
105 mThread = QThread::currentThread();
106 }
107 else
108 {
109 Q_ASSERT_X( mThread == QThread::currentThread(), "QgsFeatureRenderer::startRender", "startRender called in a different thread - use a cloned renderer instead" );
110 }
111#endif
112
113 mDataDefinedProperties.prepare( context.expressionContext() );
114}
115
117{
118 return false;
119}
120
122{
123#ifdef QGISDEBUG
124 Q_ASSERT_X( mThread == QThread::currentThread(), "QgsFeatureRenderer::stopRender", "stopRender called in a different thread - use a cloned renderer instead" );
125#endif
126}
127
129{
130 return false;
131}
132
134{
135 return false;
136}
137
138bool QgsFeatureRenderer::renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker )
139{
140#ifdef QGISDEBUG
141 Q_ASSERT_X( mThread == QThread::currentThread(), "QgsFeatureRenderer::renderFeature", "renderFeature called in a different thread - use a cloned renderer instead" );
142#endif
143
144 QgsSymbol *symbol = symbolForFeature( feature, context );
145 if ( !symbol )
146 return false;
147
148 renderFeatureWithSymbol( feature, symbol, context, layer, selected, drawVertexMarker );
149 return true;
150}
151
152void QgsFeatureRenderer::renderFeatureWithSymbol( const QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker )
153{
154 symbol->renderFeature( feature, context, layer, selected, drawVertexMarker, mCurrentVertexMarkerType, mCurrentVertexMarkerSize );
155}
156
158{
159 return QStringLiteral( "UNKNOWN RENDERER\n" );
160}
161
166
168{
169 Q_UNUSED( context )
170 return QgsSymbolList();
171}
172
174{
175 // <renderer-v2 type=""> ... </renderer-v2>
176
177 if ( element.isNull() )
178 return nullptr;
179
180 // load renderer
181 const QString rendererType = element.attribute( QStringLiteral( "type" ) );
182
184 if ( !m )
185 return nullptr;
186
187 QgsFeatureRenderer *r = m->createRenderer( element, context );
188 if ( r )
189 {
190 r->setUsingSymbolLevels( element.attribute( QStringLiteral( "symbollevels" ), QStringLiteral( "0" ) ).toInt() );
191 r->setForceRasterRender( element.attribute( QStringLiteral( "forceraster" ), QStringLiteral( "0" ) ).toInt() );
192 r->setReferenceScale( element.attribute( QStringLiteral( "referencescale" ), QStringLiteral( "-1" ) ).toDouble() );
193
194 //restore layer effect
195 const QDomElement effectElem = element.firstChildElement( QStringLiteral( "effect" ) );
196 if ( !effectElem.isNull() )
197 {
198 r->setPaintEffect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
199 }
200
201 // restore order by
202 const QDomElement orderByElem = element.firstChildElement( QStringLiteral( "orderby" ) );
203 r->mOrderBy.load( orderByElem );
204 r->setOrderByEnabled( element.attribute( QStringLiteral( "enableorderby" ), QStringLiteral( "0" ) ).toInt() );
205
206 const QDomElement elemDataDefinedProperties = element.firstChildElement( QStringLiteral( "data-defined-properties" ) );
207 if ( !elemDataDefinedProperties.isNull() )
208 r->mDataDefinedProperties.readXml( elemDataDefinedProperties, propertyDefinitions() );
209 }
210 return r;
211}
212
213QDomElement QgsFeatureRenderer::save( QDomDocument &doc, const QgsReadWriteContext &context )
214{
215 Q_UNUSED( context )
216 // create empty renderer element
217 QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
218
219 saveRendererData( doc, rendererElem, context );
220
221 return rendererElem;
222}
223
224void QgsFeatureRenderer::saveRendererData( QDomDocument &doc, QDomElement &rendererElem, const QgsReadWriteContext & )
225{
226 rendererElem.setAttribute( QStringLiteral( "forceraster" ), ( mForceRaster ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ) );
227 rendererElem.setAttribute( QStringLiteral( "symbollevels" ), ( mUsingSymbolLevels ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ) );
228 rendererElem.setAttribute( QStringLiteral( "referencescale" ), mReferenceScale );
229
230 QDomElement elemDataDefinedProperties = doc.createElement( QStringLiteral( "data-defined-properties" ) );
231 mDataDefinedProperties.writeXml( elemDataDefinedProperties, propertyDefinitions() );
232 rendererElem.appendChild( elemDataDefinedProperties );
233
235 mPaintEffect->saveProperties( doc, rendererElem );
236
237 if ( !mOrderBy.isEmpty() )
238 {
239 QDomElement orderBy = doc.createElement( QStringLiteral( "orderby" ) );
241 rendererElem.appendChild( orderBy );
242 }
243 rendererElem.setAttribute( QStringLiteral( "enableorderby" ), ( mOrderByEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ) );
244}
245
246QgsFeatureRenderer *QgsFeatureRenderer::loadSld( const QDomNode &node, Qgis::GeometryType geomType, QString &errorMessage )
247{
248 const QDomElement element = node.toElement();
249 if ( element.isNull() )
250 return nullptr;
251
252 // get the UserStyle element
253 const QDomElement userStyleElem = element.firstChildElement( QStringLiteral( "UserStyle" ) );
254 if ( userStyleElem.isNull() )
255 {
256 // UserStyle element not found, nothing will be rendered
257 errorMessage = QStringLiteral( "Info: UserStyle element not found." );
258 return nullptr;
259 }
260
261 // get the FeatureTypeStyle element
262 QDomElement featTypeStyleElem = userStyleElem.firstChildElement( QStringLiteral( "FeatureTypeStyle" ) );
263 if ( featTypeStyleElem.isNull() )
264 {
265 errorMessage = QStringLiteral( "Info: FeatureTypeStyle element not found." );
266 return nullptr;
267 }
268
269 // create empty FeatureTypeStyle element to merge Rule's from all FeatureTypeStyle's
270 QDomElement mergedFeatTypeStyle = featTypeStyleElem.cloneNode( false ).toElement();
271
272 // use the RuleRenderer when more rules are present or the rule
273 // has filters or min/max scale denominators set,
274 // otherwise use the SingleSymbol renderer
275 bool needRuleRenderer = false;
276 int ruleCount = 0;
277
278 while ( !featTypeStyleElem.isNull() )
279 {
280 QDomElement ruleElem = featTypeStyleElem.firstChildElement( QStringLiteral( "Rule" ) );
281 while ( !ruleElem.isNull() )
282 {
283 // test rule children element to check if we need to create RuleRenderer
284 // and if the rule has a symbolizer
285 bool hasRendererSymbolizer = false;
286 bool hasRuleRenderer = false;
287 QDomElement ruleChildElem = ruleElem.firstChildElement();
288 while ( !ruleChildElem.isNull() )
289 {
290 // rule has filter or min/max scale denominator, use the RuleRenderer
291 if ( ruleChildElem.localName() == QLatin1String( "Filter" ) ||
292 ruleChildElem.localName() == QLatin1String( "ElseFilter" ) ||
293 ruleChildElem.localName() == QLatin1String( "MinScaleDenominator" ) ||
294 ruleChildElem.localName() == QLatin1String( "MaxScaleDenominator" ) )
295 {
296 hasRuleRenderer = true;
297 }
298 // rule has a renderer symbolizer, not a text symbolizer
299 else if ( ruleChildElem.localName().endsWith( QLatin1String( "Symbolizer" ) ) &&
300 ruleChildElem.localName() != QLatin1String( "TextSymbolizer" ) )
301 {
302 QgsDebugMsgLevel( QStringLiteral( "Symbolizer element found and not a TextSymbolizer" ), 2 );
303 hasRendererSymbolizer = true;
304 }
305
306 ruleChildElem = ruleChildElem.nextSiblingElement();
307 }
308
309 if ( hasRendererSymbolizer )
310 {
311 ruleCount++;
312
313 // append a clone of all Rules to the merged FeatureTypeStyle element
314 mergedFeatTypeStyle.appendChild( ruleElem.cloneNode().toElement() );
315
316 if ( hasRuleRenderer )
317 {
318 QgsDebugMsgLevel( QStringLiteral( "Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" ), 2 );
319 needRuleRenderer = true;
320 }
321 }
322
323 // more rules present, use the RuleRenderer
324 if ( ruleCount > 1 )
325 {
326 QgsDebugMsgLevel( QStringLiteral( "more Rule elements found: need a RuleRenderer" ), 2 );
327 needRuleRenderer = true;
328 }
329
330 ruleElem = ruleElem.nextSiblingElement( QStringLiteral( "Rule" ) );
331 }
332 featTypeStyleElem = featTypeStyleElem.nextSiblingElement( QStringLiteral( "FeatureTypeStyle" ) );
333 }
334
335 QString rendererType;
336 if ( needRuleRenderer )
337 {
338 rendererType = QStringLiteral( "RuleRenderer" );
339 }
340 else
341 {
342 rendererType = QStringLiteral( "singleSymbol" );
343 }
344 QgsDebugMsgLevel( QStringLiteral( "Instantiating a '%1' renderer..." ).arg( rendererType ), 2 );
345
346 // create the renderer and return it
348 if ( !m )
349 {
350 errorMessage = QStringLiteral( "Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
351 return nullptr;
352 }
353
354 QgsFeatureRenderer *r = m->createRendererFromSld( mergedFeatTypeStyle, geomType );
355 return r;
356}
357
359{
360 // build up a list of unique legend keys
361 const QgsLegendSymbolList allLegendSymbols = legendSymbolItems();
362 QSet< QString > keys;
363 keys.reserve( allLegendSymbols.size() );
364 for ( const QgsLegendSymbolItem &symbol : allLegendSymbols )
365 {
366 keys.insert( symbol.ruleKey() );
367 }
368 return keys;
369}
370
371QDomElement QgsFeatureRenderer::writeSld( QDomDocument &doc, const QString &styleName, const QVariantMap &props ) const
372{
373 QDomElement userStyleElem = doc.createElement( QStringLiteral( "UserStyle" ) );
374
375 QDomElement nameElem = doc.createElement( QStringLiteral( "se:Name" ) );
376 nameElem.appendChild( doc.createTextNode( styleName ) );
377 userStyleElem.appendChild( nameElem );
378
379 QDomElement featureTypeStyleElem = doc.createElement( QStringLiteral( "se:FeatureTypeStyle" ) );
380 toSld( doc, featureTypeStyleElem, props );
381 userStyleElem.appendChild( featureTypeStyleElem );
382
383 return userStyleElem;
384}
385
387{
388 return false;
389}
390
392{
393 Q_UNUSED( key )
394 return false;
395}
396
397void QgsFeatureRenderer::checkLegendSymbolItem( const QString &key, bool state )
398{
399 Q_UNUSED( key )
400 Q_UNUSED( state )
401}
402
403void QgsFeatureRenderer::setLegendSymbolItem( const QString &key, QgsSymbol *symbol )
404{
405 Q_UNUSED( key )
406 delete symbol;
407}
408
409QString QgsFeatureRenderer::legendKeyToExpression( const QString &, QgsVectorLayer *, bool &ok ) const
410{
411 ok = false;
412 return QString();
413}
414
419
420QList<QgsLayerTreeModelLegendNode *> QgsFeatureRenderer::createLegendNodes( QgsLayerTreeLayer *nodeLayer ) const
421{
422 QList<QgsLayerTreeModelLegendNode *> nodes;
423
424 const QgsLegendSymbolList symbolItems = legendSymbolItems();
425 nodes.reserve( symbolItems.size() );
426
427 for ( const QgsLegendSymbolItem &item : symbolItems )
428 {
429 if ( const QgsDataDefinedSizeLegend *dataDefinedSizeLegendSettings = item.dataDefinedSizeLegendSettings() )
430 {
431 nodes << new QgsDataDefinedSizeLegendNode( nodeLayer, *dataDefinedSizeLegendSettings );
432 }
433 else
434 {
435 nodes << new QgsSymbolLegendNode( nodeLayer, item );
436 }
437 }
438 return nodes;
439}
440
446
448{
449 return nullptr != symbolForFeature( feature, context );
450}
451
453{
455 QgsSymbolLayerUtils::drawVertexMarker( pt.x(), pt.y(), *context.painter(),
457 markerSize );
458}
459
461{
462 const auto constPts = pts;
463 for ( const QPointF pt : constPts )
464 renderVertexMarker( pt, context );
465}
466
467void QgsFeatureRenderer::renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context )
468{
469 const auto constPts = pts;
470 for ( const QPointF pt : constPts )
471 renderVertexMarker( pt, context );
472
473 if ( rings )
474 {
475 const auto constRings = *rings;
476 for ( const QPolygonF &ring : constRings )
477 {
478 const auto constRing = ring;
479 for ( const QPointF pt : constRing )
480 renderVertexMarker( pt, context );
481 }
482 }
483}
484
486{
487 QgsSymbolList lst;
488 QgsSymbol *s = symbolForFeature( feature, context );
489 if ( s ) lst.append( s );
490 return lst;
491}
492
494{
495 Q_UNUSED( extent )
496 Q_UNUSED( context )
497}
498
500{
501 QgsSymbolList lst;
502 QgsSymbol *s = originalSymbolForFeature( feature, context );
503 if ( s ) lst.append( s );
504 return lst;
505}
506
511
513{
514 delete mPaintEffect;
515 mPaintEffect = effect;
516}
517
519{
520 mDataDefinedProperties.setProperty( key, property );
521}
522
527
532
534{
535 return mOrderByEnabled;
536}
537
539{
540 mOrderByEnabled = enabled;
541}
542
544{
545 delete subRenderer;
546}
547
549{
550 return nullptr;
551}
552
554{
555 return true;
556}
557
558void QgsFeatureRenderer::convertSymbolSizeScale( QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field )
559{
560 if ( symbol->type() == Qgis:: SymbolType::Marker )
561 {
562 QgsMarkerSymbol *s = static_cast<QgsMarkerSymbol *>( symbol );
563 if ( Qgis::ScaleMethod::ScaleArea == method )
564 {
565 s->setDataDefinedSize( QgsProperty::fromExpression( "coalesce(sqrt(" + QString::number( s->size() ) + " * (" + field + ")),0)" ) );
566 }
567 else
568 {
569 s->setDataDefinedSize( QgsProperty::fromExpression( "coalesce(" + QString::number( s->size() ) + " * (" + field + "),0)" ) );
570 }
572 }
573 else if ( symbol->type() == Qgis::SymbolType::Line )
574 {
575 QgsLineSymbol *s = static_cast<QgsLineSymbol *>( symbol );
576 s->setDataDefinedWidth( QgsProperty::fromExpression( "coalesce(" + QString::number( s->width() ) + " * (" + field + "),0)" ) );
577 }
578}
579
580void QgsFeatureRenderer::convertSymbolRotation( QgsSymbol *symbol, const QString &field )
581{
582 if ( symbol->type() == Qgis::SymbolType::Marker )
583 {
584 QgsMarkerSymbol *s = static_cast<QgsMarkerSymbol *>( symbol );
586 ? QString::number( s->angle() ) + " + "
587 : QString() ) + field );
588 s->setDataDefinedAngle( dd );
589 }
590}
591
592void QgsFeatureRenderer::initPropertyDefinitions()
593{
594 if ( !sPropertyDefinitions.isEmpty() )
595 return;
596
597 QString origin = QStringLiteral( "renderer" );
598
599 sPropertyDefinitions = QgsPropertiesDefinition
600 {
601 { static_cast< int >( QgsFeatureRenderer::Property::HeatmapRadius ), QgsPropertyDefinition( "heatmapRadius", QObject::tr( "Radius" ), QgsPropertyDefinition::DoublePositive, origin )},
602 { static_cast< int >( QgsFeatureRenderer::Property::HeatmapMaximum ), QgsPropertyDefinition( "heatmapMaximum", QObject::tr( "Maximum" ), QgsPropertyDefinition::DoublePositive, origin )},
603 };
604}
605
607{
608 return mSymbol;
609}
610
612{
613 return mLayer;
614}
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.
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.
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
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.
Contains information about the context of a rendering operation.
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
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:882
Qgis::SymbolType type() const
Returns the symbol's type.
Definition qgssymbol.h:293
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