QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsgraduatedsymbolrenderer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgraduatedsymbolrenderer.cpp
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include <QDomDocument>
17 #include <QDomElement>
18 
19 #include <ctime>
20 #include <cmath>
21 
23 
24 #include "qgsattributes.h"
26 #include "qgscolorramp.h"
27 #include "qgscolorrampimpl.h"
29 #include "qgsexpression.h"
30 #include "qgsfeature.h"
32 #include "qgslogger.h"
33 #include "qgspainteffect.h"
34 #include "qgspainteffectregistry.h"
36 #include "qgsproperty.h"
37 #include "qgssymbol.h"
38 #include "qgssymbollayer.h"
39 #include "qgssymbollayerutils.h"
40 #include "qgsvectordataprovider.h"
41 #include "qgsvectorlayer.h"
42 #include "qgsvectorlayerutils.h"
44 #include "qgsstyleentityvisitor.h"
47 #include "qgsapplication.h"
50 #include "qgsmarkersymbol.h"
51 #include "qgslinesymbol.h"
52 
54  : QgsFeatureRenderer( QStringLiteral( "graduatedSymbol" ) )
55  , mAttrName( attrName )
56 {
57  // TODO: check ranges for sanity (NULL symbols, invalid ranges)
58 
59  //important - we need a deep copy of the ranges list, not a shared copy. This is required because
60  //QgsRendererRange::symbol() is marked const, and so retrieving the symbol via this method does not
61  //trigger a detachment and copy of mRanges BUT that same method CAN be used to modify a symbol in place
62  const auto constRanges = ranges;
63  for ( const QgsRendererRange &range : constRanges )
64  {
65  mRanges << range;
66  }
67 
69 }
70 
72 {
73  mRanges.clear(); // should delete all the symbols
74 }
75 
76 
78 {
79  for ( const QgsRendererRange &range : mRanges )
80  {
81  if ( range.lowerValue() <= value && range.upperValue() >= value )
82  {
83  if ( range.renderState() || mCounting )
84  return &range;
85  else
86  return nullptr;
87  }
88  }
89 
90  // second chance -- use a bit of double tolerance to avoid floating point equality fuzziness
91  // if a value falls just outside of a range, but within acceptable double precision tolerance
92  // then we accept it anyway
93  for ( const QgsRendererRange &range : mRanges )
94  {
95  if ( qgsDoubleNear( range.lowerValue(), value ) || qgsDoubleNear( range.upperValue(), value ) )
96  {
97  if ( range.renderState() || mCounting )
98  return &range;
99  else
100  return nullptr;
101  }
102  }
103  // the value is out of the range: return NULL instead of symbol
104  return nullptr;
105 }
106 
108 {
109  if ( const QgsRendererRange *range = rangeForValue( value ) )
110  return range->symbol();
111  return nullptr;
112 }
113 
115 {
116  if ( const QgsRendererRange *matchingRange = rangeForValue( value ) )
117  {
118  int i = 0;
119  for ( const QgsRendererRange &range : mRanges )
120  {
121  if ( matchingRange == &range )
122  return QString::number( i );
123  i++;
124  }
125  }
126  return QString();
127 }
128 
130 {
131  return originalSymbolForFeature( feature, context );
132 }
133 
134 QVariant QgsGraduatedSymbolRenderer::valueForFeature( const QgsFeature &feature, QgsRenderContext &context ) const
135 {
136  QgsAttributes attrs = feature.attributes();
137  QVariant value;
138  if ( mExpression )
139  {
140  value = mExpression->evaluate( &context.expressionContext() );
141  }
142  else
143  {
144  value = attrs.value( mAttrNum );
145  }
146 
147  return value;
148 }
149 
151 {
152  QVariant value = valueForFeature( feature, context );
153 
154  // Null values should not be categorized
155  if ( value.isNull() )
156  return nullptr;
157 
158  // find the right category
159  return symbolForValue( value.toDouble() );
160 }
161 
163 {
164  QgsFeatureRenderer::startRender( context, fields );
165 
166  mCounting = context.rendererScale() == 0.0;
167 
168  // find out classification attribute index from name
169  mAttrNum = fields.lookupField( mAttrName );
170 
171  if ( mAttrNum == -1 )
172  {
173  mExpression.reset( new QgsExpression( mAttrName ) );
174  mExpression->prepare( &context.expressionContext() );
175  }
176 
177  for ( const QgsRendererRange &range : std::as_const( mRanges ) )
178  {
179  if ( !range.symbol() )
180  continue;
181 
182  range.symbol()->startRender( context, fields );
183  }
184 }
185 
187 {
189 
190  for ( const QgsRendererRange &range : std::as_const( mRanges ) )
191  {
192  if ( !range.symbol() )
193  continue;
194 
195  range.symbol()->stopRender( context );
196  }
197 }
198 
200 {
201  QSet<QString> attributes;
202 
203  // mAttrName can contain either attribute name or an expression.
204  // Sometimes it is not possible to distinguish between those two,
205  // e.g. "a - b" can be both a valid attribute name or expression.
206  // Since we do not have access to fields here, try both options.
207  attributes << mAttrName;
208 
209  QgsExpression testExpr( mAttrName );
210  if ( !testExpr.hasParserError() )
211  attributes.unite( testExpr.referencedColumns() );
212 
213  QgsRangeList::const_iterator range_it = mRanges.constBegin();
214  for ( ; range_it != mRanges.constEnd(); ++range_it )
215  {
216  QgsSymbol *symbol = range_it->symbol();
217  if ( symbol )
218  {
219  attributes.unite( symbol->usedAttributes( context ) );
220  }
221  }
222  return attributes;
223 }
224 
226 {
227  QgsExpression testExpr( mAttrName );
228  if ( !testExpr.hasParserError() )
229  {
230  QgsExpressionContext context;
231  context.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( nullptr ) ); // unfortunately no layer access available!
232  testExpr.prepare( &context );
233  return testExpr.needsGeometry();
234  }
235  return false;
236 }
237 
239 {
240  if ( rangeIndex < 0 || rangeIndex >= mRanges.size() )
241  return false;
242  mRanges[rangeIndex].setSymbol( symbol );
243  return true;
244 }
245 
246 bool QgsGraduatedSymbolRenderer::updateRangeLabel( int rangeIndex, const QString &label )
247 {
248  if ( rangeIndex < 0 || rangeIndex >= mRanges.size() )
249  return false;
250  mRanges[rangeIndex].setLabel( label );
251  return true;
252 }
253 
254 bool QgsGraduatedSymbolRenderer::updateRangeUpperValue( int rangeIndex, double value )
255 {
256  if ( rangeIndex < 0 || rangeIndex >= mRanges.size() )
257  return false;
258  QgsRendererRange &range = mRanges[rangeIndex];
260  if ( rangeIndex == 0 )
262  else if ( rangeIndex == mRanges.count() )
264 
265  bool isDefaultLabel = mClassificationMethod->labelForRange( range, pos ) == range.label();
266  range.setUpperValue( value );
267  if ( isDefaultLabel )
268  range.setLabel( mClassificationMethod->labelForRange( range, pos ) );
269 
270  return true;
271 }
272 
273 bool QgsGraduatedSymbolRenderer::updateRangeLowerValue( int rangeIndex, double value )
274 {
275  if ( rangeIndex < 0 || rangeIndex >= mRanges.size() )
276  return false;
277 
278  QgsRendererRange &range = mRanges[rangeIndex];
280  if ( rangeIndex == 0 )
282  else if ( rangeIndex == mRanges.count() )
284 
285  bool isDefaultLabel = mClassificationMethod->labelForRange( range, pos ) == range.label();
286  range.setLowerValue( value );
287  if ( isDefaultLabel )
288  range.setLabel( mClassificationMethod->labelForRange( range, pos ) );
289 
290  return true;
291 }
292 
293 bool QgsGraduatedSymbolRenderer::updateRangeRenderState( int rangeIndex, bool value )
294 {
295  if ( rangeIndex < 0 || rangeIndex >= mRanges.size() )
296  return false;
297  mRanges[rangeIndex].setRenderState( value );
298  return true;
299 }
300 
302 {
303  QString s = QStringLiteral( "GRADUATED: attr %1\n" ).arg( mAttrName );
304  for ( int i = 0; i < mRanges.count(); i++ )
305  s += mRanges[i].dump();
306  return s;
307 }
308 
310 {
312 
314 
315  if ( mSourceSymbol )
316  r->setSourceSymbol( mSourceSymbol->clone() );
317  if ( mSourceColorRamp )
318  {
319  r->setSourceColorRamp( mSourceColorRamp->clone() );
320  }
323  copyRendererData( r );
324  return r;
325 }
326 
327 void QgsGraduatedSymbolRenderer::toSld( QDomDocument &doc, QDomElement &element, const QVariantMap &props ) const
328 {
329  QVariantMap newProps = props;
330  newProps[ QStringLiteral( "attribute" )] = mAttrName;
331  newProps[ QStringLiteral( "method" )] = graduatedMethodStr( mGraduatedMethod );
332 
333  // create a Rule for each range
334  bool first = true;
335  for ( QgsRangeList::const_iterator it = mRanges.constBegin(); it != mRanges.constEnd(); ++it )
336  {
337  it->toSld( doc, element, newProps, first );
338  first = false;
339  }
340 }
341 
343 {
344  Q_UNUSED( context )
345  QgsSymbolList lst;
346  lst.reserve( mRanges.count() );
347  for ( const QgsRendererRange &range : std::as_const( mRanges ) )
348  {
349  lst.append( range.symbol() );
350  }
351  return lst;
352 }
353 
355 {
356  for ( const QgsRendererRange &range : std::as_const( mRanges ) )
357  {
358  QgsStyleSymbolEntity entity( range.symbol() );
359  if ( !visitor->visit( QgsStyleEntityVisitorInterface::StyleLeaf( &entity, QStringLiteral( "%1 - %2" ).arg( range.lowerValue() ).arg( range.upperValue() ), range.label() ) ) )
360  return false;
361  }
362 
363  if ( mSourceColorRamp )
364  {
366  if ( !visitor->visit( QgsStyleEntityVisitorInterface::StyleLeaf( &entity ) ) )
367  return false;
368  }
369 
370  return true;
371 }
372 
373 void QgsGraduatedSymbolRenderer::makeBreaksSymmetric( QList<double> &breaks, double symmetryPoint, bool astride )
374 {
376 }
377 
378 QList<double> QgsGraduatedSymbolRenderer::calcEqualIntervalBreaks( double minimum, double maximum, int classes, bool useSymmetricMode, double symmetryPoint, bool astride )
379 {
382  QList<QgsClassificationRange> _classes = method.classes( minimum, maximum, classes );
383  return QgsClassificationMethod::rangesToBreaks( _classes );
384 }
385 
388  QgsVectorLayer *vlayer,
389  const QString &attrName,
390  int classes,
391  Mode mode,
392  QgsSymbol *symbol,
393  QgsColorRamp *ramp,
394  const QgsRendererRangeLabelFormat &labelFormat,
395  bool useSymmetricMode,
396  double symmetryPoint,
397  const QStringList &listForCboPrettyBreaks,
398  bool astride
399 )
400 {
401  Q_UNUSED( listForCboPrettyBreaks )
402 
405  r->setSourceSymbol( symbol->clone() );
406  r->setSourceColorRamp( ramp->clone() );
407 
408  QString methodId = methodIdFromMode( mode );
410 
411  if ( method )
412  {
414  method->setLabelFormat( labelFormat.format() );
417  }
418  r->setClassificationMethod( method );
419 
420  r->updateClasses( vlayer, classes );
421  return r;
422 }
424 
426  bool useSymmetricMode, double symmetryPoint, bool astride )
427 {
428  if ( mAttrName.isEmpty() )
429  return;
430 
431  QString methodId = methodIdFromMode( mode );
434  setClassificationMethod( method );
435 
436  updateClasses( vlayer, nclasses );
437 }
438 
440 {
442  return;
443 
444  QList<QgsClassificationRange> classes = mClassificationMethod->classes( vl, mAttrName, nclasses );
445 
447 
448  for ( QList<QgsClassificationRange>::iterator it = classes.begin(); it != classes.end(); ++it )
449  {
451  addClass( QgsRendererRange( *it, newSymbol ) );
452  }
453  updateColorRamp( nullptr );
454 }
455 
458 {
459  return QgsRendererRangeLabelFormat( mClassificationMethod->labelFormat(), mClassificationMethod->labelPrecision(), mClassificationMethod->labelTrimTrailingZeroes() );
460 }
462 
464 {
465  QDomElement symbolsElem = element.firstChildElement( QStringLiteral( "symbols" ) );
466  if ( symbolsElem.isNull() )
467  return nullptr;
468 
469  QDomElement rangesElem = element.firstChildElement( QStringLiteral( "ranges" ) );
470  if ( rangesElem.isNull() )
471  return nullptr;
472 
473  QgsSymbolMap symbolMap = QgsSymbolLayerUtils::loadSymbols( symbolsElem, context );
475 
476  QDomElement rangeElem = rangesElem.firstChildElement();
477  while ( !rangeElem.isNull() )
478  {
479  if ( rangeElem.tagName() == QLatin1String( "range" ) )
480  {
481  double lowerValue = rangeElem.attribute( QStringLiteral( "lower" ) ).toDouble();
482  double upperValue = rangeElem.attribute( QStringLiteral( "upper" ) ).toDouble();
483  QString symbolName = rangeElem.attribute( QStringLiteral( "symbol" ) );
484  QString label = rangeElem.attribute( QStringLiteral( "label" ) );
485  bool render = rangeElem.attribute( QStringLiteral( "render" ), QStringLiteral( "true" ) ) != QLatin1String( "false" );
486  if ( symbolMap.contains( symbolName ) )
487  {
488  QgsSymbol *symbol = symbolMap.take( symbolName );
489  ranges.append( QgsRendererRange( lowerValue, upperValue, symbol, label, render ) );
490  }
491  }
492  rangeElem = rangeElem.nextSiblingElement();
493  }
494 
495  QString attrName = element.attribute( QStringLiteral( "attr" ) );
496 
498 
499  QString attrMethod = element.attribute( QStringLiteral( "graduatedMethod" ) );
500  if ( !attrMethod.isEmpty() )
501  {
502  if ( attrMethod == graduatedMethodStr( Qgis::GraduatedMethod::Color ) )
503  r->setGraduatedMethod( Qgis::GraduatedMethod::Color );
504  else if ( attrMethod == graduatedMethodStr( Qgis::GraduatedMethod::Size ) )
505  r->setGraduatedMethod( Qgis::GraduatedMethod::Size );
506  }
507 
508 
509  // delete symbols if there are any more
511 
512  // try to load source symbol (optional)
513  QDomElement sourceSymbolElem = element.firstChildElement( QStringLiteral( "source-symbol" ) );
514  if ( !sourceSymbolElem.isNull() )
515  {
516  QgsSymbolMap sourceSymbolMap = QgsSymbolLayerUtils::loadSymbols( sourceSymbolElem, context );
517  if ( sourceSymbolMap.contains( QStringLiteral( "0" ) ) )
518  {
519  r->setSourceSymbol( sourceSymbolMap.take( QStringLiteral( "0" ) ) );
520  }
521  QgsSymbolLayerUtils::clearSymbolMap( sourceSymbolMap );
522  }
523 
524  // try to load color ramp (optional)
525  QDomElement sourceColorRampElem = element.firstChildElement( QStringLiteral( "colorramp" ) );
526  if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( QStringLiteral( "name" ) ) == QLatin1String( "[source]" ) )
527  {
528  r->setSourceColorRamp( QgsSymbolLayerUtils::loadColorRamp( sourceColorRampElem ) );
529  }
530 
531  // try to load mode
532 
533  QDomElement modeElem = element.firstChildElement( QStringLiteral( "mode" ) ); // old format, backward compatibility
534  QDomElement methodElem = element.firstChildElement( QStringLiteral( "classificationMethod" ) );
535  QgsClassificationMethod *method = nullptr;
536 
537  // TODO QGIS 4 Remove
538  // backward compatibility for QGIS project < 3.10
539  if ( !modeElem.isNull() )
540  {
541  QString modeString = modeElem.attribute( QStringLiteral( "name" ) );
542  QString methodId;
543  // the strings saved in the project does not match with the old Mode enum
544  if ( modeString == QLatin1String( "equal" ) )
545  methodId = QStringLiteral( "EqualInterval" );
546  else if ( modeString == QLatin1String( "quantile" ) )
547  methodId = QStringLiteral( "Quantile" );
548  else if ( modeString == QLatin1String( "jenks" ) )
549  methodId = QStringLiteral( "Jenks" );
550  else if ( modeString == QLatin1String( "stddev" ) )
551  methodId = QStringLiteral( "StdDev" );
552  else if ( modeString == QLatin1String( "pretty" ) )
553  methodId = QStringLiteral( "Pretty" );
554 
556 
557  // symmetric mode
558  QDomElement symmetricModeElem = element.firstChildElement( QStringLiteral( "symmetricMode" ) );
559  if ( !symmetricModeElem.isNull() )
560  {
561  // symmetry
562  QString symmetricEnabled = symmetricModeElem.attribute( QStringLiteral( "enabled" ) );
563  QString symmetricPointString = symmetricModeElem.attribute( QStringLiteral( "symmetryPoint" ) );
564  QString astrideEnabled = symmetricModeElem.attribute( QStringLiteral( "astride" ) );
565  method->setSymmetricMode( symmetricEnabled == QLatin1String( "true" ), symmetricPointString.toDouble(), astrideEnabled == QLatin1String( "true" ) );
566  }
567  QDomElement labelFormatElem = element.firstChildElement( QStringLiteral( "labelformat" ) );
568  if ( !labelFormatElem.isNull() )
569  {
570  // label format
571  QString format = labelFormatElem.attribute( QStringLiteral( "format" ), "%1" + QStringLiteral( " - " ) + "%2" );
572  int precision = labelFormatElem.attribute( QStringLiteral( "decimalplaces" ), QStringLiteral( "4" ) ).toInt();
573  bool trimTrailingZeroes = labelFormatElem.attribute( QStringLiteral( "trimtrailingzeroes" ), QStringLiteral( "false" ) ) == QLatin1String( "true" );
574  method->setLabelFormat( format );
575  method->setLabelPrecision( precision );
576  method->setLabelTrimTrailingZeroes( trimTrailingZeroes );
577  }
578  // End of backward compatibility
579  }
580  else
581  {
582  // QGIS project 3.10+
583  method = QgsClassificationMethod::create( methodElem, context );
584  }
585 
586  // apply the method
587  r->setClassificationMethod( method );
588 
589  QDomElement rotationElem = element.firstChildElement( QStringLiteral( "rotation" ) );
590  if ( !rotationElem.isNull() && !rotationElem.attribute( QStringLiteral( "field" ) ).isEmpty() )
591  {
592  for ( const QgsRendererRange &range : std::as_const( r->mRanges ) )
593  {
594  convertSymbolRotation( range.symbol(), rotationElem.attribute( QStringLiteral( "field" ) ) );
595  }
596  if ( r->mSourceSymbol )
597  {
598  convertSymbolRotation( r->mSourceSymbol.get(), rotationElem.attribute( QStringLiteral( "field" ) ) );
599  }
600  }
601  QDomElement sizeScaleElem = element.firstChildElement( QStringLiteral( "sizescale" ) );
602  if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( QStringLiteral( "field" ) ).isEmpty() )
603  {
604  for ( const QgsRendererRange &range : std::as_const( r->mRanges ) )
605  {
606  convertSymbolSizeScale( range.symbol(),
607  QgsSymbolLayerUtils::decodeScaleMethod( sizeScaleElem.attribute( QStringLiteral( "scalemethod" ) ) ),
608  sizeScaleElem.attribute( QStringLiteral( "field" ) ) );
609  }
610  if ( r->mSourceSymbol && r->mSourceSymbol->type() == Qgis::SymbolType::Marker )
611  {
613  QgsSymbolLayerUtils::decodeScaleMethod( sizeScaleElem.attribute( QStringLiteral( "scalemethod" ) ) ),
614  sizeScaleElem.attribute( QStringLiteral( "field" ) ) );
615  }
616  }
617 
618  QDomElement ddsLegendSizeElem = element.firstChildElement( QStringLiteral( "data-defined-size-legend" ) );
619  if ( !ddsLegendSizeElem.isNull() )
620  {
621  r->mDataDefinedSizeLegend.reset( QgsDataDefinedSizeLegend::readXml( ddsLegendSizeElem, context ) );
622  }
623 // TODO: symbol levels
624  return r;
625 }
626 
627 QDomElement QgsGraduatedSymbolRenderer::save( QDomDocument &doc, const QgsReadWriteContext &context )
628 {
629  QDomElement rendererElem = doc.createElement( RENDERER_TAG_NAME );
630  rendererElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "graduatedSymbol" ) );
631  rendererElem.setAttribute( QStringLiteral( "attr" ), mAttrName );
632  rendererElem.setAttribute( QStringLiteral( "graduatedMethod" ), graduatedMethodStr( mGraduatedMethod ) );
633 
634  // ranges
635  int i = 0;
637  QDomElement rangesElem = doc.createElement( QStringLiteral( "ranges" ) );
638  QgsRangeList::const_iterator it = mRanges.constBegin();
639  for ( ; it != mRanges.constEnd(); ++it )
640  {
641  const QgsRendererRange &range = *it;
642  QString symbolName = QString::number( i );
643  symbols.insert( symbolName, range.symbol() );
644 
645  QDomElement rangeElem = doc.createElement( QStringLiteral( "range" ) );
646  rangeElem.setAttribute( QStringLiteral( "lower" ), QString::number( range.lowerValue(), 'f', 15 ) );
647  rangeElem.setAttribute( QStringLiteral( "upper" ), QString::number( range.upperValue(), 'f', 15 ) );
648  rangeElem.setAttribute( QStringLiteral( "symbol" ), symbolName );
649  rangeElem.setAttribute( QStringLiteral( "label" ), range.label() );
650  rangeElem.setAttribute( QStringLiteral( "render" ), range.renderState() ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );
651  rangesElem.appendChild( rangeElem );
652  i++;
653  }
654 
655  rendererElem.appendChild( rangesElem );
656 
657  // save symbols
658  QDomElement symbolsElem = QgsSymbolLayerUtils::saveSymbols( symbols, QStringLiteral( "symbols" ), doc, context );
659  rendererElem.appendChild( symbolsElem );
660 
661  // save source symbol
662  if ( mSourceSymbol )
663  {
664  QgsSymbolMap sourceSymbols;
665  sourceSymbols.insert( QStringLiteral( "0" ), mSourceSymbol.get() );
666  QDomElement sourceSymbolElem = QgsSymbolLayerUtils::saveSymbols( sourceSymbols, QStringLiteral( "source-symbol" ), doc, context );
667  rendererElem.appendChild( sourceSymbolElem );
668  }
669 
670  // save source color ramp
671  if ( mSourceColorRamp )
672  {
673  QDomElement colorRampElem = QgsSymbolLayerUtils::saveColorRamp( QStringLiteral( "[source]" ), mSourceColorRamp.get(), doc );
674  rendererElem.appendChild( colorRampElem );
675  }
676 
677  // save classification method
678  QDomElement classificationMethodElem = mClassificationMethod->save( doc, context );
679  rendererElem.appendChild( classificationMethodElem );
680 
681  QDomElement rotationElem = doc.createElement( QStringLiteral( "rotation" ) );
682  rendererElem.appendChild( rotationElem );
683 
684  QDomElement sizeScaleElem = doc.createElement( QStringLiteral( "sizescale" ) );
685  rendererElem.appendChild( sizeScaleElem );
686 
688  {
689  QDomElement ddsLegendElem = doc.createElement( QStringLiteral( "data-defined-size-legend" ) );
690  mDataDefinedSizeLegend->writeXml( ddsLegendElem, context );
691  rendererElem.appendChild( ddsLegendElem );
692  }
693 
694  saveRendererData( doc, rendererElem, context );
695 
696  return rendererElem;
697 }
698 
699 QgsLegendSymbolList QgsGraduatedSymbolRenderer::baseLegendSymbolItems() const
700 {
702  int i = 0;
703  lst.reserve( mRanges.size() );
704  for ( const QgsRendererRange &range : mRanges )
705  {
706  lst << QgsLegendSymbolItem( range.symbol(), range.label(), QString::number( i++ ), true );
707  }
708  return lst;
709 }
710 
712 QString QgsGraduatedSymbolRenderer::methodIdFromMode( QgsGraduatedSymbolRenderer::Mode mode )
713 {
714  switch ( mode )
715  {
716  case EqualInterval:
717  return QStringLiteral( "EqualInterval" );
718  case Quantile:
719  return QStringLiteral( "Quantile" );
720  case Jenks:
721  return QStringLiteral( "Jenks" );
722  case StdDev:
723  return QStringLiteral( "StdDev" );
724  case Pretty:
725  return QStringLiteral( "Pretty" );
726  case Custom:
727  return QString();
728  }
729  return QString();
730 }
731 
732 QgsGraduatedSymbolRenderer::Mode QgsGraduatedSymbolRenderer::modeFromMethodId( const QString &methodId )
733 {
734  if ( methodId == QLatin1String( "EqualInterval" ) )
735  return EqualInterval;
736  if ( methodId == QLatin1String( "Quantile" ) )
737  return Quantile;
738  if ( methodId == QLatin1String( "Jenks" ) )
739  return Jenks;
740  if ( methodId == QLatin1String( "StdDev" ) )
741  return StdDev;
742  if ( methodId == QLatin1String( "Pretty" ) )
743  return Pretty;
744  else
745  return Custom;
746 }
748 
750 {
752  {
753  // check that all symbols that have the same size expression
754  QgsProperty ddSize;
755  for ( const QgsRendererRange &range : mRanges )
756  {
757  const QgsMarkerSymbol *symbol = static_cast<const QgsMarkerSymbol *>( range.symbol() );
758  if ( ddSize )
759  {
760  QgsProperty sSize( symbol->dataDefinedSize() );
761  if ( sSize && sSize != ddSize )
762  {
763  // no common size expression
764  return baseLegendSymbolItems();
765  }
766  }
767  else
768  {
769  ddSize = symbol->dataDefinedSize();
770  }
771  }
772 
773  if ( ddSize && ddSize.isActive() )
774  {
776 
778  ddSizeLegend.updateFromSymbolAndProperty( static_cast<const QgsMarkerSymbol *>( mSourceSymbol.get() ), ddSize );
779  lst += ddSizeLegend.legendSymbolList();
780 
781  lst += baseLegendSymbolItems();
782  return lst;
783  }
784  }
785 
786  return baseLegendSymbolItems();
787 }
788 
789 QSet< QString > QgsGraduatedSymbolRenderer::legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const
790 {
791  QVariant value = valueForFeature( feature, context );
792 
793  // Null values should not be categorized
794  if ( value.isNull() )
795  return QSet< QString >();
796 
797  // find the right category
798  QString key = legendKeyForValue( value.toDouble() );
799  if ( !key.isNull() )
800  return QSet< QString >() << key;
801  else
802  return QSet< QString >();
803 }
804 
805 QString QgsGraduatedSymbolRenderer::legendKeyToExpression( const QString &key, QgsVectorLayer *layer, bool &ok ) const
806 {
807  ok = false;
808  int ruleIndex = key.toInt( &ok );
809  if ( !ok || ruleIndex < 0 || ruleIndex >= mRanges.size() )
810  {
811  ok = false;
812  return QString();
813  }
814 
815  const QString attributeComponent = QgsExpression::quoteFieldExpression( mAttrName, layer );
816 
817  ok = true;
818  const QgsRendererRange &range = mRanges[ ruleIndex ];
819 
820  return QStringLiteral( "(%1 >= %2) AND (%1 <= %3)" ).arg( attributeComponent, QgsExpression::quotedValue( range.lowerValue(), QVariant::Double ),
821  QgsExpression::quotedValue( range.upperValue(), QVariant::Double ) );
822 }
823 
825 {
826  return mSourceSymbol.get();
827 }
828 
830 {
831  return mSourceSymbol.get();
832 }
833 
835 {
836  mSourceSymbol.reset( sym );
837 }
838 
840 {
841  return mSourceColorRamp.get();
842 }
843 
845 {
846  return mSourceColorRamp.get();
847 }
848 
850 {
851  if ( ramp == mSourceColorRamp.get() )
852  return;
853 
854  mSourceColorRamp.reset( ramp );
855 }
856 
858 {
859  double min = std::numeric_limits<double>::max();
860  for ( int i = 0; i < mRanges.count(); i++ )
861  {
862  double sz = 0;
863  if ( mRanges[i].symbol()->type() == Qgis::SymbolType::Marker )
864  sz = static_cast< QgsMarkerSymbol * >( mRanges[i].symbol() )->size();
865  else if ( mRanges[i].symbol()->type() == Qgis::SymbolType::Line )
866  sz = static_cast< QgsLineSymbol * >( mRanges[i].symbol() )->width();
867  min = std::min( sz, min );
868  }
869  return min;
870 }
871 
873 {
874  double max = std::numeric_limits<double>::min();
875  for ( int i = 0; i < mRanges.count(); i++ )
876  {
877  double sz = 0;
878  if ( mRanges[i].symbol()->type() == Qgis::SymbolType::Marker )
879  sz = static_cast< QgsMarkerSymbol * >( mRanges[i].symbol() )->size();
880  else if ( mRanges[i].symbol()->type() == Qgis::SymbolType::Line )
881  sz = static_cast< QgsLineSymbol * >( mRanges[i].symbol() )->width();
882  max = std::max( sz, max );
883  }
884  return max;
885 }
886 
887 void QgsGraduatedSymbolRenderer::setSymbolSizes( double minSize, double maxSize )
888 {
889  for ( int i = 0; i < mRanges.count(); i++ )
890  {
891  std::unique_ptr<QgsSymbol> symbol( mRanges.at( i ).symbol() ? mRanges.at( i ).symbol()->clone() : nullptr );
892  const double size = mRanges.count() > 1
893  ? minSize + i * ( maxSize - minSize ) / ( mRanges.count() - 1 )
894  : .5 * ( maxSize + minSize );
895  if ( symbol->type() == Qgis::SymbolType::Marker )
896  static_cast< QgsMarkerSymbol * >( symbol.get() )->setSize( size );
897  if ( symbol->type() == Qgis::SymbolType::Line )
898  static_cast< QgsLineSymbol * >( symbol.get() )->setWidth( size );
899  updateRangeSymbol( i, symbol.release() );
900  }
901 }
902 
904 {
905  int i = 0;
906  if ( ramp )
907  {
908  setSourceColorRamp( ramp );
909  }
910 
911  if ( mSourceColorRamp )
912  {
913  for ( const QgsRendererRange &range : std::as_const( mRanges ) )
914  {
915  QgsSymbol *symbol = range.symbol() ? range.symbol()->clone() : nullptr;
916  if ( symbol )
917  {
918  double colorValue;
919  colorValue = ( mRanges.count() > 1 ? static_cast< double >( i ) / ( mRanges.count() - 1 ) : 0 );
920  symbol->setColor( mSourceColorRamp->color( colorValue ) );
921  }
922  updateRangeSymbol( i, symbol );
923  ++i;
924  }
925  }
926 
927 }
928 
930 {
931  if ( !sym )
932  return;
933 
934  int i = 0;
935  for ( const QgsRendererRange &range : std::as_const( mRanges ) )
936  {
937  std::unique_ptr<QgsSymbol> symbol( sym->clone() );
938  switch ( mGraduatedMethod )
939  {
940  case Qgis::GraduatedMethod::Color:
941  {
942  symbol->setColor( range.symbol()->color() );
943  break;
944  }
945  case Qgis::GraduatedMethod::Size:
946  {
947  if ( symbol->type() == Qgis::SymbolType::Marker )
948  static_cast<QgsMarkerSymbol *>( symbol.get() )->setSize(
949  static_cast<QgsMarkerSymbol *>( range.symbol() )->size() );
950  else if ( symbol->type() == Qgis::SymbolType::Line )
951  static_cast<QgsLineSymbol *>( symbol.get() )->setWidth(
952  static_cast<QgsLineSymbol *>( range.symbol() )->width() );
953  break;
954  }
955  }
956  updateRangeSymbol( i, symbol.release() );
957  ++i;
958  }
959  setSourceSymbol( sym->clone() );
960 }
961 
963 {
964  return true;
965 }
966 
968 {
969  bool ok;
970  int index = key.toInt( &ok );
971  if ( ok && index >= 0 && index < mRanges.size() )
972  return mRanges.at( index ).renderState();
973  else
974  return true;
975 }
976 
977 void QgsGraduatedSymbolRenderer::checkLegendSymbolItem( const QString &key, bool state )
978 {
979  bool ok;
980  int index = key.toInt( &ok );
981  if ( ok )
982  updateRangeRenderState( index, state );
983 }
984 
986 {
987  bool ok;
988  int index = key.toInt( &ok );
989  if ( ok )
990  updateRangeSymbol( index, symbol );
991  else
992  delete symbol;
993 }
994 
996 {
997  QgsSymbol *newSymbol = symbol->clone();
998  QString label = QStringLiteral( "0.0 - 0.0" );
999  mRanges.insert( 0, QgsRendererRange( 0.0, 0.0, newSymbol, label ) );
1000 }
1001 
1002 void QgsGraduatedSymbolRenderer::addClass( double lower, double upper )
1003 {
1004  QgsSymbol *newSymbol = mSourceSymbol->clone();
1005  QString label = mClassificationMethod->labelForRange( lower, upper );
1006  mRanges.append( QgsRendererRange( lower, upper, newSymbol, label ) );
1007 }
1008 
1009 void QgsGraduatedSymbolRenderer::addBreak( double breakValue, bool updateSymbols )
1010 {
1011  QMutableListIterator< QgsRendererRange > it( mRanges );
1012  while ( it.hasNext() )
1013  {
1014  QgsRendererRange range = it.next();
1015  if ( range.lowerValue() < breakValue && range.upperValue() > breakValue )
1016  {
1017  QgsRendererRange newRange = QgsRendererRange();
1018  newRange.setLowerValue( breakValue );
1019  newRange.setUpperValue( range.upperValue() );
1020  newRange.setLabel( mClassificationMethod->labelForRange( newRange ) );
1021  newRange.setSymbol( mSourceSymbol->clone() );
1022 
1023  //update old range
1024  bool isDefaultLabel = range.label() == mClassificationMethod->labelForRange( range );
1025  range.setUpperValue( breakValue );
1026  if ( isDefaultLabel )
1027  range.setLabel( mClassificationMethod->labelForRange( range.lowerValue(), breakValue ) );
1028  it.setValue( range );
1029 
1030  it.insert( newRange );
1031  break;
1032  }
1033  }
1034 
1035  if ( updateSymbols )
1036  {
1037  switch ( mGraduatedMethod )
1038  {
1039  case Qgis::GraduatedMethod::Color:
1041  break;
1042  case Qgis::GraduatedMethod::Size:
1044  break;
1045  }
1046  }
1047 }
1048 
1050 {
1051  mRanges.append( range );
1052 }
1053 
1055 {
1056  mRanges.removeAt( idx );
1057 }
1058 
1060 {
1061  mRanges.clear();
1062 }
1063 
1066 {
1067  mClassificationMethod->setLabelFormat( labelFormat.format() );
1068  mClassificationMethod->setLabelPrecision( labelFormat.precision() );
1069  mClassificationMethod->setLabelTrimTrailingZeroes( labelFormat.trimTrailingZeroes() );
1070 
1071  if ( updateRanges )
1072  {
1074  }
1075 }
1077 
1079 {
1080  for ( int i = 0; i < mRanges.count(); i++ )
1081  {
1083  if ( i == 0 )
1085  else if ( i == mRanges.count() - 1 )
1087  mRanges[i].setLabel( mClassificationMethod->labelForRange( mRanges[i], pos ) );
1088  }
1089 }
1090 
1092 {
1093  // Find the minimum size of a class
1094  double minClassRange = 0.0;
1095  for ( const QgsRendererRange &rendererRange : std::as_const( mRanges ) )
1096  {
1097  double range = rendererRange.upperValue() - rendererRange.lowerValue();
1098  if ( range <= 0.0 )
1099  continue;
1100  if ( minClassRange == 0.0 || range < minClassRange )
1101  minClassRange = range;
1102  }
1103  if ( minClassRange <= 0.0 )
1104  return;
1105 
1106  // Now set the number of decimal places to ensure no more than 20% error in
1107  // representing this range (up to 10% at upper and lower end)
1108 
1109  int ndp = 10;
1110  double nextDpMinRange = 0.0000000099;
1111  while ( ndp > 0 && nextDpMinRange < minClassRange )
1112  {
1113  ndp--;
1114  nextDpMinRange *= 10.0;
1115  }
1116  mClassificationMethod->setLabelPrecision( ndp );
1117  if ( updateRanges )
1119 }
1120 
1122 {
1123  if ( from < 0 || from >= mRanges.size() || to < 0 || to >= mRanges.size() )
1124  return;
1125  mRanges.move( from, to );
1126 }
1127 
1129 {
1130  return r1 < r2;
1131 }
1132 
1134 {
1135  return !valueLessThan( r1, r2 );
1136 }
1137 
1138 void QgsGraduatedSymbolRenderer::sortByValue( Qt::SortOrder order )
1139 {
1140  if ( order == Qt::AscendingOrder )
1141  {
1142  std::sort( mRanges.begin(), mRanges.end(), valueLessThan );
1143  }
1144  else
1145  {
1146  std::sort( mRanges.begin(), mRanges.end(), valueGreaterThan );
1147  }
1148 }
1149 
1151 {
1152  QgsRangeList sortedRanges = mRanges;
1153  std::sort( sortedRanges.begin(), sortedRanges.end(), valueLessThan );
1154 
1155  QgsRangeList::const_iterator it = sortedRanges.constBegin();
1156  if ( it == sortedRanges.constEnd() )
1157  return false;
1158 
1159  if ( ( *it ).upperValue() < ( *it ).lowerValue() )
1160  return true;
1161 
1162  double prevMax = ( *it ).upperValue();
1163  ++it;
1164 
1165  for ( ; it != sortedRanges.constEnd(); ++it )
1166  {
1167  if ( ( *it ).upperValue() < ( *it ).lowerValue() )
1168  return true;
1169 
1170  if ( ( *it ).lowerValue() < prevMax )
1171  return true;
1172 
1173  prevMax = ( *it ).upperValue();
1174  }
1175  return false;
1176 }
1177 
1179 {
1180  QgsRangeList sortedRanges = mRanges;
1181  std::sort( sortedRanges.begin(), sortedRanges.end(), valueLessThan );
1182 
1183  QgsRangeList::const_iterator it = sortedRanges.constBegin();
1184  if ( it == sortedRanges.constEnd() )
1185  return false;
1186 
1187  double prevMax = ( *it ).upperValue();
1188  ++it;
1189 
1190  for ( ; it != sortedRanges.constEnd(); ++it )
1191  {
1192  if ( !qgsDoubleNear( ( *it ).lowerValue(), prevMax ) )
1193  return true;
1194 
1195  prevMax = ( *it ).upperValue();
1196  }
1197  return false;
1198 }
1199 
1201 {
1202  return QString::localeAwareCompare( r1.label(), r2.label() ) < 0;
1203 }
1204 
1206 {
1207  return !labelLessThan( r1, r2 );
1208 }
1209 
1210 void QgsGraduatedSymbolRenderer::sortByLabel( Qt::SortOrder order )
1211 {
1212  if ( order == Qt::AscendingOrder )
1213  {
1214  std::sort( mRanges.begin(), mRanges.end(), labelLessThan );
1215  }
1216  else
1217  {
1218  std::sort( mRanges.begin(), mRanges.end(), labelGreaterThan );
1219  }
1220 }
1221 
1223 {
1224  return mClassificationMethod.get();
1225 }
1226 
1228 {
1229  mClassificationMethod.reset( method );
1230 }
1231 
1233 {
1234  QString methodId = methodIdFromMode( mode );
1236  setClassificationMethod( method );
1237 }
1238 
1240 {
1241  mClassificationMethod->setSymmetricMode( useSymmetricMode, mClassificationMethod->symmetryPoint(), mClassificationMethod->symmetryAstride() );
1242 }
1243 
1245 {
1246  mClassificationMethod->setSymmetricMode( mClassificationMethod->symmetricModeEnabled(), symmetryPoint, mClassificationMethod->symmetryAstride() );
1247 }
1248 
1250 {
1251  mClassificationMethod->setSymmetricMode( mClassificationMethod->symmetricModeEnabled(), mClassificationMethod->symmetryPoint(), astride );
1252 }
1253 
1255 {
1256  std::unique_ptr< QgsGraduatedSymbolRenderer > r;
1257  if ( renderer->type() == QLatin1String( "graduatedSymbol" ) )
1258  {
1259  r.reset( static_cast<QgsGraduatedSymbolRenderer *>( renderer->clone() ) );
1260  }
1261  else if ( renderer->type() == QLatin1String( "categorizedSymbol" ) )
1262  {
1263  const QgsCategorizedSymbolRenderer *categorizedSymbolRenderer = dynamic_cast<const QgsCategorizedSymbolRenderer *>( renderer );
1264  if ( categorizedSymbolRenderer )
1265  {
1266  r = std::make_unique< QgsGraduatedSymbolRenderer >( QString(), QgsRangeList() );
1267  if ( categorizedSymbolRenderer->sourceSymbol() )
1268  r->setSourceSymbol( categorizedSymbolRenderer->sourceSymbol()->clone() );
1269  if ( categorizedSymbolRenderer->sourceColorRamp() )
1270  {
1271  bool isRandom = dynamic_cast<const QgsRandomColorRamp *>( categorizedSymbolRenderer->sourceColorRamp() ) ||
1272  dynamic_cast<const QgsLimitedRandomColorRamp *>( categorizedSymbolRenderer->sourceColorRamp() );
1273  if ( !isRandom )
1274  r->setSourceColorRamp( categorizedSymbolRenderer->sourceColorRamp()->clone() );
1275  }
1276  r->setClassAttribute( categorizedSymbolRenderer->classAttribute() );
1277  }
1278  }
1279  else if ( renderer->type() == QLatin1String( "pointDisplacement" ) || renderer->type() == QLatin1String( "pointCluster" ) )
1280  {
1281  const QgsPointDistanceRenderer *pointDistanceRenderer = dynamic_cast<const QgsPointDistanceRenderer *>( renderer );
1282  if ( pointDistanceRenderer )
1283  r.reset( convertFromRenderer( pointDistanceRenderer->embeddedRenderer() ) );
1284  }
1285  else if ( renderer->type() == QLatin1String( "invertedPolygonRenderer" ) )
1286  {
1287  const QgsInvertedPolygonRenderer *invertedPolygonRenderer = dynamic_cast<const QgsInvertedPolygonRenderer *>( renderer );
1288  if ( invertedPolygonRenderer )
1289  r.reset( convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() ) );
1290  }
1291 
1292  // If not one of the specifically handled renderers, then just grab the symbol from the renderer
1293  // Could have applied this to specific renderer types (singleSymbol, graduatedSymbol)
1294 
1295  if ( !r )
1296  {
1297  r = std::make_unique< QgsGraduatedSymbolRenderer >( QString(), QgsRangeList() );
1298  QgsRenderContext context;
1299  QgsSymbolList symbols = const_cast<QgsFeatureRenderer *>( renderer )->symbols( context );
1300  if ( !symbols.isEmpty() )
1301  {
1302  r->setSourceSymbol( symbols.at( 0 )->clone() );
1303  }
1304  }
1305 
1306  renderer->copyRendererData( r.get() );
1307 
1308  return r.release();
1309 }
1310 
1312 {
1313  mDataDefinedSizeLegend.reset( settings );
1314 }
1315 
1317 {
1318  return mDataDefinedSizeLegend.get();
1319 }
1320 
1322 {
1323  switch ( method )
1324  {
1325  case Qgis::GraduatedMethod::Color:
1326  return QStringLiteral( "GraduatedColor" );
1327  case Qgis::GraduatedMethod::Size:
1328  return QStringLiteral( "GraduatedSize" );
1329  }
1330  return QString();
1331 }
1332 
1333 
QgsGraduatedSymbolRenderer::sourceColorRamp
QgsColorRamp * sourceColorRamp()
Returns the source color ramp, from which each classes' color is derived.
Definition: qgsgraduatedsymbolrenderer.cpp:839
QgsGraduatedSymbolRenderer::Custom
@ Custom
Definition: qgsgraduatedsymbolrenderer.h:145
QgsFeatureRenderer::copyRendererData
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
Definition: qgsrenderer.cpp:52
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsProperty::isActive
bool isActive() const
Returns whether the property is currently active.
Definition: qgsproperty.cpp:291
QgsGraduatedSymbolRenderer::setSourceColorRamp
void setSourceColorRamp(QgsColorRamp *ramp)
Sets the source color ramp.
Definition: qgsgraduatedsymbolrenderer.cpp:849
QgsClassificationCustom::METHOD_ID
static const QString METHOD_ID
Definition: qgsclassificationcustom.h:52
QgsColorRamp
Abstract base class for color ramps.
Definition: qgscolorramp.h:29
qgsexpressioncontextutils.h
QgsGraduatedSymbolRenderer::symbolForValue
QgsSymbol * symbolForValue(double value) const
Gets the symbol which is used to represent value.
Definition: qgsgraduatedsymbolrenderer.cpp:107
QgsExpressionContext::appendScopes
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Definition: qgsexpressioncontext.cpp:499
qgscolorrampimpl.h
QgsGraduatedSymbolRenderer::mDataDefinedSizeLegend
std::unique_ptr< QgsDataDefinedSizeLegend > mDataDefinedSizeLegend
Definition: qgsgraduatedsymbolrenderer.h:465
QgsGraduatedSymbolRenderer::setSymmetryPoint
Q_DECL_DEPRECATED void setSymmetryPoint(double symmetryPoint)
Set the pivot point.
Definition: qgsgraduatedsymbolrenderer.cpp:1244
QgsRendererRangeLabelFormat
Definition: qgsrendererrange.h:200
QgsClassificationMethod
QgsClassificationMethod is an abstract class for implementations of classification methods.
Definition: qgsclassificationmethod.h:88
QgsGraduatedSymbolRenderer::Mode
Mode
Classification mode.
Definition: qgsgraduatedsymbolrenderer.h:138
QgsGraduatedSymbolRenderer::setSymbolSizes
void setSymbolSizes(double minSize, double maxSize)
set varying symbol size for classes
Definition: qgsgraduatedsymbolrenderer.cpp:887
QgsSymbolLayerUtils::loadSymbols
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 ...
Definition: qgssymbollayerutils.cpp:3189
QgsProperty
A store for object properties.
Definition: qgsproperty.h:230
QgsGraduatedSymbolRenderer::addBreak
void addBreak(double breakValue, bool updateSymbols=true)
Add a breakpoint by splitting existing classes so that the specified value becomes a break between tw...
Definition: qgsgraduatedsymbolrenderer.cpp:1009
QgsGraduatedSymbolRenderer::sourceSymbol
QgsSymbol * sourceSymbol()
Returns the renderer's source symbol, which is the base symbol used for the each classes' symbol befo...
Definition: qgsgraduatedsymbolrenderer.cpp:824
Qgis::SymbolType::Line
@ Line
Line symbol.
QgsRenderContext::expressionContext
QgsExpressionContext & expressionContext()
Gets the expression context.
Definition: qgsrendercontext.h:625
QgsRendererRange::label
QString label() const
Returns the label used for the range.
Definition: qgsrendererrange.cpp:89
QgsGraduatedSymbolRenderer::symbolForFeature
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
Definition: qgsgraduatedsymbolrenderer.cpp:129
QgsGraduatedSymbolRenderer::labelFormat
Q_DECL_DEPRECATED QgsRendererRangeLabelFormat labelFormat() const
Returns the label format used to generate default classification labels.
Definition: qgsgraduatedsymbolrenderer.cpp:457
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsSymbol::defaultSymbol
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
Definition: qgssymbol.cpp:673
qgscategorizedsymbolrenderer.h
QgsGraduatedSymbolRenderer::updateRangeLabel
bool updateRangeLabel(int rangeIndex, const QString &label)
Definition: qgsgraduatedsymbolrenderer.cpp:246
QgsExpression::referencedColumns
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
Definition: qgsexpression.cpp:221
qgsclassificationcustom.h
QgsMarkerSymbol::size
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
Definition: qgsmarkersymbol.cpp:197
valueLessThan
bool valueLessThan(const QgsRendererRange &r1, const QgsRendererRange &r2)
Definition: qgsgraduatedsymbolrenderer.cpp:1128
QgsClassificationMethod::UpperBound
@ UpperBound
The class is at the upper bound.
Definition: qgsclassificationmethod.h:128
QgsGraduatedSymbolRenderer::toSld
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
Definition: qgsgraduatedsymbolrenderer.cpp:327
QgsStyleSymbolEntity
A symbol entity for QgsStyle databases.
Definition: qgsstyle.h:1341
qgsexpression.h
QgsGraduatedSymbolRenderer::mSourceSymbol
std::unique_ptr< QgsSymbol > mSourceSymbol
Definition: qgsgraduatedsymbolrenderer.h:455
QgsMarkerSymbol::dataDefinedSize
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
Definition: qgsmarkersymbol.cpp:343
QgsFeatureRenderer::convertSymbolSizeScale
static void convertSymbolSizeScale(QgsSymbol *symbol, Qgis::ScaleMethod method, const QString &field)
Definition: qgsrenderer.cpp:494
QgsSymbolMap
QMap< QString, QgsSymbol * > QgsSymbolMap
Definition: qgsrenderer.h:45
QgsClassificationMethod::create
static QgsClassificationMethod * create(const QDomElement &element, const QgsReadWriteContext &context)
Reads the DOM element and return a new classification method from it.
Definition: qgsclassificationmethod.cpp:61
QgsLineSymbol::width
double width() const
Returns the estimated width for the whole symbol, which is the maximum width of all marker symbol lay...
Definition: qgslinesymbol.cpp:96
QgsStyleColorRampEntity
A color ramp entity for QgsStyle databases.
Definition: qgsstyle.h:1373
labelLessThan
bool labelLessThan(const QgsRendererRange &r1, const QgsRendererRange &r2)
Definition: qgsgraduatedsymbolrenderer.cpp:1200
labelGreaterThan
bool labelGreaterThan(const QgsRendererRange &r1, const QgsRendererRange &r2)
Definition: qgsgraduatedsymbolrenderer.cpp:1205
qgssymbollayerutils.h
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
QgsClassificationMethodRegistry::method
QgsClassificationMethod * method(const QString &id)
Returns a new instance of the method for the given id.
Definition: qgsclassificationmethodregistry.cpp:55
QgsGraduatedSymbolRenderer::updateRangeLowerValue
bool updateRangeLowerValue(int rangeIndex, double value)
Definition: qgsgraduatedsymbolrenderer.cpp:273
QgsRendererRange::symbol
QgsSymbol * symbol() const
Returns the symbol used for the range.
Definition: qgsrendererrange.cpp:84
QgsRendererRange
Definition: qgsrendererrange.h:36
qgsfeature.h
QgsFeatureRenderer::convertSymbolRotation
static void convertSymbolRotation(QgsSymbol *symbol, const QString &field)
Definition: qgsrenderer.cpp:516
QgsGraduatedSymbolRenderer::accept
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
Definition: qgsgraduatedsymbolrenderer.cpp:354
QgsFeatureRenderer::type
QString type() const
Definition: qgsrenderer.h:142
QgsGraduatedSymbolRenderer::startRender
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
Definition: qgsgraduatedsymbolrenderer.cpp:162
QgsGraduatedSymbolRenderer::rangeForValue
const QgsRendererRange * rangeForValue(double value) const
Returns the renderer range matching the provided value, or nullptr if no range matches the value.
Definition: qgsgraduatedsymbolrenderer.cpp:77
QgsDataDefinedSizeLegend
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
Definition: qgsdatadefinedsizelegend.h:42
QgsGraduatedSymbolRenderer::setLegendSymbolItem
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
Definition: qgsgraduatedsymbolrenderer.cpp:985
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsClassificationMethod::classes
QList< QgsClassificationRange > classes(const QgsVectorLayer *layer, const QString &expression, int nclasses)
This will calculate the classes for a given layer to define the classes.
Definition: qgsclassificationmethod.cpp:209
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Definition: qgsstyleentityvisitor.h:33
QgsGraduatedSymbolRenderer::~QgsGraduatedSymbolRenderer
~QgsGraduatedSymbolRenderer() override
Definition: qgsgraduatedsymbolrenderer.cpp:71
QgsExpressionContextUtils::globalProjectLayerScopes
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Definition: qgsexpressioncontextutils.cpp:377
QgsGraduatedSymbolRenderer::filterNeedsGeometry
bool filterNeedsGeometry() const override
Returns true if this renderer requires the geometry to apply the filter.
Definition: qgsgraduatedsymbolrenderer.cpp:225
qgspainteffectregistry.h
QgsGraduatedSymbolRenderer::setGraduatedMethod
void setGraduatedMethod(Qgis::GraduatedMethod method)
Set the method used for graduation (either size or color).
Definition: qgsgraduatedsymbolrenderer.h:404
QgsRendererRange::lowerValue
double lowerValue() const
Returns the lower bound of the range.
Definition: qgsrendererrange.cpp:74
QgsGraduatedSymbolRenderer::updateClasses
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.
Definition: qgsgraduatedsymbolrenderer.cpp:425
QgsPointDistanceRenderer::embeddedRenderer
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
Definition: qgspointdistancerenderer.cpp:173
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
QgsGraduatedSymbolRenderer::moveClass
void moveClass(int from, int to)
Moves the category at index position from to index position to.
Definition: qgsgraduatedsymbolrenderer.cpp:1121
qgspainteffect.h
MathUtils::lower
int ANALYSIS_EXPORT lower(int n, int i)
Lower function.
Definition: MathUtils.cpp:407
QgsGraduatedSymbolRenderer::EqualInterval
@ EqualInterval
Definition: qgsgraduatedsymbolrenderer.h:140
QgsGraduatedSymbolRenderer::Quantile
@ Quantile
Definition: qgsgraduatedsymbolrenderer.h:141
QgsGraduatedSymbolRenderer::symmetryPoint
Q_DECL_DEPRECATED double symmetryPoint() const
Returns the pivot value for symmetric classification.
Definition: qgsgraduatedsymbolrenderer.h:176
QgsLimitedRandomColorRamp
Constrained random color ramp, which returns random colors based on preset parameters.
Definition: qgscolorrampimpl.h:340
QgsGraduatedSymbolRenderer::graduatedMethod
Qgis::GraduatedMethod graduatedMethod() const
Returns the method used for graduation (either size or color).
Definition: qgsgraduatedsymbolrenderer.h:396
QgsStyleEntityVisitorInterface::StyleLeaf
Contains information relating to the style entity currently being visited.
Definition: qgsstyleentityvisitor.h:60
QgsGraduatedSymbolRenderer::mAttrName
QString mAttrName
Definition: qgsgraduatedsymbolrenderer.h:453
QgsExpression::quoteFieldExpression
static QString quoteFieldExpression(const QString &expression, const QgsVectorLayer *layer)
Validate if the expression is a field in the layer and ensure it is quoted.
Definition: qgsexpression.cpp:1385
QgsFeatureRenderer::stopRender
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
Definition: qgsrenderer.cpp:110
QgsGraduatedSymbolRenderer::Pretty
@ Pretty
Definition: qgsgraduatedsymbolrenderer.h:144
QgsGraduatedSymbolRenderer::classificationMethod
QgsClassificationMethod * classificationMethod() const
Returns the classification method.
Definition: qgsgraduatedsymbolrenderer.cpp:1222
QgsGraduatedSymbolRenderer::updateRangeLabels
void updateRangeLabels()
Updates the labels of the ranges.
Definition: qgsgraduatedsymbolrenderer.cpp:1078
QgsGraduatedSymbolRenderer::updateColorRamp
void updateColorRamp(QgsColorRamp *ramp=nullptr)
Update the color ramp used.
Definition: qgsgraduatedsymbolrenderer.cpp:903
QgsGraduatedSymbolRenderer::updateRangeSymbol
bool updateRangeSymbol(int rangeIndex, QgsSymbol *symbol)
Definition: qgsgraduatedsymbolrenderer.cpp:238
QgsGraduatedSymbolRenderer::setAstride
Q_DECL_DEPRECATED void setAstride(bool astride)
Set if we want a central class astride the pivot value.
Definition: qgsgraduatedsymbolrenderer.cpp:1249
QgsRendererRangeLabelFormat::trimTrailingZeroes
bool trimTrailingZeroes() const
Definition: qgsrendererrange.h:215
QgsClassificationEqualInterval
QgsClassificationEqualInterval is an implementation of QgsClassificationMethod for equal intervals.
Definition: qgsclassificationequalinterval.h:28
QgsGraduatedSymbolRenderer::dataDefinedSizeLegend
QgsDataDefinedSizeLegend * dataDefinedSizeLegend() const
Returns configuration of appearance of legend when using data-defined size for marker symbols.
Definition: qgsgraduatedsymbolrenderer.cpp:1316
QgsRandomColorRamp
Totally random color ramp. Returns colors generated at random, but constrained to some hardcoded satu...
Definition: qgscolorrampimpl.h:492
QgsGraduatedSymbolRenderer::deleteAllClasses
void deleteAllClasses()
Definition: qgsgraduatedsymbolrenderer.cpp:1059
QgsGraduatedSymbolRenderer::mExpression
std::unique_ptr< QgsExpression > mExpression
Definition: qgsgraduatedsymbolrenderer.h:458
qgsapplication.h
QgsGraduatedSymbolRenderer::setUseSymmetricMode
Q_DECL_DEPRECATED void setUseSymmetricMode(bool useSymmetricMode)
Set if we want to classify symmetric around a given value.
Definition: qgsgraduatedsymbolrenderer.cpp:1239
QgsGraduatedSymbolRenderer::mClassificationMethod
std::shared_ptr< QgsClassificationMethod > mClassificationMethod
Definition: qgsgraduatedsymbolrenderer.h:480
QgsExpression::quotedValue
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
Definition: qgsexpression.cpp:82
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsGraduatedSymbolRenderer::updateRangeUpperValue
bool updateRangeUpperValue(int rangeIndex, double value)
Definition: qgsgraduatedsymbolrenderer.cpp:254
Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:2820
QgsClassificationMethod::LowerBound
@ LowerBound
The class is at the lower bound.
Definition: qgsclassificationmethod.h:126
QgsGraduatedSymbolRenderer::legendKeyToExpression
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...
Definition: qgsgraduatedsymbolrenderer.cpp:805
QgsLegendSymbolItem
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
Definition: qgslegendsymbolitem.h:36
precision
int precision
Definition: qgswfsgetfeature.cpp:103
QgsDataDefinedSizeLegend::legendSymbolList
QgsLegendSymbolList legendSymbolList() const
Generates legend symbol items according to the configuration.
Definition: qgsdatadefinedsizelegend.cpp:122
QgsClassificationCustom
QgsClassificationCustom is a dummy implementation of QgsClassification which does not compute any bre...
Definition: qgsclassificationcustom.h:28
QgsGraduatedSymbolRenderer::legendKeysForFeature
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
Definition: qgsgraduatedsymbolrenderer.cpp:789
QgsGraduatedSymbolRenderer::addClass
void addClass(QgsSymbol *symbol)
Definition: qgsgraduatedsymbolrenderer.cpp:995
QgsGraduatedSymbolRenderer::originalSymbolForFeature
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
Definition: qgsgraduatedsymbolrenderer.cpp:150
QgsRendererRange::setLowerValue
void setLowerValue(double lowerValue)
Sets the lower bound of the range.
Definition: qgsrendererrange.cpp:109
QgsGraduatedSymbolRenderer::legendSymbolItemsCheckable
bool legendSymbolItemsCheckable() const override
items of symbology items in legend should be checkable
Definition: qgsgraduatedsymbolrenderer.cpp:962
QgsClassificationMethod::setLabelFormat
void setLabelFormat(const QString &format)
Defines the format of the labels for the classes, using %1 and %2 for the bounds.
Definition: qgsclassificationmethod.h:220
QgsGraduatedSymbolRenderer::mGraduatedMethod
Qgis::GraduatedMethod mGraduatedMethod
Definition: qgsgraduatedsymbolrenderer.h:459
QgsRangeList
QList< QgsRendererRange > QgsRangeList
Definition: qgsrendererrange.h:191
QgsClassificationMethod::setSymmetricMode
void setSymmetricMode(bool enabled, double symmetryPoint=0, bool symmetryAstride=false)
Defines if the symmetric mode is enables and configures its parameters.
Definition: qgsclassificationmethod.cpp:135
QgsGraduatedSymbolRenderer::rangesHaveGaps
bool rangesHaveGaps() const
Tests whether classes assigned to the renderer have gaps between the ranges.
Definition: qgsgraduatedsymbolrenderer.cpp:1178
QgsSymbolLayerUtils::decodeScaleMethod
static Qgis::ScaleMethod decodeScaleMethod(const QString &str)
Decodes a symbol scale method from a string.
Definition: qgssymbollayerutils.cpp:838
QgsGraduatedSymbolRenderer::mode
Q_DECL_DEPRECATED Mode mode() const
Definition: qgsgraduatedsymbolrenderer.h:153
qgscolorramp.h
QgsSymbolList
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:44
QgsMarkerSymbol
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgsmarkersymbol.h:30
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:2265
QgsGraduatedSymbolRenderer::calcEqualIntervalBreaks
static Q_DECL_DEPRECATED QList< double > calcEqualIntervalBreaks(double minimum, double maximum, int classes, bool useSymmetricMode, double symmetryPoint, bool astride)
Compute the equal interval classification.
Definition: qgsgraduatedsymbolrenderer.cpp:378
QgsFeatureRenderer::saveRendererData
void saveRendererData(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context)
Saves generic renderer data into the specified element.
Definition: qgsrenderer.cpp:204
QgsFeatureRenderer::clone
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
QgsGraduatedSymbolRenderer::setClassificationMethod
void setClassificationMethod(QgsClassificationMethod *method)
Defines the classification method This will take ownership of the method.
Definition: qgsgraduatedsymbolrenderer.cpp:1227
QgsGraduatedSymbolRenderer::StdDev
@ StdDev
Definition: qgsgraduatedsymbolrenderer.h:143
QgsGraduatedSymbolRenderer::usedAttributes
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
Definition: qgsgraduatedsymbolrenderer.cpp:199
QgsGraduatedSymbolRenderer::graduatedMethodStr
static QString graduatedMethodStr(Qgis::GraduatedMethod method)
Definition: qgsgraduatedsymbolrenderer.cpp:1321
QgsGraduatedSymbolRenderer
Definition: qgsgraduatedsymbolrenderer.h:35
QgsSymbolLayerUtils::saveColorRamp
static QDomElement saveColorRamp(const QString &name, QgsColorRamp *ramp, QDomDocument &doc)
Encodes a color ramp's settings to an XML element.
Definition: qgssymbollayerutils.cpp:3355
QgsRendererRange::setSymbol
void setSymbol(QgsSymbol *s)
Sets the symbol used for the range.
Definition: qgsrendererrange.cpp:94
RENDERER_TAG_NAME
#define RENDERER_TAG_NAME
Definition: qgsrenderer.h:50
QgsPointDistanceRenderer
An abstract base class for distance based point renderers (e.g., clusterer and displacement renderers...
Definition: qgspointdistancerenderer.h:41
QgsGraduatedSymbolRenderer::mCounting
bool mCounting
Definition: qgsgraduatedsymbolrenderer.h:463
QgsMergedFeatureRenderer::embeddedRenderer
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
Definition: qgsmergedfeaturerenderer.cpp:53
QgsGraduatedSymbolRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
create renderer from XML element
Definition: qgsgraduatedsymbolrenderer.cpp:463
qgsvectordataprovider.h
QgsGraduatedSymbolRenderer::mSourceColorRamp
std::unique_ptr< QgsColorRamp > mSourceColorRamp
Definition: qgsgraduatedsymbolrenderer.h:456
QgsClassificationMethod::setLabelPrecision
void setLabelPrecision(int labelPrecision)
Defines the precision for the formatting of the labels.
Definition: qgsclassificationmethod.cpp:142
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:29
QgsCategorizedSymbolRenderer::sourceColorRamp
QgsColorRamp * sourceColorRamp()
Returns the source color ramp, from which each categories' color is derived.
Definition: qgscategorizedsymbolrenderer.cpp:1197
qgsvectorlayerutils.h
QgsClassificationMethod::Inner
@ Inner
The class is not at a bound.
Definition: qgsclassificationmethod.h:127
qgssymbollayer.h
QgsRendererRange::upperValue
double upperValue() const
Returns the upper bound of the range.
Definition: qgsrendererrange.cpp:79
QgsGraduatedSymbolRenderer::sortByLabel
void sortByLabel(Qt::SortOrder order=Qt::AscendingOrder)
Definition: qgsgraduatedsymbolrenderer.cpp:1210
QgsGraduatedSymbolRenderer::sortByValue
void sortByValue(Qt::SortOrder order=Qt::AscendingOrder)
Definition: qgsgraduatedsymbolrenderer.cpp:1138
qgsclassificationequalinterval.h
QgsRendererRangeLabelFormat::format
QString format() const
Definition: qgsrendererrange.h:209
QgsApplication::classificationMethodRegistry
static QgsClassificationMethodRegistry * classificationMethodRegistry()
Returns the application's classification methods registry, used in graduated renderer.
Definition: qgsapplication.cpp:2420
QgsGraduatedSymbolRenderer::checkLegendSymbolItem
void checkLegendSymbolItem(const QString &key, bool state=true) override
item in symbology was checked
Definition: qgsgraduatedsymbolrenderer.cpp:977
QgsGraduatedSymbolRenderer::legendSymbolItemChecked
bool legendSymbolItemChecked(const QString &key) override
items of symbology items in legend is checked
Definition: qgsgraduatedsymbolrenderer.cpp:967
QgsGraduatedSymbolRenderer::setSourceSymbol
void setSourceSymbol(QgsSymbol *sym)
Sets the source symbol for the renderer, which is the base symbol used for the each classes' symbol b...
Definition: qgsgraduatedsymbolrenderer.cpp:834
QgsExpression::prepare
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
Definition: qgsexpression.cpp:327
QgsFeature::attributes
QgsAttributes attributes
Definition: qgsfeature.h:69
QgsRendererRange::renderState
bool renderState() const
Returns true if the range should be rendered.
Definition: qgsrendererrange.cpp:114
QgsGraduatedSymbolRenderer::mAttrNum
int mAttrNum
attribute index (derived from attribute name in startRender)
Definition: qgsgraduatedsymbolrenderer.h:462
QgsGraduatedSymbolRenderer::dump
QString dump() const override
Returns debug information about this renderer.
Definition: qgsgraduatedsymbolrenderer.cpp:301
QgsColorRamp::clone
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
QgsGraduatedSymbolRenderer::astride
Q_DECL_DEPRECATED bool astride() const
Returns if we want to have a central class astride the pivot value.
Definition: qgsgraduatedsymbolrenderer.h:191
QgsGraduatedSymbolRenderer::legendKeyForValue
QString legendKeyForValue(double value) const
Returns the matching legend key for a value.
Definition: qgsgraduatedsymbolrenderer.cpp:114
QgsSymbolLayerUtils::loadColorRamp
static QgsColorRamp * loadColorRamp(QDomElement &element)
Creates a color ramp from the settings encoded in an XML element.
Definition: qgssymbollayerutils.cpp:3330
QgsGraduatedSymbolRenderer::setDataDefinedSizeLegend
void setDataDefinedSizeLegend(QgsDataDefinedSizeLegend *settings)
Configures appearance of legend when renderer is configured to use data-defined size for marker symbo...
Definition: qgsgraduatedsymbolrenderer.cpp:1311
qgsclassificationmethod.h
qgsvectorlayer.h
QgsDataDefinedSizeLegend::updateFromSymbolAndProperty
void updateFromSymbolAndProperty(const QgsMarkerSymbol *symbol, const QgsProperty &ddSize)
Updates the list of classes, source symbol and title label from given symbol and property.
Definition: qgsdatadefinedsizelegend.cpp:99
QgsGraduatedSymbolRenderer::createRenderer
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.
Definition: qgsgraduatedsymbolrenderer.cpp:387
QgsSymbol::clone
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
QgsGraduatedSymbolRenderer::ranges
const QgsRangeList & ranges() const
Returns a list of all ranges used in the classification.
Definition: qgsgraduatedsymbolrenderer.h:73
QgsClassificationMethod::makeBreaksSymmetric
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...
Definition: qgsclassificationmethod.cpp:301
Qgis::GraduatedMethod
GraduatedMethod
Methods for modifying symbols by range in a graduated symbol renderer.
Definition: qgis.h:1561
qgsattributes.h
QgsGraduatedSymbolRenderer::deleteClass
void deleteClass(int idx)
Definition: qgsgraduatedsymbolrenderer.cpp:1054
QgsGraduatedSymbolRenderer::clone
QgsGraduatedSymbolRenderer * clone() const override
Create a deep copy of this renderer.
Definition: qgsgraduatedsymbolrenderer.cpp:309
QgsGraduatedSymbolRenderer::updateRangeRenderState
bool updateRangeRenderState(int rangeIndex, bool render)
Definition: qgsgraduatedsymbolrenderer.cpp:293
QgsFeatureRenderer
Definition: qgsrenderer.h:101
QgsGraduatedSymbolRenderer::maxSymbolSize
double maxSymbolSize() const
Returns the max symbol size when graduated by size.
Definition: qgsgraduatedsymbolrenderer.cpp:872
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsSymbolLayerUtils::saveSymbols
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.
Definition: qgssymbollayerutils.cpp:3267
QgsGraduatedSymbolRenderer::setLabelFormat
Q_DECL_DEPRECATED void setLabelFormat(const QgsRendererRangeLabelFormat &labelFormat, bool updateRanges=false)
Set the label format used to generate default classification labels.
Definition: qgsgraduatedsymbolrenderer.cpp:1065
qgsmarkersymbol.h
QgsSymbolLayerUtils::clearSymbolMap
static void clearSymbolMap(QgsSymbolMap &symbols)
Definition: qgssymbollayerutils.cpp:3281
QgsClassificationMethod::ClassPosition
ClassPosition
Defines the class position.
Definition: qgsclassificationmethod.h:124
QgsGraduatedSymbolRenderer::symbols
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
Definition: qgsgraduatedsymbolrenderer.cpp:342
QgsSymbol::usedAttributes
QSet< QString > usedAttributes(const QgsRenderContext &context) const
Returns a list of attributes required to render this feature.
Definition: qgssymbol.cpp:1151
qgspointdisplacementrenderer.h
qgsproperty.h
QgsGraduatedSymbolRenderer::Jenks
@ Jenks
Definition: qgsgraduatedsymbolrenderer.h:142
QgsGraduatedSymbolRenderer::useSymmetricMode
Q_DECL_DEPRECATED bool useSymmetricMode() const
Returns if we want to classify symmetric around a given value.
Definition: qgsgraduatedsymbolrenderer.h:162
QgsGraduatedSymbolRenderer::makeBreaksSymmetric
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...
Definition: qgsgraduatedsymbolrenderer.cpp:373
QgsClassificationMethod::setLabelTrimTrailingZeroes
void setLabelTrimTrailingZeroes(bool trimTrailingZeroes)
Defines if the trailing 0 are trimmed in the label.
Definition: qgsclassificationmethod.h:228
QgsGraduatedSymbolRenderer::mRanges
QgsRangeList mRanges
Definition: qgsgraduatedsymbolrenderer.h:454
QgsGraduatedSymbolRenderer::convertFromRenderer
static QgsGraduatedSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
creates a QgsGraduatedSymbolRenderer from an existing renderer.
Definition: qgsgraduatedsymbolrenderer.cpp:1254
QgsGraduatedSymbolRenderer::minSymbolSize
double minSymbolSize() const
Returns the min symbol size when graduated by size.
Definition: qgsgraduatedsymbolrenderer.cpp:857
QgsStyleEntityVisitorInterface::visit
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
Definition: qgsstyleentityvisitor.h:153
QgsExpression::needsGeometry
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
Definition: qgsexpression.cpp:270
QgsGraduatedSymbolRenderer::QgsGraduatedSymbolRenderer
QgsGraduatedSymbolRenderer(const QString &attrName=QString(), const QgsRangeList &ranges=QgsRangeList())
Definition: qgsgraduatedsymbolrenderer.cpp:53
QgsGraduatedSymbolRenderer::setMode
Q_DECL_DEPRECATED void setMode(Mode mode)
Definition: qgsgraduatedsymbolrenderer.cpp:1232
QgsAttributes
A vector of attributes. Mostly equal to QVector<QVariant>.
Definition: qgsattributes.h:57
QgsGraduatedSymbolRenderer::stopRender
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
Definition: qgsgraduatedsymbolrenderer.cpp:186
qgsinvertedpolygonrenderer.h
QgsCategorizedSymbolRenderer
Definition: qgscategorizedsymbolrenderer.h:164
QgsDataDefinedSizeLegend::readXml
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...
Definition: qgsdatadefinedsizelegend.cpp:364
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsRendererRange::setUpperValue
void setUpperValue(double upperValue)
Sets the upper bound of the range.
Definition: qgsrendererrange.cpp:104
qgsdatadefinedsizelegend.h
QgsRendererRangeLabelFormat::precision
int precision() const
Definition: qgsrendererrange.h:212
QgsExpression::hasParserError
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
Definition: qgsexpression.cpp:206
QgsGraduatedSymbolRenderer::calculateLabelPrecision
void calculateLabelPrecision(bool updateRanges=true)
Reset the label decimal places to a numberbased on the minimum class interval.
Definition: qgsgraduatedsymbolrenderer.cpp:1091
qgslogger.h
QgsGraduatedSymbolRenderer::updateSymbols
void updateSymbols(QgsSymbol *sym)
Update all the symbols but leave breaks and colors.
Definition: qgsgraduatedsymbolrenderer.cpp:929
QgsFields::lookupField
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Definition: qgsfields.cpp:349
QgsRenderContext::rendererScale
double rendererScale() const
Returns the renderer map scale.
Definition: qgsrendercontext.h:344
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings")....
Definition: qgsexpression.h:102
qgsgraduatedsymbolrenderer.h
QgsLegendSymbolList
QList< QgsLegendSymbolItem > QgsLegendSymbolList
Definition: qgslegendsymbolitem.h:144
QgsFeatureRenderer::startRender
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
Definition: qgsrenderer.cpp:96
QgsVectorLayer::geometryType
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Definition: qgsvectorlayer.cpp:720
Q_NOWARN_DEPRECATED_PUSH
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:2819
qgsclassificationmethodregistry.h
QgsClassificationMethod::rangesToBreaks
static QList< double > rangesToBreaks(const QList< QgsClassificationRange > &classes)
Transforms a list of classes to a list of breaks.
Definition: qgsclassificationmethod.cpp:31
QgsGraduatedSymbolRenderer::save
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
Stores renderer properties to an XML element.
Definition: qgsgraduatedsymbolrenderer.cpp:627
QgsRendererRange::setLabel
void setLabel(const QString &label)
Sets the label used for the range.
Definition: qgsrendererrange.cpp:99
QgsGraduatedSymbolRenderer::legendSymbolItems
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
Definition: qgsgraduatedsymbolrenderer.cpp:749
QgsSymbol::setColor
void setColor(const QColor &color) const
Sets the color for the symbol.
Definition: qgssymbol.cpp:867
qgssymbol.h
QgsCategorizedSymbolRenderer::classAttribute
QString classAttribute() const
Returns the class attribute for the renderer, which is the field name or expression string from the l...
Definition: qgscategorizedsymbolrenderer.h:312
Qgis::SymbolType::Marker
@ Marker
Marker symbol.
qgsstyleentityvisitor.h
QgsGraduatedSymbolRenderer::rangesOverlap
bool rangesOverlap() const
Tests whether classes assigned to the renderer have ranges which overlap.
Definition: qgsgraduatedsymbolrenderer.cpp:1150
QgsCategorizedSymbolRenderer::sourceSymbol
QgsSymbol * sourceSymbol()
Returns the renderer's source symbol, which is the base symbol used for the each categories' symbol b...
Definition: qgscategorizedsymbolrenderer.cpp:1182
qgslinesymbol.h
QgsInvertedPolygonRenderer
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted,...
Definition: qgsinvertedpolygonrenderer.h:42
valueGreaterThan
bool valueGreaterThan(const QgsRendererRange &r1, const QgsRendererRange &r2)
Definition: qgsgraduatedsymbolrenderer.cpp:1133