MCPcopy Index your code
hub / github.com/Audio4Linux/JDSP4Linux / drawLabelMaybeCached

Method drawLabelMaybeCached

3rdparty/qcustomplot/qcustomplot.cpp:5683–5742  ·  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

5681 getTickLabelData).
5682*/
5683void QCPLabelPainterPrivate::drawLabelMaybeCached(QCPPainter *painter, const QFont &font, const QColor &color, const QPointF &pos, AnchorSide side, double rotation, const QString &text)
5684{
5685 // warning: if you change anything here, also adapt getMaxTickLabelSize() accordingly!
5686 if (text.isEmpty()) return;
5687 QSize finalSize;
5688
5689 if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && !painter->modes().testFlag(QCPPainter::pmNoCaching)) // label caching enabled
5690 {
5691 QByteArray key = cacheKey(text, color, rotation, side);
5692 CachedLabel *cachedLabel = mLabelCache.take(QString::fromUtf8(key)); // attempt to take label from cache (don't use object() because we want ownership/prevent deletion during our operations, we re-insert it afterwards)
5693 if (!cachedLabel) // no cached label existed, create it
5694 {
5695 LabelData labelData = getTickLabelData(font, color, rotation, side, text);
5696 cachedLabel = createCachedLabel(labelData);
5697 }
5698 // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels):
5699 bool labelClippedByBorder = false;
5700 /*
5701 if (tickLabelSide == QCPAxis::lsOutside)
5702 {
5703 if (QCPAxis::orientation(type) == Qt::Horizontal)
5704 labelClippedByBorder = labelAnchor.x()+cachedLabel->offset.x()+cachedLabel->pixmap.width()/mParentPlot->bufferDevicePixelRatio() > viewportRect.right() || labelAnchor.x()+cachedLabel->offset.x() < viewportRect.left();
5705 else
5706 labelClippedByBorder = labelAnchor.y()+cachedLabel->offset.y()+cachedLabel->pixmap.height()/mParentPlot->bufferDevicePixelRatio() > viewportRect.bottom() || labelAnchor.y()+cachedLabel->offset.y() < viewportRect.top();
5707 }
5708 */
5709 if (!labelClippedByBorder)
5710 {
5711 painter->drawPixmap(pos+cachedLabel->offset, cachedLabel->pixmap);
5712 finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); // TODO: collect this in a member rect list?
5713 }
5714 mLabelCache.insert(QString::fromUtf8(key), cachedLabel);
5715 } else // label caching disabled, draw text directly on surface:
5716 {
5717 LabelData labelData = getTickLabelData(font, color, rotation, side, text);
5718 // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels):
5719 bool labelClippedByBorder = false;
5720 /*
5721 if (tickLabelSide == QCPAxis::lsOutside)
5722 {
5723 if (QCPAxis::orientation(type) == Qt::Horizontal)
5724 labelClippedByBorder = finalPosition.x()+(labelData.rotatedTotalBounds.width()+labelData.rotatedTotalBounds.left()) > viewportRect.right() || finalPosition.x()+labelData.rotatedTotalBounds.left() < viewportRect.left();
5725 else
5726 labelClippedByBorder = finalPosition.y()+(labelData.rotatedTotalBounds.height()+labelData.rotatedTotalBounds.top()) > viewportRect.bottom() || finalPosition.y()+labelData.rotatedTotalBounds.top() < viewportRect.top();
5727 }
5728 */
5729 if (!labelClippedByBorder)
5730 {
5731 drawText(painter, pos, labelData);
5732 finalSize = labelData.rotatedTotalBounds.size();
5733 }
5734 }
5735 /*
5736 // expand passed tickLabelsSize if current tick label is larger:
5737 if (finalSize.width() > tickLabelsSize->width())
5738 tickLabelsSize->setWidth(finalSize.width());
5739 if (finalSize.height() > tickLabelsSize->height())
5740 tickLabelsSize->setHeight(finalSize.height());

Callers

nothing calls this directly

Calls 4

takeMethod · 0.80
insertMethod · 0.80
isEmptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected