MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / adjustViewToRect

Method adjustViewToRect

src/gui/map/map_widget.cpp:462–483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

460}
461
462void 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
485void MapWidget::moveDirtyRect(QRect& dirty_rect, qreal x, qreal y)
486{

Callers 1

showWholeMapMethod · 0.80

Calls 9

log2Function · 0.85
centerMethod · 0.80
getZoomMethod · 0.80
lengthToPixelMethod · 0.80
setZoomMethod · 0.80
setCenterMethod · 0.45
isValidMethod · 0.45
heightMethod · 0.45
widthMethod · 0.45

Tested by

no test coverage detected