| 103 | } |
| 104 | |
| 105 | void PlotViewWidget::zoomToFitInternal() |
| 106 | { |
| 107 | if (!this->model) |
| 108 | return; |
| 109 | |
| 110 | const auto plotXMin = this->convertPixelPosToPlotPos(this->plotRect.bottomLeft(), 1.0).x() - 0.5; |
| 111 | const auto plotXMax = this->convertPixelPosToPlotPos(this->plotRect.bottomRight(), 1.0).x() + 0.5; |
| 112 | const auto widthInPlotSpace = plotXMax - plotXMin; |
| 113 | |
| 114 | bool modelContainsDataYet = false; |
| 115 | double minZoomFactor = -1; |
| 116 | for (auto streamIndex : this->showStreamList) |
| 117 | { |
| 118 | const auto param = this->model->getStreamParameter(streamIndex); |
| 119 | |
| 120 | bool streamContainsData = false; |
| 121 | for (const auto &plotParam : param.plotParameters) |
| 122 | streamContainsData |= plotParam.nrpoints > 0; |
| 123 | |
| 124 | if (!streamContainsData) |
| 125 | continue; |
| 126 | |
| 127 | modelContainsDataYet = true; |
| 128 | const auto streamXRange = param.xRange.max - param.xRange.min; |
| 129 | |
| 130 | double newZoomFactor = 1.0; |
| 131 | while (streamXRange * newZoomFactor > widthInPlotSpace) |
| 132 | newZoomFactor /= ZOOM_STEP_FACTOR; |
| 133 | if (newZoomFactor == 1.0) |
| 134 | { |
| 135 | while (streamXRange * newZoomFactor < widthInPlotSpace) |
| 136 | newZoomFactor *= ZOOM_STEP_FACTOR; |
| 137 | } |
| 138 | |
| 139 | if (minZoomFactor == -1) |
| 140 | minZoomFactor = newZoomFactor; |
| 141 | else |
| 142 | minZoomFactor = std::min(minZoomFactor, newZoomFactor); |
| 143 | } |
| 144 | |
| 145 | if (!modelContainsDataYet) |
| 146 | return; |
| 147 | |
| 148 | if (minZoomFactor < ZOOMINGLIMIT.min || minZoomFactor > ZOOMINGLIMIT.max) |
| 149 | return; |
| 150 | |
| 151 | // Zoom the view so that we can see a certain amount of items |
| 152 | this->setZoomFactor(minZoomFactor); |
| 153 | |
| 154 | // Move the view so that the first value is at the left |
| 155 | auto visibleRange = this->getVisibleRange(Axis::X); |
| 156 | if (!visibleRange) |
| 157 | return; |
| 158 | |
| 159 | this->update(); |
| 160 | } |
| 161 | |
| 162 | void drawTextInCenterOfArea(QPainter &painter, QRect area, QString text) |
nothing calls this directly
no test coverage detected