Class: QgsNumericFormat

Abstract base class for numeric formatters, which allow for formatting a numeric value for display.

Numeric formatters use a variety of different formatting techniques (e.g. as scientific notation, currency values, percentage values, etc).

This is an abstract base class and will always need to be subclassed.

Added in version 3.12.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: clone(), configuration(), create(), formatDouble(), id(), visibleName()

Class Hierarchy

Inheritance diagram of qgis.core.QgsNumericFormat

Subclasses

QgsBasicNumericFormat

A numeric formatter which returns a simple text representation of a value.

QgsExpressionBasedNumericFormat

A numeric formatter which uses a QgsExpression to calculate the text representation of a value.

QgsFallbackNumericFormat

A basic numeric formatter which returns a simple text representation of a value.

QgsFractionNumericFormat

A numeric formatter which returns a vulgar fractional representation of a decimal value (e.g. “1/2” instead of 0.5).

Abstract Methods

clone

Clones the format, returning a new object.

configuration

Returns the current configuration of the formatter.

create

Creates a new copy of the format, using the supplied configuration.

formatDouble

Returns a formatted string representation of a numeric double value.

id

Returns a unique id for this numeric format.

visibleName

Returns the translated, user-visible name for this format.

Methods

writeXml

Writes the format to an XML element.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsNumericFormat. See the FAQ for more details.

sortKey

Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists.

suggestSampleValue

Returns a suggested sample value which nicely represents the current format configuration.

class qgis.core.QgsNumericFormat[source]

Bases: object

abstract clone(self) QgsNumericFormat | None[source]

Clones the format, returning a new object.

The caller takes ownership of the returned object.

Return type:

Optional[QgsNumericFormat]

abstract configuration(self, context: QgsReadWriteContext) Dict[str, Any][source]

Returns the current configuration of the formatter. This value can be used in a call to create() in order to recreate this formatter in its current state.

Parameters:

context (QgsReadWriteContext)

Return type:

Dict[str, Any]

abstract create(self, configuration: Dict[str, Any], context: QgsReadWriteContext) QgsNumericFormat | None[source]

Creates a new copy of the format, using the supplied configuration.

The caller takes ownership of the returned object.

Parameters:
Return type:

Optional[QgsNumericFormat]

abstract formatDouble(self, value: float, context: QgsNumericFormatContext) str[source]

Returns a formatted string representation of a numeric double value.

Parameters:
Return type:

str

abstract id(self) str[source]

Returns a unique id for this numeric format.

This id is used to identify this numeric format in the registry with QgsNumericFormatRegistry.format().

Return type:

str

virtual sortKey(self) int[source]

Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists.

Generally, subclasses should return QgsNumericFormat.sortKey() as their sorting key.

Return type:

int

virtual suggestSampleValue(self) float[source]

Returns a suggested sample value which nicely represents the current format configuration.

Return type:

float

abstract visibleName(self) str[source]

Returns the translated, user-visible name for this format.

Return type:

str

writeXml(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext)[source]

Writes the format to an XML element.

Parameters: