| 460 | } |
| 461 | |
| 462 | void MapWidget::adjustViewToRect(QRectF map_rect, ZoomOption zoom_option) |
| 463 | { |
| 464 | view->setCenter(MapCoord{ map_rect.center() }); |
| 465 | |
| 466 | if (map_rect.isValid()) |
| 467 | { |
| 468 | // NOTE: The loop is an inelegant way to fight inaccuracies that occur somewhere ... |
| 469 | const int pixel_border = 15; |
| 470 | const float initial_zoom = view->getZoom(); |
| 471 | for (int i = 0; i < 10; ++i) |
| 472 | { |
| 473 | float zoom_factor = qMin(height() / (view->lengthToPixel(1000.0 * map_rect.height()) + 2*pixel_border), |
| 474 | width() / (view->lengthToPixel(1000.0 * map_rect.width()) + 2*pixel_border)); |
| 475 | float zoom = view->getZoom() * zoom_factor; |
| 476 | if (zoom_option == DiscreteZoom) |
| 477 | { |
| 478 | zoom = pow(2, 0.5 * floor(2.0 * (std::log2(zoom) - std::log2(initial_zoom))) + std::log2(initial_zoom)); |
| 479 | } |
| 480 | view->setZoom(zoom); |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | void MapWidget::moveDirtyRect(QRect& dirty_rect, qreal x, qreal y) |
| 486 | { |
no test coverage detected