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¶
Subclasses¶
A numeric formatter which returns a simple text representation of a value. |
|
A numeric formatter which uses a |
|
A basic numeric formatter which returns a simple text representation of a value. |
|
A numeric formatter which returns a vulgar fractional representation of a decimal value (e.g. “1/2” instead of 0.5). |
- 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:
configuration (Dict[str, Any])
context (QgsReadWriteContext)
- Return type:
Optional[QgsNumericFormat]
- abstract formatDouble(self, value: float, context: QgsNumericFormatContext) str[source]¶
Returns a formatted string representation of a numeric double value.
- Parameters:
value (float)
context (QgsNumericFormatContext)
- 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:
element (QDomElement)
document (QDomDocument)
context (QgsReadWriteContext)