47#include <QDomDocument>
49#include <QRegularExpression>
54using namespace Qt::StringLiterals;
62 mUuid = !
uuid.isEmpty() ?
uuid : QUuid::createUuid().toString();
141 if ( !
mSymbol.get() || props.value( u
"attribute"_s, QString() ).toString().isEmpty() )
144 QString attrName = props[u
"attribute"_s].toString();
148 toSld( doc, element, attrName, context );
153 if ( !
mSymbol.get() || classAttribute.isEmpty() )
156 QString attrName = classAttribute;
167 else if ( attrExpression.
isField() )
172 QDomElement ruleElem = doc.createElement( u
"se:Rule"_s );
174 QDomElement nameElem = doc.createElement( u
"se:Name"_s );
175 nameElem.appendChild( doc.createTextNode(
mLabel ) );
176 ruleElem.appendChild( nameElem );
178 QDomElement descrElem = doc.createElement( u
"se:Description"_s );
179 QDomElement titleElem = doc.createElement( u
"se:Title"_s );
180 QString descrStr = u
"%1 is '%2'"_s.arg( attrName,
mValue.toString() );
181 titleElem.appendChild( doc.createTextNode( !
mLabel.isEmpty() ?
mLabel : descrStr ) );
182 descrElem.appendChild( titleElem );
183 ruleElem.appendChild( descrElem );
187 if (
mValue.userType() == QMetaType::Type::QVariantList )
189 const QVariantList list =
mValue.toList();
190 if ( list.size() == 1 )
196 QStringList valuesList;
197 valuesList.reserve( list.size() );
198 for (
const QVariant &v : list )
202 filterFunc = u
"%1 IN (%2)"_s.arg( attrName, valuesList.join(
',' ) );
207 filterFunc = u
"ELSE"_s;
218 QVariantMap props = oldProps;
221 mSymbol->toSld( doc, ruleElem, context );
230 element.appendChild( ruleElem );
247 QgsDebugError( u
"invalid symbol in a category! ignoring..."_s );
256 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();
259 if (
QgsSymbol *catSymbol = catIt->symbol() )
277 const QVariant val = cat.value();
278 if ( val.userType() == QMetaType::Type::QVariantList )
280 const QVariantList list = val.toList();
281 for (
const QVariant &v : list )
283 mSymbolHash.insert( v.toString(), ( cat.renderState() ||
mCounting ) ? cat.symbol() :
nullptr );
288 mSymbolHash.insert( val.toString(), ( cat.renderState() ||
mCounting ) ? cat.symbol() :
nullptr );
306 foundMatchingSymbol =
false;
323 foundMatchingSymbol =
true;
353 QVariant value = valueForFeature( feature, context );
355 bool foundCategory =
false;
359 if ( !foundCategory )
397 if ( catIndex < 0 || catIndex >=
mCategories.size() )
405 if ( catIndex < 0 || catIndex >=
mCategories.size() )
413 if ( catIndex < 0 || catIndex >=
mCategories.size() )
421 if ( catIndex < 0 || catIndex >=
mCategories.size() )
431 QgsDebugError( u
"invalid symbol in a category! ignoring..."_s );
440 if ( catIndex < 0 || catIndex >=
mCategories.size() )
470 if ( order == Qt::AscendingOrder )
482 return QString::localeAwareCompare( c1.
label(), c2.
label() ) < 0;
487 return QString::localeAwareCompare( c1.
label(), c2.
label() ) > 0;
492 if ( order == Qt::AscendingOrder )
523 cat.symbol()->startRender( context, fields );
533 cat.symbol()->stopRender( context );
540 QSet<QString> attributes;
552 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();
579 QString s = u
"CATEGORIZED: idx %1\n"_s.arg(
mAttrName );
604 toSld( doc, element, context );
610 QVariantMap newProps = oldProps;
618 if ( !it->toSld( doc, element,
mAttrName, context ) )
628 bool isExpression = ( attrNum == -1 );
630 bool hasDefault =
false;
631 bool defaultActive =
false;
632 bool allActive =
true;
633 bool noneActive =
true;
637 QString activeValues;
638 QString inactiveValues;
645 defaultActive = cat.renderState();
648 noneActive = noneActive && !cat.renderState();
649 allActive = allActive && cat.renderState();
651 const bool isList = cat.value().userType() == QMetaType::Type::QVariantList;
654 if ( !cat.renderState() )
660 const QVariantList list = cat.value().toList();
661 for (
const QVariant &v : list )
663 if ( !inactiveValues.isEmpty() )
664 inactiveValues.append(
',' );
671 if ( !inactiveValues.isEmpty() )
672 inactiveValues.append(
',' );
674 inactiveValues.append( value );
684 const QVariantList list = cat.value().toList();
685 for (
const QVariant &v : list )
687 if ( !activeValues.isEmpty() )
688 activeValues.append(
',' );
695 if ( !activeValues.isEmpty() )
696 activeValues.append(
',' );
698 activeValues.append( value );
706 if ( allActive && hasDefault )
710 else if ( noneActive )
714 else if ( defaultActive )
716 return u
"(%1) NOT IN (%2) OR (%1) IS NULL"_s.arg( attr, inactiveValues );
720 return u
"(%1) IN (%2)"_s.arg( attr, activeValues );
731 lst.append( cat.symbol() );
757 QDomElement symbolsElem = element.firstChildElement( u
"symbols"_s );
758 if ( symbolsElem.isNull() )
761 QDomElement catsElem = element.firstChildElement( u
"categories"_s );
762 if ( catsElem.isNull() )
769 const auto valueFromString = [](
const QString &value,
const QString &valueType ) -> QVariant {
770 if ( valueType ==
"double"_L1 )
773 const auto val { value.toDouble( &ok ) };
779 else if ( valueType ==
"ulong"_L1 )
782 const auto val { value.toULongLong( &ok ) };
788 else if ( valueType ==
"long"_L1 )
791 const auto val { value.toLongLong( &ok ) };
797 else if ( valueType ==
"bool"_L1 )
799 if ( value.toLower() ==
"false"_L1 )
801 if ( value.toLower() ==
"true"_L1 )
804 else if ( valueType ==
"NULL"_L1 )
812 QDomElement catElem = catsElem.firstChildElement();
814 QSet<QString> usedUuids;
815 while ( !catElem.isNull() )
817 if ( catElem.tagName() ==
"category"_L1 )
820 if ( catElem.hasAttribute( u
"value"_s ) )
822 value = valueFromString( catElem.attribute( u
"value"_s ), catElem.attribute( u
"type"_s, QString() ) );
827 QDomElement valElem = catElem.firstChildElement();
828 while ( !valElem.isNull() )
830 if ( valElem.tagName() ==
"val"_L1 )
832 values << valueFromString( valElem.attribute( u
"value"_s ), valElem.attribute( u
"type"_s, QString() ) );
834 valElem = valElem.nextSiblingElement();
836 if ( !values.isEmpty() )
840 QString symbolName = catElem.attribute( u
"symbol"_s );
842 QgsDebugMsgLevel(
"context" + u
"project:layers:%1:legendsymbollabels"_s.arg( context.
currentLayerId() ) +
" source " + catElem.attribute( u
"label"_s ), 3 );
844 bool render = catElem.attribute( u
"render"_s ) !=
"false"_L1;
845 QString uuid = catElem.attribute( u
"uuid"_s, QString::number( i++ ) );
847 while ( usedUuids.contains( uuid ) )
849 uuid = QUuid::createUuid().toString();
851 if ( symbolMap.contains( symbolName ) )
853 QgsSymbol *symbol = symbolMap.take( symbolName );
858 catElem = catElem.nextSiblingElement();
861 QString attrName = element.attribute( u
"attr"_s );
869 QDomElement sourceSymbolElem = element.firstChildElement( u
"source-symbol"_s );
870 if ( !sourceSymbolElem.isNull() )
873 if ( sourceSymbolMap.contains( u
"0"_s ) )
881 QDomElement sourceColorRampElem = element.firstChildElement( u
"colorramp"_s );
882 if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( u
"name"_s ) ==
"[source]"_L1 )
887 QDomElement rotationElem = element.firstChildElement( u
"rotation"_s );
888 if ( !rotationElem.isNull() && !rotationElem.attribute( u
"field"_s ).isEmpty() )
900 QDomElement sizeScaleElem = element.firstChildElement( u
"sizescale"_s );
901 if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( u
"field"_s ).isEmpty() )
913 QDomElement ddsLegendSizeElem = element.firstChildElement( u
"data-defined-size-legend"_s );
914 if ( !ddsLegendSizeElem.isNull() )
927 rendererElem.setAttribute( u
"type"_s, u
"categorizedSymbol"_s );
928 rendererElem.setAttribute( u
"attr"_s,
mAttrName );
932 const auto stringForType = [](
const QMetaType::Type
type ) -> QString {
933 if (
type == QMetaType::Type::QChar ||
type == QMetaType::Type::Int ||
type == QMetaType::Type::LongLong )
937 else if (
type == QMetaType::Type::UInt ||
type == QMetaType::Type::ULongLong )
941 else if (
type == QMetaType::Type::Double )
945 else if (
type == QMetaType::Type::Bool )
960 QDomElement catsElem = doc.createElement( u
"categories"_s );
961 QgsCategoryList::const_iterator it =
mCategories.constBegin();
965 QString symbolName = QString::number( i );
968 QDomElement catElem = doc.createElement( u
"category"_s );
969 if ( cat.
value().userType() == QMetaType::Type::QVariantList )
971 const QVariantList list = cat.
value().toList();
972 for (
const QVariant &v : list )
974 QDomElement valueElem = doc.createElement( u
"val"_s );
975 valueElem.setAttribute( u
"value"_s, v.toString() );
976 valueElem.setAttribute( u
"type"_s, stringForType(
static_cast<QMetaType::Type
>( v.userType() ) ) );
977 catElem.appendChild( valueElem );
985 catElem.setAttribute( u
"value"_s,
"NULL" );
986 catElem.setAttribute( u
"type"_s,
"NULL" );
990 catElem.setAttribute( u
"value"_s, cat.
value().toString() );
991 catElem.setAttribute( u
"type"_s, stringForType(
static_cast<QMetaType::Type
>( cat.
value().userType() ) ) );
994 catElem.setAttribute( u
"symbol"_s, symbolName );
995 catElem.setAttribute( u
"label"_s, cat.
label() );
996 catElem.setAttribute( u
"render"_s, cat.
renderState() ?
"true" :
"false" );
997 catElem.setAttribute( u
"uuid"_s, cat.
uuid() );
998 catsElem.appendChild( catElem );
1001 rendererElem.appendChild( catsElem );
1005 rendererElem.appendChild( symbolsElem );
1014 rendererElem.appendChild( sourceSymbolElem );
1021 rendererElem.appendChild( colorRampElem );
1024 QDomElement rotationElem = doc.createElement( u
"rotation"_s );
1025 rendererElem.appendChild( rotationElem );
1027 QDomElement sizeScaleElem = doc.createElement( u
"sizescale"_s );
1028 rendererElem.appendChild( sizeScaleElem );
1032 QDomElement ddsLegendElem = doc.createElement( u
"data-defined-size-legend"_s );
1034 rendererElem.appendChild( ddsLegendElem );
1039 return rendererElem;
1070 if ( sSize != ddSize )
1073 return baseLegendSymbolItems();
1090 lst += baseLegendSymbolItems();
1095 return baseLegendSymbolItems();
1100 const QVariant value = valueForFeature( feature, context );
1103 QString elseRuleUUID;
1111 elseRuleUUID = cat.uuid();
1114 if ( cat.value().userType() == QMetaType::Type::QVariantList )
1116 const QVariantList list = cat.value().toList();
1117 for (
const QVariant &v : list )
1136 match = value == cat.value();
1143 return QSet< QString >() << cat.uuid();
1145 return QSet< QString >();
1150 if ( !elseRuleUUID.isEmpty() )
1152 return QSet< QString >() << elseRuleUUID;
1155 return QSet< QString >();
1178 const bool isNumeric = layer && fieldIndex >= 0 ? layer->
fields().
at( fieldIndex ).
isNumeric() :
false;
1179 const QMetaType::Type fieldType = layer && fieldIndex >= 0 ? layer->
fields().
at( fieldIndex ).
type() : QMetaType::Type::UnknownType;
1184 if ( cat.
value().userType() == QMetaType::Type::QVariantList )
1186 const QVariantList list = cat.
value().toList();
1188 parts.reserve( list.size() );
1189 for (
const QVariant &v : list )
1194 return u
"%1 IN (%2)"_s.arg( attributeComponent, parts.join(
", "_L1 ) );
1199 QVariant value = cat.
value();
1200 if ( isNumeric && value.toString().isEmpty() )
1206 return u
"%1 IS NULL"_s.arg( attributeComponent );
1207 else if ( fieldType == QMetaType::Type::UnknownType )
1260 double value = count / num;
1272 symbol->
setColor( cat.symbol()->color() );
1288 if ( category.uuid() == key )
1290 return category.renderState();
1330 std::unique_ptr< QgsCategorizedSymbolRenderer > r;
1331 if ( renderer->
type() ==
"categorizedSymbol"_L1 )
1335 else if ( renderer->
type() ==
"graduatedSymbol"_L1 )
1338 if ( graduatedSymbolRenderer )
1340 r = std::make_unique<QgsCategorizedSymbolRenderer>( QString(),
QgsCategoryList() );
1347 r->setClassAttribute( graduatedSymbolRenderer->
classAttribute() );
1350 else if ( renderer->
type() ==
"RuleRenderer"_L1 )
1353 if ( ruleBasedSymbolRenderer )
1355 r = std::make_unique<QgsCategorizedSymbolRenderer>( QString(),
QgsCategoryList() );
1357 const QList< QgsRuleBasedRenderer::Rule * > rules =
const_cast< QgsRuleBasedRenderer *
>( ruleBasedSymbolRenderer )->rootRule()->children();
1358 bool canConvert =
true;
1360 bool isFirst =
true;
1367 if ( rule->isElse() || rule->minimumScale() != 0 || rule->maximumScale() != 0 || !rule->symbol() || !rule->children().isEmpty() )
1385 const QString left = binOp->opLeft()->dump();
1386 if ( !isFirst && left != attribute )
1401 cat.
setSymbol( rule->symbol()->clone() );
1402 cat.
setLabel( rule->label().isEmpty() ? literal->
value().toString() : rule->label() );
1428 r = std::make_unique< QgsCategorizedSymbolRenderer >( attribute,
categories );
1436 else if ( renderer->
type() ==
"pointDisplacement"_L1 || renderer->
type() ==
"pointCluster"_L1 )
1439 if ( pointDistanceRenderer )
1442 else if ( renderer->
type() ==
"invertedPolygonRenderer"_L1 )
1445 if ( invertedPolygonRenderer )
1448 else if ( renderer->
type() ==
"embeddedSymbol"_L1 && layer )
1463 r = std::make_unique<QgsCategorizedSymbolRenderer>( u
"$id"_s,
categories );
1471 r = std::make_unique< QgsCategorizedSymbolRenderer >( QString(),
QgsCategoryList() );
1479 r->setSourceSymbol( newSymbol );
1499 QgsStyle *style,
Qgis::SymbolType type, QVariantList &unmatchedCategories, QStringList &unmatchedSymbols,
const bool caseSensitive,
const bool useTolerantMatch
1507 const QSet< QString > allSymbolNames( unmatchedSymbols.begin(), unmatchedSymbols.end() );
1509 const thread_local QRegularExpression tolerantMatchRe( u
"[^\\w\\d ]"_s, QRegularExpression::UseUnicodePropertiesOption );
1511 for (
int catIdx = 0; catIdx <
mCategories.count(); ++catIdx )
1513 const QVariant value =
mCategories.at( catIdx ).value();
1514 const QString val = value.toString().trimmed();
1515 std::unique_ptr< QgsSymbol > symbol( style->
symbol( val ) );
1517 if ( symbol && symbol->type() ==
type )
1520 unmatchedSymbols.removeAll( val );
1525 if ( !caseSensitive || useTolerantMatch )
1527 QString testVal = val;
1528 if ( useTolerantMatch )
1529 testVal.replace( tolerantMatchRe, QString() );
1531 bool foundMatch =
false;
1532 for (
const QString &name : allSymbolNames )
1534 QString testName = name.trimmed();
1535 if ( useTolerantMatch )
1536 testName.replace( tolerantMatchRe, QString() );
1538 if ( testName == testVal || ( !caseSensitive && testName.trimmed().compare( testVal, Qt::CaseInsensitive ) == 0 ) )
1541 std::unique_ptr< QgsSymbol > symbol( style->
symbol( name ) );
1542 if ( symbol && symbol->type() ==
type )
1545 unmatchedSymbols.removeAll( name );
1556 unmatchedCategories << value;
1565 QVariantList vals = values;
1569 if ( layer && !attributeName.isNull() )
1572 for (
const QVariant &value : vals )
1578 const int fieldIdx = fields.
lookupField( attributeName );
1580 if ( fieldIdx != -1 )
1582 const QgsField field = fields.
at( fieldIdx );
1585 categoryName = formatter->
representValue( layer, fieldIdx, setup.
config(), QVariant(), value );
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
@ EmbeddedSymbols
Retrieve any embedded feature symbology.
QFlags< FeatureRendererFlag > FeatureRendererFlags
Flags controlling behavior of vector feature renderers.
@ AffectsLabeling
If present, indicates that the renderer will participate in the map labeling problem.
@ AffectsLabeling
If present, indicates that the symbol will participate in the map labeling problem.
static QgsFieldFormatterRegistry * fieldFormatterRegistry()
Gets the registry of available field formatters.
void sortByValue(Qt::SortOrder order=Qt::AscendingOrder)
Sorts the existing categories by their value.
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...
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
void updateSymbols(QgsSymbol *sym)
Update all the symbols but leave categories and colors.
bool updateCategoryRenderState(int catIndex, bool render)
Changes the render state for the category with the specified index.
void setSourceColorRamp(QgsColorRamp *ramp)
Sets the source color ramp.
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
QgsSymbol * sourceSymbol()
Returns the renderer's source symbol, which is the base symbol used for the each categories' symbol b...
const QgsCategoryList & categories() const
Returns a list of all categories recognized by the renderer.
QString legendKeyToExpression(const QString &key, QgsVectorLayer *layer, bool &ok) const override
Attempts to convert the specified legend rule key to a QGIS expression matching the features displaye...
int matchToSymbols(QgsStyle *style, Qgis::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.
std::unique_ptr< QgsColorRamp > mSourceColorRamp
Q_DECL_DEPRECATED QgsSymbol * symbolForValue(const QVariant &value) const
Returns the matching symbol corresponding to an attribute value.
std::unique_ptr< QgsSymbol > mSourceSymbol
static QgsCategorizedSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer, QgsVectorLayer *layer=nullptr)
Creates a new QgsCategorizedSymbolRenderer from an existing renderer.
void updateColorRamp(QgsColorRamp *ramp)
Update the color ramp used and all symbols colors.
QgsDataDefinedSizeLegend * dataDefinedSizeLegend() const
Returns configuration of appearance of legend when using data-defined size for marker symbols.
static QgsCategoryList createCategories(const QVariantList &values, const QgsSymbol *symbol, QgsVectorLayer *layer=nullptr, const QString &fieldName=QString())
Create categories for a list of values.
QHash< QString, QgsSymbol * > mSymbolHash
hashtable for faster access to symbols
bool filterNeedsGeometry() const override
Returns true if this renderer requires the geometry to apply the filter.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
void setSourceSymbol(QgsSymbol *sym)
Sets the source symbol for the renderer, which is the base symbol used for the each categories' symbo...
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
int categoryIndexForValue(const QVariant &val)
Returns the index for the category with the specified value (or -1 if not found).
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a categorized renderer from an XML element.
bool updateCategorySymbol(int catIndex, QgsSymbol *symbol)
Changes the symbol for the category with the specified index.
QgsCategoryList mCategories
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
std::unique_ptr< QgsExpression > mExpression
std::unique_ptr< QgsDataDefinedSizeLegend > mDataDefinedSizeLegend
bool legendSymbolItemChecked(const QString &key) override
Returns true if the legend symbology item with the specified key is checked.
bool legendSymbolItemsCheckable() const override
Returns true if symbology items in legend are checkable.
void addCategory(const QgsRendererCategory &category)
Adds a new category to the renderer.
QgsCategorizedSymbolRenderer(const QString &attrName=QString(), const QgsCategoryList &categories=QgsCategoryList())
Constructor for QgsCategorizedSymbolRenderer.
void sortByLabel(Qt::SortOrder order=Qt::AscendingOrder)
Sorts the existing categories by their label.
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
int mAttrNum
attribute index (derived from attribute name in startRender)
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
void moveCategory(int from, int to)
Moves an existing category at index position from to index position to.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
Stores renderer properties to an XML element.
bool deleteCategory(int catIndex)
Deletes the category with the specified index from the renderer.
Qgis::FeatureRendererFlags flags() const override
Returns flags associated with the renderer.
Q_DECL_DEPRECATED QgsSymbol * skipRender()
void checkLegendSymbolItem(const QString &key, bool state=true) override
Sets whether the legend symbology item with the specified ley should be checked.
QString dump() const override
Returns debug information about this renderer.
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
QgsColorRamp * sourceColorRamp()
Returns the source color ramp, from which each categories' color is derived.
bool mAttrIsNumeric
whether the attribute is numeric (derived from attribute name in startRender)
bool updateCategoryValue(int catIndex, const QVariant &value)
Changes the value for the category with the specified index.
Q_DECL_DEPRECATED void toSld(QDomDocument &doc, QDomElement &element, const QVariantMap &props=QVariantMap()) const override
Used from subclasses to create SLD Rule elements following SLD v1.1 specs.
QgsCategorizedSymbolRenderer * clone() const override
Create a deep copy of this renderer.
void deleteAllCategories()
Deletes all existing categories from the renderer.
void setDataDefinedSizeLegend(QgsDataDefinedSizeLegend *settings)
Configures appearance of legend when renderer is configured to use data-defined size for marker symbo...
bool updateCategoryLabel(int catIndex, const QString &label)
Changes the label for the category with the specified index.
static Q_DECL_DEPRECATED QString displayString(const QVariant &value, int precision=-1)
Returns a localized representation of value with the given precision, if precision is -1 then precisi...
~QgsCategorizedSymbolRenderer() override
int categoryIndexForLabel(const QString &val)
Returns the index of the category with the specified label (or -1 if the label was not found,...
Abstract base class for color ramps.
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
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...
void updateFromSymbolAndProperty(const QgsMarkerSymbol *symbol, const QgsProperty &ddSize)
Updates the list of classes, source symbol and title label from given symbol and property.
QgsLegendSymbolList legendSymbolList() const
Generates legend symbol items according to the configuration.
A vector feature renderer which uses embedded feature symbology to render per-feature symbols.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
A binary expression operator, which operates on two values.
An expression node for literal values.
QVariant value() const
The value of the literal.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
static QString quoteFieldExpression(const QString &expression, const QgsVectorLayer *layer)
Validate if the expression is a field in the layer and ensure it is quoted.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
bool isField() const
Checks whether an expression consists only of a single field reference.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes).
const QgsExpressionNode * rootNode() const
Returns the root node of the expression.
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
QgsFeatureRenderer(const QString &type)
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
static void convertSymbolRotation(QgsSymbol *symbol, const QString &field)
Converts old rotation expressions to symbol level data defined angles.
void saveRendererData(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context)
Saves generic renderer data into the specified element.
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
static void convertSymbolSizeScale(QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field)
Converts old sizeScale expressions to symbol level data defined sizes.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
const QgsSymbol * embeddedSymbol() const
Returns the feature's embedded symbology, or nullptr if the feature has no embedded symbol.
Encapsulate a field in an attribute table or data source.
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
Container of fields for a vector layer.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
A vector feature renderer which uses numeric attributes to classify features into different ranges.
QgsSymbol * sourceSymbol()
Returns the renderer's source symbol, which is the base symbol used for the each classes' symbol befo...
QgsColorRamp * sourceColorRamp()
Returns the source color ramp, from which each classes' color is derived.
QString classAttribute() const
Returns the attribute name (or expression) used for the classification.
A polygon-only feature renderer used to display features inverted.
Stores information about one class/rule of a vector layer renderer in a unified way that can be used ...
A marker symbol type, for rendering Point and MultiPoint geometries.
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
An abstract base class for distance based point renderers (e.g., clusterer and displacement renderers...
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
Translates a string using the Qt QTranslator mechanism.
A store for object properties.
bool isActive() const
Returns whether the property is currently active.
A color ramp consisting of random colors, constrained within component ranges.
virtual void setTotalColorCount(int colorCount)
Sets the desired total number of unique colors for the resultant ramp.
A container for the context for various read/write operations on objects.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
const QString currentLayerId() const
Returns the currently used layer id as string.
Contains information about the context of a rendering operation.
double rendererScale() const
Returns the renderer map scale.
QgsExpressionContext & expressionContext()
Gets the expression context.
Represents an individual category (class) from a QgsCategorizedSymbolRenderer.
void setRenderState(bool render)
Sets whether the category is currently enabled and should be rendered.
std::unique_ptr< QgsSymbol > mSymbol
QgsSymbol * symbol() const
Returns the symbol which will be used to render this category.
void setSymbol(QgsSymbol *s)
Sets the symbol which will be used to render this category.
QString uuid() const
Returns the unique identifier for this category.
QgsRendererCategory()=default
bool renderState() const
Returns true if the category is currently enabled and should be rendered.
QString dump() const
Returns a string representing the categories settings, used for debugging purposes only.
void setLabel(const QString &label)
Sets the label for this category, which is used to represent the category within legends and the laye...
Q_DECL_DEPRECATED void toSld(QDomDocument &doc, QDomElement &element, QVariantMap props) const
Converts the category to a matching SLD rule, within the specified DOM document and element.
void setValue(const QVariant &value)
Sets the value corresponding to this category.
QVariant value() const
Returns the value corresponding to this category.
QString label() const
Returns the label for this category, which is used to represent the category within legends and the l...
QgsRendererCategory & operator=(QgsRendererCategory cat)
Represents an individual rule for a rule-based renderer.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
void setExtraProperties(const QVariantMap &properties)
Sets the open ended set of properties that can drive/inform the SLD encoding.
QVariantMap extraProperties() const
Returns the open ended set of properties that can drive/inform the SLD encoding.
A color ramp entity for QgsStyle databases.
An interface for classes which can visit style entity (e.g.
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
A symbol entity for QgsStyle databases.
A database of saved style entities, including symbols, color ramps, text formats and others.
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
QStringList symbolNames() const
Returns a list of names of symbols.
static void sortVariantList(QList< QVariant > &list, Qt::SortOrder order)
Sorts the passed list in requested order.
static void applyScaleDependency(QDomDocument &doc, QDomElement &ruleElem, QVariantMap &props)
Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into t...
static std::unique_ptr< QgsColorRamp > loadColorRamp(QDomElement &element)
Creates a color ramp from the settings encoded in an XML element.
static Q_DECL_DEPRECATED bool createFunctionElement(QDomDocument &doc, QDomElement &element, const QString &function)
Creates an OGC function element.
static bool hasSldSymbolizer(const QDomElement &element)
Returns true if a DOM element contains an SLD Symbolizer element.
static void clearSymbolLayerMasks(QgsSymbol *symbol)
Remove recursively masks from all symbol symbol layers.
static Qgis::ScaleMethod decodeScaleMethod(const QString &str)
Decodes a symbol scale method from a string.
static QDomElement saveColorRamp(const QString &name, const QgsColorRamp *ramp, QDomDocument &doc)
Encodes a color ramp's settings to an XML element.
static void clearSymbolMap(QgsSymbolMap &symbols)
static void resetSymbolLayerIds(QgsSymbol *symbol)
Regenerate recursively unique id from all symbol symbol layers.
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 ...
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.
Abstract base class for all rendered symbols.
void setColor(const QColor &color) const
Sets the color for the symbol.
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns a list of attributes required to render this feature.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
static QString displayString(const QVariant &variant, int precision=-1)
Returns a localized representation of value with the given precision, if precision is -1 then precisi...
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based dataset.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const final
Queries the layer for features specified in request.
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.
bool labelGreaterThan(const QgsRendererCategory &c1, const QgsRendererCategory &c2)
bool valueLessThan(const QgsRendererCategory &c1, const QgsRendererCategory &c2)
bool valueGreaterThan(const QgsRendererCategory &c1, const QgsRendererCategory &c2)
bool labelLessThan(const QgsRendererCategory &c1, const QgsRendererCategory &c2)
QList< QgsRendererCategory > QgsCategoryList
QList< QgsLegendSymbolItem > QgsLegendSymbolList
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
#define RENDERER_TAG_NAME
QMap< QString, QgsSymbol * > QgsSymbolMap
QList< QgsSymbol * > QgsSymbolList
Contains information relating to the style entity currently being visited.