43#include <QDomDocument>
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(
"ELSE" );
154 filterFunc = QStringLiteral(
"%1 = '%2'" )
155 .arg( attrName.replace(
'\"', QLatin1String(
"\"\"" ) ).append(
'"' ).prepend(
'"' ),
156 mValue.toString().replace(
'\'', QLatin1String(
"''" ) ) );
164 mSymbol->toSld( doc, ruleElem, props );
171 , mAttrName( attrName )
180 QgsDebugError( QStringLiteral(
"invalid symbol in a category! ignoring..." ) );
194 const QVariant val = cat.value();
195 if ( val.type() == QVariant::List )
197 const QVariantList list = val.toList();
198 for (
const QVariant &v : list )
200 mSymbolHash.insert( v.toString(), ( cat.renderState() ||
mCounting ) ? cat.symbol() :
nullptr );
205 mSymbolHash.insert( val.toString(), ( cat.renderState() ||
mCounting ) ? cat.symbol() :
nullptr );
223 foundMatchingSymbol =
false;
231 QgsDebugError( QStringLiteral(
"there are no hashed symbols!!!" ) );
240 foundMatchingSymbol =
true;
270 QVariant value = valueForFeature( feature, context );
272 bool foundCategory =
false;
276 if ( !foundCategory )
314 if ( catIndex < 0 || catIndex >=
mCategories.size() )
322 if ( catIndex < 0 || catIndex >=
mCategories.size() )
330 if ( catIndex < 0 || catIndex >=
mCategories.size() )
338 if ( catIndex < 0 || catIndex >=
mCategories.size() )
348 QgsDebugError( QStringLiteral(
"invalid symbol in a category! ignoring..." ) );
357 if ( catIndex < 0 || catIndex >=
mCategories.size() )
386 if ( order == Qt::AscendingOrder )
398 return QString::localeAwareCompare( c1.
label(), c2.
label() ) < 0;
408 if ( order == Qt::AscendingOrder )
437 cat.symbol()->startRender( context, fields );
447 cat.symbol()->stopRender( context );
454 QSet<QString> attributes;
466 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();
493 QString s = QStringLiteral(
"CATEGORIZED: idx %1\n" ).arg(
mAttrName );
516 QVariantMap newProps = props;
517 newProps[ QStringLiteral(
"attribute" )] =
mAttrName;
522 it->toSld( doc, element, newProps );
529 bool isExpression = ( attrNum == -1 );
531 bool hasDefault =
false;
532 bool defaultActive =
false;
533 bool allActive =
true;
534 bool noneActive =
true;
538 QString activeValues;
539 QString inactiveValues;
546 defaultActive = cat.renderState();
549 noneActive = noneActive && !cat.renderState();
550 allActive = allActive && cat.renderState();
552 QVariant::Type valType = isExpression ? cat.value().type() : fields.
at( attrNum ).
type();
553 const bool isList = cat.value().type() == QVariant::List;
556 if ( !cat.renderState() )
558 if ( cat.value() !=
"" )
562 const QVariantList list = cat.value().toList();
563 for (
const QVariant &v : list )
565 if ( !inactiveValues.isEmpty() )
566 inactiveValues.append(
',' );
573 if ( !inactiveValues.isEmpty() )
574 inactiveValues.append(
',' );
576 inactiveValues.append( value );
582 if ( cat.value() !=
"" )
586 const QVariantList list = cat.value().toList();
587 for (
const QVariant &v : list )
589 if ( !activeValues.isEmpty() )
590 activeValues.append(
',' );
597 if ( !activeValues.isEmpty() )
598 activeValues.append(
',' );
600 activeValues.append( value );
606 QString attr = isExpression ?
mAttrName : QStringLiteral(
"\"%1\"" ).arg(
mAttrName );
608 if ( allActive && hasDefault )
612 else if ( noneActive )
614 return QStringLiteral(
"FALSE" );
616 else if ( defaultActive )
618 return QStringLiteral(
"(%1) NOT IN (%2) OR (%1) IS NULL" ).arg( attr, inactiveValues );
622 return QStringLiteral(
"(%1) IN (%2)" ).arg( attr, activeValues );
633 lst.append( cat.symbol() );
659 QDomElement symbolsElem = element.firstChildElement( QStringLiteral(
"symbols" ) );
660 if ( symbolsElem.isNull() )
663 QDomElement catsElem = element.firstChildElement( QStringLiteral(
"categories" ) );
664 if ( catsElem.isNull() )
671 const auto valueFromString = [](
const QString & value,
const QString & valueType ) -> QVariant
673 if ( valueType == QLatin1String(
"double" ) )
676 const auto val { value.toDouble( &ok ) };
682 else if ( valueType == QLatin1String(
"ulong" ) )
685 const auto val { value.toULongLong( &ok ) };
691 else if ( valueType == QLatin1String(
"long" ) )
694 const auto val { value.toLongLong( &ok ) };
703 QDomElement catElem = catsElem.firstChildElement();
704 while ( !catElem.isNull() )
706 if ( catElem.tagName() == QLatin1String(
"category" ) )
709 if ( catElem.hasAttribute( QStringLiteral(
"value" ) ) )
711 value = valueFromString( catElem.attribute( QStringLiteral(
"value" ) ), catElem.attribute( QStringLiteral(
"type" ), QString() ) ) ;
717 QDomElement valElem = catElem.firstChildElement();
718 while ( !valElem.isNull() )
720 if ( valElem.tagName() == QLatin1String(
"val" ) )
722 values << valueFromString( valElem.attribute( QStringLiteral(
"value" ) ), valElem.attribute( QStringLiteral(
"type" ), QString() ) );
724 valElem = valElem.nextSiblingElement();
726 if ( !values.isEmpty() )
729 QString symbolName = catElem.attribute( QStringLiteral(
"symbol" ) );
730 QString label = catElem.attribute( QStringLiteral(
"label" ) );
731 bool render = catElem.attribute( QStringLiteral(
"render" ) ) != QLatin1String(
"false" );
732 if ( symbolMap.contains( symbolName ) )
734 QgsSymbol *symbol = symbolMap.take( symbolName );
738 catElem = catElem.nextSiblingElement();
741 QString attrName = element.attribute( QStringLiteral(
"attr" ) );
749 QDomElement sourceSymbolElem = element.firstChildElement( QStringLiteral(
"source-symbol" ) );
750 if ( !sourceSymbolElem.isNull() )
753 if ( sourceSymbolMap.contains( QStringLiteral(
"0" ) ) )
761 QDomElement sourceColorRampElem = element.firstChildElement( QStringLiteral(
"colorramp" ) );
762 if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( QStringLiteral(
"name" ) ) == QLatin1String(
"[source]" ) )
767 QDomElement rotationElem = element.firstChildElement( QStringLiteral(
"rotation" ) );
768 if ( !rotationElem.isNull() && !rotationElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
780 QDomElement sizeScaleElem = element.firstChildElement( QStringLiteral(
"sizescale" ) );
781 if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
787 sizeScaleElem.attribute( QStringLiteral(
"field" ) ) );
793 sizeScaleElem.attribute( QStringLiteral(
"field" ) ) );
797 QDomElement ddsLegendSizeElem = element.firstChildElement( QStringLiteral(
"data-defined-size-legend" ) );
798 if ( !ddsLegendSizeElem.isNull() )
811 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"categorizedSymbol" ) );
812 rendererElem.setAttribute( QStringLiteral(
"attr" ),
mAttrName );
816 const auto stringForType = [](
const QVariant::Type
type ) -> QString
818 if (
type == QVariant::Char ||
type == QVariant::Int ||
type == QVariant::LongLong )
820 return QStringLiteral(
"long" );
822 else if (
type == QVariant::UInt ||
type == QVariant::ULongLong )
824 return QStringLiteral(
"ulong" );
826 else if (
type == QVariant::Double )
828 return QStringLiteral(
"double" ) ;
832 return QStringLiteral(
"string" );
841 QDomElement catsElem = doc.createElement( QStringLiteral(
"categories" ) );
842 QgsCategoryList::const_iterator it =
mCategories.constBegin();
846 QString symbolName = QString::number( i );
849 QDomElement catElem = doc.createElement( QStringLiteral(
"category" ) );
850 if ( cat.
value().type() == QVariant::List )
852 const QVariantList list = cat.
value().toList();
853 for (
const QVariant &v : list )
855 QDomElement valueElem = doc.createElement( QStringLiteral(
"val" ) );
856 valueElem.setAttribute( QStringLiteral(
"value" ), v.toString() );
857 valueElem.setAttribute( QStringLiteral(
"type" ), stringForType( v.type() ) );
858 catElem.appendChild( valueElem );
863 catElem.setAttribute( QStringLiteral(
"value" ), cat.
value().toString() );
864 catElem.setAttribute( QStringLiteral(
"type" ), stringForType( cat.
value().type() ) );
866 catElem.setAttribute( QStringLiteral(
"symbol" ), symbolName );
867 catElem.setAttribute( QStringLiteral(
"label" ), cat.
label() );
868 catElem.setAttribute( QStringLiteral(
"render" ), cat.
renderState() ?
"true" :
"false" );
869 catsElem.appendChild( catElem );
872 rendererElem.appendChild( catsElem );
876 rendererElem.appendChild( symbolsElem );
883 sourceSymbols.insert( QStringLiteral(
"0" ),
mSourceSymbol.get() );
885 rendererElem.appendChild( sourceSymbolElem );
892 rendererElem.appendChild( colorRampElem );
895 QDomElement rotationElem = doc.createElement( QStringLiteral(
"rotation" ) );
896 rendererElem.appendChild( rotationElem );
898 QDomElement sizeScaleElem = doc.createElement( QStringLiteral(
"sizescale" ) );
899 rendererElem.appendChild( sizeScaleElem );
903 QDomElement ddsLegendElem = doc.createElement( QStringLiteral(
"data-defined-size-legend" ) );
905 rendererElem.appendChild( ddsLegendElem );
928 auto _displayString = [ ](
const QVariant & v,
int precision ) -> QString
936 const bool isNumeric {v.type() == QVariant::Double || v.type() == QVariant::Int || v.type() == QVariant::UInt || v.type() == QVariant::LongLong || v.type() == QVariant::ULongLong};
939 if ( v.type() == QVariant::Double )
949 if ( QLocale().decimalPoint() !=
'.' ||
950 !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
954 if ( -1 < v.toDouble() && v.toDouble() < 1 )
956 return QLocale().toString( v.toDouble(),
'g',
precision );
960 return QLocale().toString( v.toDouble(),
'f',
precision );
967 const QString s( v.toString() );
968 const int dotPosition( s.indexOf(
'.' ) );
970 if ( dotPosition < 0 && s.indexOf(
'e' ) < 0 )
973 return QLocale().toString( v.toDouble(),
'f',
precision );
978 else precision = s.length() - dotPosition - 1;
980 if ( -1 < v.toDouble() && v.toDouble() < 1 )
982 return QLocale().toString( v.toDouble(),
'g',
precision );
986 return QLocale().toString( v.toDouble(),
'f',
precision );
994 if ( -1 < v.toDouble() && v.toDouble() < 1 )
996 return QString::number( v.toDouble(),
'g',
precision );
1000 return QString::number( v.toDouble(),
'f',
precision );
1005 else if ( isNumeric &&
1006 !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
1009 const qlonglong converted( v.toLongLong( &ok ) );
1011 return QLocale().toString( converted );
1013 else if ( v.type() == QVariant::ByteArray )
1015 return QObject::tr(
"BLOB" );
1019 return v.toString();
1022 if ( v.type() == QVariant::StringList || v.type() == QVariant::List )
1028 const QVariantList list = v.toList();
1029 for (
const QVariant &var : list )
1031 if ( !result.isEmpty() )
1033 result.append(
';' );
1035 result.append( _displayString( var,
precision ) );
1057 if ( sSize != ddSize )
1060 return baseLegendSymbolItems();
1077 lst += baseLegendSymbolItems();
1082 return baseLegendSymbolItems();
1087 const QVariant value = valueForFeature( feature, context );
1093 if ( cat.value().type() == QVariant::List )
1095 const QVariantList list = cat.value().toList();
1096 for (
const QVariant &v : list )
1108 if (
QgsVariantUtils::isNull( value ) && ( value.type() == QVariant::Double || value.type() == QVariant::Int ||
1109 value.type() == QVariant::UInt || value.type() == QVariant::LongLong ||
1110 value.type() == QVariant::ULongLong ) )
1112 match = cat.value().toString().isEmpty();
1116 match = value == cat.value();
1123 return QSet< QString >() << QString::number( i );
1125 return QSet< QString >();
1130 return QSet< QString >();
1136 int ruleIndex = key.toInt( &ok );
1137 if ( !ok || ruleIndex < 0 || ruleIndex >=
mCategories.size() )
1144 const bool isNumeric = layer && fieldIndex >= 0 ? layer->
fields().
at( fieldIndex ).
isNumeric() :
false;
1145 const QVariant::Type fieldType = layer && fieldIndex >= 0 ? layer->
fields().
at( fieldIndex ).
type() : QVariant::Invalid;
1150 if ( cat.
value().type() == QVariant::List )
1152 const QVariantList list = cat.
value().toList();
1154 parts.reserve( list.size() );
1155 for (
const QVariant &v : list )
1160 return QStringLiteral(
"%1 IN (%2)" ).arg( attributeComponent, parts.join( QLatin1String(
", " ) ) );
1165 QVariant value = cat.
value();
1166 if ( isNumeric && value.toString().isEmpty() )
1172 return QStringLiteral(
"%1 IS NULL" ).arg( attributeComponent );
1173 else if ( fieldType == QVariant::Type::Invalid )
1226 double value = count / num;
1238 symbol->
setColor( cat.symbol()->color() );
1253 int index = key.toInt( &ok );
1254 if ( ok && index >= 0 && index <
mCategories.size() )
1263 int index = key.toInt( &ok );
1273 int index = key.toInt( &ok );
1280 std::unique_ptr< QgsCategorizedSymbolRenderer > r;
1281 if ( renderer->
type() == QLatin1String(
"categorizedSymbol" ) )
1285 else if ( renderer->
type() == QLatin1String(
"graduatedSymbol" ) )
1288 if ( graduatedSymbolRenderer )
1297 r->setClassAttribute( graduatedSymbolRenderer->
classAttribute() );
1300 else if ( renderer->
type() == QLatin1String(
"pointDisplacement" ) || renderer->
type() == QLatin1String(
"pointCluster" ) )
1303 if ( pointDistanceRenderer )
1306 else if ( renderer->
type() == QLatin1String(
"invertedPolygonRenderer" ) )
1309 if ( invertedPolygonRenderer )
1312 else if ( renderer->
type() == QLatin1String(
"embeddedSymbol" ) && layer )
1335 r = std::make_unique< QgsCategorizedSymbolRenderer >( QString(),
QgsCategoryList() );
1340 r->setSourceSymbol(
symbols.at( 0 )->clone() );
1366 const QSet< QString > allSymbolNames( unmatchedSymbols.begin(), unmatchedSymbols.end() );
1368 const thread_local QRegularExpression tolerantMatchRe( QStringLiteral(
"[^\\w\\d ]" ), QRegularExpression::UseUnicodePropertiesOption );
1370 for (
int catIdx = 0; catIdx <
mCategories.count(); ++catIdx )
1372 const QVariant value =
mCategories.at( catIdx ).value();
1373 const QString val = value.toString().trimmed();
1374 std::unique_ptr< QgsSymbol > symbol( style->
symbol( val ) );
1376 if ( symbol && symbol->type() ==
type )
1379 unmatchedSymbols.removeAll( val );
1384 if ( !caseSensitive || useTolerantMatch )
1386 QString testVal = val;
1387 if ( useTolerantMatch )
1388 testVal.replace( tolerantMatchRe, QString() );
1390 bool foundMatch =
false;
1391 for (
const QString &name : allSymbolNames )
1393 QString testName = name.trimmed();
1394 if ( useTolerantMatch )
1395 testName.replace( tolerantMatchRe, QString() );
1397 if ( testName == testVal || ( !caseSensitive && testName.trimmed().compare( testVal, Qt::CaseInsensitive ) == 0 ) )
1400 std::unique_ptr< QgsSymbol > symbol( style->
symbol( name ) );
1401 if ( symbol && symbol->type() ==
type )
1404 unmatchedSymbols.removeAll( name );
1415 unmatchedCategories << value;
1424 QVariantList vals = values;
1428 if ( layer && !attributeName.isNull() )
1431 for (
const QVariant &value : vals )
1436 const int fieldIdx = fields.
lookupField( attributeName );
1438 if ( fieldIdx != -1 )
1443 categoryName =
formatter->representValue( layer, fieldIdx, setup.
config(), QVariant(), value );
SymbolType
Attribute editing capabilities which may be supported by vector data providers.
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
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.
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 updateCategoryValue(int catIndex, const QVariant &value)
Changes the value for the category with the specified index.
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 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.
Class for 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.
QSet< QString > referencedColumns() const
Gets list of columns referenced by 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)
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)
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)
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
@ EmbeddedSymbols
Retrieve any embedded feature symbology (since QGIS 3.20)
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
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).
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
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.
void setSourceSymbol(QgsSymbol *sym)
Sets the source symbol for the renderer, which is the base symbol used for the each classes' symbol b...
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted,...
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
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.
A store for object properties.
bool isActive() const
Returns whether the property is currently active.
Totally random color ramp.
virtual void setTotalColorCount(int colorCount)
Sets the desired total number of unique colors for the resultant ramp.
The class is used as a container of context for various read/write operations on other objects.
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.
void swap(QgsRendererCategory &other)
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.
QgsRendererCategory()=default
Constructor for QgsRendererCategory.
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...
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)
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.
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 bool createFunctionElement(QDomDocument &doc, QDomElement &element, const QString &function)
static QgsColorRamp * loadColorRamp(QDomElement &element)
Creates a color ramp from the settings encoded in an XML element.
static Qgis::ScaleMethod decodeScaleMethod(const QString &str)
Decodes a symbol scale method from a string.
static QDomElement saveColorRamp(const QString &name, QgsColorRamp *ramp, QDomDocument &doc)
Encodes a color ramp's settings to an XML element.
static void clearSymbolMap(QgsSymbolMap &symbols)
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 bool isNull(const QVariant &variant)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based data sets.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
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.