MCPcopy Create free account
hub / github.com/LUX-Core/lux / getTickLabelData

Method getTickLabelData

src/qt/qcustomplot.cpp:9616–9686  ·  view source on GitHub ↗

! \internal This is a \ref placeTickLabel helper function. Transforms the passed \a text and \a font to a tickLabelData structure that can then be further processed by \ref getTickLabelDrawOffset and \ref drawTickLabel. It splits the text into base and exponent if necessary (member substituteExponent) and calculates appropriate bounding boxes. */

Source from the content-addressed store, hash-verified

9614 exponent if necessary (member substituteExponent) and calculates appropriate bounding boxes.
9615*/
9616QCPAxisPainterPrivate::TickLabelData QCPAxisPainterPrivate::getTickLabelData(const QFont &font, const QString &text) const
9617{
9618 TickLabelData result;
9619
9620 // determine whether beautiful decimal powers should be used
9621 bool useBeautifulPowers = false;
9622 int ePos = -1; // first index of exponent part, text before that will be basePart, text until eLast will be expPart
9623 int eLast = -1; // last index of exponent part, rest of text after this will be suffixPart
9624 if (substituteExponent)
9625 {
9626 ePos = text.indexOf(QLatin1Char('e'));
9627 if (ePos > 0 && text.at(ePos-1).isDigit())
9628 {
9629 eLast = ePos;
9630 while (eLast+1 < text.size() && (text.at(eLast+1) == QLatin1Char('+') || text.at(eLast+1) == QLatin1Char('-') || text.at(eLast+1).isDigit()))
9631 ++eLast;
9632 if (eLast > ePos) // only if also to right of 'e' is a digit/+/- interpret it as beautifiable power
9633 useBeautifulPowers = true;
9634 }
9635 }
9636
9637 // calculate text bounding rects and do string preparation for beautiful decimal powers:
9638 result.baseFont = font;
9639 if (result.baseFont.pointSizeF() > 0) // might return -1 if specified with setPixelSize, in that case we can't do correction in next line
9640 result.baseFont.setPointSizeF(result.baseFont.pointSizeF()+0.05); // QFontMetrics.boundingRect has a bug for exact point sizes that make the results oscillate due to internal rounding
9641 if (useBeautifulPowers)
9642 {
9643 // split text into parts of number/symbol that will be drawn normally and part that will be drawn as exponent:
9644 result.basePart = text.left(ePos);
9645 result.suffixPart = text.mid(eLast+1); // also drawn normally but after exponent
9646 // in log scaling, we want to turn "1*10^n" into "10^n", else add multiplication sign and decimal base:
9647 if (abbreviateDecimalPowers && result.basePart == QLatin1String("1"))
9648 result.basePart = QLatin1String("10");
9649 else
9650 result.basePart += (numberMultiplyCross ? QString(QChar(215)) : QString(QChar(183))) + QLatin1String("10");
9651 result.expPart = text.mid(ePos+1, eLast-ePos);
9652 // clip "+" and leading zeros off expPart:
9653 while (result.expPart.length() > 2 && result.expPart.at(1) == QLatin1Char('0')) // length > 2 so we leave one zero when numberFormatChar is 'e'
9654 result.expPart.remove(1, 1);
9655 if (!result.expPart.isEmpty() && result.expPart.at(0) == QLatin1Char('+'))
9656 result.expPart.remove(0, 1);
9657 // prepare smaller font for exponent:
9658 result.expFont = font;
9659 if (result.expFont.pointSize() > 0)
9660 result.expFont.setPointSize(result.expFont.pointSize()*0.75);
9661 else
9662 result.expFont.setPixelSize(result.expFont.pixelSize()*0.75);
9663 // calculate bounding rects of base part(s), exponent part and total one:
9664 result.baseBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.basePart);
9665 result.expBounds = QFontMetrics(result.expFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.expPart);
9666 if (!result.suffixPart.isEmpty())
9667 result.suffixBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.suffixPart);
9668 result.totalBounds = result.baseBounds.adjusted(0, 0, result.expBounds.width()+result.suffixBounds.width()+2, 0); // +2 consists of the 1 pixel spacing between base and exponent (see drawTickLabel) and an extra pixel to include AA
9669 } else // useBeautifulPowers == false
9670 {
9671 result.basePart = text;
9672 result.totalBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, result.basePart);
9673 }

Callers

nothing calls this directly

Calls 6

midMethod · 0.80
atMethod · 0.45
sizeMethod · 0.45
lengthMethod · 0.45
removeMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected