18 #include "qgsexpression.h" 33 #include <QDomDocument> 34 #include <QDomElement> 41 , mMaximumScale( scaleMinDenom )
42 , mMinimumScale( scaleMaxDenom )
43 , mFilterExp( filterExp )
45 , mDescription( description )
46 , mElseRule( elseRule )
53 mRuleKey = QUuid::createUuid().toString();
67 if (
mFilterExp.trimmed().compare( QLatin1String(
"ELSE" ), Qt::CaseInsensitive ) == 0 )
146 void QgsRuleBasedRenderer::Rule::updateElseRules()
168 off.fill( QChar(
' ' ), indent );
170 QString msg = off + QStringLiteral(
"RULE %1 - scale [%2,%3] - filter %4 - symbol %5\n" )
177 lst.append( rule->
dump( indent + 2 ) );
179 msg += lst.join( QStringLiteral(
"\n" ) );
188 attrs.unite(
mFilter->referencedColumns() );
222 lst += rule->
symbols( context );
242 if ( currentLevel != -1 )
247 for ( RuleList::const_iterator it =
mChildren.constBegin(); it !=
mChildren.constEnd(); ++it )
263 return res.toInt() != 0;
292 QDomElement ruleElem = doc.createElement( QStringLiteral(
"rule" ) );
296 int symbolIndex = symbolMap.size();
297 symbolMap[QString::number( symbolIndex )] =
mSymbol;
298 ruleElem.setAttribute( QStringLiteral(
"symbol" ), symbolIndex );
301 ruleElem.setAttribute( QStringLiteral(
"filter" ),
mFilterExp );
303 ruleElem.setAttribute( QStringLiteral(
"scalemindenom" ),
mMaximumScale );
305 ruleElem.setAttribute( QStringLiteral(
"scalemaxdenom" ),
mMinimumScale );
307 ruleElem.setAttribute( QStringLiteral(
"label" ),
mLabel );
309 ruleElem.setAttribute( QStringLiteral(
"description" ),
mDescription );
311 ruleElem.setAttribute( QStringLiteral(
"checkstate" ), 0 );
312 ruleElem.setAttribute( QStringLiteral(
"key" ),
mRuleKey );
316 ruleElem.appendChild( rule->
save( doc, symbolMap ) );
325 if (
symbols( context ).isEmpty() )
330 if ( !props.value( QStringLiteral(
"filter" ), QLatin1String(
"" ) ).isEmpty() )
331 props[ QStringLiteral(
"filter" )] += QLatin1String(
" AND " );
332 props[ QStringLiteral(
"filter" )] +=
mFilterExp;
339 QDomElement ruleElem = doc.createElement( QStringLiteral(
"se:Rule" ) );
340 element.appendChild( ruleElem );
344 QDomElement nameElem = doc.createElement( QStringLiteral(
"se:Name" ) );
345 nameElem.appendChild( doc.createTextNode(
mLabel ) );
346 ruleElem.appendChild( nameElem );
350 QDomElement descrElem = doc.createElement( QStringLiteral(
"se:Description" ) );
353 QDomElement titleElem = doc.createElement( QStringLiteral(
"se:Title" ) );
354 titleElem.appendChild( doc.createTextNode(
mLabel ) );
355 descrElem.appendChild( titleElem );
359 QDomElement abstractElem = doc.createElement( QStringLiteral(
"se:Abstract" ) );
360 abstractElem.appendChild( doc.createTextNode(
mDescription ) );
361 descrElem.appendChild( abstractElem );
363 ruleElem.appendChild( descrElem );
366 if ( !props.value( QStringLiteral(
"filter" ), QLatin1String(
"" ) ).isEmpty() )
379 rule->
toSld( doc, element, props );
402 QStringList subfilters;
406 if ( rule->
startRender( context, fields, subfilter ) )
410 subfilters.append( subfilter );
418 if ( subfilters.length() > 1 || !subfilters.value( 0 ).isEmpty() )
420 if ( subfilters.contains( QStringLiteral(
"TRUE" ) ) )
421 sf = QStringLiteral(
"TRUE" );
423 sf = subfilters.join( QStringLiteral(
") OR (" ) ).prepend(
'(' ).append(
')' );
434 filter = QStringLiteral(
"TRUE" );
440 else if ( !
mFilterExp.trimmed().isEmpty() && !sf.isEmpty() )
441 filter = QStringLiteral(
"(%1) AND (%2)" ).arg(
mFilterExp, sf );
444 else if ( sf.isEmpty() )
445 filter = QStringLiteral(
"TRUE" );
449 filter = filter.trimmed();
456 QSet<int> symbolZLevelsSet;
469 QList<Rule *>::iterator it;
475 return symbolZLevelsSet;
502 bool rendered =
false;
511 renderQueue[normZLevel].jobs.append(
new RenderJob( featToRender,
mSymbol ) );
516 bool willrendersomething =
false;
532 if ( !willrendersomething )
623 QString symbolIdx = ruleElem.attribute( QStringLiteral(
"symbol" ) );
625 if ( !symbolIdx.isEmpty() )
627 if ( symbolMap.contains( symbolIdx ) )
629 symbol = symbolMap.take( symbolIdx );
633 QgsDebugMsg(
"symbol for rule " + symbolIdx +
" not found!" );
637 QString filterExp = ruleElem.attribute( QStringLiteral(
"filter" ) );
638 QString
label = ruleElem.attribute( QStringLiteral(
"label" ) );
639 QString
description = ruleElem.attribute( QStringLiteral(
"description" ) );
640 int scaleMinDenom = ruleElem.attribute( QStringLiteral(
"scalemindenom" ), QStringLiteral(
"0" ) ).toInt();
641 int scaleMaxDenom = ruleElem.attribute( QStringLiteral(
"scalemaxdenom" ), QStringLiteral(
"0" ) ).toInt();
642 QString
ruleKey = ruleElem.attribute( QStringLiteral(
"key" ) );
643 Rule *rule =
new Rule( symbol, scaleMinDenom, scaleMaxDenom, filterExp, label, description );
645 if ( !ruleKey.isEmpty() )
648 rule->
setActive( ruleElem.attribute( QStringLiteral(
"checkstate" ), QStringLiteral(
"1" ) ).toInt() );
650 QDomElement childRuleElem = ruleElem.firstChildElement( QStringLiteral(
"rule" ) );
651 while ( !childRuleElem.isNull() )
653 Rule *childRule =
create( childRuleElem, symbolMap );
662 childRuleElem = childRuleElem.nextSiblingElement( QStringLiteral(
"rule" ) );
670 if ( ruleElem.localName() != QLatin1String(
"Rule" ) )
672 QgsDebugMsg( QString(
"invalid element: Rule element expected, %1 found!" ).arg( ruleElem.tagName() ) );
677 int scaleMinDenom = 0, scaleMaxDenom = 0;
681 QDomElement childElem = ruleElem.firstChildElement();
682 while ( !childElem.isNull() )
684 if ( childElem.localName() == QLatin1String(
"Name" ) )
688 if ( label.isEmpty() )
689 label = childElem.firstChild().nodeValue();
691 else if ( childElem.localName() == QLatin1String(
"Description" ) )
694 QDomElement titleElem = childElem.firstChildElement( QStringLiteral(
"Title" ) );
695 if ( !titleElem.isNull() )
697 label = titleElem.firstChild().nodeValue();
700 QDomElement abstractElem = childElem.firstChildElement( QStringLiteral(
"Abstract" ) );
701 if ( !abstractElem.isNull() )
703 description = abstractElem.firstChild().nodeValue();
706 else if ( childElem.localName() == QLatin1String(
"Abstract" ) )
709 description = childElem.firstChild().nodeValue();
711 else if ( childElem.localName() == QLatin1String(
"Title" ) )
714 label = childElem.firstChild().nodeValue();
716 else if ( childElem.localName() == QLatin1String(
"Filter" ) )
721 if ( filter->hasParserError() )
723 QgsDebugMsg(
"parser error: " + filter->parserErrorString() );
727 filterExp = filter->expression();
732 else if ( childElem.localName() == QLatin1String(
"MinScaleDenominator" ) )
735 int v = childElem.firstChild().nodeValue().toInt( &ok );
739 else if ( childElem.localName() == QLatin1String(
"MaxScaleDenominator" ) )
742 int v = childElem.firstChild().nodeValue().toInt( &ok );
746 else if ( childElem.localName().endsWith( QLatin1String(
"Symbolizer" ) ) )
752 childElem = childElem.nextSiblingElement();
757 if ( !layers.isEmpty() )
774 QgsDebugMsg( QString(
"invalid geometry type: found %1" ).arg( geomType ) );
780 return new Rule( symbol, scaleMinDenom, scaleMaxDenom, filterExp, label, description );
815 bool drawVertexMarker )
835 QList<int> symbolZLevels = symbolZLevelsSet.toList();
836 std::sort( symbolZLevels.begin(), symbolZLevels.end() );
840 QMap<int, int> zLevelsToNormLevels;
841 int maxNormLevel = -1;
842 Q_FOREACH (
int zLevel, symbolZLevels )
844 zLevelsToNormLevels[zLevel] = ++maxNormLevel;
846 QgsDebugMsgLevel( QString(
"zLevel %1 -> %2" ).arg( zLevel ).arg( maxNormLevel ), 4 );
872 for (
int i = 0; i < count; i++ )
920 Q_ASSERT( origDescendants.count() == clonedDescendants.count() );
921 for (
int i = 0; i < origDescendants.count(); ++i )
922 clonedDescendants[i]->setRuleKey( origDescendants[i]->ruleKey() );
945 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"RuleRenderer" ) );
946 rendererElem.setAttribute( QStringLiteral(
"symbollevels" ), (
mUsingSymbolLevels ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
947 rendererElem.setAttribute( QStringLiteral(
"forceraster" ), (
mForceRaster ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
952 rulesElem.setTagName( QStringLiteral(
"rules" ) );
953 rendererElem.appendChild( rulesElem );
956 rendererElem.appendChild( symbolsElem );
963 QDomElement
orderBy = doc.createElement( QStringLiteral(
"orderby" ) );
965 rendererElem.appendChild( orderBy );
967 rendererElem.setAttribute( QStringLiteral(
"enableorderby" ), (
mOrderByEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
980 return rule ? rule->
active() :
true;
1008 QDomElement symbolsElem = element.firstChildElement( QStringLiteral(
"symbols" ) );
1009 if ( symbolsElem.isNull() )
1014 QDomElement rulesElem = element.firstChildElement( QStringLiteral(
"rules" ) );
1031 Rule *root =
nullptr;
1033 QDomElement ruleElem = element.firstChildElement( QStringLiteral(
"Rule" ) );
1034 while ( !ruleElem.isNull() )
1041 root =
new Rule(
nullptr );
1046 ruleElem = ruleElem.nextSiblingElement( QStringLiteral(
"Rule" ) );
1067 QgsExpression testExpr( attr );
1068 if ( testExpr.hasParserError() || ( testExpr.isField() && !attr.startsWith(
'\"' ) ) )
1071 attr = QgsExpression::quotedColumnRef( attr );
1078 if ( cat.
value().type() == QVariant::Int )
1079 value = cat.
value().toString();
1080 else if ( cat.
value().type() == QVariant::Double )
1083 value = QString::number( cat.
value().toDouble(),
'f', 4 );
1085 value = QgsExpression::quotedString( cat.
value().toString() );
1086 QString
filter = QStringLiteral(
"%1 = %2" ).arg( attr, value );
1097 QgsExpression testExpr( attr );
1098 if ( testExpr.hasParserError() || ( testExpr.isField() && !attr.startsWith(
'\"' ) ) )
1101 attr = QgsExpression::quotedColumnRef( attr );
1103 else if ( !testExpr.isField() )
1106 attr = QStringLiteral(
"(%1)" ).arg( attr );
1109 bool firstRange =
true;
1114 QString
filter = QStringLiteral(
"%1 %2 %3 AND %1 <= %4" ).arg( attr, firstRange ? QStringLiteral(
">=" ) : QStringLiteral(
">" ),
1116 QString::number( rng.
upperValue(),
'f', 4 ) );
1125 std::sort( scales.begin(), scales.end() );
1129 Q_FOREACH (
int scale, scales )
1133 if ( maxDenom != 0 && maxDenom <= scale )
1135 initialRule->
appendChild(
new Rule( symbol->
clone(), oldScale, scale, QString(), QStringLiteral(
"%1 - %2" ).arg( oldScale ).arg( scale ) ) );
1139 initialRule->
appendChild(
new Rule( symbol->
clone(), oldScale, maxDenom, QString(), QStringLiteral(
"%1 - %2" ).arg( oldScale ).arg( maxDenom ) ) );
1144 QString msg( QStringLiteral(
"Rule-based renderer:\n" ) );
1172 if ( renderer->
type() == QLatin1String(
"RuleRenderer" ) )
1176 else if ( renderer->
type() == QLatin1String(
"singleSymbol" ) )
1179 if ( !singleSymbolRenderer )
1185 else if ( renderer->
type() == QLatin1String(
"categorizedSymbol" ) )
1188 if ( !categorizedRenderer )
1194 QgsExpression testExpr( attr );
1195 if ( testExpr.hasParserError() || ( testExpr.isField() && !attr.startsWith(
'\"' ) ) )
1198 attr = QgsExpression::quotedColumnRef( attr );
1206 for (
int i = 0; i < categorizedRenderer->
categories().size(); ++i )
1208 category = categorizedRenderer->
categories().value( i );
1215 if ( QVariant( category.
value() ).convert( QVariant::Double ) )
1217 value = category.
value().toString();
1221 value = QgsExpression::quotedString( category.
value().toString() );
1225 if ( value == QLatin1String(
"''" ) )
1227 expression = QStringLiteral(
"ELSE" );
1231 expression = QStringLiteral(
"%1 = %2" ).arg( attr, value );
1247 else if ( renderer->
type() == QLatin1String(
"graduatedSymbol" ) )
1250 if ( !graduatedRenderer )
1256 QgsExpression testExpr( attr );
1257 if ( testExpr.hasParserError() || ( testExpr.isField() && !attr.startsWith(
'\"' ) ) )
1260 attr = QgsExpression::quotedColumnRef( attr );
1262 else if ( !testExpr.isField() )
1265 attr = QStringLiteral(
"(%1)" ).arg( attr );
1272 for (
int i = 0; i < graduatedRenderer->
ranges().size(); ++i )
1274 range = graduatedRenderer->
ranges().value( i );
1279 expression = attr +
" >= " + QString::number( range.
lowerValue(),
'f' ) +
" AND " + \
1280 attr +
" <= " + QString::number( range.
upperValue(),
'f' );
1284 expression = attr +
" > " + QString::number( range.
lowerValue(),
'f' ) +
" AND " + \
1285 attr +
" <= " + QString::number( range.
upperValue(),
'f' );
1301 else if ( renderer->
type() == QLatin1String(
"pointDisplacement" ) || renderer->
type() == QLatin1String(
"pointCluster" ) )
1304 if ( pointDistanceRenderer )
1307 else if ( renderer->
type() == QLatin1String(
"invertedPolygonRenderer" ) )
1310 if ( invertedPolygonRenderer )
1325 QString sizeExpression;
1326 switch ( symbol->
type() )
1332 if ( ! sizeScaleField.isEmpty() )
1334 sizeExpression = QStringLiteral(
"%1*(%2)" ).arg( msl->
size() ).arg( sizeScaleField );
1337 if ( ! rotationField.isEmpty() )
1344 if ( ! sizeScaleField.isEmpty() )
1351 sizeExpression = QStringLiteral(
"%1*(%2)" ).arg( lsl->
width() ).arg( sizeScaleField );
1360 sizeExpression = QStringLiteral(
"%1*(%2)" ).arg( msl->
size() ).arg( sizeScaleField );
QgsRuleBasedRenderer(QgsRuleBasedRenderer::Rule *root)
Constructs the renderer from given tree of rules (takes ownership)
An abstract base class for distance based point renderers (e.g., clusterer and displacement renderers...
The class is used as a container of context for various read/write operations on other objects...
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Return the attributes used to evaluate the expression of this rule.
double rendererScale() const
Returns the renderer map scale.
QDomElement save(QDomDocument &doc, QgsSymbolMap &symbolMap) const
QSet< QString > legendKeysForFeature(QgsFeature &feature, QgsRenderContext &context) override
Return legend keys matching a specified feature.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
bool filterNeedsGeometry() const override
Returns true if this renderer requires the geometry to apply the filter.
QgsFeatureRequest::OrderBy mOrderBy
QgsRuleBasedRenderer::RuleList descendants() const
Returns all children, grand-children, grand-grand-children, grand-gra...
static bool createFunctionElement(QDomDocument &doc, QDomElement &element, const QString &function)
QgsRuleBasedRenderer::Rule * takeChild(QgsRuleBasedRenderer::Rule *rule)
take child rule out, set parent as null
virtual QgsSymbol * subSymbol()
Returns the symbol's sub symbol, if present.
bool isFilterOK(QgsFeature &f, QgsRenderContext *context=nullptr) const
Check if a given feature shall be rendered by this rule.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Return a list of attributes required by this renderer.
bool isElse()
Check if this rule is an ELSE rule.
QList< QgsRuleBasedRenderer::RenderLevel > RenderQueue
static void applyScaleDependency(QDomDocument &doc, QDomElement &ruleElem, QgsStringMap &props)
Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into t...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
static void convertToDataDefinedSymbology(QgsSymbol *symbol, const QString &sizeScaleField, const QString &rotationField=QString())
helper function to convert the size scale and rotation fields present in some other renderers to data...
This class keeps data about a rules for rule-based renderer.
QString ruleKey() const
Unique rule identifier (for identification of rule within renderer)
QgsSymbol * symbol() const
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
store renderer info to XML element
void setRuleKey(const QString &key)
Override the assigned rule key (should be used just internally by rule-based renderer) ...
QgsFeatureRequest::OrderBy orderBy() const
Get the order in which features shall be processed by this renderer.
QString classAttribute() const
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
static void mergeScaleDependencies(int mScaleMinDenom, int mScaleMaxDenom, QgsStringMap &props)
Merges the local scale limits, if any, with the ones already in the map, if any.
QString classAttribute() const
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
QgsRuleBasedRenderer::FeatureToRender & ftr
Container of fields for a vector layer.
#define RENDERER_TAG_NAME
void setUsingSymbolLevels(bool usingSymbolLevels)
void checkLegendSymbolItem(const QString &key, bool state=true) override
item in symbology was checked
QSet< int > collectZLevels()
get all used z-levels from this rule and children
Rule * mRootRule
the root node with hierarchical list of rules
int symbolLayerCount() const
Returns total number of symbol layers contained in the symbol.
QList< FeatureToRender > mCurrentFeatures
static void clearSymbolMap(QgsSymbolMap &symbols)
double maximumScale() const
Returns the maximum map scale (i.e.
QgsPaintEffect * mPaintEffect
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void setNormZLevels(const QMap< int, int > &zLevelsToNormLevels)
assign normalized z-levels [0..N-1] for this rule's symbol for quick access during rendering ...
QString description() const
A human readable description for this rule.
QMap< QString, QString > QgsStringMap
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
virtual double width() const
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
bool startRender(QgsRenderContext &context, const QgsFields &fields, QString &filter)
prepare the rule for rendering and its children (build active children array)
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
bool active() const
Returns if this rule is active.
QList< QgsRuleBasedRenderer::Rule * > RuleList
QString dump(int indent=0) const
Dump for debug purpose.
double lowerValue() const
int renderingPass() const
QgsRuleBasedRenderer::RuleList rulesForFeature(QgsFeature &feat, QgsRenderContext *context=nullptr)
tell which rules will be used to render the feature
RenderResult
The result of rendering a rule.
QList< QgsSymbol * > QgsSymbolList
bool legendSymbolItemsCheckable() const override
items of symbology items in legend should be checkable
static QgsFeatureRenderer * createFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType)
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted...
#define QgsDebugMsgLevel(str, level)
const QgsCategoryList & categories() const
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new rule-based renderer instance from XML.
static QDomElement saveSymbols(QgsSymbolMap &symbols, const QString &tagName, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a collection of symbols to XML with specified tagName for the top-level element.
double size() const
Returns the symbol size.
QgsSymbolList symbols(const QgsRenderContext &context=QgsRenderContext()) const
void removeChild(QgsRuleBasedRenderer::Rule *rule)
delete child rule
QgsExpression * filter() const
A filter that will check if this rule applies.
bool willRenderFeature(QgsFeature &feat, QgsRenderContext *context=nullptr)
only tell whether a feature will be rendered without actually rendering it
~QgsRuleBasedRenderer() override
QList< QgsSymbolLayer * > QgsSymbolLayerList
When drawing a vector layer with rule-based renderer, it goes through the rules and draws features wi...
QList< QgsRuleBasedRenderer::RenderJob * > jobs
QgsSymbolList symbolsForFeature(QgsFeature &feat, QgsRenderContext *context=nullptr)
tell which symbols will be used to render the feature
QgsSymbol * symbol() const
double minimumScale() const
Returns the minimum map scale (i.e.
void insertChild(int i, QgsRuleBasedRenderer::Rule *rule)
add child rule, take ownership, sets this as parent
bool isScaleOK(double scale) const
Check if this rule applies for a given scale.
static QgsSymbolMap loadSymbols(QDomElement &element, const QgsReadWriteContext &context)
Reads a collection of symbols from XML and returns them in a map. Caller is responsible for deleting ...
QgsSymbolLayer * symbolLayer(int layer)
Returns a specific symbol layers contained in the symbol.
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer...
QgsSymbolList symbolsForFeature(QgsFeature &feat, QgsRenderContext &context) override
Returns list of symbols used for rendering the feature.
void stopRender(QgsRenderContext &context)
Stop a rendering process.
QgsSymbolList symbols(QgsRenderContext &context) override
Returns list of symbols used by the renderer.
void setOrderBy(const QgsFeatureRequest::OrderBy &orderBy)
Define the order in which features shall be processed by this renderer.
QgsRuleBasedRenderer::Rule * takeChildAt(int i)
take child rule out, set parent as null
void setSymbol(QgsSymbol *sym)
set a new symbol (or NULL). Deletes old symbol.
QgsExpressionContext & expressionContext()
Gets the expression context.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
static void refineRuleRanges(QgsRuleBasedRenderer::Rule *initialRule, QgsGraduatedSymbolRenderer *r)
take a rule and create a list of new rules based on the ranges from graduated symbol renderer ...
void setActive(bool state)
Sets if this rule is active.
QgsRuleBasedRenderer::Rule * clone() const
clone this rule, return new instance
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Return a list of attributes required to render this feature.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
Contains information about the context of a rendering operation.
Abstract base class for marker symbol layers.
void setIsElse(bool iselse)
Sets if this rule is an ELSE rule.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
void setLabel(const QString &label)
bool usingSymbolLevels() const
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
virtual QgsSymbol * clone() const =0
Get a deep copy of this symbol.
bool willRenderFeature(QgsFeature &feat, QgsRenderContext &context) override
Returns whether the renderer will render a feature or not.
static QgsRuleBasedRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
creates a QgsRuleBasedRenderer from an existing renderer.
static QgsExpression * expressionFromOgcFilter(const QDomElement &element)
Parse XML with OGC filter into QGIS expression.
void CORE_EXPORT save(QDomElement &elem) const
Serialize to XML.
double upperValue() const
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
QMap< QString, QgsSymbol *> QgsSymbolMap
bool needsGeometry() const
Returns true if this rule or one of its chilren needs the geometry to be applied. ...
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
QgsSymbolList originalSymbolsForFeature(QgsFeature &feat, QgsRenderContext &context) override
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
QgsSymbol * symbolForFeature(QgsFeature &feature, QgsRenderContext &context) override
return symbol for current feature. Should not be used individually: there could be more symbols for a...
bool legendSymbolItemChecked(const QString &key) override
items of symbology items in legend is checked
Rule(QgsSymbol *symbol, int maximumScale=0, int minimumScale=0, const QString &filterExp=QString(), const QString &label=QString(), const QString &description=QString(), bool elseRule=false)
Constructor takes ownership of the symbol.
QgsRuleBasedRenderer * clone() const override
Create a deep copy of this renderer.
QgsLegendSymbolList legendSymbolItems(int currentLevel=-1) const
QgsRuleBasedRenderer::Rule::RenderResult renderFeature(QgsRuleBasedRenderer::FeatureToRender &featToRender, QgsRenderContext &context, QgsRuleBasedRenderer::RenderQueue &renderQueue)
Render a given feature, will recursively call subclasses and only render if the constraints apply...
static void refineRuleCategories(QgsRuleBasedRenderer::Rule *initialRule, QgsCategorizedSymbolRenderer *r)
take a rule and create a list of new rules based on the categories from categorized symbol renderer ...
QString filter(const QgsFields &fields=QgsFields()) override
If a renderer does not require all the features this method may be overridden and return an expressio...
void setFilterExpression(const QString &filterExp)
Set the expression used to check if a given feature shall be rendered with this rule.
bool renderFeature(QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) override
Render a feature using this renderer in the given context.
QSet< QString > legendKeysForFeature(QgsFeature &feat, QgsRenderContext *context=nullptr)
Returns which legend keys match the feature.
static void refineRuleScales(QgsRuleBasedRenderer::Rule *initialRule, QList< int > scales)
take a rule and create a list of new rules with intervals of scales given by the passed scale denomin...
void removeChildAt(int i)
delete child rule
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
void renderFeatureWithSymbol(QgsFeature &feature, QgsSymbol *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker)
static QgsRuleBasedRenderer::Rule * create(QDomElement &ruleElem, QgsSymbolMap &symbolMap)
Create a rule from an XML definition.
QgsRuleBasedRenderer::Rule * findRuleByKey(const QString &key)
Try to find a rule given its unique key.
QSet< int > mSymbolNormZLevels
void stopRender(QgsRenderContext &context)
Ends the rendering process.
const QgsRangeList & ranges() const
static bool createSymbolLayerListFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType, QgsSymbolLayerList &layers)
void setOrderByEnabled(bool enabled)
Sets whether custom ordering should be applied before features are processed by this renderer...
QgsSymbol * symbol() const
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
void appendChild(QgsRuleBasedRenderer::Rule *rule)
add child rule, take ownership, sets this as parent
static QgsRuleBasedRenderer::Rule * createFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType)
Create a rule from the SLD provided in element and for the specified geometry type.
virtual void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the layer.
void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props=QgsStringMap()) const override
used from subclasses to create SLD Rule elements following SLD v1.1 specs
QString dump() const override
Returns debug information about this renderer.
virtual QString layerType() const =0
Returns a string that represents this layer type.
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.