MCPcopy Create free account
hub / github.com/cutechess/cutechess / getTickLabelData

Method getTickLabelData

projects/gui/3rdparty/qcustomplot/qcustomplot.cpp:5840–5908  ·  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

5838 exponent if necessary (member substituteExponent) and calculates appropriate bounding boxes.
5839*/
5840QCPLabelPainterPrivate::LabelData QCPLabelPainterPrivate::getTickLabelData(const QFont &font, const QColor &color, double rotation, AnchorSide side, const QString &text) const
5841{
5842 LabelData result;
5843 result.rotation = rotation;
5844 result.side = side;
5845 result.color = color;
5846
5847 // determine whether beautiful decimal powers should be used
5848 bool useBeautifulPowers = false;
5849 int ePos = -1; // first index of exponent part, text before that will be basePart, text until eLast will be expPart
5850 int eLast = -1; // last index of exponent part, rest of text after this will be suffixPart
5851 if (mSubstituteExponent)
5852 {
5853 ePos = text.indexOf(QLatin1Char('e'));
5854 if (ePos > 0 && text.at(ePos-1).isDigit())
5855 {
5856 eLast = ePos;
5857 while (eLast+1 < text.size() && (text.at(eLast+1) == QLatin1Char('+') || text.at(eLast+1) == QLatin1Char('-') || text.at(eLast+1).isDigit()))
5858 ++eLast;
5859 if (eLast > ePos) // only if also to right of 'e' is a digit/+/- interpret it as beautifiable power
5860 useBeautifulPowers = true;
5861 }
5862 }
5863
5864 // calculate text bounding rects and do string preparation for beautiful decimal powers:
5865 result.baseFont = font;
5866 if (result.baseFont.pointSizeF() > 0) // might return -1 if specified with setPixelSize, in that case we can't do correction in next line
5867 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
5868
5869 QFontMetrics baseFontMetrics(result.baseFont);
5870 if (useBeautifulPowers)
5871 {
5872 // split text into parts of number/symbol that will be drawn normally and part that will be drawn as exponent:
5873 result.basePart = text.left(ePos);
5874 result.suffixPart = text.mid(eLast+1); // also drawn normally but after exponent
5875 // in log scaling, we want to turn "1*10^n" into "10^n", else add multiplication sign and decimal base:
5876 if (mAbbreviateDecimalPowers && result.basePart == QLatin1String("1"))
5877 result.basePart = QLatin1String("10");
5878 else
5879 result.basePart += QString(mMultiplicationSymbol) + QLatin1String("10");
5880 result.expPart = text.mid(ePos+1, eLast-ePos);
5881 // clip "+" and leading zeros off expPart:
5882 while (result.expPart.length() > 2 && result.expPart.at(1) == QLatin1Char('0')) // length > 2 so we leave one zero when numberFormatChar is 'e'
5883 result.expPart.remove(1, 1);
5884 if (!result.expPart.isEmpty() && result.expPart.at(0) == QLatin1Char('+'))
5885 result.expPart.remove(0, 1);
5886 // prepare smaller font for exponent:
5887 result.expFont = font;
5888 if (result.expFont.pointSize() > 0)
5889 result.expFont.setPointSize(result.expFont.pointSize()*0.75);
5890 else
5891 result.expFont.setPixelSize(result.expFont.pixelSize()*0.75);
5892 // calculate bounding rects of base part(s), exponent part and total one:
5893 result.baseBounds = baseFontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.basePart);
5894 result.expBounds = QFontMetrics(result.expFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.expPart);
5895 if (!result.suffixPart.isEmpty())
5896 result.suffixBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.suffixPart);
5897 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

Callers

nothing calls this directly

Calls 8

atMethod · 0.80
lengthMethod · 0.80
removeMethod · 0.60
QStringClass · 0.50
sizeMethod · 0.45
isEmptyMethod · 0.45
boundingRectMethod · 0.45
widthMethod · 0.45

Tested by

no test coverage detected