QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
|
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. 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... | |
Public Member Functions inherited from QgsNumericFormat | |
QgsNumericFormat ()=default | |
Default constructor. More... | |
virtual | ~QgsNumericFormat ()=default |
virtual QgsNumericFormat * | clone () 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 QgsNumericFormat * | create (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 |
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.