QGIS API Documentation 3.37.0-Master (df6056bf1be)
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
163{
164 Q_UNUSED( context )
165 return QgsSymbolList();
166}
167
169{
170 // <renderer-v2 type=""> ... </renderer-v2>
171
172 if ( element.isNull() )
173 return nullptr;
174
175 // load renderer
176 const QString rendererType = element.attribute( QStringLiteral( "type" ) );
177
179 if ( !m )
180 return nullptr;
181
182 QgsFeatureRenderer *r = m->createRenderer( element, context );
183 if ( r )
184 {
185 r->setUsingSymbolLevels( element.attribute( QStringLiteral( "symbollevels" ), QStringLiteral( "0" ) ).toInt() );
186 r->setForceRasterRender( element.attribute( QStringLiteral( "forceraster" ), QStringLiteral( "0" ) ).toInt() );
187 r->setReferenceScale( element.attribute( QStringLiteral( "referencescale" ), QStringLiteral( "-1" ) ).toDouble() );
188
189 //restore layer effect
190 const QDomElement effectElem = element.firstChildElement( QStringLiteral( "effect" ) );
191 if ( !effectElem.isNull() )
192 {
193 r->setPaintEffect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
194 }
195
196 // restore order by
197 const QDomElement orderByElem = element.firstChildElement( QStringLiteral( "orderby" ) );
198 r->mOrderBy.load( orderByElem );
199 r->setOrderByEnabled( element.attribute( QStringLiteral( "enableorderby" ), QStringLiteral( "0" ) ).toInt() );
200
201 const QDomElement elemDataDefinedProperties = element.firstChildElement( QStringLiteral( "data-defined-properties" ) );
202 if ( !elemDataDefinedProperties.isNull() )
203 r->mDataDefinedProperties.readXml( elemDataDefinedProperties, propertyDefinitions() );
204 }
205 return r;
206}
207
208QDomElement QgsFeatureRenderer::save( QDomDocument &doc, const QgsReadWriteContext &context )
209{
210 Q_UNUSED( context )
211 // create empty renderer element
212 QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
213
214 saveRendererData( doc, rendererElem, context );
215
216 return rendererElem;
217}
218
219void QgsFeatureRenderer::saveRendererData( QDomDocument &doc, QDomElement &rendererElem, const QgsReadWriteContext & )
220{
221 rendererElem.setAttribute( QStringLiteral( "forceraster" ), ( mForceRaster ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ) );
222 rendererElem.setAttribute( QStringLiteral( "symbollevels" ), ( mUsingSymbolLevels ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ) );
223 rendererElem.setAttribute( QStringLiteral( "referencescale" ), mReferenceScale );
224
225 QDomElement elemDataDefinedProperties = doc.createElement( QStringLiteral( "data-defined-properties" ) );
226 mDataDefinedProperties.writeXml( elemDataDefinedProperties, propertyDefinitions() );
227 rendererElem.appendChild( elemDataDefinedProperties );
228
230 mPaintEffect->saveProperties( doc, rendererElem );
231
232 if ( !mOrderBy.isEmpty() )
233 {
234 QDomElement orderBy = doc.createElement( QStringLiteral( "orderby" ) );
236 rendererElem.appendChild( orderBy );
237 }
238 rendererElem.setAttribute( QStringLiteral( "enableorderby" ), ( mOrderByEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ) );
239}
240
241QgsFeatureRenderer *QgsFeatureRenderer::loadSld( const QDomNode &node, Qgis::GeometryType geomType, QString &errorMessage )
242{
243 const QDomElement element = node.toElement();
244 if ( element.isNull() )
245 return nullptr;
246
247 // get the UserStyle element
248 const QDomElement userStyleElem = element.firstChildElement( QStringLiteral( "UserStyle" ) );
249 if ( userStyleElem.isNull() )
250 {
251 // UserStyle element not found, nothing will be rendered
252 errorMessage = QStringLiteral( "Info: UserStyle element not found." );
253 return nullptr;
254 }
255
256 // get the FeatureTypeStyle element
257 QDomElement featTypeStyleElem = userStyleElem.firstChildElement( QStringLiteral( "FeatureTypeStyle" ) );
258 if ( featTypeStyleElem.isNull() )
259 {
260 errorMessage = QStringLiteral( "Info: FeatureTypeStyle element not found." );
261 return nullptr;
262 }
263
264 // create empty FeatureTypeStyle element to merge Rule's from all FeatureTypeStyle's
265 QDomElement mergedFeatTypeStyle = featTypeStyleElem.cloneNode( false ).toElement();
266
267 // use the RuleRenderer when more rules are present or the rule
268 // has filters or min/max scale denominators set,
269 // otherwise use the SingleSymbol renderer
270 bool needRuleRenderer = false;
271 int ruleCount = 0;
272
273 while ( !featTypeStyleElem.isNull() )
274 {
275 QDomElement ruleElem = featTypeStyleElem.firstChildElement( QStringLiteral( "Rule" ) );
276 while ( !ruleElem.isNull() )
277 {
278 // test rule children element to check if we need to create RuleRenderer
279 // and if the rule has a symbolizer
280 bool hasRendererSymbolizer = false;
281 bool hasRuleRenderer = false;
282 QDomElement ruleChildElem = ruleElem.firstChildElement();
283 while ( !ruleChildElem.isNull() )
284 {
285 // rule has filter or min/max scale denominator, use the RuleRenderer
286 if ( ruleChildElem.localName() == QLatin1String( "Filter" ) ||
287 ruleChildElem.localName() == QLatin1String( "ElseFilter" ) ||
288 ruleChildElem.localName() == QLatin1String( "MinScaleDenominator" ) ||
289 ruleChildElem.localName() == QLatin1String( "MaxScaleDenominator" ) )
290 {
291 hasRuleRenderer = true;
292 }
293 // rule has a renderer symbolizer, not a text symbolizer
294 else if ( ruleChildElem.localName().endsWith( QLatin1String( "Symbolizer" ) ) &&
295 ruleChildElem.localName() != QLatin1String( "TextSymbolizer" ) )
296 {
297 QgsDebugMsgLevel( QStringLiteral( "Symbolizer element found and not a TextSymbolizer" ), 2 );
298 hasRendererSymbolizer = true;
299 }
300
301 ruleChildElem = ruleChildElem.nextSiblingElement();
302 }
303
304 if ( hasRendererSymbolizer )
305 {
306 ruleCount++;
307
308 // append a clone of all Rules to the merged FeatureTypeStyle element
309 mergedFeatTypeStyle.appendChild( ruleElem.cloneNode().toElement() );
310
311 if ( hasRuleRenderer )
312 {
313 QgsDebugMsgLevel( QStringLiteral( "Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" ), 2 );
314 needRuleRenderer = true;
315 }
316 }
317
318 // more rules present, use the RuleRenderer
319 if ( ruleCount > 1 )
320 {
321 QgsDebugMsgLevel( QStringLiteral( "more Rule elements found: need a RuleRenderer" ), 2 );
322 needRuleRenderer = true;
323 }
324
325 ruleElem = ruleElem.nextSiblingElement( QStringLiteral( "Rule" ) );
326 }
327 featTypeStyleElem = featTypeStyleElem.nextSiblingElement( QStringLiteral( "FeatureTypeStyle" ) );
328 }
329
330 QString rendererType;
331 if ( needRuleRenderer )
332 {
333 rendererType = QStringLiteral( "RuleRenderer" );
334 }
335 else
336 {
337 rendererType = QStringLiteral( "singleSymbol" );
338 }
339 QgsDebugMsgLevel( QStringLiteral( "Instantiating a '%1' renderer..." ).arg( rendererType ), 2 );
340
341 // create the renderer and return it
343 if ( !m )
344 {
345 errorMessage = QStringLiteral( "Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
346 return nullptr;
347 }
348
349 QgsFeatureRenderer *r = m->createRendererFromSld( mergedFeatTypeStyle, geomType );
350 return r;
351}
352
354{
355 // build up a list of unique legend keys
356 const QgsLegendSymbolList allLegendSymbols = legendSymbolItems();
357 QSet< QString > keys;
358 keys.reserve( allLegendSymbols.size() );
359 for ( const QgsLegendSymbolItem &symbol : allLegendSymbols )
360 {
361 keys.insert( symbol.ruleKey() );
362 }
363 return keys;
364}
365
366QDomElement QgsFeatureRenderer::writeSld( QDomDocument &doc, const QString &styleName, const QVariantMap &props ) const
367{
368 QDomElement userStyleElem = doc.createElement( QStringLiteral( "UserStyle" ) );
369
370 QDomElement nameElem = doc.createElement( QStringLiteral( "se:Name" ) );
371 nameElem.appendChild( doc.createTextNode( styleName ) );
372 userStyleElem.appendChild( nameElem );
373
374 QDomElement featureTypeStyleElem = doc.createElement( QStringLiteral( "se:FeatureTypeStyle" ) );
375 toSld( doc, featureTypeStyleElem, props );
376 userStyleElem.appendChild( featureTypeStyleElem );
377
378 return userStyleElem;
379}
380
382{
383 return false;
384}
385
387{
388 Q_UNUSED( key )
389 return false;
390}
391
392void QgsFeatureRenderer::checkLegendSymbolItem( const QString &key, bool state )
393{
394 Q_UNUSED( key )
395 Q_UNUSED( state )
396}
397
398void QgsFeatureRenderer::setLegendSymbolItem( const QString &key, QgsSymbol *symbol )
399{
400 Q_UNUSED( key )
401 delete symbol;
402}
403
404QString QgsFeatureRenderer::legendKeyToExpression( const QString &, QgsVectorLayer *, bool &ok ) const
405{
406 ok = false;
407 return QString();
408}
409
414
415QList<QgsLayerTreeModelLegendNode *> QgsFeatureRenderer::createLegendNodes( QgsLayerTreeLayer *nodeLayer ) const
416{
417 QList<QgsLayerTreeModelLegendNode *> nodes;
418
419 const QgsLegendSymbolList symbolItems = legendSymbolItems();
420 nodes.reserve( symbolItems.size() );
421
422 for ( const QgsLegendSymbolItem &item : symbolItems )
423 {
424 if ( const QgsDataDefinedSizeLegend *dataDefinedSizeLegendSettings = item.dataDefinedSizeLegendSettings() )
425 {
426 nodes << new QgsDataDefinedSizeLegendNode( nodeLayer, *dataDefinedSizeLegendSettings );
427 }
428 else
429 {
430 nodes << new QgsSymbolLegendNode( nodeLayer, item );
431 }
432 }
433 return nodes;
434}
435
441
443{
444 return nullptr != symbolForFeature( feature, context );
445}
446
448{
450 QgsSymbolLayerUtils::drawVertexMarker( pt.x(), pt.y(), *context.painter(),
452 markerSize );
453}
454
456{
457 const auto constPts = pts;
458 for ( const QPointF pt : constPts )
459 renderVertexMarker( pt, context );
460}
461
462void QgsFeatureRenderer::renderVertexMarkerPolygon( QPolygonF &pts, QList<QPolygonF> *rings, QgsRenderContext &context )
463{
464 const auto constPts = pts;
465 for ( const QPointF pt : constPts )
466 renderVertexMarker( pt, context );
467
468 if ( rings )
469 {
470 const auto constRings = *rings;
471 for ( const QPolygonF &ring : constRings )
472 {
473 const auto constRing = ring;
474 for ( const QPointF pt : constRing )
475 renderVertexMarker( pt, context );
476 }
477 }
478}
479
481{
482 QgsSymbolList lst;
483 QgsSymbol *s = symbolForFeature( feature, context );
484 if ( s ) lst.append( s );
485 return lst;
486}
487
489{
490 Q_UNUSED( extent )
491 Q_UNUSED( context )
492}
493
495{
496 QgsSymbolList lst;
497 QgsSymbol *s = originalSymbolForFeature( feature, context );
498 if ( s ) lst.append( s );
499 return lst;
500}
501
506
508{
509 delete mPaintEffect;
510 mPaintEffect = effect;
511}
512
514{
515 mDataDefinedProperties.setProperty( key, property );
516}
517
522
527
529{
530 return mOrderByEnabled;
531}
532
534{
535 mOrderByEnabled = enabled;
536}
537
539{
540 delete subRenderer;
541}
542
544{
545 return nullptr;
546}
547
549{
550 return true;
551}
552
553void QgsFeatureRenderer::convertSymbolSizeScale( QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field )
554{
555 if ( symbol->type() == Qgis:: SymbolType::Marker )
556 {
557 QgsMarkerSymbol *s = static_cast<QgsMarkerSymbol *>( symbol );
558 if ( Qgis::ScaleMethod::ScaleArea == method )
559 {
560 s->setDataDefinedSize( QgsProperty::fromExpression( "coalesce(sqrt(" + QString::number( s->size() ) + " * (" + field + ")),0)" ) );
561 }
562 else
563 {
564 s->setDataDefinedSize( QgsProperty::fromExpression( "coalesce(" + QString::number( s->size() ) + " * (" + field + "),0)" ) );
565 }
567 }
568 else if ( symbol->type() == Qgis::SymbolType::Line )
569 {
570 QgsLineSymbol *s = static_cast<QgsLineSymbol *>( symbol );
571 s->setDataDefinedWidth( QgsProperty::fromExpression( "coalesce(" + QString::number( s->width() ) + " * (" + field + "),0)" ) );
572 }
573}
574
575void QgsFeatureRenderer::convertSymbolRotation( QgsSymbol *symbol, const QString &field )
576{
577 if ( symbol->type() == Qgis::SymbolType::Marker )
578 {
579 QgsMarkerSymbol *s = static_cast<QgsMarkerSymbol *>( symbol );
581 ? QString::number( s->angle() ) + " + "
582 : QString() ) + field );
583 s->setDataDefinedAngle( dd );
584 }
585}
586
587void QgsFeatureRenderer::initPropertyDefinitions()
588{
589 if ( !sPropertyDefinitions.isEmpty() )
590 return;
591
592 QString origin = QStringLiteral( "renderer" );
593
594 sPropertyDefinitions = QgsPropertiesDefinition
595 {
596 { static_cast< int >( QgsFeatureRenderer::Property::HeatmapRadius ), QgsPropertyDefinition( "heatmapRadius", QObject::tr( "Radius" ), QgsPropertyDefinition::DoublePositive, origin )},
597 { static_cast< int >( QgsFeatureRenderer::Property::HeatmapMaximum ), QgsPropertyDefinition( "heatmapMaximum", QObject::tr( "Maximum" ), QgsPropertyDefinition::DoublePositive, origin )},
598 };
599}
600
602{
603 return mSymbol;
604}
605
607{
608 return mLayer;
609}
ScaleMethod
Scale methods.
Definition qgis.h:434
@ ScaleDiameter
Calculate scale by the diameter.
@ ScaleArea
Calculate scale by the area.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:274
@ Millimeters
Millimeters.
VertexMarkerType
Editing vertex markers, used for showing vertices during a edit operation.
Definition qgis.h:1500
@ 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.
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 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:94
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:715
Qgis::SymbolType type() const
Returns the symbol's type.
Definition qgssymbol.h:156
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