QGIS API Documentation 3.41.0-Master (cea29feecf2)
|
A numeric formatter which returns a vulgar fractional representation of a decimal value (e.g. More...
#include <qgsfractionnumericformat.h>
Public Member Functions | |
QgsFractionNumericFormat () | |
Default constructor. | |
QgsNumericFormat * | clone () const override |
Clones the format, returning a new object. | |
QVariantMap | configuration (const QgsReadWriteContext &context) const override |
Returns the current configuration of the formatter. | |
QgsNumericFormat * | create (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 | |
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 |
A numeric formatter which returns a vulgar fractional representation of a decimal value (e.g.
"1/2" instead of 0.5).
Definition at line 30 of file qgsfractionnumericformat.h.
QgsFractionNumericFormat::QgsFractionNumericFormat | ( | ) |
Default constructor.
Definition at line 45 of file qgsfractionnumericformat.cpp.
|
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.
|
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.
|
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.
|
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).
value | input value to convert |
numerator | will be set to calculated fraction numerator |
denominator | will be set to the calculated fraction denominator |
sign | will be set to the sign of the result (as -1 or +1 values) |
tolerance | acceptable tolerance. Larger values will give "nicer" fractions. |
true
if value was successfully converted to a fraction Definition at line 131 of file qgsfractionnumericformat.h.
|
overridevirtual |
Returns a formatted string representation of a numeric double value.
Implements QgsNumericFormat.
Definition at line 64 of file qgsfractionnumericformat.cpp.
|
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.
|
protectedvirtual |
Sets the format's configuration.
Definition at line 199 of file qgsfractionnumericformat.cpp.
void QgsFractionNumericFormat::setShowPlusSign | ( | bool | show | ) |
Sets whether a leading plus sign will be shown for positive values.
Definition at line 223 of file qgsfractionnumericformat.cpp.
void QgsFractionNumericFormat::setShowThousandsSeparator | ( | bool | show | ) |
Sets whether the thousands grouping separator will be shown.
Definition at line 213 of file qgsfractionnumericformat.cpp.
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.
Definition at line 233 of file qgsfractionnumericformat.cpp.
void QgsFractionNumericFormat::setUseDedicatedUnicodeCharacters | ( | bool | enabled | ) |
Sets whether dedicated unicode characters should be used, when the are available for the particular fraction (e.g.
½, ¼).
Definition at line 184 of file qgsfractionnumericformat.cpp.
void QgsFractionNumericFormat::setUseUnicodeSuperSubscript | ( | bool | enabled | ) |
Sets whether unicode superscript and subscript characters should be used, (e.g.
"⁶/₇").
Definition at line 194 of file qgsfractionnumericformat.cpp.
bool QgsFractionNumericFormat::showPlusSign | ( | ) | const |
Returns true
if a leading plus sign will be shown for positive values.
Definition at line 218 of file qgsfractionnumericformat.cpp.
bool QgsFractionNumericFormat::showThousandsSeparator | ( | ) | const |
Returns true
if the thousands grouping separator will be shown.
Definition at line 208 of file qgsfractionnumericformat.cpp.
|
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.
|
overridevirtual |
Returns a suggested sample value which nicely represents the current format configuration.
Reimplemented from QgsNumericFormat.
Definition at line 174 of file qgsfractionnumericformat.cpp.
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.
Definition at line 228 of file qgsfractionnumericformat.cpp.
|
static |
Converts numbers in an input string to unicode subscript equivalents.
Definition at line 268 of file qgsfractionnumericformat.cpp.
|
static |
Converts numbers in an input string to unicode superscript equivalents.
Definition at line 238 of file qgsfractionnumericformat.cpp.
bool QgsFractionNumericFormat::useDedicatedUnicodeCharacters | ( | ) | const |
Returns true
if dedicated unicode characters should be used, when the are available for the particular fraction (e.g.
½, ¼).
Definition at line 179 of file qgsfractionnumericformat.cpp.
bool QgsFractionNumericFormat::useUnicodeSuperSubscript | ( | ) | const |
Returns true
if unicode superscript and subscript characters should be used, (e.g.
"⁶/₇").
Definition at line 189 of file qgsfractionnumericformat.cpp.
|
overridevirtual |
Returns the translated, user-visible name for this format.
Implements QgsNumericFormat.
Definition at line 54 of file qgsfractionnumericformat.cpp.