@@ -837,21 +837,21 @@ void QgsLayoutItemMap::paint( QPainter *painter, const QStyleOptionGraphicsItem
837
837
// rasterize
838
838
double destinationDpi = QgsLayoutUtils::scaleFactorFromItemStyle ( style ) * 25.4 ;
839
839
double layoutUnitsInInches = mLayout ? mLayout ->convertFromLayoutUnits ( 1 , QgsUnitTypes::LayoutInches ).length () : 1 ;
840
- int widthInPixels = std::round ( boundingRect ().width () * layoutUnitsInInches * destinationDpi );
841
- int heightInPixels = std::round ( boundingRect ().height () * layoutUnitsInInches * destinationDpi );
840
+ int widthInPixels = static_cast < int >( std::round ( boundingRect ().width () * layoutUnitsInInches * destinationDpi ) );
841
+ int heightInPixels = static_cast < int >( std::round ( boundingRect ().height () * layoutUnitsInInches * destinationDpi ) );
842
842
QImage image = QImage ( widthInPixels, heightInPixels, QImage::Format_ARGB32 );
843
843
844
844
image.fill ( Qt::transparent );
845
- image.setDotsPerMeterX ( 1000 * destinationDpi / 25.4 );
846
- image.setDotsPerMeterY ( 1000 * destinationDpi / 25.4 );
845
+ image.setDotsPerMeterX ( static_cast < int >( std::round ( 1000 * destinationDpi / 25.4 ) ) );
846
+ image.setDotsPerMeterY ( static_cast < int >( std::round ( 1000 * destinationDpi / 25.4 ) ) );
847
847
double dotsPerMM = destinationDpi / 25.4 ;
848
848
QPainter p ( &image );
849
849
850
850
QPointF tl = -boundingRect ().topLeft ();
851
- QRect imagePaintRect ( std::round ( tl.x () * dotsPerMM ),
852
- std::round ( tl.y () * dotsPerMM ),
853
- std::round ( thisPaintRect.width () * dotsPerMM ),
854
- std::round ( thisPaintRect.height () * dotsPerMM ) );
851
+ QRect imagePaintRect ( static_cast < int >( std::round ( tl.x () * dotsPerMM ) ),
852
+ static_cast < int >( std::round ( tl.y () * dotsPerMM ) ),
853
+ static_cast < int >( std::round ( thisPaintRect.width () * dotsPerMM ) ),
854
+ static_cast < int >( std::round ( thisPaintRect.height () * dotsPerMM ) ) );
855
855
p.setClipRect ( imagePaintRect );
856
856
857
857
p.translate ( imagePaintRect.topLeft () );
@@ -884,7 +884,7 @@ void QgsLayoutItemMap::paint( QPainter *painter, const QStyleOptionGraphicsItem
884
884
885
885
painter->save ();
886
886
painter->scale ( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
887
- painter->drawImage ( std::round ( -tl.x ()* dotsPerMM ), std::round ( -tl.y () * dotsPerMM ), image );
887
+ painter->drawImage ( QPointF ( -tl.x ()* dotsPerMM, -tl.y () * dotsPerMM ), image );
888
888
painter->scale ( dotsPerMM, dotsPerMM );
889
889
painter->restore ();
890
890
}
@@ -994,21 +994,21 @@ void QgsLayoutItemMap::recreateCachedImageInBackground()
994
994
double widthLayoutUnits = ext.width () * mapUnitsToLayoutUnits ();
995
995
double heightLayoutUnits = ext.height () * mapUnitsToLayoutUnits ();
996
996
997
- int w = widthLayoutUnits * mPreviewScaleFactor ;
998
- int h = heightLayoutUnits * mPreviewScaleFactor ;
997
+ int w = static_cast < int >( std::round ( widthLayoutUnits * mPreviewScaleFactor ) ) ;
998
+ int h = static_cast < int >( std::round ( heightLayoutUnits * mPreviewScaleFactor ) ) ;
999
999
1000
1000
// limit size of image for better performance
1001
1001
if ( w > 5000 || h > 5000 )
1002
1002
{
1003
1003
if ( w > h )
1004
1004
{
1005
1005
w = 5000 ;
1006
- h = w * heightLayoutUnits / widthLayoutUnits;
1006
+ h = static_cast < int >( std::round ( w * heightLayoutUnits / widthLayoutUnits ) ) ;
1007
1007
}
1008
1008
else
1009
1009
{
1010
1010
h = 5000 ;
1011
- w = h * widthLayoutUnits / heightLayoutUnits;
1011
+ w = static_cast < int >( std::round ( h * widthLayoutUnits / heightLayoutUnits ) ) ;
1012
1012
}
1013
1013
}
1014
1014
@@ -1018,8 +1018,8 @@ void QgsLayoutItemMap::recreateCachedImageInBackground()
1018
1018
mCacheRenderingImage .reset ( new QImage ( w, h, QImage::Format_ARGB32 ) );
1019
1019
1020
1020
// set DPI of the image
1021
- mCacheRenderingImage ->setDotsPerMeterX ( 1000 * w / widthLayoutUnits );
1022
- mCacheRenderingImage ->setDotsPerMeterY ( 1000 * h / heightLayoutUnits );
1021
+ mCacheRenderingImage ->setDotsPerMeterX ( static_cast < int >( std::round ( 1000 * w / widthLayoutUnits ) ) );
1022
+ mCacheRenderingImage ->setDotsPerMeterY ( static_cast < int >( std::round ( 1000 * h / heightLayoutUnits ) ) );
1023
1023
1024
1024
if ( hasBackground () )
1025
1025
{
0 commit comments