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