| 951 | } |
| 952 | |
| 953 | QPointF PlotViewWidget::convertPlotPosToPixelPos(const QPointF & plotPos, |
| 954 | std::optional<double> zoomFactor) const |
| 955 | { |
| 956 | if (!zoomFactor) |
| 957 | zoomFactor = this->zoomFactor; |
| 958 | |
| 959 | Range<double> yRange = {0, 100}; |
| 960 | if (this->model) |
| 961 | yRange = this->model->getYRange(); |
| 962 | const auto rangeY = double(yRange.max - yRange.min); |
| 963 | |
| 964 | const auto pixelPosX = this->propertiesAxis[0].line.p1().x() + |
| 965 | (plotPos.x() * this->zoomToPixelsPerValueX) * (*zoomFactor) + |
| 966 | this->moveOffset.x(); |
| 967 | |
| 968 | // line.p1 maps to the maximum y value and line.p2 to the lowest value |
| 969 | if (this->fixYAxis) |
| 970 | { |
| 971 | const auto lineLength = |
| 972 | this->propertiesAxis[1].line.p1().y() - this->propertiesAxis[1].line.p2().y(); |
| 973 | const auto relativePos = (plotPos.y() - yRange.min) / rangeY; |
| 974 | const auto pixelPosY = this->propertiesAxis[1].line.p1().y() - (relativePos * lineLength); |
| 975 | return {pixelPosX, pixelPosY}; |
| 976 | } |
| 977 | else |
| 978 | { |
| 979 | const auto rangeY = double(yRange.max - yRange.min); |
| 980 | const auto zoomToPixelsPerValueY = |
| 981 | (this->propertiesAxis[1].line.p1().y() - this->propertiesAxis[1].line.p2().y()) / rangeY; |
| 982 | const auto pixelPosY = this->propertiesAxis[1].line.p1().y() - |
| 983 | (plotPos.y() * zoomToPixelsPerValueY) * (*zoomFactor) + |
| 984 | this->moveOffset.y(); |
| 985 | return {pixelPosX, pixelPosY}; |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | QPointF PlotViewWidget::convertPixelPosToPlotPos(const QPointF & pixelPos, |
| 990 | std::optional<double> zoomFactor) const |
no test coverage detected