Skip to content
Permalink
Browse files

Fix scale calculation when layout is in pixels

  • Loading branch information
nyalldawson committed Jul 25, 2017
1 parent 1e4c954 commit 3d94f733498e17251946df9e4e508a1d47a57168
Showing with 34 additions and 18 deletions.
  1. +18 −10 src/app/layout/qgslayoutdesignerdialog.cpp
  2. +16 −8 src/gui/layout/qgslayoutview.cpp
@@ -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 );
}
@@ -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();
}

0 comments on commit 3d94f73

Please sign in to comment.
You can’t perform that action at this time.