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

Method placeTickLabel

src/qt/qcustomplot.cpp:9488–9566  ·  view source on GitHub ↗

! \internal Draws a single tick label with the provided \a painter, utilizing the internal label cache to significantly speed up drawing of labels that were drawn in previous calls. The tick label is always bound to an axis, the distance to the axis is controllable via \a distanceToAxis in pixels. The pixel position in the axis direction is passed in the \a position parameter. Hence f

Source from the content-addressed store, hash-verified

9486 getTickLabelData).
9487*/
9488void QCPAxisPainterPrivate::placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize)
9489{
9490 // warning: if you change anything here, also adapt getMaxTickLabelSize() accordingly!
9491 if (text.isEmpty()) return;
9492 QSize finalSize;
9493 QPointF labelAnchor;
9494 switch (type)
9495 {
9496 case QCPAxis::atLeft: labelAnchor = QPointF(axisRect.left()-distanceToAxis-offset, position); break;
9497 case QCPAxis::atRight: labelAnchor = QPointF(axisRect.right()+distanceToAxis+offset, position); break;
9498 case QCPAxis::atTop: labelAnchor = QPointF(position, axisRect.top()-distanceToAxis-offset); break;
9499 case QCPAxis::atBottom: labelAnchor = QPointF(position, axisRect.bottom()+distanceToAxis+offset); break;
9500 }
9501 if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && !painter->modes().testFlag(QCPPainter::pmNoCaching)) // label caching enabled
9502 {
9503 CachedLabel *cachedLabel = mLabelCache.take(text); // attempt to get label from cache
9504 if (!cachedLabel) // no cached label existed, create it
9505 {
9506 cachedLabel = new CachedLabel;
9507 TickLabelData labelData = getTickLabelData(painter->font(), text);
9508 cachedLabel->offset = getTickLabelDrawOffset(labelData)+labelData.rotatedTotalBounds.topLeft();
9509 if (!qFuzzyCompare(1.0, mParentPlot->bufferDevicePixelRatio()))
9510 {
9511 cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()*mParentPlot->bufferDevicePixelRatio());
9512#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED
9513# ifdef QCP_DEVICEPIXELRATIO_FLOAT
9514 cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatioF());
9515# else
9516 cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatio());
9517# endif
9518#endif
9519 } else
9520 cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size());
9521 cachedLabel->pixmap.fill(Qt::transparent);
9522 QCPPainter cachePainter(&cachedLabel->pixmap);
9523 cachePainter.setPen(painter->pen());
9524 drawTickLabel(&cachePainter, -labelData.rotatedTotalBounds.topLeft().x(), -labelData.rotatedTotalBounds.topLeft().y(), labelData);
9525 }
9526 // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels):
9527 bool labelClippedByBorder = false;
9528 if (tickLabelSide == QCPAxis::lsOutside)
9529 {
9530 if (QCPAxis::orientation(type) == Qt::Horizontal)
9531 labelClippedByBorder = labelAnchor.x()+cachedLabel->offset.x()+cachedLabel->pixmap.width()/mParentPlot->bufferDevicePixelRatio() > viewportRect.right() || labelAnchor.x()+cachedLabel->offset.x() < viewportRect.left();
9532 else
9533 labelClippedByBorder = labelAnchor.y()+cachedLabel->offset.y()+cachedLabel->pixmap.height()/mParentPlot->bufferDevicePixelRatio() > viewportRect.bottom() || labelAnchor.y()+cachedLabel->offset.y() < viewportRect.top();
9534 }
9535 if (!labelClippedByBorder)
9536 {
9537 painter->drawPixmap(labelAnchor+cachedLabel->offset, cachedLabel->pixmap);
9538 finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio();
9539 }
9540 mLabelCache.insert(text, cachedLabel); // return label to cache or insert for the first time if newly created
9541 } else // label caching disabled, draw text directly on surface:
9542 {
9543 TickLabelData labelData = getTickLabelData(painter->font(), text);
9544 QPointF finalPosition = labelAnchor + getTickLabelDrawOffset(labelData);
9545 // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels):

Callers

nothing calls this directly

Calls 9

orientationFunction · 0.85
takeMethod · 0.80
setDevicePixelRatioMethod · 0.80
fillMethod · 0.80
setPenMethod · 0.80
setWidthMethod · 0.80
isEmptyMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected