QGIS API Documentation 3.37.0-Master (4ace69f83af)
Loading...
Searching...
No Matches
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.
 
QgsNumericFormatclone () const override
 Clones the format, returning a new object.
 
QVariantMap configuration (const QgsReadWriteContext &context) const override
 Returns the current configuration of the formatter.
 
QgsNumericFormatcreate (const QVariantMap &configuration, const QgsReadWriteContext &context) const override
 Creates a new copy of the format, using the supplied configuration.
 
QString formatDouble (double value, const QgsNumericFormatContext &context) const override
 Returns a formatted string representation of a numeric double value.
 
QString id () const override
 Returns a unique id for this numeric format.
 
void setShowPlusSign (bool show)
 Sets whether a leading plus sign will be shown for positive values.
 
void setShowThousandsSeparator (bool show)
 Sets whether the thousands grouping separator will be shown.
 
void setThousandsSeparator (QChar character)
 Sets an override character for the thousands separator character.
 
void setUseDedicatedUnicodeCharacters (bool enabled)
 Sets whether dedicated unicode characters should be used, when the are available for the particular fraction (e.g.
 
void setUseUnicodeSuperSubscript (bool enabled)
 Sets whether unicode superscript and subscript characters should be used, (e.g.
 
bool showPlusSign () const
 Returns true if a leading plus sign will be shown for positive values.
 
bool showThousandsSeparator () const
 Returns true if the thousands grouping separator will be shown.
 
int sortKey () override
 Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists.
 
double suggestSampleValue () const override
 Returns a suggested sample value which nicely represents the current format configuration.
 
QChar thousandsSeparator () const
 Returns any override for the thousands separator character.
 
bool useDedicatedUnicodeCharacters () const
 Returns true if dedicated unicode characters should be used, when the are available for the particular fraction (e.g.
 
bool useUnicodeSuperSubscript () const
 Returns true if unicode superscript and subscript characters should be used, (e.g.
 
QString visibleName () const override
 Returns the translated, user-visible name for this format.
 
- Public Member Functions inherited from QgsNumericFormat
 QgsNumericFormat ()=default
 Default constructor.
 
virtual ~QgsNumericFormat ()=default
 
bool operator!= (const QgsNumericFormat &other) const
 
bool operator== (const QgsNumericFormat &other) const
 
void writeXml (QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
 Writes the format to an XML element.
 

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.
 
static QString toUnicodeSubscript (const QString &input)
 Converts numbers in an input string to unicode subscript equivalents.
 
static QString toUnicodeSuperscript (const QString &input)
 Converts numbers in an input string to unicode superscript equivalents.
 

Protected Member Functions

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

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 45 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 151 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 163 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 156 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 64 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 49 of file qgsfractionnumericformat.cpp.

◆ setConfiguration()

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

Sets the format's configuration.

Definition at line 199 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 223 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 213 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 233 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 184 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 194 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 218 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 208 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 59 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 174 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 228 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 268 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 238 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 179 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 189 of file qgsfractionnumericformat.cpp.

◆ visibleName()

QString QgsFractionNumericFormat::visibleName ( ) const
overridevirtual

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

Implements QgsNumericFormat.

Definition at line 54 of file qgsfractionnumericformat.cpp.


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