QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsBasicNumericFormat Class Reference

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

#include <qgsbasicnumericformat.h>

Inheritance diagram for QgsBasicNumericFormat:
Inheritance graph
[legend]

Public Types

enum  RoundingType { DecimalPlaces, SignificantFigures }
 Sets rounding type and behavior of the numberDecimalPlaces() setting. More...
 

Public Member Functions

 QgsBasicNumericFormat ()
 Default constructor. More...
 
QgsNumericFormatclone () const override
 Clones the format, returning a new object. More...
 
QVariantMap configuration (const QgsReadWriteContext &context) const override
 Returns the current configuration of the formatter. More...
 
QgsNumericFormatcreate (const QVariantMap &configuration, const QgsReadWriteContext &context) const override
 Creates a new copy of the format, using the supplied configuration. More...
 
QChar decimalSeparator () const
 Returns any override for the decimal separator character. More...
 
QString formatDouble (double value, const QgsNumericFormatContext &context) const override
 Returns a formatted string representation of a numeric double value. More...
 
QString id () const override
 Returns a unique id for this numeric format. More...
 
int numberDecimalPlaces () const
 Returns the maximum number of decimal places to show. More...
 
RoundingType roundingType () const
 Returns the rounding type, which controls the behavior of the numberDecimalPlaces() setting. More...
 
void setDecimalSeparator (QChar character)
 Sets an override character for the decimal separator character. More...
 
virtual void setNumberDecimalPlaces (int places)
 Sets the maximum number of decimal places to show. More...
 
void setRoundingType (RoundingType type)
 Sets the rounding type, which controls the behavior of the numberDecimalPlaces() setting. More...
 
void setShowPlusSign (bool show)
 Sets whether a leading plus sign will be shown for positive values. More...
 
void setShowThousandsSeparator (bool show)
 Sets whether the thousands grouping separator will be shown. More...
 
void setShowTrailingZeros (bool show)
 Sets whether trailing zeros will be shown (up to the specified numberDecimalPlaces()). More...
 
void setThousandsSeparator (QChar character)
 Sets an override character for the thousands separator character. More...
 
bool showPlusSign () const
 Returns true if a leading plus sign will be shown for positive values. More...
 
bool showThousandsSeparator () const
 Returns true if the thousands grouping separator will be shown. More...
 
bool showTrailingZeros () const
 Returns true if trailing zeros will be shown (up to the specified numberDecimalPlaces()). More...
 
int sortKey () override
 Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists. More...
 
QChar thousandsSeparator () const
 Returns any override for the thousands separator character. More...
 
QString visibleName () const override
 Returns the translated, user-visible name for this format. More...
 
- Public Member Functions inherited from QgsNumericFormat
 QgsNumericFormat ()=default
 Default constructor. More...
 
virtual ~QgsNumericFormat ()=default
 
bool operator!= (const QgsNumericFormat &other) const
 
bool operator== (const QgsNumericFormat &other) const
 
virtual double suggestSampleValue () const
 Returns a suggested sample value which nicely represents the current format configuration. More...
 
void writeXml (QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
 Writes the format to an XML element. More...
 

Protected Member Functions

virtual void setConfiguration (const QVariantMap &configuration, const QgsReadWriteContext &context)
 Sets the format's configuration. More...
 

Protected Attributes

bool mUseScientific = false
 

Detailed Description

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

Since
QGIS 3.12

Definition at line 31 of file qgsbasicnumericformat.h.

Member Enumeration Documentation

◆ RoundingType

Sets rounding type and behavior of the numberDecimalPlaces() setting.

Enumerator
DecimalPlaces 

Maximum number of decimal places.

SignificantFigures 

Maximum number of significant figures.

Definition at line 38 of file qgsbasicnumericformat.h.

Constructor & Destructor Documentation

◆ QgsBasicNumericFormat()

QgsBasicNumericFormat::QgsBasicNumericFormat ( )

Default constructor.

Definition at line 40 of file qgsbasicnumericformat.cpp.

Member Function Documentation

◆ clone()

QgsNumericFormat * QgsBasicNumericFormat::clone ( ) const
overridevirtual

Clones the format, returning a new object.

The caller takes ownership of the returned object.

Implements QgsNumericFormat.

Reimplemented in QgsScientificNumericFormat, QgsPercentageNumericFormat, QgsCurrencyNumericFormat, and QgsBearingNumericFormat.

Definition at line 131 of file qgsbasicnumericformat.cpp.

◆ configuration()

QVariantMap QgsBasicNumericFormat::configuration ( const QgsReadWriteContext context) const
overridevirtual

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.

Implements QgsNumericFormat.

Reimplemented in QgsScientificNumericFormat, QgsPercentageNumericFormat, QgsCurrencyNumericFormat, and QgsBearingNumericFormat.

Definition at line 143 of file qgsbasicnumericformat.cpp.

◆ create()

QgsNumericFormat * QgsBasicNumericFormat::create ( const QVariantMap &  configuration,
const QgsReadWriteContext context 
) const
overridevirtual

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

The caller takes ownership of the returned object.

Implements QgsNumericFormat.

Reimplemented in QgsScientificNumericFormat, QgsPercentageNumericFormat, QgsCurrencyNumericFormat, and QgsBearingNumericFormat.

Definition at line 136 of file qgsbasicnumericformat.cpp.

◆ decimalSeparator()

QChar QgsBasicNumericFormat::decimalSeparator ( ) const

Returns any override for the decimal separator character.

If an invalid QChar is returned, then the QGIS locale separator is used instead.

See also
setDecimalSeparator()

Definition at line 227 of file qgsbasicnumericformat.cpp.

◆ formatDouble()

QString QgsBasicNumericFormat::formatDouble ( double  value,
const QgsNumericFormatContext context 
) const
overridevirtual

Returns a formatted string representation of a numeric double value.

Implements QgsNumericFormat.

Reimplemented in QgsScientificNumericFormat, QgsPercentageNumericFormat, QgsCurrencyNumericFormat, and QgsBearingNumericFormat.

Definition at line 59 of file qgsbasicnumericformat.cpp.

◆ id()

QString QgsBasicNumericFormat::id ( ) const
overridevirtual

Returns a unique id for this numeric format.

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

Implements QgsNumericFormat.

Reimplemented in QgsScientificNumericFormat, QgsPercentageNumericFormat, QgsCurrencyNumericFormat, and QgsBearingNumericFormat.

Definition at line 44 of file qgsbasicnumericformat.cpp.

◆ numberDecimalPlaces()

int QgsBasicNumericFormat::numberDecimalPlaces ( ) const

Returns the maximum number of decimal places to show.

See also
setNumberDecimalPlaces()
showTrailingZeros()

Definition at line 167 of file qgsbasicnumericformat.cpp.

◆ roundingType()

QgsBasicNumericFormat::RoundingType QgsBasicNumericFormat::roundingType ( ) const

Returns the rounding type, which controls the behavior of the numberDecimalPlaces() setting.

See also
setRoundingType()

Definition at line 207 of file qgsbasicnumericformat.cpp.

◆ setConfiguration()

void QgsBasicNumericFormat::setConfiguration ( const QVariantMap &  configuration,
const QgsReadWriteContext context 
)
protectedvirtual

Sets the format's configuration.

Reimplemented in QgsBearingNumericFormat.

Definition at line 156 of file qgsbasicnumericformat.cpp.

◆ setDecimalSeparator()

void QgsBasicNumericFormat::setDecimalSeparator ( QChar  character)

Sets an override character for the decimal separator character.

If an invalid QChar is set, then the QGIS locale separator is used instead.

See also
decimalSeparator()

Definition at line 232 of file qgsbasicnumericformat.cpp.

◆ setNumberDecimalPlaces()

void QgsBasicNumericFormat::setNumberDecimalPlaces ( int  places)
virtual

Sets the maximum number of decimal places to show.

See also
numberDecimalPlaces()
setShowTrailingZeros()

Reimplemented in QgsScientificNumericFormat.

Definition at line 172 of file qgsbasicnumericformat.cpp.

◆ setRoundingType()

void QgsBasicNumericFormat::setRoundingType ( QgsBasicNumericFormat::RoundingType  type)

Sets the rounding type, which controls the behavior of the numberDecimalPlaces() setting.

See also
roundingType()

Definition at line 212 of file qgsbasicnumericformat.cpp.

◆ setShowPlusSign()

void QgsBasicNumericFormat::setShowPlusSign ( bool  show)

Sets whether a leading plus sign will be shown for positive values.

See also
showPlusSign()

Definition at line 192 of file qgsbasicnumericformat.cpp.

◆ setShowThousandsSeparator()

void QgsBasicNumericFormat::setShowThousandsSeparator ( bool  show)

Sets whether the thousands grouping separator will be shown.

See also
showThousandsSeparator()

Definition at line 182 of file qgsbasicnumericformat.cpp.

◆ setShowTrailingZeros()

void QgsBasicNumericFormat::setShowTrailingZeros ( bool  show)

Sets whether trailing zeros will be shown (up to the specified numberDecimalPlaces()).

See also
showTrailingZeros()
setNumberDecimalPlaces()

Definition at line 202 of file qgsbasicnumericformat.cpp.

◆ setThousandsSeparator()

void QgsBasicNumericFormat::setThousandsSeparator ( QChar  character)

Sets an override character for the thousands separator character.

If an invalid QChar is set, then the QGIS locale separator is used instead.

See also
thousandsSeparator()

Definition at line 222 of file qgsbasicnumericformat.cpp.

◆ showPlusSign()

bool QgsBasicNumericFormat::showPlusSign ( ) const

Returns true if a leading plus sign will be shown for positive values.

See also
setShowPlusSign()

Definition at line 187 of file qgsbasicnumericformat.cpp.

◆ showThousandsSeparator()

bool QgsBasicNumericFormat::showThousandsSeparator ( ) const

Returns true if the thousands grouping separator will be shown.

See also
setShowThousandsSeparator()

Definition at line 177 of file qgsbasicnumericformat.cpp.

◆ showTrailingZeros()

bool QgsBasicNumericFormat::showTrailingZeros ( ) const

Returns true if trailing zeros will be shown (up to the specified numberDecimalPlaces()).

See also
setShowTrailingZeros()
numberDecimalPlaces()

Definition at line 197 of file qgsbasicnumericformat.cpp.

◆ sortKey()

int QgsBasicNumericFormat::sortKey ( )
overridevirtual

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.

Reimplemented from QgsNumericFormat.

Reimplemented in QgsScientificNumericFormat, QgsPercentageNumericFormat, QgsCurrencyNumericFormat, and QgsBearingNumericFormat.

Definition at line 54 of file qgsbasicnumericformat.cpp.

◆ thousandsSeparator()

QChar QgsBasicNumericFormat::thousandsSeparator ( ) const

Returns any override for the thousands separator character.

If an invalid QChar is returned, then the QGIS locale separator is used instead.

See also
setThousandsSeparator()

Definition at line 217 of file qgsbasicnumericformat.cpp.

◆ visibleName()

QString QgsBasicNumericFormat::visibleName ( ) const
overridevirtual

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

Implements QgsNumericFormat.

Reimplemented in QgsScientificNumericFormat, QgsPercentageNumericFormat, QgsCurrencyNumericFormat, and QgsBearingNumericFormat.

Definition at line 49 of file qgsbasicnumericformat.cpp.

Member Data Documentation

◆ mUseScientific

bool QgsBasicNumericFormat::mUseScientific = false
protected

Definition at line 168 of file qgsbasicnumericformat.h.


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