/*!
Sets the number format for the numbers drawn as tick labels (if tick label type is \ref
ltNumber). This \a formatCode is an extended version of the format code used e.g. by
QString::number() and QLocale::toString(). For reference about that, see the "Argument Formats"
section in the detailed description of the QString class. \a formatCode is a string of one, two
or three characters. The first character is identical to the normal format code used by Qt. In
short, this means: 'e'/'E' scientific format, 'f' fixed format, 'g'/'G' scientific or fixed,
whichever is shorter.
The second and third characters are optional and specific to QCustomPlot:\n
If the first char was 'e' or 'g', numbers are/might be displayed in the scientific format, e.g.
"5.5e9", which is ugly in a plot. So when the second char of \a formatCode is set to 'b' (for
"beautiful"), those exponential numbers are formatted in a more natural way, i.e. "5.5
[multiplication sign] 10 [superscript] 9". By default, the multiplication sign is a centered dot.
If instead a cross should be shown (as is usual in the USA), the third char of \a formatCode can
be set to 'c'. The inserted multiplication signs are the UTF-8 characters 215 (0xD7) for the
cross and 183 (0xB7) for the dot.
If the scale type (\ref setScaleType) is \ref stLogarithmic and the \a formatCode uses the 'b'
option (beautifully typeset decimal powers), the display usually is "1 [multiplication sign] 10
[superscript] n", which looks unnatural for logarithmic scaling (the "1 [multiplication sign]"
part). To only display the decimal power, set the number precision to zero with \ref
setNumberPrecision.
Examples for \a formatCode:
\li \c g normal format code behaviour. If number is small, fixed format is used, if number is large,
normal scientific format is used
\li \c gb If number is small, fixed format is used, if number is large, scientific format is used with
beautifully typeset decimal powers and a dot as multiplication sign
\li \c ebc All numbers are in scientific format with beautifully typeset decimal power and a cross as
multiplication sign
\li \c fb illegal format code, since fixed format doesn't support (or need) beautifully typeset decimal
powers. Format code will be reduced to 'f'.
\li \c hello illegal format code, since first char is not 'e', 'E', 'f', 'g' or 'G'. Current format
code will not be changed.
*/
void QCPAxis::setNumberFormat(const QString &formatCode)
{
if (formatCode.length() < 1) return;
// interpret first char as number format char:
QString allowedFormatChars = "eEfgG";
if (allowedFormatChars.contains(formatCode.at(0)))
{
mNumberFormatChar = formatCode.at(0).toAscii();
} else
{
qDebug() << Q_FUNC_INFO << "Invalid number format code (first char not in 'eEfgG'):" << formatCode;
return;
}
if (formatCode.length() < 2)
{
mNumberBeautifulPowers = false;
mNumberMultiplyCross = false;
return;
}
// interpret second char as indicator for beautiful decimal powers:
if (formatCode.at(1) == 'b' && (mNumberFormatChar == 'e' || mNumberFormatChar == 'g'))
{
mNumberBeautifulPowers = true;
} else
{
qDebug() << Q_FUNC_INFO << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode;
return;
}
if (formatCode.length() < 3)
{
mNumberMultiplyCross = false;
return;
}
// interpret third char as indicator for dot or cross multiplication symbol:
if (formatCode.at(2) == 'c')
{
mNumberMultiplyCross = true;
} else if (formatCode.at(2) == 'd')
{
mNumberMultiplyCross = false;
} else
{
qDebug() << Q_FUNC_INFO << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode;
return;
}
}