Skip to content

Commit 1ae010a

Browse files
committedOct 26, 2018
Fix some clang truncate to int warnings
1 parent 1a2d0cc commit 1ae010a

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed
 

‎python/core/auto_generated/qgsscalecalculator.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Set the map units
5757
Returns current map units
5858
%End
5959

60-
double calculate( const QgsRectangle &mapExtent, int canvasWidth );
60+
double calculate( const QgsRectangle &mapExtent, double canvasWidth );
6161
%Docstring
6262
Calculate the scale denominator
6363

‎src/core/layout/qgslayoutitemmap.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -837,21 +837,21 @@ void QgsLayoutItemMap::paint( QPainter *painter, const QStyleOptionGraphicsItem
837837
// rasterize
838838
double destinationDpi = QgsLayoutUtils::scaleFactorFromItemStyle( style ) * 25.4;
839839
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 ) );
842842
QImage image = QImage( widthInPixels, heightInPixels, QImage::Format_ARGB32 );
843843

844844
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 ) ) );
847847
double dotsPerMM = destinationDpi / 25.4;
848848
QPainter p( &image );
849849

850850
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 ) ) );
855855
p.setClipRect( imagePaintRect );
856856

857857
p.translate( imagePaintRect.topLeft() );
@@ -884,7 +884,7 @@ void QgsLayoutItemMap::paint( QPainter *painter, const QStyleOptionGraphicsItem
884884

885885
painter->save();
886886
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 );
888888
painter->scale( dotsPerMM, dotsPerMM );
889889
painter->restore();
890890
}
@@ -994,21 +994,21 @@ void QgsLayoutItemMap::recreateCachedImageInBackground()
994994
double widthLayoutUnits = ext.width() * mapUnitsToLayoutUnits();
995995
double heightLayoutUnits = ext.height() * mapUnitsToLayoutUnits();
996996

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 ) );
999999

10001000
// limit size of image for better performance
10011001
if ( w > 5000 || h > 5000 )
10021002
{
10031003
if ( w > h )
10041004
{
10051005
w = 5000;
1006-
h = w * heightLayoutUnits / widthLayoutUnits;
1006+
h = static_cast< int>( std::round( w * heightLayoutUnits / widthLayoutUnits ) );
10071007
}
10081008
else
10091009
{
10101010
h = 5000;
1011-
w = h * widthLayoutUnits / heightLayoutUnits;
1011+
w = static_cast< int >( std::round( h * widthLayoutUnits / heightLayoutUnits ) );
10121012
}
10131013
}
10141014

@@ -1018,8 +1018,8 @@ void QgsLayoutItemMap::recreateCachedImageInBackground()
10181018
mCacheRenderingImage.reset( new QImage( w, h, QImage::Format_ARGB32 ) );
10191019

10201020
// 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 ) ) );
10231023

10241024
if ( hasBackground() )
10251025
{

‎src/core/qgsscalecalculator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ QgsUnitTypes::DistanceUnit QgsScaleCalculator::mapUnits() const
4747
return mMapUnits;
4848
}
4949

50-
double QgsScaleCalculator::calculate( const QgsRectangle &mapExtent, int canvasWidth )
50+
double QgsScaleCalculator::calculate( const QgsRectangle &mapExtent, double canvasWidth )
5151
{
5252
double conversionFactor = 0;
5353
double delta = 0;
@@ -77,7 +77,7 @@ double QgsScaleCalculator::calculate( const QgsRectangle &mapExtent, int canvasW
7777
delta = calculateGeographicDistance( mapExtent );
7878
break;
7979
}
80-
if ( canvasWidth == 0 || qgsDoubleNear( mDpi, 0.0 ) )
80+
if ( qgsDoubleNear( canvasWidth, 0. ) || qgsDoubleNear( mDpi, 0.0 ) )
8181
{
8282
QgsDebugMsg( QStringLiteral( "Can't calculate scale from the input values" ) );
8383
return 0;

‎src/core/qgsscalecalculator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class CORE_EXPORT QgsScaleCalculator
7070
* \param canvasWidth Width of the map canvas in pixel (physical) units
7171
* \returns scale denominator of current map view, e.g. 1000.0 for a 1:1000 map.
7272
*/
73-
double calculate( const QgsRectangle &mapExtent, int canvasWidth );
73+
double calculate( const QgsRectangle &mapExtent, double canvasWidth );
7474

7575
/**
7676
* Calculate the distance between two points in geographic coordinates.

0 commit comments

Comments
 (0)
Please sign in to comment.