QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
#include <qgsfractionnumericformat.h>
Public Member Functions | |
QgsFractionNumericFormat () | |
Default constructor. More... | |
QgsNumericFormat * | clone () 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... | |
QgsNumericFormat * | create (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... | |
![]() | |
QgsNumericFormat ()=default | |
Default constructor. More... | |
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. 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... | |
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 42 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 148 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 160 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 153 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 144 of file qgsfractionnumericformat.h.
|
overridevirtual |
Returns a formatted string representation of a numeric double value.
Implements QgsNumericFormat.
Definition at line 61 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 46 of file qgsfractionnumericformat.cpp.
|
protectedvirtual |
Sets the format's configuration.
Definition at line 196 of file qgsfractionnumericformat.cpp.
void QgsFractionNumericFormat::setShowPlusSign | ( | bool | show | ) |
Sets whether a leading plus sign will be shown for positive values.
Definition at line 220 of file qgsfractionnumericformat.cpp.
void QgsFractionNumericFormat::setShowThousandsSeparator | ( | bool | show | ) |
Sets whether the thousands grouping separator will be shown.
Definition at line 210 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 230 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 181 of file qgsfractionnumericformat.cpp.
void QgsFractionNumericFormat::setUseUnicodeSuperSubscript | ( | bool | enabled | ) |
Sets whether unicode superscript and subscript characters should be used, (e.g.
"⁶/₇").
Definition at line 191 of file qgsfractionnumericformat.cpp.
bool QgsFractionNumericFormat::showPlusSign | ( | ) | const |
Returns true
if a leading plus sign will be shown for positive values.
Definition at line 215 of file qgsfractionnumericformat.cpp.
bool QgsFractionNumericFormat::showThousandsSeparator | ( | ) | const |
Returns true
if the thousands grouping separator will be shown.
Definition at line 205 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 56 of file qgsfractionnumericformat.cpp.
|
overridevirtual |
Returns a suggested sample value which nicely represents the current format configuration.
Reimplemented from QgsNumericFormat.
Definition at line 171 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 225 of file qgsfractionnumericformat.cpp.
|
static |
Converts numbers in an input string to unicode subscript equivalents.
Definition at line 265 of file qgsfractionnumericformat.cpp.
|
static |
Converts numbers in an input string to unicode superscript equivalents.
Definition at line 235 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 176 of file qgsfractionnumericformat.cpp.
bool QgsFractionNumericFormat::useUnicodeSuperSubscript | ( | ) | const |
Returns true
if unicode superscript and subscript characters should be used, (e.g.
"⁶/₇").
Definition at line 186 of file qgsfractionnumericformat.cpp.
|
overridevirtual |
Returns the translated, user-visible name for this format.
Implements QgsNumericFormat.
Definition at line 51 of file qgsfractionnumericformat.cpp.