| 987 | } |
| 988 | |
| 989 | QPointF PlotViewWidget::convertPixelPosToPlotPos(const QPointF & pixelPos, |
| 990 | std::optional<double> zoomFactor) const |
| 991 | { |
| 992 | if (!zoomFactor) |
| 993 | zoomFactor = this->zoomFactor; |
| 994 | |
| 995 | Range<double> yRange = {0, 100}; |
| 996 | if (this->model) |
| 997 | yRange = this->model->getYRange(); |
| 998 | const auto rangeY = double(yRange.max - yRange.min); |
| 999 | |
| 1000 | const auto valueX = |
| 1001 | ((pixelPos.x() - this->propertiesAxis[0].line.p1().x() - this->moveOffset.x()) / |
| 1002 | (*zoomFactor)) / |
| 1003 | this->zoomToPixelsPerValueX; |
| 1004 | |
| 1005 | // line.p1 maps to the maximum y value and line.p2 to the lowest value |
| 1006 | if (this->fixYAxis) |
| 1007 | { |
| 1008 | const auto lineLength = |
| 1009 | this->propertiesAxis[1].line.p1().y() - this->propertiesAxis[1].line.p2().y(); |
| 1010 | const double relativePos = (this->propertiesAxis[1].line.p1().y() - pixelPos.y()) / lineLength; |
| 1011 | const auto valueY = yRange.min + relativePos * rangeY; |
| 1012 | return {valueX, valueY}; |
| 1013 | } |
| 1014 | else |
| 1015 | { |
| 1016 | const auto zoomToPixelsPerValueY = |
| 1017 | (this->propertiesAxis[1].line.p1().y() - this->propertiesAxis[1].line.p2().y()) / rangeY; |
| 1018 | const auto valueY = |
| 1019 | ((-pixelPos.y() + this->propertiesAxis[1].line.p1().y() + this->moveOffset.y()) / |
| 1020 | (*zoomFactor)) / |
| 1021 | zoomToPixelsPerValueY; |
| 1022 | return {valueX, valueY}; |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | void PlotViewWidget::onZoomRectUpdateOffsetAndZoom(QRectF zoomRect, double additionalZoomFactor) |
| 1027 | { |
no test coverage detected