Skip to content

Commit

Permalink
Fix scale calculation when layout is in pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 25, 2017
1 parent 1e4c954 commit 3d94f73
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
28 changes: 18 additions & 10 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -406,16 +406,24 @@ void QgsLayoutDesignerDialog::sliderZoomChanged( int value )

void QgsLayoutDesignerDialog::updateStatusZoom()
{
double dpi = QgsApplication::desktop()->logicalDpiX();
//monitor dpi is not always correct - so make sure the value is sane
if ( ( dpi < 60 ) || ( dpi > 1200 ) )
dpi = 72;

//pixel width for 1mm on screen
double scale100 = dpi / 25.4;
//current zoomLevel
double zoomLevel = mView->transform().m11() * 100 / scale100;

double zoomLevel = 0;
if ( currentLayout()->units() == QgsUnitTypes::LayoutPixels )
{
zoomLevel = mView->transform().m11() * 100;
}
else
{
double dpi = QgsApplication::desktop()->logicalDpiX();
//monitor dpi is not always correct - so make sure the value is sane
if ( ( dpi < 60 ) || ( dpi > 1200 ) )
dpi = 72;

//pixel width for 1mm on screen
double scale100 = dpi / 25.4;
scale100 = currentLayout()->convertFromLayoutUnits( scale100, QgsUnitTypes::LayoutMillimeters ).length();
//current zoomLevel
zoomLevel = mView->transform().m11() * 100 / scale100;
}
whileBlocking( mStatusZoomCombo )->lineEdit()->setText( tr( "%1%" ).arg( zoomLevel, 0, 'f', 1 ) );
whileBlocking( mStatusZoomSlider )->setValue( zoomLevel );
}
Expand Down
24 changes: 16 additions & 8 deletions src/gui/layout/qgslayoutview.cpp
Expand Up @@ -105,14 +105,22 @@ void QgsLayoutView::scaleSafe( double scale )

void QgsLayoutView::setZoomLevel( double level )
{
double dpi = QgsApplication::desktop()->logicalDpiX();
//monitor dpi is not always correct - so make sure the value is sane
if ( ( dpi < 60 ) || ( dpi > 1200 ) )
dpi = 72;

//desired pixel width for 1mm on screen
double scale = qBound( MIN_VIEW_SCALE, level * dpi / 25.4, MAX_VIEW_SCALE );
setTransform( QTransform::fromScale( scale, scale ) );
if ( currentLayout()->units() == QgsUnitTypes::LayoutPixels )
{
setTransform( QTransform::fromScale( level, level ) );
}
else
{
double dpi = QgsApplication::desktop()->logicalDpiX();
//monitor dpi is not always correct - so make sure the value is sane
if ( ( dpi < 60 ) || ( dpi > 1200 ) )
dpi = 72;

//desired pixel width for 1mm on screen
level = qBound( MIN_VIEW_SCALE, level, MAX_VIEW_SCALE );
double mmLevel = currentLayout()->convertFromLayoutUnits( level, QgsUnitTypes::LayoutMillimeters ).length() * dpi / 25.4;
setTransform( QTransform::fromScale( mmLevel, mmLevel ) );
}
emit zoomLevelChanged();
updateRulers();
}
Expand Down

0 comments on commit 3d94f73

Please sign in to comment.