! \internal Returns the appropriate outward margin for this axis. It is needed if \ref QCPAxisRect::setAutoMargins is set to true on the parent axis rect. An axis with axis type \ref atLeft will return an appropriate left margin, \ref atBottom will return an appropriate bottom margin and so forth. For the calculation, this function goes through similar steps as \ref draw, so changing
| 9826 | unchanged are very fast. |
| 9827 | */ |
| 9828 | int QCPAxis::calculateMargin() |
| 9829 | { |
| 9830 | if (!mVisible) // if not visible, directly return 0, don't cache 0 because we can't react to setVisible in QCPAxis |
| 9831 | return 0; |
| 9832 | |
| 9833 | if (mCachedMarginValid) |
| 9834 | return mCachedMargin; |
| 9835 | |
| 9836 | // run through similar steps as QCPAxis::draw, and calculate margin needed to fit axis and its labels |
| 9837 | int margin = 0; |
| 9838 | |
| 9839 | QVector<double> tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter |
| 9840 | QVector<QString> tickLabels; // the final vector passed to QCPAxisPainter |
| 9841 | tickPositions.reserve(mTickVector.size()); |
| 9842 | tickLabels.reserve(mTickVector.size()); |
| 9843 | |
| 9844 | if (mTicks) |
| 9845 | { |
| 9846 | for (int i=0; i<mTickVector.size(); ++i) |
| 9847 | { |
| 9848 | tickPositions.append(coordToPixel(mTickVector.at(i))); |
| 9849 | if (mTickLabels) |
| 9850 | tickLabels.append(mTickVectorLabels.at(i)); |
| 9851 | } |
| 9852 | } |
| 9853 | // transfer all properties of this axis to QCPAxisPainterPrivate which it needs to calculate the size. |
| 9854 | // Note that some axis painter properties are already set by direct feed-through with QCPAxis setters |
| 9855 | mAxisPainter->type = mAxisType; |
| 9856 | mAxisPainter->labelFont = getLabelFont(); |
| 9857 | mAxisPainter->label = mLabel; |
| 9858 | mAxisPainter->tickLabelFont = mTickLabelFont; |
| 9859 | mAxisPainter->axisRect = mAxisRect->rect(); |
| 9860 | mAxisPainter->viewportRect = mParentPlot->viewport(); |
| 9861 | mAxisPainter->tickPositions = tickPositions; |
| 9862 | mAxisPainter->tickLabels = tickLabels; |
| 9863 | margin += mAxisPainter->size(); |
| 9864 | margin += mPadding; |
| 9865 | |
| 9866 | mCachedMargin = margin; |
| 9867 | mCachedMarginValid = true; |
| 9868 | return margin; |
| 9869 | } |
| 9870 | |
| 9871 | /* inherits documentation from base class */ |
| 9872 | QCP::Interaction QCPAxis::selectionCategory() const |
no test coverage detected