50#include <QDomDocument>
54using namespace Qt::StringLiterals;
65 const auto constRanges =
ranges;
82 auto catIt =
mRanges.constBegin();
83 for ( ; catIt !=
mRanges.constEnd(); ++catIt )
85 if (
QgsSymbol *catSymbol = catIt->symbol() )
99 if ( range.lowerValue() <= value && range.upperValue() >= value )
128 return range->symbol();
134 if ( rangeIndex < 0 || rangeIndex >=
mRanges.size() )
137 return !valueCapturedByEarlierRange( rangeIndex,
mRanges.at( rangeIndex ).lowerValue() );
142 if ( rangeIndex < 0 || rangeIndex >=
mRanges.size() )
145 return !valueCapturedByEarlierRange( rangeIndex,
mRanges.at( rangeIndex ).upperValue() );
150 if ( rangeIndex <= 0 || rangeIndex >=
mRanges.size() )
154 for (
int i = 0; i < rangeIndex; ++i )
169 if ( matchingRange == &range )
199 QVariant value = valueForFeature( feature, context );
226 if ( !range.symbol() )
229 range.symbol()->startRender( context, fields );
239 if ( !range.symbol() )
242 range.symbol()->stopRender( context );
248 QSet<QString> attributes;
260 QgsRangeList::const_iterator range_it =
mRanges.constBegin();
261 for ( ; range_it !=
mRanges.constEnd(); ++range_it )
287 if ( rangeIndex < 0 || rangeIndex >=
mRanges.size() )
289 mRanges[rangeIndex].setSymbol( symbol );
295 if ( rangeIndex < 0 || rangeIndex >=
mRanges.size() )
297 mRanges[rangeIndex].setLabel( label );
303 if ( rangeIndex < 0 || rangeIndex >=
mRanges.size() )
307 if ( rangeIndex == 0 )
309 else if ( rangeIndex ==
mRanges.count() )
314 if ( isDefaultLabel )
322 if ( rangeIndex < 0 || rangeIndex >=
mRanges.size() )
327 if ( rangeIndex == 0 )
329 else if ( rangeIndex ==
mRanges.count() )
334 if ( isDefaultLabel )
342 if ( rangeIndex < 0 || rangeIndex >=
mRanges.size() )
344 mRanges[rangeIndex].setRenderState( value );
350 QString s = u
"GRADUATED: attr %1\n"_s.arg(
mAttrName );
351 for (
int i = 0; i <
mRanges.count(); i++ )
378 toSld( doc, element, context );
384 QVariantMap newProps = oldProps;
392 for ( QgsRangeList::const_iterator it =
mRanges.constBegin(); it !=
mRanges.constEnd(); ++it )
394 if ( !it->toSld( doc, element,
mAttrName, context, first ) )
406 lst.reserve(
mRanges.count() );
409 lst.append( range.symbol() );
442 QList<QgsClassificationRange> _classes = method.
classes( minimum, maximum, classes );
449 const QString &attrName,
457 const QStringList &listForCboPrettyBreaks,
461 Q_UNUSED( listForCboPrettyBreaks )
464 auto r = std::make_unique< QgsGraduatedSymbolRenderer >( attrName,
ranges );
465 r->setSourceSymbol( symbol->
clone() );
466 r->setSourceColorRamp( ramp->
clone() );
468 QString methodId = methodIdFromMode(
mode );
475 method->setLabelTrimTrailingZeroes(
labelFormat.trimTrailingZeroes() );
476 method->setLabelPrecision(
labelFormat.precision() );
478 r->setClassificationMethod( method.release() );
481 r->updateClasses( vlayer, classes, error );
493 QString methodId = methodIdFromMode(
mode );
513 for ( QList<QgsClassificationRange>::iterator it = classes.begin(); it != classes.end(); ++it )
530 QDomElement symbolsElem = element.firstChildElement( u
"symbols"_s );
531 if ( symbolsElem.isNull() )
534 QDomElement rangesElem = element.firstChildElement( u
"ranges"_s );
535 if ( rangesElem.isNull() )
541 QDomElement rangeElem = rangesElem.firstChildElement();
543 QSet<QString> usedUuids;
544 while ( !rangeElem.isNull() )
546 if ( rangeElem.tagName() ==
"range"_L1 )
548 double lowerValue = rangeElem.attribute( u
"lower"_s ).toDouble();
549 double upperValue = rangeElem.attribute( u
"upper"_s ).toDouble();
550 QString symbolName = rangeElem.attribute( u
"symbol"_s );
552 QgsDebugMsgLevel(
"context" + u
"project:layers:%1:legendsymbollabels"_s.arg( context.
currentLayerId() ) +
" source " + rangeElem.attribute( u
"label"_s ), 3 );
554 bool render = rangeElem.attribute( u
"render"_s, u
"true"_s ) !=
"false"_L1;
555 QString uuid = rangeElem.attribute( u
"uuid"_s, QString::number( i++ ) );
556 while ( usedUuids.contains( uuid ) )
558 uuid = QUuid::createUuid().toString();
560 if ( symbolMap.contains( symbolName ) )
562 QgsSymbol *symbol = symbolMap.take( symbolName );
567 rangeElem = rangeElem.nextSiblingElement();
570 QString attrName = element.attribute( u
"attr"_s );
572 auto r = std::make_unique< QgsGraduatedSymbolRenderer >( attrName,
ranges );
574 QString attrMethod = element.attribute( u
"graduatedMethod"_s );
575 if ( !attrMethod.isEmpty() )
588 QDomElement sourceSymbolElem = element.firstChildElement( u
"source-symbol"_s );
589 if ( !sourceSymbolElem.isNull() )
592 if ( sourceSymbolMap.contains( u
"0"_s ) )
594 r->setSourceSymbol( sourceSymbolMap.take( u
"0"_s ) );
600 QDomElement sourceColorRampElem = element.firstChildElement( u
"colorramp"_s );
601 if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( u
"name"_s ) ==
"[source]"_L1 )
608 QDomElement modeElem = element.firstChildElement( u
"mode"_s );
609 QDomElement methodElem = element.firstChildElement( u
"classificationMethod"_s );
610 std::unique_ptr< QgsClassificationMethod > method;
614 if ( !modeElem.isNull() )
616 QString modeString = modeElem.attribute( u
"name"_s );
619 if ( modeString ==
"equal"_L1 )
620 methodId = u
"EqualInterval"_s;
621 else if ( modeString ==
"quantile"_L1 )
622 methodId = u
"Quantile"_s;
623 else if ( modeString ==
"jenks"_L1 )
624 methodId = u
"Jenks"_s;
625 else if ( modeString ==
"stddev"_L1 )
626 methodId = u
"StdDev"_s;
627 else if ( modeString ==
"pretty"_L1 )
628 methodId = u
"Pretty"_s;
633 QDomElement symmetricModeElem = element.firstChildElement( u
"symmetricMode"_s );
634 if ( !symmetricModeElem.isNull() )
637 QString symmetricEnabled = symmetricModeElem.attribute( u
"enabled"_s );
638 QString symmetricPointString = symmetricModeElem.attribute( u
"symmetryPoint"_s );
639 QString astrideEnabled = symmetricModeElem.attribute( u
"astride"_s );
640 method->setSymmetricMode( symmetricEnabled ==
"true"_L1, symmetricPointString.toDouble(), astrideEnabled ==
"true"_L1 );
642 QDomElement labelFormatElem = element.firstChildElement( u
"labelformat"_s );
643 if ( !labelFormatElem.isNull() )
646 QString format = labelFormatElem.attribute( u
"format"_s,
"%1" + u
" - "_s +
"%2" );
647 int precision = labelFormatElem.attribute( u
"decimalplaces"_s, u
"4"_s ).toInt();
648 bool trimTrailingZeroes = labelFormatElem.attribute( u
"trimtrailingzeroes"_s, u
"false"_s ) ==
"true"_L1;
649 method->setLabelFormat( format );
650 method->setLabelPrecision( precision );
651 method->setLabelTrimTrailingZeroes( trimTrailingZeroes );
662 r->setClassificationMethod( method.release() );
664 QDomElement rotationElem = element.firstChildElement( u
"rotation"_s );
665 if ( !rotationElem.isNull() && !rotationElem.attribute( u
"field"_s ).isEmpty() )
671 if ( r->mSourceSymbol )
676 QDomElement sizeScaleElem = element.firstChildElement( u
"sizescale"_s );
677 if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( u
"field"_s ).isEmpty() )
689 QDomElement ddsLegendSizeElem = element.firstChildElement( u
"data-defined-size-legend"_s );
690 if ( !ddsLegendSizeElem.isNull() )
701 rendererElem.setAttribute( u
"type"_s, u
"graduatedSymbol"_s );
702 rendererElem.setAttribute( u
"attr"_s,
mAttrName );
708 QDomElement rangesElem = doc.createElement( u
"ranges"_s );
709 QgsRangeList::const_iterator it =
mRanges.constBegin();
710 for ( ; it !=
mRanges.constEnd(); ++it )
713 QString symbolName = QString::number( i );
716 QDomElement rangeElem = doc.createElement( u
"range"_s );
717 rangeElem.setAttribute( u
"lower"_s, QString::number( range.
lowerValue(),
'f', 15 ) );
718 rangeElem.setAttribute( u
"upper"_s, QString::number( range.
upperValue(),
'f', 15 ) );
719 rangeElem.setAttribute( u
"symbol"_s, symbolName );
720 rangeElem.setAttribute( u
"label"_s, range.
label() );
721 rangeElem.setAttribute( u
"render"_s, range.
renderState() ? u
"true"_s : u
"false"_s );
722 rangeElem.setAttribute( u
"uuid"_s, range.
uuid() );
723 rangesElem.appendChild( rangeElem );
727 rendererElem.appendChild( rangesElem );
731 rendererElem.appendChild( symbolsElem );
739 rendererElem.appendChild( sourceSymbolElem );
746 rendererElem.appendChild( colorRampElem );
751 rendererElem.appendChild( classificationMethodElem );
753 QDomElement rotationElem = doc.createElement( u
"rotation"_s );
754 rendererElem.appendChild( rotationElem );
756 QDomElement sizeScaleElem = doc.createElement( u
"sizescale"_s );
757 rendererElem.appendChild( sizeScaleElem );
761 QDomElement ddsLegendElem = doc.createElement( u
"data-defined-size-legend"_s );
763 rendererElem.appendChild( ddsLegendElem );
788 return u
"EqualInterval"_s;
790 return u
"Quantile"_s;
805 if ( methodId ==
"EqualInterval"_L1 )
807 if ( methodId ==
"Quantile"_L1 )
809 if ( methodId ==
"Jenks"_L1 )
811 if ( methodId ==
"StdDev"_L1 )
813 if ( methodId ==
"Pretty"_L1 )
832 if ( sSize && sSize != ddSize )
835 return baseLegendSymbolItems();
852 lst += baseLegendSymbolItems();
857 return baseLegendSymbolItems();
862 QVariant value = valueForFeature( feature, context );
866 return QSet< QString >();
871 return QSet< QString >() << key;
873 return QSet< QString >();
880 for ( i = 0; i <
mRanges.size(); i++ )
882 if (
mRanges[i].uuid() == key )
898 return u
"(%1 >= %2) AND (%1 <= %3)"_s
937 double min = std::numeric_limits<double>::max();
938 for (
int i = 0; i <
mRanges.count(); i++ )
945 min = std::min( sz, min );
952 double max = std::numeric_limits<double>::min();
953 for (
int i = 0; i <
mRanges.count(); i++ )
960 max = std::max( sz, max );
967 for (
int i = 0; i <
mRanges.count(); i++ )
969 std::unique_ptr<QgsSymbol> symbol(
mRanges.at( i ).symbol() ?
mRanges.at( i ).symbol()->clone() :
nullptr );
970 const double size =
mRanges.count() > 1 ? minSize + i * ( maxSize - minSize ) / (
mRanges.count() - 1 ) : .5 * ( maxSize + minSize );
973 switch ( symbol->type() )
1002 QgsSymbol *symbol = range.symbol() ? range.symbol()->
clone() :
nullptr;
1006 colorValue = (
mRanges.count() > 1 ?
static_cast< double >( i ) / (
mRanges.count() - 1 ) : 0 );
1023 std::unique_ptr<QgsSymbol> symbol( sym->
clone() );
1028 symbol->setColor( range.symbol()->color() );
1055 if ( range.uuid() == key )
1057 return range.renderState();
1065 for (
int i = 0; i <
mRanges.size(); i++ )
1067 if (
mRanges[i].uuid() == key )
1079 for ( i = 0; i <
mRanges.size(); i++ )
1081 if (
mRanges[i].uuid() == key )
1096 for (
int i = 0; i <
mRanges.size(); i++ )
1098 if (
mRanges[i].uuid() == key )
1109 QString label = u
"0.0 - 0.0"_s;
1122 QMutableListIterator< QgsRendererRange > it(
mRanges );
1123 while ( it.hasNext() )
1137 if ( isDefaultLabel )
1139 it.setValue( range );
1141 it.insert( newRange );
1191 for (
int i = 0; i <
mRanges.count(); i++ )
1196 else if ( i ==
mRanges.count() - 1 )
1205 double minClassRange = 0.0;
1208 double range = rendererRange.upperValue() - rendererRange.lowerValue();
1211 if ( minClassRange == 0.0 || range < minClassRange )
1212 minClassRange = range;
1214 if ( minClassRange <= 0.0 )
1221 double nextDpMinRange = 0.0000000099;
1222 while ( ndp > 0 && nextDpMinRange < minClassRange )
1225 nextDpMinRange *= 10.0;
1234 if ( from < 0 || from >=
mRanges.size() || to < 0 || to >=
mRanges.size() )
1251 if ( order == Qt::AscendingOrder )
1264 std::sort( sortedRanges.begin(), sortedRanges.end(),
valueLessThan );
1266 QgsRangeList::const_iterator it = sortedRanges.constBegin();
1267 if ( it == sortedRanges.constEnd() )
1270 if ( ( *it ).upperValue() < ( *it ).lowerValue() )
1273 double prevMax = ( *it ).upperValue();
1276 for ( ; it != sortedRanges.constEnd(); ++it )
1278 if ( ( *it ).upperValue() < ( *it ).lowerValue() )
1281 if ( ( *it ).lowerValue() < prevMax )
1284 prevMax = ( *it ).upperValue();
1292 std::sort( sortedRanges.begin(), sortedRanges.end(),
valueLessThan );
1294 QgsRangeList::const_iterator it = sortedRanges.constBegin();
1295 if ( it == sortedRanges.constEnd() )
1298 double prevMax = ( *it ).upperValue();
1301 for ( ; it != sortedRanges.constEnd(); ++it )
1306 prevMax = ( *it ).upperValue();
1313 return QString::localeAwareCompare( r1.
label(), r2.
label() ) < 0;
1323 if ( order == Qt::AscendingOrder )
1345 QString methodId = methodIdFromMode(
mode );
1367 std::unique_ptr< QgsGraduatedSymbolRenderer > r;
1368 if ( renderer->
type() ==
"graduatedSymbol"_L1 )
1372 else if ( renderer->
type() ==
"categorizedSymbol"_L1 )
1375 if ( categorizedSymbolRenderer )
1377 r = std::make_unique< QgsGraduatedSymbolRenderer >( QString(),
QgsRangeList() );
1387 r->setClassAttribute( categorizedSymbolRenderer->
classAttribute() );
1390 else if ( renderer->
type() ==
"pointDisplacement"_L1 || renderer->
type() ==
"pointCluster"_L1 )
1393 if ( pointDistanceRenderer )
1396 else if ( renderer->
type() ==
"invertedPolygonRenderer"_L1 )
1399 if ( invertedPolygonRenderer )
1408 r = std::make_unique< QgsGraduatedSymbolRenderer >( QString(),
QgsRangeList() );
1413 r->setSourceSymbol(
symbols.at( 0 )->clone() );
1437 return u
"GraduatedColor"_s;
1439 return u
"GraduatedSize"_s;
1444bool QgsGraduatedSymbolRenderer::valueCapturedByEarlierRange(
const int rangeIndex,
const double value )
const
1446 for (
int i = 0; i < rangeIndex; ++i )
1448 if (
mRanges.at( i ).lowerValue() <= value &&
mRanges.at( i ).upperValue() >= value )
QFlags< FeatureRendererFlag > FeatureRendererFlags
Flags controlling behavior of vector feature renderers.
GraduatedMethod
Methods for modifying symbols by range in a graduated symbol renderer.
@ Size
Alter size of symbols.
@ Color
Alter color of symbols.
@ 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 QgsClassificationMethodRegistry * classificationMethodRegistry()
Returns the application's classification methods registry, used in graduated renderer.
A feature renderer which represents features using a list of renderer categories.
QgsSymbol * sourceSymbol()
Returns the renderer's source symbol, which is the base symbol used for the each categories' symbol b...
QString classAttribute() const
Returns the class attribute for the renderer, which is the field name or expression string from the l...
QgsColorRamp * sourceColorRamp()
Returns the source color ramp, from which each categories' color is derived.
static const QString METHOD_ID
A classification method which uses equal width intervals.
std::unique_ptr< QgsClassificationMethod > method(const QString &id)
Returns a new instance of the method for the given id.
An abstract class for implementations of classification methods.
static void makeBreaksSymmetric(QList< double > &breaks, double symmetryPoint, bool astride)
Remove the breaks that are above the existing opposite sign classes to keep colors symmetrically bala...
static std::unique_ptr< QgsClassificationMethod > create(const QDomElement &element, const QgsReadWriteContext &context)
Reads the DOM element and return a new classification method from it.
Q_DECL_DEPRECATED QList< QgsClassificationRange > classes(const QgsVectorLayer *layer, const QString &expression, int nclasses)
This will calculate the classes for a given layer to define the classes.
void setSymmetricMode(bool enabled, double symmetryPoint=0, bool symmetryAstride=false)
Defines if the symmetric mode is enables and configures its parameters.
ClassPosition
Defines the class position.
@ LowerBound
The class is at the lower bound.
@ UpperBound
The class is at the upper bound.
@ Inner
The class is not at a bound.
static QList< double > rangesToBreaks(const QList< QgsClassificationRange > &classes)
Transforms a list of classes to a list of breaks.
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.
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.
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.
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.
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 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.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Container of fields for a vector layer.
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
QgsSymbol * sourceSymbol()
Returns the renderer's source symbol, which is the base symbol used for the each classes' symbol befo...
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
Stores renderer properties to an XML element.
~QgsGraduatedSymbolRenderer() override
void updateSymbols(QgsSymbol *sym)
Update all the symbols but leave breaks and colors.
const QgsRendererRange * rangeForValue(double value) const
Returns the renderer range matching the provided value, or nullptr if no range matches the value.
QgsColorRamp * sourceColorRamp()
Returns the source color ramp, from which each classes' color is derived.
bool updateRangeSymbol(int rangeIndex, QgsSymbol *symbol)
bool rangeOverlapsEarlierRange(int rangeIndex) const
Returns true if the range at the specified rangeIndex overlaps with any range positioned earlier in t...
void addBreak(double breakValue, bool updateSymbols=true)
Add a breakpoint by splitting existing classes so that the specified value becomes a break between tw...
Q_DECL_DEPRECATED void setAstride(bool astride)
Set if we want a central class astride the pivot value.
void setClassificationMethod(QgsClassificationMethod *method)
Defines the classification method This will take ownership of the method.
static Q_DECL_DEPRECATED QList< double > calcEqualIntervalBreaks(double minimum, double maximum, int classes, bool useSymmetricMode, double symmetryPoint, bool astride)
Compute the equal interval classification.
QgsGraduatedSymbolRenderer * clone() const override
Create a deep copy of this renderer.
std::unique_ptr< QgsDataDefinedSizeLegend > mDataDefinedSizeLegend
static Q_DECL_DEPRECATED void makeBreaksSymmetric(QList< double > &breaks, double symmetryPoint, bool astride)
Remove the breaks that are above the existing opposite sign classes to keep colors symmetrically bala...
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
double maxSymbolSize() const
Returns the max symbol size when graduated by size.
Q_DECL_DEPRECATED bool useSymmetricMode() const
Returns if we want to classify symmetric around a given value.
bool updateRangeLabel(int rangeIndex, const QString &label)
void addClass(QgsSymbol *symbol)
Adds a class to the renderer, with the specified symbol.
QgsClassificationMethod * classificationMethod() const
Returns the classification method.
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
void sortByValue(Qt::SortOrder order=Qt::AscendingOrder)
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.
void checkLegendSymbolItem(const QString &key, bool state=true) override
Sets whether the legend symbology item with the specified ley should be checked.
std::unique_ptr< QgsSymbol > mSourceSymbol
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
Qgis::FeatureRendererFlags flags() const override
Returns flags associated with the renderer.
void setGraduatedMethod(Qgis::GraduatedMethod method)
Set the method used for graduation (either size or color).
Q_DECL_DEPRECATED void setMode(Mode mode)
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
bool rangesOverlap() const
Tests whether classes assigned to the renderer have ranges which overlap.
static std::unique_ptr< QgsGraduatedSymbolRenderer > convertFromRenderer(const QgsFeatureRenderer *renderer)
creates a QgsGraduatedSymbolRenderer from an existing renderer.
std::shared_ptr< QgsClassificationMethod > mClassificationMethod
Q_DECL_DEPRECATED bool astride() const
Returns if we want to have a central class astride the pivot value.
Q_DECL_DEPRECATED void setLabelFormat(const QgsRendererRangeLabelFormat &labelFormat, bool updateRanges=false)
Set the label format used to generate default classification labels.
Q_DECL_DEPRECATED void updateClasses(QgsVectorLayer *vlayer, Mode mode, int nclasses, bool useSymmetricMode=false, double symmetryPoint=0.0, bool astride=false)
Recalculate classes for a layer.
QString dump() const override
Returns debug information about this renderer.
bool updateRangeUpperValue(int rangeIndex, double value)
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...
QString legendKeyForValue(double value) const
Returns the matching legend key for a value.
void setSourceColorRamp(QgsColorRamp *ramp)
Sets the source color ramp.
void setSourceSymbol(QgsSymbol *sym)
Sets the source symbol for the renderer, which is the base symbol used for the each classes' symbol b...
bool rangeLowerBoundIsInclusive(int rangeIndex) const
Returns true if the lower bound of the range at the specified rangeIndex is inclusive,...
bool legendSymbolItemChecked(const QString &key) override
Returns true if the legend symbology item with the specified key is checked.
bool updateRangeLowerValue(int rangeIndex, double value)
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
Returns true if symbology items in legend are checkable.
void moveClass(int from, int to)
Moves the category at index position from to index position to.
void sortByLabel(Qt::SortOrder order=Qt::AscendingOrder)
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
void updateRangeLabels()
Updates the labels of the ranges.
bool updateRangeRenderState(int rangeIndex, bool render)
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
std::unique_ptr< QgsColorRamp > mSourceColorRamp
bool rangeUpperBoundIsInclusive(int rangeIndex) const
Returns true if the upper bound of the range at the specified rangeIndex is inclusive,...
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
QgsDataDefinedSizeLegend * dataDefinedSizeLegend() const
Returns configuration of appearance of legend when using data-defined size for marker symbols.
void updateColorRamp(QgsColorRamp *ramp=nullptr)
Update the color ramp used.
Q_DECL_DEPRECATED Mode mode() const
void deleteClass(int idx)
QgsGraduatedSymbolRenderer(const QString &attrName=QString(), const QgsRangeList &ranges=QgsRangeList())
void setLegendSymbolItemLabel(const QString &key, const QString &label) override
Sets the label for a legend symbol item.
Qgis::GraduatedMethod mGraduatedMethod
double minSymbolSize() const
Returns the min symbol size when graduated by size.
Qgis::GraduatedMethod graduatedMethod() const
Returns the method used for graduation (either size or color).
static std::unique_ptr< QgsFeatureRenderer > create(QDomElement &element, const QgsReadWriteContext &context)
create renderer from XML element
bool filterNeedsGeometry() const override
Returns true if this renderer requires the geometry to apply the filter.
int mAttrNum
attribute index (derived from attribute name in startRender)
Q_DECL_DEPRECATED void setSymmetryPoint(double symmetryPoint)
Set the pivot point.
std::unique_ptr< QgsExpression > mExpression
static QString graduatedMethodStr(Qgis::GraduatedMethod method)
void setSymbolSizes(double minSize, double maxSize)
set varying symbol size for classes
void calculateLabelPrecision(bool updateRanges=true)
Reset the label decimal places to a numberbased on the minimum class interval.
void setDataDefinedSizeLegend(QgsDataDefinedSizeLegend *settings)
Configures appearance of legend when renderer is configured to use data-defined size for marker symbo...
const QgsRangeList & ranges() const
Returns a list of all ranges used in the classification.
Q_DECL_DEPRECATED QgsRendererRangeLabelFormat labelFormat() const
Returns the label format used to generate default classification labels.
static Q_DECL_DEPRECATED QgsGraduatedSymbolRenderer * createRenderer(QgsVectorLayer *vlayer, const QString &attrName, int classes, Mode mode, QgsSymbol *symbol, QgsColorRamp *ramp, const QgsRendererRangeLabelFormat &legendFormat=QgsRendererRangeLabelFormat(), bool useSymmetricMode=false, double symmetryPoint=0.0, const QStringList &listForCboPrettyBreaks=QStringList(), bool astride=false)
Creates a new graduated renderer.
Q_DECL_DEPRECATED double symmetryPoint() const
Returns the pivot value for symmetric classification.
Q_DECL_DEPRECATED void setUseSymmetricMode(bool useSymmetricMode)
Set if we want to classify symmetric around a given value.
QgsSymbol * symbolForValue(double value) const
Gets the symbol which is used to represent value.
bool rangesHaveGaps() const
Tests whether classes assigned to the renderer have gaps between the ranges.
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 ...
Constrained random color ramp, which returns random colors based on preset parameters.
A line symbol type, for rendering LineString and MultiLineString geometries.
void setWidth(double width) const
Sets the width for the whole line symbol.
double width() const
Returns the estimated width for the whole symbol, which is the maximum width of all marker symbol lay...
A marker symbol type, for rendering Point and MultiPoint geometries.
void setSize(double size) const
Sets the size for the whole symbol.
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
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.
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 a value range for a QgsGraduatedSymbolRenderer.
void setUpperValue(double upperValue)
Sets the upper bound of the range.
QString label() const
Returns the label used for the range.
void setSymbol(QgsSymbol *s)
Sets the symbol used for the range.
QgsSymbol * symbol() const
Returns the symbol used for the range.
void setLabel(const QString &label)
Sets the label used for the range.
bool renderState() const
Returns true if the range should be rendered.
double upperValue() const
Returns the upper bound of the range.
void setLowerValue(double lowerValue)
Sets the lower bound of the range.
QString uuid() const
Returns the unique identifier for this range.
double lowerValue() const
Returns the lower bound of the range.
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.
static std::unique_ptr< 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, const 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 std::unique_ptr< QgsSymbol > defaultSymbol(Qgis::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
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.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
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)
bool valueLessThan(const QgsRendererRange &r1, const QgsRendererRange &r2)
bool labelGreaterThan(const QgsRendererRange &r1, const QgsRendererRange &r2)
bool labelLessThan(const QgsRendererRange &r1, const QgsRendererRange &r2)
bool valueGreaterThan(const QgsRendererRange &r1, const QgsRendererRange &r2)
QList< QgsLegendSymbolItem > QgsLegendSymbolList
#define QgsDebugMsgLevel(str, level)
#define RENDERER_TAG_NAME
QMap< QString, QgsSymbol * > QgsSymbolMap
QList< QgsSymbol * > QgsSymbolList
QList< QgsRendererRange > QgsRangeList
Contains information relating to the style entity currently being visited.