37 #include <QDomDocument> 38 #include <QDomElement> 45 : mLowerValue( lowerValue )
46 , mUpperValue( upperValue )
142 if ( !
mSymbol || props.value( QStringLiteral(
"attribute" ), QLatin1String(
"" ) ).isEmpty() )
145 QString attrName = props[ QStringLiteral(
"attribute" )];
147 QDomElement ruleElem = doc.createElement( QStringLiteral(
"se:Rule" ) );
148 element.appendChild( ruleElem );
150 QDomElement nameElem = doc.createElement( QStringLiteral(
"se:Name" ) );
151 nameElem.appendChild( doc.createTextNode(
mLabel ) );
152 ruleElem.appendChild( nameElem );
154 QDomElement descrElem = doc.createElement( QStringLiteral(
"se:Description" ) );
155 QDomElement titleElem = doc.createElement( QStringLiteral(
"se:Title" ) );
157 titleElem.appendChild( doc.createTextNode( !
mLabel.isEmpty() ?
mLabel : descrStr ) );
158 descrElem.appendChild( titleElem );
159 ruleElem.appendChild( descrElem );
162 QString filterFunc = QStringLiteral(
"\"%1\" %2 %3 AND \"%1\" <= %4" )
163 .arg( attrName.replace(
'\"', QLatin1String(
"\"\"" ) ),
164 firstRange ? QStringLiteral(
">=" ) : QStringLiteral(
">" ),
169 mSymbol->toSld( doc, ruleElem, props );
178 : mFormat( QStringLiteral(
" %1 - %2 " ) )
179 , mReTrailingZeroes(
"[.,]?0*$" )
180 , mReNegativeZero(
"^\\-0(?:[.,]0*)?$" )
204 return !( *
this == other );
214 while ( precision < 0 )
231 QString valueStr = QString::number( value,
'f',
mPrecision );
235 valueStr = valueStr.mid( 1 );
240 QString valueStr = QString::number( value *
mNumberScale,
'f', 0 );
241 if ( valueStr == QLatin1String(
"-0" ) )
243 if ( valueStr != QLatin1String(
"0" ) )
255 return legend.replace( QLatin1String(
"%1" ), lowerStr ).replace( QLatin1String(
"%2" ), upperStr );
260 mFormat = element.attribute( QStringLiteral(
"format" ),
261 element.attribute( QStringLiteral(
"prefix" ), QStringLiteral(
" " ) ) +
"%1" +
262 element.attribute( QStringLiteral(
"separator" ), QStringLiteral(
" - " ) ) +
"%2" +
263 element.attribute( QStringLiteral(
"suffix" ), QStringLiteral(
" " ) )
265 setPrecision( element.attribute( QStringLiteral(
"decimalplaces" ), QStringLiteral(
"4" ) ).toInt() );
266 mTrimTrailingZeroes = element.attribute( QStringLiteral(
"trimtrailingzeroes" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" );
271 element.setAttribute( QStringLiteral(
"format" ),
mFormat );
272 element.setAttribute( QStringLiteral(
"decimalplaces" ),
mPrecision );
273 element.setAttribute( QStringLiteral(
"trimtrailingzeroes" ),
mTrimTrailingZeroes ? QStringLiteral(
"true" ) : QStringLiteral(
"false" ) );
280 , mAttrName( attrName )
323 return QString::number( i );
342 if ( mAttrNum < 0 || mAttrNum >= attrs.count() )
356 QVariant value = valueForFeature( feature, context );
359 if ( value.isNull() )
405 QSet<QString> attributes;
417 QgsRangeList::const_iterator range_it =
mRanges.constBegin();
418 for ( ; range_it !=
mRanges.constEnd(); ++range_it )
431 if ( rangeIndex < 0 || rangeIndex >=
mRanges.size() )
433 mRanges[rangeIndex].setSymbol( symbol );
439 if ( rangeIndex < 0 || rangeIndex >=
mRanges.size() )
441 mRanges[rangeIndex].setLabel( label );
447 if ( rangeIndex < 0 || rangeIndex >=
mRanges.size() )
458 if ( rangeIndex < 0 || rangeIndex >=
mRanges.size() )
469 if ( rangeIndex < 0 || rangeIndex >=
mRanges.size() )
471 mRanges[rangeIndex].setRenderState( value );
477 QString s = QStringLiteral(
"GRADUATED: attr %1\n" ).arg(
mAttrName );
478 for (
int i = 0; i <
mRanges.count(); i++ )
504 newProps[ QStringLiteral(
"attribute" )] =
mAttrName;
509 for ( QgsRangeList::const_iterator it =
mRanges.constBegin(); it !=
mRanges.constEnd(); ++it )
511 it->toSld( doc, element, newProps, first );
520 lst.reserve(
mRanges.count() );
523 lst.append( range.
symbol() );
528 static QList<double> _calcEqualIntervalBreaks(
double minimum,
double maximum,
int classes )
536 double step = ( maximum - minimum ) / classes;
538 QList<double> breaks;
539 double value = minimum;
540 breaks.reserve( classes );
541 for (
int i = 0; i < classes; i++ )
544 breaks.append( value );
549 breaks[classes - 1] = maximum;
554 static QList<double> _calcQuantileBreaks( QList<double> values,
int classes )
565 std::sort( values.begin(), values.end() );
567 QList<double> breaks;
570 if ( values.isEmpty() )
573 int n = values.count();
574 double Xq = n > 0 ? values[0] : 0.0;
576 breaks.reserve( classes );
577 for (
int i = 1; i < classes; i++ )
581 double q = i /
static_cast< double >( classes );
582 double a = q * ( n - 1 );
583 int aa =
static_cast< int >( a );
586 Xq = ( 1 - r ) * values[aa] + r * values[aa + 1];
591 breaks.append( values[ n - 1 ] );
596 static QList<double> _calcStdDevBreaks( QList<double> values,
int classes, QList<double> &labels )
607 if ( values.isEmpty() )
608 return QList<double>();
612 int n = values.count();
613 double minimum = values[0];
614 double maximum = values[0];
616 for (
int i = 0; i < n; i++ )
619 minimum = std::min( values[i], minimum );
620 maximum = std::max( values[i], maximum );
622 mean = mean /
static_cast< double >( n );
625 for (
int i = 0; i < n; i++ )
627 sd = values[i] - mean;
630 stdDev = std::sqrt( stdDev / n );
633 for (
int i = 0; i < breaks.count(); i++ )
635 labels.append( breaks[i] );
636 breaks[i] = ( breaks[i] * stdDev ) + mean;
642 static QList<double> _calcJenksBreaks( QList<double> values,
int classes,
643 double minimum,
double maximum,
644 int maximumSize = 3000 )
656 if ( values.isEmpty() )
657 return QList<double>();
661 return QList<double>() << maximum;
664 if ( classes >= values.size() )
669 QVector<double> sample;
672 if ( values.size() > maximumSize )
678 sample.resize( std::max( maximumSize, values.size() / 10 ) );
680 QgsDebugMsg( QString(
"natural breaks (jenks) sample size: %1" ).arg( sample.size() ) );
681 QgsDebugMsg( QString(
"values:%1" ).arg( values.size() ) );
683 sample[ 0 ] = minimum;
684 sample[ 1 ] = maximum;
685 for (
int i = 2; i < sample.size(); i++ )
689 int j = std::floor( r / RAND_MAX * ( values.size() - 1 ) );
690 sample[ i ] = values[ j ];
695 sample = values.toVector();
698 int n = sample.size();
701 std::sort( sample.begin(), sample.end() );
703 QVector< QVector<int> > matrixOne( n + 1 );
704 QVector< QVector<double> > matrixTwo( n + 1 );
706 for (
int i = 0; i <= n; i++ )
708 matrixOne[i].resize( classes + 1 );
709 matrixTwo[i].resize( classes + 1 );
712 for (
int i = 1; i <= classes; i++ )
716 matrixTwo[0][i] = 0.0;
717 for (
int j = 2; j <= n; j++ )
719 matrixTwo[j][i] = std::numeric_limits<double>::max();
723 for (
int l = 2; l <= n; l++ )
731 for (
int m = 1; m <= l; m++ )
735 double val = sample[ i3 - 1 ];
741 v = s2 - ( s1 * s1 ) / static_cast< double >( w );
745 for (
int j = 2; j <= classes; j++ )
747 if ( matrixTwo[l][j] >= v + matrixTwo[i4][j - 1] )
749 matrixOne[l][j] = i4;
750 matrixTwo[l][j] = v + matrixTwo[i4][j - 1];
759 QVector<double> breaks( classes );
760 breaks[classes - 1] = sample[n - 1];
762 for (
int j = classes, k = n; j >= 2; j-- )
764 int id = matrixOne[k][j] - 1;
765 breaks[j - 2] = sample[id];
766 k = matrixOne[k][j] - 1;
769 return breaks.toList();
775 const QString &attrName,
806 QList<double> values;
807 bool valuesLoaded =
false;
817 if ( !ok || values.isEmpty() )
820 auto result = std::minmax_element( values.begin(), values.end() );
821 minimum = *result.first;
822 maximum = *result.second;
831 QgsDebugMsg( QString(
"min %1 // max %2" ).arg( minimum ).arg( maximum ) );
832 QList<double> breaks;
833 QList<double> labels;
836 breaks = _calcEqualIntervalBreaks( minimum, maximum, nclasses );
838 else if ( mode ==
Pretty )
853 breaks = _calcQuantileBreaks( values, nclasses );
855 else if ( mode ==
Jenks )
857 breaks = _calcJenksBreaks( values, nclasses, minimum, maximum );
859 else if ( mode ==
StdDev )
861 breaks = _calcStdDevBreaks( values, nclasses, labels );
869 double lower, upper = minimum;
876 for ( QList<double>::iterator it = breaks.begin(); it != breaks.end(); ++it, ++i )
886 label =
"< " + QString::number( labels[i],
'f', 2 ) +
" Std Dev";
888 else if ( i == labels.count() - 1 )
890 label =
">= " + QString::number( labels[i - 1],
'f', 2 ) +
" Std Dev";
894 label = QString::number( labels[i - 1],
'f', 2 ) +
" Std Dev" +
" - " + QString::number( labels[i],
'f', 2 ) +
" Std Dev";
909 QDomElement symbolsElem = element.firstChildElement( QStringLiteral(
"symbols" ) );
910 if ( symbolsElem.isNull() )
913 QDomElement rangesElem = element.firstChildElement( QStringLiteral(
"ranges" ) );
914 if ( rangesElem.isNull() )
920 QDomElement rangeElem = rangesElem.firstChildElement();
921 while ( !rangeElem.isNull() )
923 if ( rangeElem.tagName() == QLatin1String(
"range" ) )
925 double lowerValue = rangeElem.attribute( QStringLiteral(
"lower" ) ).toDouble();
926 double upperValue = rangeElem.attribute( QStringLiteral(
"upper" ) ).toDouble();
927 QString symbolName = rangeElem.attribute( QStringLiteral(
"symbol" ) );
928 QString label = rangeElem.attribute( QStringLiteral(
"label" ) );
929 bool render = rangeElem.attribute( QStringLiteral(
"render" ), QStringLiteral(
"true" ) ) != QLatin1String(
"false" );
930 if ( symbolMap.contains( symbolName ) )
932 QgsSymbol *symbol = symbolMap.take( symbolName );
933 ranges.append(
QgsRendererRange( lowerValue, upperValue, symbol, label, render ) );
936 rangeElem = rangeElem.nextSiblingElement();
939 QString attrName = element.attribute( QStringLiteral(
"attr" ) );
943 QString attrMethod = element.attribute( QStringLiteral(
"graduatedMethod" ) );
944 if ( !attrMethod.isEmpty() )
957 QDomElement sourceSymbolElem = element.firstChildElement( QStringLiteral(
"source-symbol" ) );
958 if ( !sourceSymbolElem.isNull() )
961 if ( sourceSymbolMap.contains( QStringLiteral(
"0" ) ) )
969 QDomElement sourceColorRampElem = element.firstChildElement( QStringLiteral(
"colorramp" ) );
970 if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( QStringLiteral(
"name" ) ) == QLatin1String(
"[source]" ) )
976 QDomElement modeElem = element.firstChildElement( QStringLiteral(
"mode" ) );
977 if ( !modeElem.isNull() )
979 QString modeString = modeElem.attribute( QStringLiteral(
"name" ) );
980 if ( modeString == QLatin1String(
"equal" ) )
982 else if ( modeString == QLatin1String(
"quantile" ) )
984 else if ( modeString == QLatin1String(
"jenks" ) )
986 else if ( modeString == QLatin1String(
"stddev" ) )
988 else if ( modeString == QLatin1String(
"pretty" ) )
992 QDomElement rotationElem = element.firstChildElement( QStringLiteral(
"rotation" ) );
993 if ( !rotationElem.isNull() && !rotationElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
1005 QDomElement sizeScaleElem = element.firstChildElement( QStringLiteral(
"sizescale" ) );
1006 if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( QStringLiteral(
"field" ) ).isEmpty() )
1012 sizeScaleElem.attribute( QStringLiteral(
"field" ) ) );
1018 sizeScaleElem.attribute( QStringLiteral(
"field" ) ) );
1022 QDomElement labelFormatElem = element.firstChildElement( QStringLiteral(
"labelformat" ) );
1023 if ( ! labelFormatElem.isNull() )
1030 QDomElement ddsLegendSizeElem = element.firstChildElement( QStringLiteral(
"data-defined-size-legend" ) );
1031 if ( !ddsLegendSizeElem.isNull() )
1043 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"graduatedSymbol" ) );
1044 rendererElem.setAttribute( QStringLiteral(
"symbollevels" ), (
mUsingSymbolLevels ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
1045 rendererElem.setAttribute( QStringLiteral(
"forceraster" ), (
mForceRaster ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
1046 rendererElem.setAttribute( QStringLiteral(
"attr" ),
mAttrName );
1052 QDomElement rangesElem = doc.createElement( QStringLiteral(
"ranges" ) );
1053 QgsRangeList::const_iterator it =
mRanges.constBegin();
1054 for ( ; it !=
mRanges.constEnd(); ++it )
1057 QString symbolName = QString::number( i );
1058 symbols.insert( symbolName, range.
symbol() );
1060 QDomElement rangeElem = doc.createElement( QStringLiteral(
"range" ) );
1061 rangeElem.setAttribute( QStringLiteral(
"lower" ), QString::number( range.
lowerValue(),
'f', 15 ) );
1062 rangeElem.setAttribute( QStringLiteral(
"upper" ), QString::number( range.
upperValue(),
'f', 15 ) );
1063 rangeElem.setAttribute( QStringLiteral(
"symbol" ), symbolName );
1064 rangeElem.setAttribute( QStringLiteral(
"label" ), range.
label() );
1065 rangeElem.setAttribute( QStringLiteral(
"render" ), range.
renderState() ? QStringLiteral(
"true" ) : QStringLiteral(
"false" ) );
1066 rangesElem.appendChild( rangeElem );
1070 rendererElem.appendChild( rangesElem );
1074 rendererElem.appendChild( symbolsElem );
1080 sourceSymbols.insert( QStringLiteral(
"0" ),
mSourceSymbol.get() );
1082 rendererElem.appendChild( sourceSymbolElem );
1089 rendererElem.appendChild( colorRampElem );
1095 modeString = QStringLiteral(
"equal" );
1097 modeString = QStringLiteral(
"quantile" );
1099 modeString = QStringLiteral(
"jenks" );
1101 modeString = QStringLiteral(
"stddev" );
1103 modeString = QStringLiteral(
"pretty" );
1104 if ( !modeString.isEmpty() )
1106 QDomElement modeElem = doc.createElement( QStringLiteral(
"mode" ) );
1107 modeElem.setAttribute( QStringLiteral(
"name" ), modeString );
1108 rendererElem.appendChild( modeElem );
1111 QDomElement rotationElem = doc.createElement( QStringLiteral(
"rotation" ) );
1112 rendererElem.appendChild( rotationElem );
1114 QDomElement sizeScaleElem = doc.createElement( QStringLiteral(
"sizescale" ) );
1115 rendererElem.appendChild( sizeScaleElem );
1117 QDomElement labelFormatElem = doc.createElement( QStringLiteral(
"labelformat" ) );
1119 rendererElem.appendChild( labelFormatElem );
1126 QDomElement
orderBy = doc.createElement( QStringLiteral(
"orderby" ) );
1128 rendererElem.appendChild( orderBy );
1130 rendererElem.setAttribute( QStringLiteral(
"enableorderby" ), (
mOrderByEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
1134 QDomElement ddsLegendElem = doc.createElement( QStringLiteral(
"data-defined-size-legend" ) );
1136 rendererElem.appendChild( ddsLegendElem );
1139 return rendererElem;
1165 if ( sSize && sSize != ddSize )
1168 return baseLegendSymbolItems();
1185 lst += baseLegendSymbolItems();
1190 return baseLegendSymbolItems();
1195 QVariant value = valueForFeature( feature, context );
1198 if ( value.isNull() )
1199 return QSet< QString >();
1203 if ( !key.isNull() )
1204 return QSet< QString >() << key;
1206 return QSet< QString >();
1233 double min = std::numeric_limits<double>::max();
1234 for (
int i = 0; i <
mRanges.count(); i++ )
1238 sz = static_cast< QgsMarkerSymbol * >(
mRanges[i].symbol() )->size();
1240 sz = static_cast< QgsLineSymbol * >(
mRanges[i].symbol() )->width();
1241 min = std::min( sz, min );
1248 double max = std::numeric_limits<double>::min();
1249 for (
int i = 0; i <
mRanges.count(); i++ )
1253 sz = static_cast< QgsMarkerSymbol * >(
mRanges[i].symbol() )->size();
1255 sz = static_cast< QgsLineSymbol * >(
mRanges[i].symbol() )->width();
1256 max = std::max( sz, max );
1263 for (
int i = 0; i <
mRanges.count(); i++ )
1265 std::unique_ptr<QgsSymbol> symbol(
mRanges.at( i ).symbol() ?
mRanges.at( i ).symbol()->clone() : nullptr );
1266 const double size =
mRanges.count() > 1
1267 ? minSize + i * ( maxSize - minSize ) / (
mRanges.count() - 1 )
1268 : .5 * ( maxSize + minSize );
1270 static_cast< QgsMarkerSymbol * >( symbol.get() )->setSize( size );
1272 static_cast< QgsLineSymbol * >( symbol.get() )->setWidth( size );
1293 colorValue = (
mRanges.count() > 1 ?
static_cast< double >( i ) / (
mRanges.count() - 1 ) : 0 );
1311 std::unique_ptr<QgsSymbol> symbol( sym->
clone() );
1319 static_cast<QgsMarkerSymbol *>( symbol.get() )->setSize(
1320 static_cast<QgsMarkerSymbol *>( range.
symbol() )->size() );
1322 static_cast<QgsLineSymbol *>( symbol.get() )->setWidth(
1323 static_cast<QgsLineSymbol *>( range.
symbol() )->width() );
1339 int index = key.toInt( &ok );
1340 if ( ok && index >= 0 && index <
mRanges.size() )
1341 return mRanges.at( index ).renderState();
1349 int index = key.toInt( &ok );
1357 int index = key.toInt( &ok );
1367 QString label = QStringLiteral(
"0.0 - 0.0" );
1380 QMutableListIterator< QgsRendererRange > it(
mRanges );
1381 while ( it.hasNext() )
1396 it.setValue( range );
1398 it.insert( newRange );
1403 if ( updateSymbols )
1436 for ( QgsRangeList::iterator it =
mRanges.begin(); it !=
mRanges.end(); ++it )
1448 double minClassRange = 0.0;
1454 if ( minClassRange == 0.0 || range < minClassRange )
1455 minClassRange = range;
1457 if ( minClassRange <= 0.0 )
1464 double nextDpMinRange = 0.0000000099;
1465 while ( ndp > 0 && nextDpMinRange < minClassRange )
1468 nextDpMinRange *= 10.0;
1476 if ( from < 0 || from >=
mRanges.size() || to < 0 || to >=
mRanges.size() )
1493 if ( order == Qt::AscendingOrder )
1506 std::sort( sortedRanges.begin(), sortedRanges.end(),
valueLessThan );
1508 QgsRangeList::const_iterator it = sortedRanges.constBegin();
1509 if ( it == sortedRanges.constEnd() )
1512 if ( ( *it ).upperValue() < ( *it ).lowerValue() )
1515 double prevMax = ( *it ).upperValue();
1518 for ( ; it != sortedRanges.constEnd(); ++it )
1520 if ( ( *it ).upperValue() < ( *it ).lowerValue() )
1523 if ( ( *it ).lowerValue() < prevMax )
1526 prevMax = ( *it ).upperValue();
1534 std::sort( sortedRanges.begin(), sortedRanges.end(),
valueLessThan );
1536 QgsRangeList::const_iterator it = sortedRanges.constBegin();
1537 if ( it == sortedRanges.constEnd() )
1540 double prevMax = ( *it ).upperValue();
1543 for ( ; it != sortedRanges.constEnd(); ++it )
1548 prevMax = ( *it ).upperValue();
1555 return QString::localeAwareCompare( r1.
label(), r2.
label() ) < 0;
1565 if ( order == Qt::AscendingOrder )
1578 if ( renderer->
type() == QLatin1String(
"graduatedSymbol" ) )
1582 else if ( renderer->
type() == QLatin1String(
"pointDisplacement" ) || renderer->
type() == QLatin1String(
"pointCluster" ) )
1585 if ( pointDistanceRenderer )
1588 else if ( renderer->
type() == QLatin1String(
"invertedPolygonRenderer" ) )
1591 if ( invertedPolygonRenderer )
1603 if ( !symbols.isEmpty() )
1630 return "GraduatedColor";
1632 return "GraduatedSize";
An abstract base class for distance based point renderers (e.g., clusterer and displacement renderers...
int lookupField(const QString &fieldName) const
Look up field's index from the field name.
Class for parsing and evaluation of expressions (formerly called "search strings").
const QgsRendererRangeLabelFormat & labelFormat() const
Returns the label format used to generate default classification labels.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
static QgsGraduatedSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
creates a QgsGraduatedSymbolRenderer from an existing renderer.
The class is used as a container of context for various read/write operations on other objects...
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
double rendererScale() const
Returns the renderer map scale.
static QgsSymbol::ScaleMethod decodeScaleMethod(const QString &str)
std::unique_ptr< QgsSymbol > mSourceSymbol
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QgsFeatureRequest::OrderBy mOrderBy
static bool createFunctionElement(QDomDocument &doc, QDomElement &element, const QString &function)
bool labelLessThan(const QgsRendererRange &r1, const QgsRendererRange &r2)
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
create renderer from XML element
bool updateRangeUpperValue(int rangeIndex, double value)
QList< QgsRendererRange > QgsRangeList
bool rangesOverlap() const
Tests whether classes assigned to the renderer have ranges which overlap.
void setLabel(const QString &label)
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
QVariant minimumValue(int index) const override
Returns the minimum value for an attribute column or an invalid variant in case of error...
static QList< double > getDoubleValues(const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly=false, int *nullCount=nullptr, QgsFeedback *feedback=nullptr)
Fetches all double values from a specified field name or expression.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
Abstract base class for color ramps.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
void addBreak(double breakValue, bool updateSymbols=true)
Add a breakpoint by splitting existing classes so that the specified value becomes a break between tw...
static QDomElement saveColorRamp(const QString &name, QgsColorRamp *ramp, QDomDocument &doc)
Encodes a color ramp's settings to an XML element.
void setGraduatedMethod(GraduatedMethod method)
set the method used for graduation (either size or color)
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Container of fields for a vector layer.
void setRenderState(bool render)
#define RENDERER_TAG_NAME
void setUsingSymbolLevels(bool usingSymbolLevels)
static void clearSymbolMap(QgsSymbolMap &symbols)
QgsRendererRange & operator=(QgsRendererRange range)
QgsPaintEffect * mPaintEffect
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void setSymbolSizes(double minSize, double maxSize)
set varying symbol size for classes
bool operator<(const QgsRendererRange &other) const
QgsLegendSymbolList legendSymbolList() const
Generates legend symbol items according to the configuration.
static const char * graduatedMethodStr(GraduatedMethod method)
std::unique_ptr< QgsExpression > mExpression
void setUpperValue(double upperValue)
void addClass(QgsSymbol *symbol)
QMap< QString, QString > QgsStringMap
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
bool rangesHaveGaps() const
Tests whether classes assigned to the renderer have gaps between the ranges.
void checkLegendSymbolItem(const QString &key, bool state=true) override
item in symbology was checked
void sortByValue(Qt::SortOrder order=Qt::AscendingOrder)
double lowerValue() const
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
bool updateRangeSymbol(int rangeIndex, QgsSymbol *symbol)
GraduatedMethod mGraduatedMethod
QList< QgsSymbol * > QgsSymbolList
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns new default symbol for specified geometry type.
void updateColorRamp(QgsColorRamp *ramp=nullptr)
Update the color ramp used.
QgsFields fields() const override
Returns the list of fields of this layer.
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted...
bool updateRangeLowerValue(int rangeIndex, double value)
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.
void setLowerValue(double lowerValue)
bool labelGreaterThan(const QgsRendererRange &r1, const QgsRendererRange &r2)
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QgsColorRamp * sourceColorRamp()
Returns the source color ramp, from which each classes' color is derived.
void updateFromSymbolAndProperty(const QgsMarkerSymbol *symbol, const QgsProperty &ddSize)
Updates the list of classes, source symbol and title label from given symbol and property.
static QgsColorRamp * loadColorRamp(QDomElement &element)
Creates a color ramp from the settings encoded in an XML element.
static void convertSymbolSizeScale(QgsSymbol *symbol, QgsSymbol::ScaleMethod method, const QString &field)
QgsSymbol * symbol() const
A store for object properties.
bool valueLessThan(const QgsRendererRange &r1, const QgsRendererRange &r2)
~QgsGraduatedSymbolRenderer() override
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 QgsGraduatedSymbolRenderer * createRenderer(QgsVectorLayer *vlayer, const QString &attrName, int classes, Mode mode, QgsSymbol *symbol, QgsColorRamp *ramp, const QgsRendererRangeLabelFormat &legendFormat=QgsRendererRangeLabelFormat())
Creates a new graduated renderer.
void swap(QgsRendererRange &other)
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer...
QgsDataDefinedSizeLegend * dataDefinedSizeLegend() const
Returns configuration of appearance of legend when using data-defined size for marker symbols...
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
void setOrderBy(const QgsFeatureRequest::OrderBy &orderBy)
Define the order in which features shall be processed by this renderer.
void moveClass(int from, int to)
Moves the category at index position from to index position to.
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
QgsRendererRange()=default
Constructor for QgsRendererRange.
void calculateLabelPrecision(bool updateRanges=true)
Reset the label decimal places to a numberbased on the minimum class interval.
static QList< double > prettyBreaks(double minimum, double maximum, int classes)
Computes a sequence of about 'classes' equally spaced round values which cover the range of values fr...
void updateClasses(QgsVectorLayer *vlayer, Mode mode, int nclasses)
Recalculate classes for a layer.
QVariant maximumValue(int index) const override
Returns the maximum value for an attribute column or an invalid variant in case of error...
static void convertSymbolRotation(QgsSymbol *symbol, const QString &field)
bool legendSymbolItemsCheckable() const override
items of symbology items in legend should be checkable
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
double minSymbolSize() const
Returns the min symbol size when graduated by size.
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns a list of attributes required to render this feature.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
Contains information about the context of a rendering operation.
QgsRendererRangeLabelFormat mLabelFormat
bool usingSymbolLevels() const
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
void sortByLabel(Qt::SortOrder order=Qt::AscendingOrder)
void setSymbol(QgsSymbol *s)
GraduatedMethod graduatedMethod() const
Returns the method used for graduation (either size or color)
QgsGraduatedSymbolRenderer(const QString &attrName=QString(), const QgsRangeList &ranges=QgsRangeList())
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
double maxSymbolSize() const
Returns the max symbol size when graduated by size.
virtual QgsSymbol * clone() const =0
Gets a deep copy of this symbol.
void setDataDefinedSizeLegend(QgsDataDefinedSizeLegend *settings)
Configures appearance of legend when renderer is configured to use data-defined size for marker symbo...
void CORE_EXPORT save(QDomElement &elem) const
Serialize to XML.
QString dump() const override
Returns debug information about this renderer.
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props, bool firstRange=false) const
Creates a DOM element representing the range in SLD format.
void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props=QgsStringMap()) const override
used from subclasses to create SLD Rule elements following SLD v1.1 specs
QgsGraduatedSymbolRenderer * clone() const override
Create a deep copy of this renderer.
double upperValue() const
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
QMap< QString, QgsSymbol *> QgsSymbolMap
std::unique_ptr< QgsSymbol > mSymbol
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
bool updateRangeRenderState(int rangeIndex, bool render)
bool valueGreaterThan(const QgsRendererRange &r1, const QgsRendererRange &r2)
bool updateRangeLabel(int rangeIndex, const QString &label)
bool legendSymbolItemChecked(const QString &key) override
items of symbology items in legend is checked
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
store renderer info to XML element
int mAttrNum
attribute index (derived from attribute name in startRender)
int ANALYSIS_EXPORT lower(int n, int i)
Lower function.
std::unique_ptr< QgsColorRamp > mSourceColorRamp
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
QString legendKeyForValue(double value) const
Returns the matching legend key for a value.
Represents a vector layer which manages a vector based data sets.
Object that keeps configuration of appearance of marker symbol's data-defined size in legend...
QgsSymbol * symbolForValue(double value) const
Gets the symbol which is used to represent value.
std::unique_ptr< QgsDataDefinedSizeLegend > mDataDefinedSizeLegend
void stopRender(QgsRenderContext &context)
Ends the rendering process.
const QgsRangeList & ranges() const
static QgsDataDefinedSizeLegend * readXml(const QDomElement &elem, const QgsReadWriteContext &context) SIP_FACTORY
Creates instance from given element and returns it (caller takes ownership). Returns null on error...
void setSourceColorRamp(QgsColorRamp *ramp)
Sets the source color ramp.
void updateSymbols(QgsSymbol *sym)
Update all the symbols but leave breaks and colors.
void setOrderByEnabled(bool enabled)
Sets whether custom ordering should be applied before features are processed by this renderer...
QgsSymbol * sourceSymbol()
Returns the renderer's source symbol, which is the base symbol used for the each classes' symbol befo...
void setSourceSymbol(QgsSymbol *sym)
Sets the source symbol for the renderer, which is the base symbol used for the each classes' symbol b...
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
void deleteClass(int idx)
bool isActive() const
Returns whether the property is currently active.
void setLabelFormat(const QgsRendererRangeLabelFormat &labelFormat, bool updateRanges=false)
Set the label format used to generate default classification labels.
void setColor(const QColor &color)
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.