40 #include <QDomDocument> 41 #include <QDomElement> 121 if ( !
mSymbol.get() || props.value( QStringLiteral(
"attribute" ), QString() ).isEmpty() )
124 QString attrName = props[ QStringLiteral(
"attribute" )];
126 QDomElement ruleElem = doc.createElement( QStringLiteral(
"se:Rule" ) );
127 element.appendChild( ruleElem );
129 QDomElement nameElem = doc.createElement( QStringLiteral(
"se:Name" ) );
130 nameElem.appendChild( doc.createTextNode(
mLabel ) );
131 ruleElem.appendChild( nameElem );
133 QDomElement descrElem = doc.createElement( QStringLiteral(
"se:Description" ) );
134 QDomElement titleElem = doc.createElement( QStringLiteral(
"se:Title" ) );
135 QString descrStr = QStringLiteral(
"%1 is '%2'" ).arg( attrName,
mValue.toString() );
136 titleElem.appendChild( doc.createTextNode( !
mLabel.isEmpty() ?
mLabel : descrStr ) );
137 descrElem.appendChild( titleElem );
138 ruleElem.appendChild( descrElem );
144 filterFunc = QStringLiteral(
"%1 = '%2' or %1 is null" )
145 .arg( attrName.replace(
'\"', QLatin1String(
"\"\"" ) ),
146 mValue.toString().replace(
'\'', QLatin1String(
"''" ) ) );
150 filterFunc = QStringLiteral(
"%1 = '%2'" )
151 .arg( attrName.replace(
'\"', QLatin1String(
"\"\"" ) ),
152 mValue.toString().replace(
'\'', QLatin1String(
"''" ) ) );
160 mSymbol->toSld( doc, ruleElem, props );
167 , mAttrName( attrName )
176 QgsDebugMsg( QStringLiteral(
"invalid symbol in a category! ignoring..." ) );
188 const QVariant val = cat.value();
189 if ( val.type() == QVariant::List )
191 const QVariantList list = val.toList();
192 for (
const QVariant &v : list )
194 mSymbolHash.insert( v.toString(), ( cat.renderState() ||
mCounting ) ? cat.symbol() : nullptr );
199 mSymbolHash.insert( val.toString(), ( cat.renderState() ||
mCounting ) ? cat.symbol() : nullptr );
217 foundMatchingSymbol =
false;
220 QHash<QString, QgsSymbol *>::const_iterator it =
mSymbolHash.constFind( value.isNull() ? QString() : value.toString() );
225 QgsDebugMsg( QStringLiteral(
"there are no hashed symbols!!!" ) );
234 foundMatchingSymbol =
true;
264 QVariant value = valueForFeature( feature, context );
266 bool foundCategory =
false;
270 if ( !foundCategory )
308 if ( catIndex < 0 || catIndex >=
mCategories.size() )
316 if ( catIndex < 0 || catIndex >=
mCategories.size() )
324 if ( catIndex < 0 || catIndex >=
mCategories.size() )
332 if ( catIndex < 0 || catIndex >=
mCategories.size() )
342 QgsDebugMsg( QStringLiteral(
"invalid symbol in a category! ignoring..." ) );
351 if ( catIndex < 0 || catIndex >=
mCategories.size() )
380 if ( order == Qt::AscendingOrder )
392 return QString::localeAwareCompare( c1.
label(), c2.
label() ) < 0;
402 if ( order == Qt::AscendingOrder )
431 cat.symbol()->startRender( context, fields );
441 cat.symbol()->stopRender( context );
448 QSet<QString> attributes;
460 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();
487 QString s = QStringLiteral(
"CATEGORIZED: idx %1\n" ).arg(
mAttrName );
512 newProps[ QStringLiteral(
"attribute" )] =
mAttrName;
517 it->toSld( doc, element, newProps );
524 bool isExpression = ( attrNum == -1 );
526 bool hasDefault =
false;
527 bool defaultActive =
false;
528 bool allActive =
true;
529 bool noneActive =
true;
533 QString activeValues;
534 QString inactiveValues;
538 if ( cat.value() ==
"" || cat.value().isNull() )
541 defaultActive = cat.renderState();
544 noneActive = noneActive && !cat.renderState();
545 allActive = allActive && cat.renderState();
547 QVariant::Type valType = isExpression ? cat.value().type() : fields.
at( attrNum ).
type();
548 const bool isList = cat.value().type() == QVariant::List;
551 if ( !cat.renderState() )
553 if ( cat.value() !=
"" )
557 const QVariantList list = cat.value().toList();
558 for (
const QVariant &v : list )
560 if ( !inactiveValues.isEmpty() )
561 inactiveValues.append(
',' );
568 if ( !inactiveValues.isEmpty() )
569 inactiveValues.append(
',' );
571 inactiveValues.append( value );
577 if ( cat.value() !=
"" )
581 const QVariantList list = cat.value().toList();
582 for (
const QVariant &v : list )
584 if ( !activeValues.isEmpty() )
585 activeValues.append(
',' );
592 if ( !activeValues.isEmpty() )
593 activeValues.append(
',' );
595 activeValues.append( value );
601 QString attr = isExpression ?
mAttrName : QStringLiteral(
"\"%1\"" ).arg(
mAttrName );
603 if ( allActive && hasDefault )
607 else if ( noneActive )
609 return QStringLiteral(
"FALSE" );
611 else if ( defaultActive )
613 return QStringLiteral(
"(%1) NOT IN (%2) OR (%1) IS NULL" ).arg( attr, inactiveValues );
617 return QStringLiteral(
"(%1) IN (%2)" ).arg( attr, activeValues );
628 lst.append( cat.symbol() );
654 QDomElement symbolsElem = element.firstChildElement( QStringLiteral(
"symbols" ) );
655 if ( symbolsElem.isNull() )
658 QDomElement catsElem = element.firstChildElement( QStringLiteral(
"categories" ) );
659 if ( catsElem.isNull() )
665 QDomElement catElem = catsElem.firstChildElement();
666 while ( !catElem.isNull() )
668 if ( catElem.tagName() == QLatin1String(
"category" ) )
671 if ( catElem.hasAttribute( QStringLiteral(
"value" ) ) )
673 value = QVariant( catElem.attribute( QStringLiteral(
"value" ) ) );
678 QDomElement valElem = catElem.firstChildElement();
679 while ( !valElem.isNull() )
681 if ( valElem.tagName() == QLatin1String(
"val" ) )
683 values << QVariant( valElem.attribute( QStringLiteral(
"value" ) ) );
685 valElem = valElem.nextSiblingElement();
687 if ( !values.isEmpty() )
690 QString symbolName = catElem.attribute( QStringLiteral(
"symbol" ) );
691 QString label = catElem.attribute( QStringLiteral(
"label" ) );
692 bool render = catElem.attribute( QStringLiteral(
"render" ) ) != QLatin1String(
"false" );
693 if ( symbolMap.contains( symbolName ) )
695 QgsSymbol *symbol = symbolMap.take( symbolName );
699 catElem = catElem.nextSiblingElement();
702 QString attrName = element.attribute( QStringLiteral(
"attr" ) );
710 QDomElement sourceSymbolElem = element.firstChildElement( QStringLiteral(
"source-symbol" ) );
711 if ( !sourceSymbolElem.isNull() )
714 if ( sourceSymbolMap.contains( QStringLiteral(
"0" ) ) )
722 QDomElement sourceColorRampElem = element.firstChildElement( QStringLiteral(
"colorramp" ) );
723 if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( QStringLiteral(
"name" ) ) == QLatin1String(
"[source]" ) )
728 QDomElement rotationElem = element.firstChildElement( QStringLiteral(
"rotation" ) );
729 if ( !rotationElem.isNull() && !rotationElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
741 QDomElement sizeScaleElem = element.firstChildElement( QStringLiteral(
"sizescale" ) );
742 if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
748 sizeScaleElem.attribute( QStringLiteral(
"field" ) ) );
754 sizeScaleElem.attribute( QStringLiteral(
"field" ) ) );
758 QDomElement ddsLegendSizeElem = element.firstChildElement( QStringLiteral(
"data-defined-size-legend" ) );
759 if ( !ddsLegendSizeElem.isNull() )
772 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"categorizedSymbol" ) );
773 rendererElem.setAttribute( QStringLiteral(
"symbollevels" ), (
mUsingSymbolLevels ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
774 rendererElem.setAttribute( QStringLiteral(
"forceraster" ), (
mForceRaster ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
775 rendererElem.setAttribute( QStringLiteral(
"attr" ),
mAttrName );
782 QDomElement catsElem = doc.createElement( QStringLiteral(
"categories" ) );
783 QgsCategoryList::const_iterator it =
mCategories.constBegin();
787 QString symbolName = QString::number( i );
788 symbols.insert( symbolName, cat.
symbol() );
790 QDomElement catElem = doc.createElement( QStringLiteral(
"category" ) );
791 if ( cat.
value().type() == QVariant::List )
793 const QVariantList list = cat.
value().toList();
794 for (
const QVariant &v : list )
796 QDomElement valueElem = doc.createElement( QStringLiteral(
"val" ) );
797 valueElem.setAttribute(
"value", v.toString() );
798 catElem.appendChild( valueElem );
803 catElem.setAttribute( QStringLiteral(
"value" ), cat.
value().toString() );
805 catElem.setAttribute( QStringLiteral(
"symbol" ), symbolName );
806 catElem.setAttribute( QStringLiteral(
"label" ), cat.
label() );
807 catElem.setAttribute( QStringLiteral(
"render" ), cat.
renderState() ?
"true" :
"false" );
808 catsElem.appendChild( catElem );
811 rendererElem.appendChild( catsElem );
815 rendererElem.appendChild( symbolsElem );
823 sourceSymbols.insert( QStringLiteral(
"0" ),
mSourceSymbol.get() );
825 rendererElem.appendChild( sourceSymbolElem );
832 rendererElem.appendChild( colorRampElem );
835 QDomElement rotationElem = doc.createElement( QStringLiteral(
"rotation" ) );
836 rendererElem.appendChild( rotationElem );
838 QDomElement sizeScaleElem = doc.createElement( QStringLiteral(
"sizescale" ) );
839 rendererElem.appendChild( sizeScaleElem );
846 QDomElement
orderBy = doc.createElement( QStringLiteral(
"orderby" ) );
848 rendererElem.appendChild( orderBy );
850 rendererElem.setAttribute( QStringLiteral(
"enableorderby" ), (
mOrderByEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
854 QDomElement ddsLegendElem = doc.createElement( QStringLiteral(
"data-defined-size-legend" ) );
856 rendererElem.appendChild( ddsLegendElem );
886 if ( sSize != ddSize )
889 return baseLegendSymbolItems();
906 lst += baseLegendSymbolItems();
911 return baseLegendSymbolItems();
916 QString value = valueForFeature( feature, context ).toString();
922 if ( cat.value().type() == QVariant::List )
924 const QVariantList list = cat.value().toList();
925 for (
const QVariant &v : list )
936 match = value == cat.value();
942 return QSet< QString >() << QString::number( i );
944 return QSet< QString >();
949 return QSet< QString >();
998 double value = count / num;
1010 symbol->
setColor( cat.symbol()->color() );
1025 int index = key.toInt( &ok );
1026 if ( ok && index >= 0 && index <
mCategories.size() )
1035 int index = key.toInt( &ok );
1045 int index = key.toInt( &ok );
1052 std::unique_ptr< QgsCategorizedSymbolRenderer > r;
1053 if ( renderer->
type() == QLatin1String(
"categorizedSymbol" ) )
1055 r.reset( static_cast<QgsCategorizedSymbolRenderer *>( renderer->
clone() ) );
1057 else if ( renderer->
type() == QLatin1String(
"graduatedSymbol" ) )
1060 if ( graduatedSymbolRenderer )
1069 r->setClassAttribute( graduatedSymbolRenderer->
classAttribute() );
1072 else if ( renderer->
type() == QLatin1String(
"pointDisplacement" ) || renderer->
type() == QLatin1String(
"pointCluster" ) )
1075 if ( pointDistanceRenderer )
1078 else if ( renderer->
type() == QLatin1String(
"invertedPolygonRenderer" ) )
1081 if ( invertedPolygonRenderer )
1090 r = qgis::make_unique< QgsCategorizedSymbolRenderer >( QString(),
QgsCategoryList() );
1093 if ( !symbols.isEmpty() )
1095 r->setSourceSymbol( symbols.at( 0 )->clone() );
1099 r->setOrderBy( renderer->
orderBy() );
1122 const QSet< QString > allSymbolNames = unmatchedSymbols.toSet();
1124 const QRegularExpression tolerantMatchRe( QStringLiteral(
"[^\\w\\d ]" ), QRegularExpression::UseUnicodePropertiesOption );
1126 for (
int catIdx = 0; catIdx <
mCategories.count(); ++catIdx )
1128 const QVariant value =
mCategories.at( catIdx ).value();
1129 const QString val = value.toString().trimmed();
1130 std::unique_ptr< QgsSymbol > symbol( style->
symbol( val ) );
1132 if ( symbol && symbol->type() ==
type )
1135 unmatchedSymbols.removeAll( val );
1140 if ( !caseSensitive || useTolerantMatch )
1142 QString testVal = val;
1143 if ( useTolerantMatch )
1144 testVal.replace( tolerantMatchRe, QString() );
1146 bool foundMatch =
false;
1147 for (
const QString &name : allSymbolNames )
1149 QString testName = name.trimmed();
1150 if ( useTolerantMatch )
1151 testName.replace( tolerantMatchRe, QString() );
1153 if ( testName == testVal || ( !caseSensitive && testName.trimmed().compare( testVal, Qt::CaseInsensitive ) == 0 ) )
1156 std::unique_ptr< QgsSymbol > symbol( style->
symbol( name ) );
1157 if ( symbol && symbol->type() ==
type )
1160 unmatchedSymbols.removeAll( name );
1171 unmatchedCategories << value;
1180 QVariantList vals = values;
1184 if ( layer && !attributeName.isNull() )
1187 for (
const QVariant &value : vals )
1190 if ( !value.isNull() )
1192 int fieldIdx = fields.
lookupField( attributeName );
1193 QString categoryName = value.toString();
1194 if ( fieldIdx != -1 )
1196 const QgsField field = fields.
at( fieldIdx );
1199 categoryName = formatter->
representValue( layer, fieldIdx, setup.
config(), QVariant(), value );
An abstract base class for distance based point renderers (e.g., clusterer and displacement renderers...
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QString label() const
Returns the label for this category, which is used to represent the category within legends and the l...
Q_DECL_DEPRECATED QgsSymbol * skipRender()
Class for parsing and evaluation of expressions (formerly called "search strings").
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
The class is used as a container of context for various read/write operations on other objects...
double rendererScale() const
Returns the renderer map scale.
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
A symbol entity for QgsStyle databases.
static QgsSymbol::ScaleMethod decodeScaleMethod(const QString &str)
static QgsFieldFormatterRegistry * fieldFormatterRegistry()
Gets the registry of available field formatters.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QgsFeatureRequest::OrderBy mOrderBy
Represents an individual category (class) from a QgsCategorizedSymbolRenderer.
void updateColorRamp(QgsColorRamp *ramp)
Update the color ramp used and all symbols colors.
static bool createFunctionElement(QDomDocument &doc, QDomElement &element, const QString &function)
Abstract base class for all rendered symbols.
bool updateCategoryRenderState(int catIndex, bool render)
Changes the render state for the category with the specified index.
static void applyScaleDependency(QDomDocument &doc, QDomElement &ruleElem, QgsStringMap &props)
Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into t...
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a categorized renderer from an XML element.
QgsSymbol * symbol() const
Returns the symbol which will be used to render this category.
bool filterNeedsGeometry() const override
Returns true if this renderer requires the geometry to apply the filter.
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
QgsCategorizedSymbolRenderer(const QString &attrName=QString(), const QgsCategoryList &categories=QgsCategoryList())
Constructor for QgsCategorizedSymbolRenderer.
QString classAttribute() const
Abstract base class for color ramps.
void moveCategory(int from, int to)
Moves an existing category at index position from to index position to.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
static QDomElement saveColorRamp(const QString &name, QgsColorRamp *ramp, QDomDocument &doc)
Encodes a color ramp's settings to an XML element.
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...
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
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
bool updateCategoryLabel(int catIndex, const QString &label)
Changes the label for the category with the specified index.
static void clearSymbolMap(QgsSymbolMap &symbols)
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
QgsPaintEffect * mPaintEffect
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
An interface for classes which can visit style entity (e.g.
std::unique_ptr< QgsSymbol > mSourceSymbol
int categoryIndexForLabel(const QString &val)
Returns the index of the category with the specified label (or -1 if the label was not found...
QgsLegendSymbolList legendSymbolList() const
Generates legend symbol items according to the configuration.
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.
void swap(QgsRendererCategory &other)
QMap< QString, QString > QgsStringMap
A marker symbol type, for rendering Point and MultiPoint geometries.
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
bool valueGreaterThan(const QgsRendererCategory &c1, const QgsRendererCategory &c2)
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
QList< QgsRendererCategory > QgsCategoryList
SymbolType
Type of the symbol.
QgsCategorizedSymbolRenderer * clone() const override
Create a deep copy of this renderer.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
store renderer info to XML element
static QgsCategoryList createCategories(const QVariantList &values, const QgsSymbol *symbol, QgsVectorLayer *layer=nullptr, const QString &fieldName=QString())
Create categories for a list of values.
QgsDataDefinedSizeLegend * dataDefinedSizeLegend() const
Returns configuration of appearance of legend when using data-defined size for marker symbols...
QList< QgsSymbol * > QgsSymbolList
QgsFields fields() const FINAL
Returns the list of fields of this layer.
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
Converts the category to a matching SLD rule, within the specified DOM document and element...
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted...
#define QgsDebugMsgLevel(str, level)
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.
bool labelGreaterThan(const QgsRendererCategory &c1, const QgsRendererCategory &c2)
std::unique_ptr< QgsSymbol > mSymbol
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsCategoryList mCategories
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
QgsColorRamp * sourceColorRamp()
Returns the source color ramp, from which each classes' color is derived.
void sortByLabel(Qt::SortOrder order=Qt::AscendingOrder)
Sorts the existing categories by their label.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
void updateFromSymbolAndProperty(const QgsMarkerSymbol *symbol, const QgsProperty &ddSize)
Updates the list of classes, source symbol and title label from given symbol and property.
static QgsColorRamp * loadColorRamp(QDomElement &element)
Creates a color ramp from the settings encoded in an XML element.
static void convertSymbolSizeScale(QgsSymbol *symbol, QgsSymbol::ScaleMethod method, const QString &field)
bool legendSymbolItemChecked(const QString &key) override
items of symbology items in legend is checked
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
Encapsulate a field in an attribute table or data source.
QgsSymbol * sourceSymbol()
Returns the renderer's source symbol, which is the base symbol used for the each categories' symbol b...
A store for object properties.
void deleteAllCategories()
Deletes all existing categories from the renderer.
virtual void setTotalColorCount(int colorCount)
Sets the desired total number of unique colors for the resultant ramp.
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 ...
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer...
bool renderState() const
Returns true if the category is currently enabled and should be rendered.
void setSymbol(QgsSymbol *s)
Sets the symbol which will be used to render this category.
bool labelLessThan(const QgsRendererCategory &c1, const QgsRendererCategory &c2)
void setRenderState(bool render)
Sets whether the category is currently enabled and should be rendered.
Totally random color ramp.
QVariant value() const
Returns the value corresponding to this category.
int matchToSymbols(QgsStyle *style, QgsSymbol::SymbolType type, QVariantList &unmatchedCategories, QStringList &unmatchedSymbols, bool caseSensitive=true, bool useTolerantMatch=false)
Replaces category symbols with the symbols from a style that have a matching name and symbol type...
Q_DECL_DEPRECATED QgsSymbol * symbolForValue(const QVariant &value) const
Returns the matching symbol corresponding to an attribute value.
QString dump() const override
Returns debug information about this renderer.
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
void setDataDefinedSizeLegend(QgsDataDefinedSizeLegend *settings)
Configures appearance of legend when renderer is configured to use data-defined size for marker symbo...
bool legendSymbolItemsCheckable() const override
items of symbology items in legend should be checkable
static void sortVariantList(QList< QVariant > &list, Qt::SortOrder order)
Sorts the passed list in requested order.
static void convertSymbolRotation(QgsSymbol *symbol, const QString &field)
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns a list of attributes required to render this feature.
void addCategory(const QgsRendererCategory &category)
Adds a new category to the renderer.
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.
void setSourceColorRamp(QgsColorRamp *ramp)
Sets the source color ramp.
bool usingSymbolLevels() const
QgsColorRamp * sourceColorRamp()
Returns the source color ramp, from which each categories' color is derived.
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
QgsRendererCategory & operator=(QgsRendererCategory cat)
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
std::unique_ptr< QgsColorRamp > mSourceColorRamp
void CORE_EXPORT save(QDomElement &elem) const
Serialize to XML.
int categoryIndexForValue(const QVariant &val)
Returns the index for the category with the specified value (or -1 if not found). ...
bool updateCategoryValue(int catIndex, const QVariant &value)
Changes the value for the category with the specified index.
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 updateCategorySymbol(int catIndex, QgsSymbol *symbol)
Changes the symbol for the category with the specified index.
bool valueLessThan(const QgsRendererCategory &c1, const QgsRendererCategory &c2)
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
static QgsCategorizedSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
creates a QgsCategorizedSymbolRenderer from an existing renderer.
QHash< QString, QgsSymbol * > mSymbolHash
hashtable for faster access to symbols
void appendScopes(const QList< QgsExpressionContextScope *> &scopes)
Appends a list of scopes to the end of the context.
void sortByValue(Qt::SortOrder order=Qt::AscendingOrder)
Sorts the existing categories by their value.
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
A color ramp entity for QgsStyle databases.
void updateSymbols(QgsSymbol *sym)
Update all the symbols but leave categories and colors.
QString dump() const
Returns a string representing the categories settings, used for debugging purposes only...
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required...
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
QgsRendererCategory()=default
Constructor for QgsRendererCategory.
Represents a vector layer which manages a vector based data sets.
Object that keeps configuration of appearance of marker symbol's data-defined size in legend...
std::unique_ptr< QgsExpression > mExpression
int mAttrNum
attribute index (derived from attribute name in startRender)
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
void setSourceSymbol(QgsSymbol *sym)
Sets the source symbol for the renderer, which is the base symbol used for the each categories' symbo...
void setLabel(const QString &label)
Sets the label for this category, which is used to represent the category within legends and the laye...
static QgsDataDefinedSizeLegend * readXml(const QDomElement &elem, const QgsReadWriteContext &context) SIP_FACTORY
Creates instance from given element and returns it (caller takes ownership). Returns nullptr on error...
bool deleteCategory(int catIndex)
Deletes the category with the specified index from the renderer.
Contains information relating to the style entity currently being visited.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
QgsSymbol * sourceSymbol()
Returns the renderer's source symbol, which is the base symbol used for the each classes' symbol befo...
void setSourceSymbol(QgsSymbol *sym)
Sets the source symbol for the renderer, which is the base symbol used for the each classes' symbol b...
void setValue(const QVariant &value)
Sets the value corresponding to this category.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
bool isActive() const
Returns whether the property is currently active.
std::unique_ptr< QgsDataDefinedSizeLegend > mDataDefinedSizeLegend
void setColor(const QColor &color)
Sets the color for the symbol.
QStringList symbolNames() const
Returns a list of names of symbols.
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.