QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
QgsFractionNumericFormat Class Reference

A numeric formatter which returns a vulgar fractional representation of a decimal value (e.g. More...

#include <qgsfractionnumericformat.h>

Inheritance diagram for QgsFractionNumericFormat:
Inheritance graph
[legend]

Public Member Functions

 QgsFractionNumericFormat ()
 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...
 
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...
 
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 setThousandsSeparator (QChar character)
 Sets an override character for the thousands separator character. More...
 
void setUseDedicatedUnicodeCharacters (bool enabled)
 Sets whether dedicated unicode characters should be used, when the are available for the particular fraction (e.g. More...
 
void setUseUnicodeSuperSubscript (bool enabled)
 Sets whether unicode superscript and subscript characters should be used, (e.g. 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...
 
int sortKey () override
 Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists. More...
 
double suggestSampleValue () const override
 Returns a suggested sample value which nicely represents the current format configuration. More...
 
QChar thousandsSeparator () const
 Returns any override for the thousands separator character. More...
 
bool useDedicatedUnicodeCharacters () const
 Returns true if dedicated unicode characters should be used, when the are available for the particular fraction (e.g. More...
 
bool useUnicodeSuperSubscript () const
 Returns true if unicode superscript and subscript characters should be used, (e.g. 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
 
virtual QgsNumericFormatclone () const =0
 Clones the format, returning a new object. More...
 
virtual QVariantMap configuration (const QgsReadWriteContext &context) const =0
 Returns the current configuration of the formatter. More...
 
virtual QgsNumericFormatcreate (const QVariantMap &configuration, const QgsReadWriteContext &context) const =0
 Creates a new copy of the format, using the supplied configuration. More...
 
virtual QString formatDouble (double value, const QgsNumericFormatContext &context) const =0
 Returns a formatted string representation of a numeric double value. More...
 
virtual QString id () const =0
 Returns a unique id for this numeric format. More...
 
bool operator!= (const QgsNumericFormat &other) const
 
bool operator== (const QgsNumericFormat &other) const
 
virtual int sortKey ()
 Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists. More...
 
virtual double suggestSampleValue () const
 Returns a suggested sample value which nicely represents the current format configuration. More...
 
virtual QString visibleName () const =0
 Returns the translated, user-visible name for this format. More...
 
void writeXml (QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
 Writes the format to an XML element. More...
 

Static Public Member Functions

static bool doubleToVulgarFraction (const double value, unsigned long long &numerator, unsigned long long &denominator, int &sign, const double tolerance=1e-10)
 Converts a double value to a vulgar fraction (e.g. More...
 
static QString toUnicodeSubscript (const QString &input)
 Converts numbers in an input string to unicode subscript equivalents. More...
 
static QString toUnicodeSuperscript (const QString &input)
 Converts numbers in an input string to unicode superscript equivalents. More...
 

Protected Member Functions

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

Additional Inherited Members

- Static Protected Attributes inherited from QgsNumericFormat
static constexpr int DEFAULT_SORT_KEY = 100
 

Detailed Description

A numeric formatter which returns a vulgar fractional representation of a decimal value (e.g.

"1/2" instead of 0.5).

Since
QGIS 3.14

Definition at line 30 of file qgsfractionnumericformat.h.

Constructor & Destructor Documentation

◆ QgsFractionNumericFormat()

QgsFractionNumericFormat::QgsFractionNumericFormat ( )

Default constructor.

Definition at line 42 of file qgsfractionnumericformat.cpp.

Member Function Documentation

◆ clone()

QgsNumericFormat * QgsFractionNumericFormat::clone ( ) const
overridevirtual

Clones the format, returning a new object.

The caller takes ownership of the returned object.

Implements QgsNumericFormat.

Definition at line 148 of file qgsfractionnumericformat.cpp.

◆ configuration()

QVariantMap QgsFractionNumericFormat::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.

Definition at line 160 of file qgsfractionnumericformat.cpp.

◆ create()

QgsNumericFormat * QgsFractionNumericFormat::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.

Definition at line 153 of file qgsfractionnumericformat.cpp.

◆ doubleToVulgarFraction()

static bool QgsFractionNumericFormat::doubleToVulgarFraction ( const double  value,
unsigned long long &  numerator,
unsigned long long &  denominator,
int &  sign,
const double  tolerance = 1e-10 
)
inlinestatic

Converts a double value to a vulgar fraction (e.g.

⅓, ¼, etc) by attempting to calculate the corresponding numerator and denominator, within the specified tolerance.

This method is based of Richard's algorithm (1981) from "Continued Fractions without Tears" (University of Minnesota).

Parameters
valueinput value to convert
numeratorwill be set to calculated fraction numerator
denominatorwill be set to the calculated fraction denominator
signwill be set to the sign of the result (as -1 or +1 values)
toleranceacceptable tolerance. Larger values will give "nicer" fractions.
Returns
true if value was successfully converted to a fraction

Definition at line 131 of file qgsfractionnumericformat.h.

◆ formatDouble()

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

Returns a formatted string representation of a numeric double value.

Implements QgsNumericFormat.

Definition at line 61 of file qgsfractionnumericformat.cpp.

◆ id()

QString QgsFractionNumericFormat::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.

Definition at line 46 of file qgsfractionnumericformat.cpp.

◆ setConfiguration()

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

Sets the format's configuration.

Definition at line 196 of file qgsfractionnumericformat.cpp.

◆ setShowPlusSign()

void QgsFractionNumericFormat::setShowPlusSign ( bool  show)

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

See also
showPlusSign()

Definition at line 220 of file qgsfractionnumericformat.cpp.

◆ setShowThousandsSeparator()

void QgsFractionNumericFormat::setShowThousandsSeparator ( bool  show)

Sets whether the thousands grouping separator will be shown.

See also
showThousandsSeparator()

Definition at line 210 of file qgsfractionnumericformat.cpp.

◆ setThousandsSeparator()

void QgsFractionNumericFormat::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 230 of file qgsfractionnumericformat.cpp.

◆ setUseDedicatedUnicodeCharacters()

void QgsFractionNumericFormat::setUseDedicatedUnicodeCharacters ( bool  enabled)

Sets whether dedicated unicode characters should be used, when the are available for the particular fraction (e.g.

½, ¼).

See also
useDedicatedUnicodeCharacters()
setUseUnicodeSuperSubscript()

Definition at line 181 of file qgsfractionnumericformat.cpp.

◆ setUseUnicodeSuperSubscript()

void QgsFractionNumericFormat::setUseUnicodeSuperSubscript ( bool  enabled)

Sets whether unicode superscript and subscript characters should be used, (e.g.

"⁶/₇").

See also
useUnicodeSuperSubscript()
setUseDedicatedUnicodeCharacters()

Definition at line 191 of file qgsfractionnumericformat.cpp.

◆ showPlusSign()

bool QgsFractionNumericFormat::showPlusSign ( ) const

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

See also
setShowPlusSign()

Definition at line 215 of file qgsfractionnumericformat.cpp.

◆ showThousandsSeparator()

bool QgsFractionNumericFormat::showThousandsSeparator ( ) const

Returns true if the thousands grouping separator will be shown.

See also
setShowThousandsSeparator()

Definition at line 205 of file qgsfractionnumericformat.cpp.

◆ sortKey()

int QgsFractionNumericFormat::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.

Definition at line 56 of file qgsfractionnumericformat.cpp.

◆ suggestSampleValue()

double QgsFractionNumericFormat::suggestSampleValue ( ) const
overridevirtual

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

Reimplemented from QgsNumericFormat.

Definition at line 171 of file qgsfractionnumericformat.cpp.

◆ thousandsSeparator()

QChar QgsFractionNumericFormat::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 225 of file qgsfractionnumericformat.cpp.

◆ toUnicodeSubscript()

QString QgsFractionNumericFormat::toUnicodeSubscript ( const QString &  input)
static

Converts numbers in an input string to unicode subscript equivalents.

See also
toUnicodeSuperscript()

Definition at line 265 of file qgsfractionnumericformat.cpp.

◆ toUnicodeSuperscript()

QString QgsFractionNumericFormat::toUnicodeSuperscript ( const QString &  input)
static

Converts numbers in an input string to unicode superscript equivalents.

See also
toUnicodeSubscript()

Definition at line 235 of file qgsfractionnumericformat.cpp.

◆ useDedicatedUnicodeCharacters()

bool QgsFractionNumericFormat::useDedicatedUnicodeCharacters ( ) const

Returns true if dedicated unicode characters should be used, when the are available for the particular fraction (e.g.

½, ¼).

See also
setUseDedicatedUnicodeCharacters()
useUnicodeSuperSubscript()

Definition at line 176 of file qgsfractionnumericformat.cpp.

◆ useUnicodeSuperSubscript()

bool QgsFractionNumericFormat::useUnicodeSuperSubscript ( ) const

Returns true if unicode superscript and subscript characters should be used, (e.g.

"⁶/₇").

See also
setUseUnicodeSuperSubscript()
useDedicatedUnicodeCharacters()

Definition at line 186 of file qgsfractionnumericformat.cpp.

◆ visibleName()

QString QgsFractionNumericFormat::visibleName ( ) const
overridevirtual

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

Implements QgsNumericFormat.

Definition at line 51 of file qgsfractionnumericformat.cpp.


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