QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
43 #include <QDomDocument>
44 #include <QDomElement>
46 #include <QRegularExpression>
57 : mValue( cat.mValue )
58 , mSymbol( cat.mSymbol ? cat.mSymbol->clone() : nullptr )
59 , mLabel( cat.mLabel )
60 , mRender( cat.mRender )
127 if ( !
mSymbol.get() || props.value( QStringLiteral(
"attribute" ), QString() ).toString().isEmpty() )
130 QString attrName = props[ QStringLiteral(
"attribute" )].toString();
132 QDomElement ruleElem = doc.createElement( QStringLiteral(
"se:Rule" ) );
133 element.appendChild( ruleElem );
135 QDomElement nameElem = doc.createElement( QStringLiteral(
"se:Name" ) );
136 nameElem.appendChild( doc.createTextNode(
mLabel ) );
137 ruleElem.appendChild( nameElem );
139 QDomElement descrElem = doc.createElement( QStringLiteral(
"se:Description" ) );
140 QDomElement titleElem = doc.createElement( QStringLiteral(
"se:Title" ) );
141 QString descrStr = QStringLiteral(
"%1 is '%2'" ).arg( attrName,
mValue.toString() );
142 titleElem.appendChild( doc.createTextNode( !
mLabel.isEmpty() ?
mLabel : descrStr ) );
143 descrElem.appendChild( titleElem );
144 ruleElem.appendChild( descrElem );
150 filterFunc = QStringLiteral(
"%1 = '%2' or %1 is null" )
151 .arg( attrName.replace(
'\"', QLatin1String(
"\"\"" ) ),
152 mValue.toString().replace(
'\'', QLatin1String(
"''" ) ) );
156 filterFunc = QStringLiteral(
"%1 = '%2'" )
157 .arg( attrName.replace(
'\"', QLatin1String(
"\"\"" ) ),
158 mValue.toString().replace(
'\'', QLatin1String(
"''" ) ) );
166 mSymbol->toSld( doc, ruleElem, props );
173 , mAttrName( attrName )
182 QgsDebugMsg( QStringLiteral(
"invalid symbol in a category! ignoring..." ) );
196 const QVariant val = cat.value();
197 if ( val.type() == QVariant::List )
199 const QVariantList list = val.toList();
200 for (
const QVariant &v : list )
202 mSymbolHash.insert( v.toString(), ( cat.renderState() ||
mCounting ) ? cat.symbol() :
nullptr );
207 mSymbolHash.insert( val.toString(), ( cat.renderState() ||
mCounting ) ? cat.symbol() :
nullptr );
225 foundMatchingSymbol =
false;
228 QHash<QString, QgsSymbol *>::const_iterator it =
mSymbolHash.constFind( value.isNull() ? QString() : value.toString() );
233 QgsDebugMsg( QStringLiteral(
"there are no hashed symbols!!!" ) );
242 foundMatchingSymbol =
true;
272 QVariant value = valueForFeature( feature, context );
274 bool foundCategory =
false;
278 if ( !foundCategory )
316 if ( catIndex < 0 || catIndex >=
mCategories.size() )
324 if ( catIndex < 0 || catIndex >=
mCategories.size() )
332 if ( catIndex < 0 || catIndex >=
mCategories.size() )
340 if ( catIndex < 0 || catIndex >=
mCategories.size() )
350 QgsDebugMsg( QStringLiteral(
"invalid symbol in a category! ignoring..." ) );
359 if ( catIndex < 0 || catIndex >=
mCategories.size() )
388 if ( order == Qt::AscendingOrder )
400 return QString::localeAwareCompare( c1.
label(), c2.
label() ) < 0;
410 if ( order == Qt::AscendingOrder )
439 cat.symbol()->startRender( context, fields );
449 cat.symbol()->stopRender( context );
456 QSet<QString> attributes;
468 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();
495 QString s = QStringLiteral(
"CATEGORIZED: idx %1\n" ).arg(
mAttrName );
518 QVariantMap newProps = props;
519 newProps[ QStringLiteral(
"attribute" )] =
mAttrName;
524 it->toSld( doc, element, newProps );
531 bool isExpression = ( attrNum == -1 );
533 bool hasDefault =
false;
534 bool defaultActive =
false;
535 bool allActive =
true;
536 bool noneActive =
true;
540 QString activeValues;
541 QString inactiveValues;
545 if ( cat.value() ==
"" || cat.value().isNull() )
548 defaultActive = cat.renderState();
551 noneActive = noneActive && !cat.renderState();
552 allActive = allActive && cat.renderState();
554 QVariant::Type valType = isExpression ? cat.value().type() : fields.
at( attrNum ).
type();
555 const bool isList = cat.value().type() == QVariant::List;
558 if ( !cat.renderState() )
560 if ( cat.value() !=
"" )
564 const QVariantList list = cat.value().toList();
565 for (
const QVariant &v : list )
567 if ( !inactiveValues.isEmpty() )
568 inactiveValues.append(
',' );
575 if ( !inactiveValues.isEmpty() )
576 inactiveValues.append(
',' );
578 inactiveValues.append( value );
584 if ( cat.value() !=
"" )
588 const QVariantList list = cat.value().toList();
589 for (
const QVariant &v : list )
591 if ( !activeValues.isEmpty() )
592 activeValues.append(
',' );
599 if ( !activeValues.isEmpty() )
600 activeValues.append(
',' );
602 activeValues.append( value );
608 QString attr = isExpression ?
mAttrName : QStringLiteral(
"\"%1\"" ).arg(
mAttrName );
610 if ( allActive && hasDefault )
614 else if ( noneActive )
616 return QStringLiteral(
"FALSE" );
618 else if ( defaultActive )
620 return QStringLiteral(
"(%1) NOT IN (%2) OR (%1) IS NULL" ).arg( attr, inactiveValues );
624 return QStringLiteral(
"(%1) IN (%2)" ).arg( attr, activeValues );
635 lst.append( cat.symbol() );
661 QDomElement symbolsElem = element.firstChildElement( QStringLiteral(
"symbols" ) );
662 if ( symbolsElem.isNull() )
665 QDomElement catsElem = element.firstChildElement( QStringLiteral(
"categories" ) );
666 if ( catsElem.isNull() )
673 const auto valueFromString = [](
const QString & value,
const QString & valueType ) -> QVariant
675 if ( valueType == QLatin1String(
"double" ) )
678 const auto val { value.toDouble( &ok ) };
684 else if ( valueType == QLatin1String(
"ulong" ) )
687 const auto val { value.toULongLong( &ok ) };
693 else if ( valueType == QLatin1String(
"long" ) )
696 const auto val { value.toLongLong( &ok ) };
705 QDomElement catElem = catsElem.firstChildElement();
706 while ( !catElem.isNull() )
708 if ( catElem.tagName() == QLatin1String(
"category" ) )
711 if ( catElem.hasAttribute( QStringLiteral(
"value" ) ) )
713 value = valueFromString( catElem.attribute( QStringLiteral(
"value" ) ), catElem.attribute( QStringLiteral(
"type" ), QString() ) ) ;
719 QDomElement valElem = catElem.firstChildElement();
720 while ( !valElem.isNull() )
722 if ( valElem.tagName() == QLatin1String(
"val" ) )
724 values << valueFromString( valElem.attribute( QStringLiteral(
"value" ) ), valElem.attribute( QStringLiteral(
"type" ), QString() ) );
726 valElem = valElem.nextSiblingElement();
728 if ( !values.isEmpty() )
731 QString symbolName = catElem.attribute( QStringLiteral(
"symbol" ) );
732 QString label = catElem.attribute( QStringLiteral(
"label" ) );
733 bool render = catElem.attribute( QStringLiteral(
"render" ) ) != QLatin1String(
"false" );
734 if ( symbolMap.contains( symbolName ) )
736 QgsSymbol *symbol = symbolMap.take( symbolName );
740 catElem = catElem.nextSiblingElement();
743 QString attrName = element.attribute( QStringLiteral(
"attr" ) );
751 QDomElement sourceSymbolElem = element.firstChildElement( QStringLiteral(
"source-symbol" ) );
752 if ( !sourceSymbolElem.isNull() )
755 if ( sourceSymbolMap.contains( QStringLiteral(
"0" ) ) )
763 QDomElement sourceColorRampElem = element.firstChildElement( QStringLiteral(
"colorramp" ) );
764 if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( QStringLiteral(
"name" ) ) == QLatin1String(
"[source]" ) )
769 QDomElement rotationElem = element.firstChildElement( QStringLiteral(
"rotation" ) );
770 if ( !rotationElem.isNull() && !rotationElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
782 QDomElement sizeScaleElem = element.firstChildElement( QStringLiteral(
"sizescale" ) );
783 if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
789 sizeScaleElem.attribute( QStringLiteral(
"field" ) ) );
795 sizeScaleElem.attribute( QStringLiteral(
"field" ) ) );
799 QDomElement ddsLegendSizeElem = element.firstChildElement( QStringLiteral(
"data-defined-size-legend" ) );
800 if ( !ddsLegendSizeElem.isNull() )
813 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"categorizedSymbol" ) );
814 rendererElem.setAttribute( QStringLiteral(
"attr" ),
mAttrName );
818 const auto stringForType = [](
const QVariant::Type
type ) -> QString
820 if (
type == QVariant::Char ||
type == QVariant::Int ||
type == QVariant::LongLong )
822 return QStringLiteral(
"long" );
824 else if (
type == QVariant::UInt ||
type == QVariant::ULongLong )
826 return QStringLiteral(
"ulong" );
828 else if (
type == QVariant::Double )
830 return QStringLiteral(
"double" ) ;
834 return QStringLiteral(
"string" );
843 QDomElement catsElem = doc.createElement( QStringLiteral(
"categories" ) );
844 QgsCategoryList::const_iterator it =
mCategories.constBegin();
848 QString symbolName = QString::number( i );
851 QDomElement catElem = doc.createElement( QStringLiteral(
"category" ) );
852 if ( cat.
value().type() == QVariant::List )
854 const QVariantList list = cat.
value().toList();
855 for (
const QVariant &v : list )
857 QDomElement valueElem = doc.createElement( QStringLiteral(
"val" ) );
858 valueElem.setAttribute( QStringLiteral(
"value" ), v.toString() );
859 valueElem.setAttribute( QStringLiteral(
"type" ), stringForType( v.type() ) );
860 catElem.appendChild( valueElem );
865 catElem.setAttribute( QStringLiteral(
"value" ), cat.
value().toString() );
866 catElem.setAttribute( QStringLiteral(
"type" ), stringForType( cat.
value().type() ) );
868 catElem.setAttribute( QStringLiteral(
"symbol" ), symbolName );
869 catElem.setAttribute( QStringLiteral(
"label" ), cat.
label() );
870 catElem.setAttribute( QStringLiteral(
"render" ), cat.
renderState() ?
"true" :
"false" );
871 catsElem.appendChild( catElem );
874 rendererElem.appendChild( catsElem );
878 rendererElem.appendChild( symbolsElem );
885 sourceSymbols.insert( QStringLiteral(
"0" ),
mSourceSymbol.get() );
887 rendererElem.appendChild( sourceSymbolElem );
894 rendererElem.appendChild( colorRampElem );
897 QDomElement rotationElem = doc.createElement( QStringLiteral(
"rotation" ) );
898 rendererElem.appendChild( rotationElem );
900 QDomElement sizeScaleElem = doc.createElement( QStringLiteral(
"sizescale" ) );
901 rendererElem.appendChild( sizeScaleElem );
905 QDomElement ddsLegendElem = doc.createElement( QStringLiteral(
"data-defined-size-legend" ) );
907 rendererElem.appendChild( ddsLegendElem );
930 auto _displayString = [ ](
const QVariant & v,
int precision ) -> QString
938 const bool isNumeric {v.type() == QVariant::Double || v.type() == QVariant::Int || v.type() == QVariant::UInt || v.type() == QVariant::LongLong || v.type() == QVariant::ULongLong};
941 if ( v.type() == QVariant::Double )
951 if ( QLocale().decimalPoint() !=
'.' ||
952 !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
956 if ( -1 < v.toDouble() && v.toDouble() < 1 )
958 return QLocale().toString( v.toDouble(),
'g',
precision );
962 return QLocale().toString( v.toDouble(),
'f',
precision );
969 const QString s( v.toString() );
970 const int dotPosition( s.indexOf(
'.' ) );
972 if ( dotPosition < 0 && s.indexOf(
'e' ) < 0 )
975 return QLocale().toString( v.toDouble(),
'f',
precision );
980 else precision = s.length() - dotPosition - 1;
982 if ( -1 < v.toDouble() && v.toDouble() < 1 )
984 return QLocale().toString( v.toDouble(),
'g',
precision );
988 return QLocale().toString( v.toDouble(),
'f',
precision );
996 if ( -1 < v.toDouble() && v.toDouble() < 1 )
998 return QString::number( v.toDouble(),
'g',
precision );
1002 return QString::number( v.toDouble(),
'f',
precision );
1007 else if ( isNumeric &&
1008 !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
1011 const qlonglong converted( v.toLongLong( &ok ) );
1013 return QLocale().toString( converted );
1015 else if ( v.type() == QVariant::ByteArray )
1017 return QObject::tr(
"BLOB" );
1021 return v.toString();
1024 if ( v.type() == QVariant::StringList || v.type() == QVariant::List )
1030 const QVariantList list = v.toList();
1031 for (
const QVariant &var : list )
1033 if ( !result.isEmpty() )
1035 result.append(
';' );
1037 result.append( _displayString( var,
precision ) );
1059 if ( sSize != ddSize )
1062 return baseLegendSymbolItems();
1079 lst += baseLegendSymbolItems();
1084 return baseLegendSymbolItems();
1089 const QVariant value = valueForFeature( feature, context );
1095 if ( cat.value().type() == QVariant::List )
1097 const QVariantList list = cat.value().toList();
1098 for (
const QVariant &v : list )
1110 if ( value.isNull() && ( value.type() == QVariant::Double || value.type() == QVariant::Int ||
1111 value.type() == QVariant::UInt || value.type() == QVariant::LongLong ||
1112 value.type() == QVariant::ULongLong ) )
1114 match = cat.value().toString().isEmpty();
1118 match = value == cat.value();
1125 return QSet< QString >() << QString::number( i );
1127 return QSet< QString >();
1132 return QSet< QString >();
1138 int ruleIndex = key.toInt( &ok );
1139 if ( !ok || ruleIndex < 0 || ruleIndex >=
mCategories.size() )
1146 const bool isNumeric = layer && fieldIndex >= 0 ? layer->
fields().
at( fieldIndex ).
isNumeric() :
false;
1147 const QVariant::Type fieldType = layer && fieldIndex >= 0 ? layer->
fields().
at( fieldIndex ).
type() : QVariant::Invalid;
1152 if ( cat.
value().type() == QVariant::List )
1154 const QVariantList list = cat.
value().toList();
1156 parts.reserve( list.size() );
1157 for (
const QVariant &v : list )
1162 return QStringLiteral(
"%1 IN (%2)" ).arg( attributeComponent, parts.join( QLatin1String(
", " ) ) );
1167 QVariant value = cat.
value();
1168 if ( isNumeric && value.toString().isEmpty() )
1173 if ( value.isNull() )
1174 return QStringLiteral(
"%1 IS NULL" ).arg( attributeComponent );
1175 else if ( fieldType == QVariant::Type::Invalid )
1228 double value = count / num;
1240 symbol->
setColor( cat.symbol()->color() );
1255 int index = key.toInt( &ok );
1256 if ( ok && index >= 0 && index <
mCategories.size() )
1265 int index = key.toInt( &ok );
1275 int index = key.toInt( &ok );
1282 std::unique_ptr< QgsCategorizedSymbolRenderer > r;
1283 if ( renderer->
type() == QLatin1String(
"categorizedSymbol" ) )
1287 else if ( renderer->
type() == QLatin1String(
"graduatedSymbol" ) )
1290 if ( graduatedSymbolRenderer )
1299 r->setClassAttribute( graduatedSymbolRenderer->
classAttribute() );
1302 else if ( renderer->
type() == QLatin1String(
"pointDisplacement" ) || renderer->
type() == QLatin1String(
"pointCluster" ) )
1305 if ( pointDistanceRenderer )
1308 else if ( renderer->
type() == QLatin1String(
"invertedPolygonRenderer" ) )
1311 if ( invertedPolygonRenderer )
1314 else if ( renderer->
type() == QLatin1String(
"embeddedSymbol" ) && layer )
1337 r = std::make_unique< QgsCategorizedSymbolRenderer >( QString(),
QgsCategoryList() );
1342 r->setSourceSymbol(
symbols.at( 0 )->clone() );
1368 const QSet< QString > allSymbolNames = qgis::listToSet( unmatchedSymbols );
1370 const QRegularExpression tolerantMatchRe( QStringLiteral(
"[^\\w\\d ]" ), QRegularExpression::UseUnicodePropertiesOption );
1372 for (
int catIdx = 0; catIdx <
mCategories.count(); ++catIdx )
1374 const QVariant value =
mCategories.at( catIdx ).value();
1375 const QString val = value.toString().trimmed();
1376 std::unique_ptr< QgsSymbol > symbol( style->
symbol( val ) );
1378 if ( symbol && symbol->type() ==
type )
1381 unmatchedSymbols.removeAll( val );
1386 if ( !caseSensitive || useTolerantMatch )
1388 QString testVal = val;
1389 if ( useTolerantMatch )
1390 testVal.replace( tolerantMatchRe, QString() );
1392 bool foundMatch =
false;
1393 for (
const QString &name : allSymbolNames )
1395 QString testName = name.trimmed();
1396 if ( useTolerantMatch )
1397 testName.replace( tolerantMatchRe, QString() );
1399 if ( testName == testVal || ( !caseSensitive && testName.trimmed().compare( testVal, Qt::CaseInsensitive ) == 0 ) )
1402 std::unique_ptr< QgsSymbol > symbol( style->
symbol( name ) );
1403 if ( symbol && symbol->type() ==
type )
1406 unmatchedSymbols.removeAll( name );
1417 unmatchedCategories << value;
1426 QVariantList vals = values;
1430 if ( layer && !attributeName.isNull() )
1433 for (
const QVariant &value : vals )
1436 if ( !value.isNull() )
1438 const int fieldIdx = fields.
lookupField( attributeName );
1440 if ( fieldIdx != -1 )
1445 categoryName =
formatter->representValue( layer, fieldIdx, setup.
config(), QVariant(), value );
QString dump() const override
Returns debug information about this renderer.
QgsColorRamp * sourceColorRamp()
Returns the source color ramp, from which each classes' color is derived.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
Stores renderer properties to an XML element.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool isActive() const
Returns whether the property is currently active.
Abstract base class for color ramps.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
void setLabel(const QString &label)
Sets the label for this category, which is used to represent the category within legends and the laye...
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 ...
A store for object properties.
QgsSymbol * sourceSymbol()
Returns the renderer's source symbol, which is the base symbol used for the each classes' symbol befo...
QgsExpressionContext & expressionContext()
Gets the expression context.
The class is used as a container of context for various read/write operations on other objects.
QString classAttribute() const
Returns the attribute name (or expression) used for the classification.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
QgsDataDefinedSizeLegend * dataDefinedSizeLegend() const
Returns configuration of appearance of legend when using data-defined size for marker symbols.
QgsCategorizedSymbolRenderer * clone() const override
Create a deep copy of this renderer.
#define QgsDebugMsgLevel(str, level)
A symbol entity for QgsStyle databases.
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
void updateSymbols(QgsSymbol *sym)
Update all the symbols but leave categories and colors.
bool labelLessThan(const QgsRendererCategory &c1, const QgsRendererCategory &c2)
std::unique_ptr< QgsColorRamp > mSourceColorRamp
void sortByLabel(Qt::SortOrder order=Qt::AscendingOrder)
Sorts the existing categories by their label.
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is less than the second.
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
static void convertSymbolSizeScale(QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field)
QMap< QString, QgsSymbol * > QgsSymbolMap
bool updateCategorySymbol(int catIndex, QgsSymbol *symbol)
Changes the symbol for the category with the specified index.
A color ramp entity for QgsStyle databases.
const QgsCategoryList & categories() const
Returns a list of all categories recognized by the renderer.
Container of fields for a vector layer.
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
static void convertSymbolRotation(QgsSymbol *symbol, const QString &field)
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
Represents an individual category (class) from a QgsCategorizedSymbolRenderer.
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
std::unique_ptr< QgsDataDefinedSizeLegend > mDataDefinedSizeLegend
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
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
Abstract base class for all rendered symbols.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
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.
bool legendSymbolItemChecked(const QString &key) override
items of symbology items in legend is checked
int mAttrNum
attribute index (derived from attribute name in startRender)
static QString displayString(const QVariant &value, int precision=-1)
Returns a localized representation of value with the given precision, if precision is -1 then precisi...
void setDataDefinedSizeLegend(QgsDataDefinedSizeLegend *settings)
Configures appearance of legend when renderer is configured to use data-defined size for marker symbo...
Contains information relating to the style entity currently being visited.
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
static QString quoteFieldExpression(const QString &expression, const QgsVectorLayer *layer)
Validate if the expression is a field in the layer and ensure it is quoted.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
bool legendSymbolItemsCheckable() const override
items of symbology items in legend should be checkable
Totally random color ramp. Returns colors generated at random, but constrained to some hardcoded satu...
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
static void sortVariantList(QList< QVariant > &list, Qt::SortOrder order)
Sorts the passed list in requested order.
const QgsSymbol * embeddedSymbol() const
Returns the feature's embedded symbology, or nullptr if the feature has no embedded symbol.
Q_DECL_DEPRECATED QgsSymbol * skipRender()
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Q_DECL_DEPRECATED QgsSymbol * symbolForValue(const QVariant &value) const
Returns the matching symbol corresponding to an attribute value.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsLegendSymbolList legendSymbolList() const
Generates legend symbol items according to the configuration.
~QgsCategorizedSymbolRenderer() override
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
QgsRendererCategory & operator=(QgsRendererCategory cat)
bool updateCategoryValue(int catIndex, const QVariant &value)
Changes the value for the category with the specified index.
bool valueGreaterThan(const QgsRendererCategory &c1, const QgsRendererCategory &c2)
int categoryIndexForValue(const QVariant &val)
Returns the index for the category with the specified value (or -1 if not found).
QgsCategorizedSymbolRenderer(const QString &attrName=QString(), const QgsCategoryList &categories=QgsCategoryList())
Constructor for QgsCategorizedSymbolRenderer.
void moveCategory(int from, int to)
Moves an existing category at index position from to index position to.
static void applyScaleDependency(QDomDocument &doc, QDomElement &ruleElem, QVariantMap &props)
Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into t...
bool filterNeedsGeometry() const override
Returns true if this renderer requires the geometry to apply the filter.
static Qgis::ScaleMethod decodeScaleMethod(const QString &str)
Decodes a symbol scale method from a string.
QList< QgsRendererCategory > QgsCategoryList
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
void setSymbol(QgsSymbol *s)
Sets the symbol which will be used to render this category.
QList< QgsSymbol * > QgsSymbolList
A marker symbol type, for rendering Point and MultiPoint geometries.
bool updateCategoryRenderState(int catIndex, bool render)
Changes the render state for the category with the specified index.
virtual void setTotalColorCount(int colorCount)
Sets the desired total number of unique colors for the resultant ramp.
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 saveRendererData(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context)
Saves generic renderer data into the specified element.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
void setRenderState(bool render)
Sets whether the category is currently enabled and should be rendered.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
QgsSymbol * symbol() const
Returns the symbol which will be used to render this category.
static QDomElement saveColorRamp(const QString &name, QgsColorRamp *ramp, QDomDocument &doc)
Encodes a color ramp's settings to an XML element.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a categorized renderer from an XML element.
#define RENDERER_TAG_NAME
An abstract base class for distance based point renderers (e.g., clusterer and displacement renderers...
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
QgsColorRamp * sourceColorRamp()
Returns the source color ramp, from which each categories' color is derived.
std::unique_ptr< QgsSymbol > mSourceSymbol
std::unique_ptr< QgsExpression > mExpression
QHash< QString, QgsSymbol * > mSymbolHash
hashtable for faster access to symbols
QgsRendererCategory()=default
Constructor for QgsRendererCategory.
bool deleteCategory(int catIndex)
Deletes the category with the specified index from the renderer.
bool updateCategoryLabel(int catIndex, const QString &label)
Changes the label for the category with the specified index.
void swap(QgsRendererCategory &other)
void sortByValue(Qt::SortOrder order=Qt::AscendingOrder)
Sorts the existing categories by their value.
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 classes' symbol b...
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
static QgsFieldFormatterRegistry * fieldFormatterRegistry()
Gets the registry of available field formatters.
static QgsColorRamp * loadColorRamp(QDomElement &element)
Creates a color ramp from the settings encoded in an XML element.
int categoryIndexForLabel(const QString &val)
Returns the index of the category with the specified label (or -1 if the label was not found,...
bool valueLessThan(const QgsRendererCategory &c1, const QgsRendererCategory &c2)
QStringList symbolNames() const
Returns a list of names of symbols.
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...
void updateFromSymbolAndProperty(const QgsMarkerSymbol *symbol, const QgsProperty &ddSize)
Updates the list of classes, source symbol and title label from given symbol and property.
void setSourceSymbol(QgsSymbol *sym)
Sets the source symbol for the renderer, which is the base symbol used for the each categories' symbo...
void toSld(QDomDocument &doc, QDomElement &element, QVariantMap props) const
Converts the category to a matching SLD rule, within the specified DOM document and element.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
QString label() const
Returns the label for this category, which is used to represent the category within legends and the l...
bool renderState() const
Returns true if the category is currently enabled and should be rendered.
bool nextFeature(QgsFeature &f)
static QgsCategoryList createCategories(const QVariantList &values, const QgsSymbol *symbol, QgsVectorLayer *layer=nullptr, const QString &fieldName=QString())
Create categories for a list of values.
A vector feature renderer which uses embedded feature symbology to render per-feature symbols.
void updateColorRamp(QgsColorRamp *ramp)
Update the color ramp used and all symbols colors.
Represents a vector layer which manages a vector based data sets.
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.
QString dump() const
Returns a string representing the categories settings, used for debugging purposes only.
static void clearSymbolMap(QgsSymbolMap &symbols)
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns a list of attributes required to render this feature.
bool labelGreaterThan(const QgsRendererCategory &c1, const QgsRendererCategory &c2)
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
QgsCategoryList mCategories
A vector of attributes. Mostly equal to QVector<QVariant>.
void setValue(const QVariant &value)
Sets the value corresponding to this category.
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...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void deleteAllCategories()
Deletes all existing categories from the renderer.
@ EmbeddedSymbols
Retrieve any embedded feature symbology (since QGIS 3.20)
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
double rendererScale() const
Returns the renderer map scale.
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Class for parsing and evaluation of expressions (formerly called "search strings")....
static QgsCategorizedSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer, QgsVectorLayer *layer=nullptr)
Creates a new QgsCategorizedSymbolRenderer from an existing renderer.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
Wrapper for iterator of features from vector data provider or vector layer.
void setColor(const QColor &color) const
Sets the color for the symbol.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
QVariant value() const
Returns the value corresponding to this category.
void setSourceColorRamp(QgsColorRamp *ramp)
Sets the source color ramp.
void addCategory(const QgsRendererCategory &category)
Adds a new category to the renderer.
std::unique_ptr< QgsSymbol > mSymbol
void checkLegendSymbolItem(const QString &key, bool state=true) override
item in symbology was checked
QgsSymbol * sourceSymbol()
Returns the renderer's source symbol, which is the base symbol used for the each categories' symbol b...
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
static bool createFunctionElement(QDomDocument &doc, QDomElement &element, const QString &function)
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted,...
Encapsulate a field in an attribute table or data source.