QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
QgsClassificationMethod Class Referenceabstract

QgsClassificationMethod is an abstract class for implementations of classification methods. More...

#include <qgsclassificationmethod.h>

Inheritance diagram for QgsClassificationMethod:
Inheritance graph
[legend]

Public Types

enum  ClassPosition { LowerBound, Inner, UpperBound }
 Defines the class position. More...
 
enum  MethodProperty { NoFlag = 0, ValuesNotRequired = 1 << 1, SymmetricModeAvailable = 1 << 2 }
 Flags for the classification method. More...
 

Public Member Functions

 QgsClassificationMethod (MethodProperties properties=NoFlag, int codeComplexity=1)
 Creates a classification method. More...
 
virtual ~QgsClassificationMethod ()=default
 
QList< QgsClassificationRangeclasses (const QgsVectorLayer *layer, const QString &expression, int nclasses)
 This will calculate the classes for a given layer to define the classes. More...
 
QList< QgsClassificationRangeclasses (const QList< double > &values, int nclasses)
 This will calculate the classes for a list of values. More...
 
QList< QgsClassificationRangeclasses (double minimum, double maximum, int nclasses)
 This will calculate the classes for defined bounds without any values. More...
 
virtual QgsClassificationMethodclone () const =0
 Returns a clone of the method. More...
 
int codeComplexity () const
 Code complexity as the exponent in Big O notation. More...
 
virtual QIcon icon () const
 The icon of the method. More...
 
virtual QString id () const =0
 The id of the method as saved in the project, must be unique in registry. More...
 
QString labelFormat () const
 Returns the format of the label for the classes. More...
 
virtual QString labelForRange (double lowerValue, double upperValue, ClassPosition position=Inner) const
 Returns the label for a range. More...
 
QString labelForRange (const QgsRendererRange &range, ClassPosition position=Inner) const
 Returns the label for a range. More...
 
int labelPrecision () const
 Returns the precision for the formatting of the labels. More...
 
bool labelTrimTrailingZeroes () const
 Returns if the trailing 0 are trimmed in the label. More...
 
virtual QString name () const =0
 The readable and translate name of the method. More...
 
virtual void readXml (const QDomElement &element, const QgsReadWriteContext &context)
 Reads extra information to apply it to the method. More...
 
QDomElement save (QDomDocument &doc, const QgsReadWriteContext &context) const
 Saves the method to a DOM element and return it. More...
 
void setLabelFormat (const QString &format)
 Defines the format of the labels for the classes, using %1 and %2 for the bounds. More...
 
void setLabelPrecision (int labelPrecision)
 Defines the precision for the formatting of the labels. More...
 
void setLabelTrimTrailingZeroes (bool trimTrailingZeroes)
 Defines if the trailing 0 are trimmed in the label. More...
 
void setSymmetricMode (bool enabled, double symmetryPoint=0, bool symmetryAstride=false)
 Defines if the symmetric mode is enables and configures its parameters. More...
 
bool symmetricModeAvailable () const
 Returns if the method supports symmetric calculation. More...
 
bool symmetricModeEnabled () const
 Returns if the symmetric mode is enabled. More...
 
bool symmetryAstride () const
 Returns if the symmetric mode is astride if true, it will remove the symmetry point break so that the 2 classes form only one. More...
 
double symmetryPoint () const
 Returns the symmetry point for symmetric mode. More...
 
bool valuesRequired () const
 Returns if the method requires values to calculate the classes If not, bounds are sufficient. More...
 
virtual void writeXml (QDomElement &element, const QgsReadWriteContext &context) const
 Writes extra information about the method. More...
 

Static Public Member Functions

static QgsClassificationMethodcreate (const QDomElement &element, const QgsReadWriteContext &context)
 Reads the DOM element and return a new classification method from it. More...
 
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 balanced around symmetryPoint Does not put a break on the symmetryPoint. More...
 
static QList< double > rangesToBreaks (const QList< QgsClassificationRange > &classes)
 Transforms a list of classes to a list of breaks. More...
 

Static Public Attributes

static const int MAX_PRECISION = 15
 
static const int MIN_PRECISION = -6
 

Protected Member Functions

void copyBase (QgsClassificationMethod *c) const
 Copy the parameters (shall be used in clone implementation) More...
 
QString formatNumber (double value) const
 Format the number according to label properties. More...
 

Detailed Description

QgsClassificationMethod is an abstract class for implementations of classification methods.

See also
QgsClassificationMethodRegistry
Since
QGIS 3.10

Definition at line 87 of file qgsclassificationmethod.h.

Member Enumeration Documentation

◆ ClassPosition

Defines the class position.

Enumerator
LowerBound 

The class is at the lower bound.

Inner 

The class is not at a bound.

UpperBound 

The class is at the upper bound.

Definition at line 120 of file qgsclassificationmethod.h.

◆ MethodProperty

Flags for the classification method.

Enumerator
NoFlag 

No flag.

ValuesNotRequired 

Values are not required to calculate, min/max are enough.

SymmetricModeAvailable 

This allows using symmetric classification.

Definition at line 110 of file qgsclassificationmethod.h.

Constructor & Destructor Documentation

◆ QgsClassificationMethod()

QgsClassificationMethod::QgsClassificationMethod ( MethodProperties  properties = NoFlag,
int  codeComplexity = 1 
)
explicit

Creates a classification method.

Parameters
propertiesThe properties of the implemented method
codeComplexityas the exponent in the big O notation

Definition at line 41 of file qgsclassificationmethod.cpp.

◆ ~QgsClassificationMethod()

virtual QgsClassificationMethod::~QgsClassificationMethod ( )
virtualdefault

Member Function Documentation

◆ classes() [1/3]

QList< QgsClassificationRange > QgsClassificationMethod::classes ( const QgsVectorLayer layer,
const QString &  expression,
int  nclasses 
)

This will calculate the classes for a given layer to define the classes.

Parameters
layerThe vector layer
expressionThe name of the field on which the classes are calculated
nclassesThe number of classes to be returned

Definition at line 164 of file qgsclassificationmethod.cpp.

◆ classes() [2/3]

QList< QgsClassificationRange > QgsClassificationMethod::classes ( const QList< double > &  values,
int  nclasses 
)

This will calculate the classes for a list of values.

Parameters
valuesThe list of values
nclassesThe number of classes to be returned

Definition at line 202 of file qgsclassificationmethod.cpp.

◆ classes() [3/3]

QList< QgsClassificationRange > QgsClassificationMethod::classes ( double  minimum,
double  maximum,
int  nclasses 
)

This will calculate the classes for defined bounds without any values.

Warning
If the method implementation requires values, this will return an empty list.
Parameters
minimumThe minimum value for the breaks
maximumThe maximum value for the breaks
nclassesThe number of classes to be returned

Definition at line 215 of file qgsclassificationmethod.cpp.

◆ clone()

virtual QgsClassificationMethod* QgsClassificationMethod::clone ( ) const
pure virtual

Returns a clone of the method.

Implementation can take advantage of copyBase method which copies the parameters of the base class

Implemented in QgsClassificationQuantile, QgsClassificationEqualInterval, QgsClassificationJenks, QgsClassificationPrettyBreaks, QgsClassificationStandardDeviation, QgsClassificationCustom, and QgsClassificationLogarithmic.

◆ codeComplexity()

int QgsClassificationMethod::codeComplexity ( ) const
inline

Code complexity as the exponent in Big O notation.

Definition at line 172 of file qgsclassificationmethod.h.

◆ copyBase()

void QgsClassificationMethod::copyBase ( QgsClassificationMethod c) const
protected

Copy the parameters (shall be used in clone implementation)

Definition at line 48 of file qgsclassificationmethod.cpp.

◆ create()

QgsClassificationMethod * QgsClassificationMethod::create ( const QDomElement &  element,
const QgsReadWriteContext context 
)
static

Reads the DOM element and return a new classification method from it.

Parameters
elementthe DOM element
contextthe read/write context

Definition at line 56 of file qgsclassificationmethod.cpp.

◆ formatNumber()

QString QgsClassificationMethod::formatNumber ( double  value) const
protected

Format the number according to label properties.

Definition at line 142 of file qgsclassificationmethod.cpp.

◆ icon()

virtual QIcon QgsClassificationMethod::icon ( ) const
inlinevirtual

◆ id()

virtual QString QgsClassificationMethod::id ( ) const
pure virtual

◆ labelFormat()

QString QgsClassificationMethod::labelFormat ( ) const
inline

Returns the format of the label for the classes.

Definition at line 206 of file qgsclassificationmethod.h.

◆ labelForRange() [1/2]

QString QgsClassificationMethod::labelForRange ( double  lowerValue,
double  upperValue,
ClassPosition  position = Inner 
) const
virtual

Returns the label for a range.

Reimplemented in QgsClassificationStandardDeviation, and QgsClassificationLogarithmic.

Definition at line 290 of file qgsclassificationmethod.cpp.

◆ labelForRange() [2/2]

QString QgsClassificationMethod::labelForRange ( const QgsRendererRange range,
QgsClassificationMethod::ClassPosition  position = Inner 
) const

Returns the label for a range.

Definition at line 285 of file qgsclassificationmethod.cpp.

◆ labelPrecision()

int QgsClassificationMethod::labelPrecision ( ) const
inline

Returns the precision for the formatting of the labels.

Definition at line 210 of file qgsclassificationmethod.h.

◆ labelTrimTrailingZeroes()

bool QgsClassificationMethod::labelTrimTrailingZeroes ( ) const
inline

Returns if the trailing 0 are trimmed in the label.

Definition at line 214 of file qgsclassificationmethod.h.

◆ makeBreaksSymmetric()

void QgsClassificationMethod::makeBreaksSymmetric ( QList< double > &  breaks,
double  symmetryPoint,
bool  astride 
)
static

Remove the breaks that are above the existing opposite sign classes to keep colors symmetrically balanced around symmetryPoint Does not put a break on the symmetryPoint.

This is done before.

Parameters
breaksThe breaks of an already-done classification
symmetryPointThe point around which we want a symmetry
astrideA bool indicating if the symmetry is made astride the symmetryPoint or not ( [-1,1] vs. [-1,0][0,1] )

Definition at line 252 of file qgsclassificationmethod.cpp.

◆ name()

virtual QString QgsClassificationMethod::name ( ) const
pure virtual

◆ rangesToBreaks()

QList< double > QgsClassificationMethod::rangesToBreaks ( const QList< QgsClassificationRange > &  classes)
static

Transforms a list of classes to a list of breaks.

Definition at line 32 of file qgsclassificationmethod.cpp.

◆ readXml()

virtual void QgsClassificationMethod::readXml ( const QDomElement &  element,
const QgsReadWriteContext context 
)
inlinevirtual

Reads extra information to apply it to the method.

Reimplemented in QgsClassificationStandardDeviation.

Definition at line 160 of file qgsclassificationmethod.h.

◆ save()

QDomElement QgsClassificationMethod::save ( QDomDocument &  doc,
const QgsReadWriteContext context 
) const

Saves the method to a DOM element and return it.

Parameters
docthe DOM document
contextthe read/write context

Definition at line 91 of file qgsclassificationmethod.cpp.

◆ setLabelFormat()

void QgsClassificationMethod::setLabelFormat ( const QString &  format)
inline

Defines the format of the labels for the classes, using %1 and %2 for the bounds.

Definition at line 208 of file qgsclassificationmethod.h.

◆ setLabelPrecision()

void QgsClassificationMethod::setLabelPrecision ( int  labelPrecision)

Defines the precision for the formatting of the labels.

Definition at line 127 of file qgsclassificationmethod.cpp.

◆ setLabelTrimTrailingZeroes()

void QgsClassificationMethod::setLabelTrimTrailingZeroes ( bool  trimTrailingZeroes)
inline

Defines if the trailing 0 are trimmed in the label.

Definition at line 216 of file qgsclassificationmethod.h.

◆ setSymmetricMode()

void QgsClassificationMethod::setSymmetricMode ( bool  enabled,
double  symmetryPoint = 0,
bool  symmetryAstride = false 
)

Defines if the symmetric mode is enables and configures its parameters.

If the symmetric mode is not available in the current implementation, calling this method has no effect.

Parameters
enabledif the symmetric mode is enabled
symmetryPointthe value of the symmetry point
symmetryAstrideif true, it will remove the symmetry point break so that the 2 classes form only one

Definition at line 120 of file qgsclassificationmethod.cpp.

◆ symmetricModeAvailable()

bool QgsClassificationMethod::symmetricModeAvailable ( ) const
inline

Returns if the method supports symmetric calculation.

Definition at line 177 of file qgsclassificationmethod.h.

◆ symmetricModeEnabled()

bool QgsClassificationMethod::symmetricModeEnabled ( ) const
inline

Returns if the symmetric mode is enabled.

Definition at line 182 of file qgsclassificationmethod.h.

◆ symmetryAstride()

bool QgsClassificationMethod::symmetryAstride ( ) const
inline

Returns if the symmetric mode is astride if true, it will remove the symmetry point break so that the 2 classes form only one.

Definition at line 193 of file qgsclassificationmethod.h.

◆ symmetryPoint()

double QgsClassificationMethod::symmetryPoint ( ) const
inline

Returns the symmetry point for symmetric mode.

Definition at line 187 of file qgsclassificationmethod.h.

◆ valuesRequired()

bool QgsClassificationMethod::valuesRequired ( ) const
inline

Returns if the method requires values to calculate the classes If not, bounds are sufficient.

Definition at line 169 of file qgsclassificationmethod.h.

◆ writeXml()

virtual void QgsClassificationMethod::writeXml ( QDomElement &  element,
const QgsReadWriteContext context 
) const
inlinevirtual

Writes extra information about the method.

Reimplemented in QgsClassificationStandardDeviation.

Definition at line 158 of file qgsclassificationmethod.h.

Member Data Documentation

◆ MAX_PRECISION

const int QgsClassificationMethod::MAX_PRECISION = 15
static

Definition at line 275 of file qgsclassificationmethod.h.

◆ MIN_PRECISION

const int QgsClassificationMethod::MIN_PRECISION = -6
static

Definition at line 276 of file qgsclassificationmethod.h.


The documentation for this class was generated from the following files: