! Sets the apparent pixel position. This works no matter what type (\ref setType) this QCPItemPosition is or what parent-child situation it is in, as coordinates are transformed appropriately, to make the position finally appear at the specified pixel values. Only if the type is \ref ptAbsolute and no parent anchor is set, this function's effect is identical to that of \ref setCoords.
| 12664 | \see pixelPosition, setCoords |
| 12665 | */ |
| 12666 | void QCPItemPosition::setPixelPosition(const QPointF &pixelPosition) |
| 12667 | { |
| 12668 | double x = pixelPosition.x(); |
| 12669 | double y = pixelPosition.y(); |
| 12670 | |
| 12671 | switch (mPositionTypeX) |
| 12672 | { |
| 12673 | case ptAbsolute: |
| 12674 | { |
| 12675 | if (mParentAnchorX) |
| 12676 | x -= mParentAnchorX->pixelPosition().x(); |
| 12677 | break; |
| 12678 | } |
| 12679 | case ptViewportRatio: |
| 12680 | { |
| 12681 | if (mParentAnchorX) |
| 12682 | x -= mParentAnchorX->pixelPosition().x(); |
| 12683 | else |
| 12684 | x -= mParentPlot->viewport().left(); |
| 12685 | x /= double(mParentPlot->viewport().width()); |
| 12686 | break; |
| 12687 | } |
| 12688 | case ptAxisRectRatio: |
| 12689 | { |
| 12690 | if (mAxisRect) |
| 12691 | { |
| 12692 | if (mParentAnchorX) |
| 12693 | x -= mParentAnchorX->pixelPosition().x(); |
| 12694 | else |
| 12695 | x -= mAxisRect.data()->left(); |
| 12696 | x /= double(mAxisRect.data()->width()); |
| 12697 | } else |
| 12698 | qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; |
| 12699 | break; |
| 12700 | } |
| 12701 | case ptPlotCoords: |
| 12702 | { |
| 12703 | if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) |
| 12704 | x = mKeyAxis.data()->pixelToCoord(x); |
| 12705 | else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) |
| 12706 | y = mValueAxis.data()->pixelToCoord(x); |
| 12707 | else |
| 12708 | qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; |
| 12709 | break; |
| 12710 | } |
| 12711 | } |
| 12712 | |
| 12713 | switch (mPositionTypeY) |
| 12714 | { |
| 12715 | case ptAbsolute: |
| 12716 | { |
| 12717 | if (mParentAnchorY) |
| 12718 | y -= mParentAnchorY->pixelPosition().y(); |
| 12719 | break; |
| 12720 | } |
| 12721 | case ptViewportRatio: |
| 12722 | { |
| 12723 | if (mParentAnchorY) |
nothing calls this directly
no test coverage detected