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();
190 if ( val.type() == QVariant::List )
192 const QVariantList list = val.toList();
193 for (
const QVariant &v : list )
195 mSymbolHash.insert( v.toString(), ( cat.renderState() ||
mCounting ) ? cat.symbol() : nullptr );
200 mSymbolHash.insert( val.toString(), ( cat.renderState() ||
mCounting ) ? cat.symbol() : nullptr );
218 foundMatchingSymbol =
false;
221 QHash<QString, QgsSymbol *>::const_iterator it =
mSymbolHash.constFind( value.isNull() ? QString() : value.toString() );
226 QgsDebugMsg( QStringLiteral(
"there are no hashed symbols!!!" ) );
235 foundMatchingSymbol =
true;
265 QVariant value = valueForFeature( feature, context );
267 bool foundCategory =
false;
271 if ( !foundCategory )
309 if ( catIndex < 0 || catIndex >=
mCategories.size() )
317 if ( catIndex < 0 || catIndex >=
mCategories.size() )
325 if ( catIndex < 0 || catIndex >=
mCategories.size() )
333 if ( catIndex < 0 || catIndex >=
mCategories.size() )
343 QgsDebugMsg( QStringLiteral(
"invalid symbol in a category! ignoring..." ) );
352 if ( catIndex < 0 || catIndex >=
mCategories.size() )
381 if ( order == Qt::AscendingOrder )
393 return QString::localeAwareCompare( c1.
label(), c2.
label() ) < 0;
403 if ( order == Qt::AscendingOrder )
432 cat.symbol()->startRender( context, fields );
442 cat.symbol()->stopRender( context );
449 QSet<QString> attributes;
461 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();
488 QString s = QStringLiteral(
"CATEGORIZED: idx %1\n" ).arg(
mAttrName );
513 newProps[ QStringLiteral(
"attribute" )] =
mAttrName;
518 it->toSld( doc, element, newProps );
525 bool isExpression = ( attrNum == -1 );
527 bool hasDefault =
false;
528 bool defaultActive =
false;
529 bool allActive =
true;
530 bool noneActive =
true;
534 QString activeValues;
535 QString inactiveValues;
539 if ( cat.value() ==
"" || cat.value().isNull() )
542 defaultActive = cat.renderState();
545 noneActive = noneActive && !cat.renderState();
546 allActive = allActive && cat.renderState();
548 QVariant::Type valType = isExpression ? cat.value().type() : fields.
at( attrNum ).
type();
549 const bool isList = cat.value().type() == QVariant::List;
552 if ( !cat.renderState() )
554 if ( cat.value() !=
"" )
558 const QVariantList list = cat.value().toList();
559 for (
const QVariant &v : list )
561 if ( !inactiveValues.isEmpty() )
562 inactiveValues.append(
',' );
569 if ( !inactiveValues.isEmpty() )
570 inactiveValues.append(
',' );
572 inactiveValues.append( value );
578 if ( cat.value() !=
"" )
582 const QVariantList list = cat.value().toList();
583 for (
const QVariant &v : list )
585 if ( !activeValues.isEmpty() )
586 activeValues.append(
',' );
593 if ( !activeValues.isEmpty() )
594 activeValues.append(
',' );
596 activeValues.append( value );
602 QString attr = isExpression ?
mAttrName : QStringLiteral(
"\"%1\"" ).arg(
mAttrName );
604 if ( allActive && hasDefault )
608 else if ( noneActive )
610 return QStringLiteral(
"FALSE" );
612 else if ( defaultActive )
614 return QStringLiteral(
"(%1) NOT IN (%2) OR (%1) IS NULL" ).arg( attr, inactiveValues );
618 return QStringLiteral(
"(%1) IN (%2)" ).arg( attr, activeValues );
629 lst.append( cat.symbol() );
655 QDomElement symbolsElem = element.firstChildElement( QStringLiteral(
"symbols" ) );
656 if ( symbolsElem.isNull() )
659 QDomElement catsElem = element.firstChildElement( QStringLiteral(
"categories" ) );
660 if ( catsElem.isNull() )
666 QDomElement catElem = catsElem.firstChildElement();
667 while ( !catElem.isNull() )
669 if ( catElem.tagName() == QLatin1String(
"category" ) )
672 if ( catElem.hasAttribute( QStringLiteral(
"value" ) ) )
674 value = QVariant( catElem.attribute( QStringLiteral(
"value" ) ) );
679 QDomElement valElem = catElem.firstChildElement();
680 while ( !valElem.isNull() )
682 if ( valElem.tagName() == QLatin1String(
"val" ) )
684 values << QVariant( valElem.attribute( QStringLiteral(
"value" ) ) );
686 valElem = valElem.nextSiblingElement();
688 if ( !values.isEmpty() )
691 QString symbolName = catElem.attribute( QStringLiteral(
"symbol" ) );
692 QString label = catElem.attribute( QStringLiteral(
"label" ) );
693 bool render = catElem.attribute( QStringLiteral(
"render" ) ) != QLatin1String(
"false" );
694 if ( symbolMap.contains( symbolName ) )
696 QgsSymbol *symbol = symbolMap.take( symbolName );
700 catElem = catElem.nextSiblingElement();
703 QString attrName = element.attribute( QStringLiteral(
"attr" ) );
711 QDomElement sourceSymbolElem = element.firstChildElement( QStringLiteral(
"source-symbol" ) );
712 if ( !sourceSymbolElem.isNull() )
715 if ( sourceSymbolMap.contains( QStringLiteral(
"0" ) ) )
723 QDomElement sourceColorRampElem = element.firstChildElement( QStringLiteral(
"colorramp" ) );
724 if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( QStringLiteral(
"name" ) ) == QLatin1String(
"[source]" ) )
729 QDomElement rotationElem = element.firstChildElement( QStringLiteral(
"rotation" ) );
730 if ( !rotationElem.isNull() && !rotationElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
742 QDomElement sizeScaleElem = element.firstChildElement( QStringLiteral(
"sizescale" ) );
743 if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
749 sizeScaleElem.attribute( QStringLiteral(
"field" ) ) );
755 sizeScaleElem.attribute( QStringLiteral(
"field" ) ) );
759 QDomElement ddsLegendSizeElem = element.firstChildElement( QStringLiteral(
"data-defined-size-legend" ) );
760 if ( !ddsLegendSizeElem.isNull() )
773 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"categorizedSymbol" ) );
774 rendererElem.setAttribute( QStringLiteral(
"symbollevels" ), (
mUsingSymbolLevels ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
775 rendererElem.setAttribute( QStringLiteral(
"forceraster" ), (
mForceRaster ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
776 rendererElem.setAttribute( QStringLiteral(
"attr" ),
mAttrName );
783 QDomElement catsElem = doc.createElement( QStringLiteral(
"categories" ) );
784 QgsCategoryList::const_iterator it =
mCategories.constBegin();
788 QString symbolName = QString::number( i );
789 symbols.insert( symbolName, cat.
symbol() );
791 QDomElement catElem = doc.createElement( QStringLiteral(
"category" ) );
792 if ( cat.
value().type() == QVariant::List )
794 const QVariantList list = cat.
value().toList();
795 for (
const QVariant &v : list )
797 QDomElement valueElem = doc.createElement( QStringLiteral(
"val" ) );
798 valueElem.setAttribute(
"value", v.toString() );
799 catElem.appendChild( valueElem );
804 catElem.setAttribute( QStringLiteral(
"value" ), cat.
value().toString() );
806 catElem.setAttribute( QStringLiteral(
"symbol" ), symbolName );
807 catElem.setAttribute( QStringLiteral(
"label" ), cat.
label() );
808 catElem.setAttribute( QStringLiteral(
"render" ), cat.
renderState() ?
"true" :
"false" );
809 catsElem.appendChild( catElem );
812 rendererElem.appendChild( catsElem );
816 rendererElem.appendChild( symbolsElem );
824 sourceSymbols.insert( QStringLiteral(
"0" ),
mSourceSymbol.get() );
826 rendererElem.appendChild( sourceSymbolElem );
833 rendererElem.appendChild( colorRampElem );
836 QDomElement rotationElem = doc.createElement( QStringLiteral(
"rotation" ) );
837 rendererElem.appendChild( rotationElem );
839 QDomElement sizeScaleElem = doc.createElement( QStringLiteral(
"sizescale" ) );
840 rendererElem.appendChild( sizeScaleElem );
847 QDomElement
orderBy = doc.createElement( QStringLiteral(
"orderby" ) );
849 rendererElem.appendChild( orderBy );
851 rendererElem.setAttribute( QStringLiteral(
"enableorderby" ), (
mOrderByEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
855 QDomElement ddsLegendElem = doc.createElement( QStringLiteral(
"data-defined-size-legend" ) );
857 rendererElem.appendChild( ddsLegendElem );
887 if ( sSize != ddSize )
890 return baseLegendSymbolItems();
907 lst += baseLegendSymbolItems();
912 return baseLegendSymbolItems();
917 QString value = valueForFeature( feature, context ).toString();
923 if ( cat.value().type() == QVariant::List )
925 const QVariantList list = cat.value().toList();
926 for (
const QVariant &v : list )
937 match = value == cat.value();
943 return QSet< QString >() << QString::number( i );
945 return QSet< QString >();
950 return QSet< QString >();
999 double value = count / num;
1011 symbol->
setColor( cat.symbol()->color() );
1026 int index = key.toInt( &ok );
1027 if ( ok && index >= 0 && index <
mCategories.size() )
1036 int index = key.toInt( &ok );
1046 int index = key.toInt( &ok );
1053 std::unique_ptr< QgsCategorizedSymbolRenderer > r;
1054 if ( renderer->
type() == QLatin1String(
"categorizedSymbol" ) )
1056 r.reset( static_cast<QgsCategorizedSymbolRenderer *>( renderer->
clone() ) );
1058 else if ( renderer->
type() == QLatin1String(
"graduatedSymbol" ) )
1061 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.