Use std::round instead of qRound

Now that our minimum VS studio version allowed supports std::round,
we should use that in place of Qt's qRound method.

Because:
- it doesn't truncate to int, resulting in unpredictable
behaviour (refs #16925)
- better to stick to standard c++ methods wherever possible,
since they're likely better supported and optimised by the
compilers
- it's a tiny reduction to the barrier for entry to QGIS
development (I'm sick of pointing out the need to use
qRound during PR reviews!)
This commit is contained in:
Nyall Dawson 2017-08-24 16:24:50 +10:00
parent 50e8e1c00b
commit 4b009f96ec
54 changed files with 1811 additions and 1809 deletions

View File

@ -153,12 +153,6 @@ Compare two doubles using specified number of significant digits
:rtype: bool
%End
double qgsRound( double x );
%Docstring
A round function which returns a double to guard against overflows
:rtype: float
%End
double qgsRound( double number, double places );
%Docstring
Returns a double ``number``, rounded (as close as possible) to the specified number of ``places``.

View File

@ -30,16 +30,16 @@
static double ceil_with_tolerance( double value )
{
if ( qAbs( value - qRound( value ) ) < 1e-6 )
return qRound( value );
if ( qAbs( value - std::round( value ) ) < 1e-6 )
return std::round( value );
else
return qCeil( value );
}
static double floor_with_tolerance( double value )
{
if ( qAbs( value - qRound( value ) ) < 1e-6 )
return qRound( value );
if ( qAbs( value - std::round( value ) ) < 1e-6 )
return std::round( value );
else
return qFloor( value );
}

View File

@ -444,7 +444,7 @@ void QgsComposerMapWidget::on_mScaleLineEdit_editingFinished()
return;
}
if ( qRound( scaleDenominator ) == qRound( mComposerMap->scale() ) )
if ( std::round( scaleDenominator ) == std::round( mComposerMap->scale() ) )
return;
mComposerMap->beginCommand( tr( "Map scale changed" ) );

View File

@ -699,8 +699,8 @@ void QgsPluginManager::showPluginDetails( QStandardItem *item )
voteLabel->show();
voteSlider->show();
voteSubmit->show();
QgsDebugMsg( QString( "vote slider:%1" ).arg( qRound( metadata->value( "average_vote" ).toFloat() ) ) );
voteSlider->setValue( qRound( metadata->value( "average_vote" ).toFloat() ) );
QgsDebugMsg( QString( "vote slider:%1" ).arg( std::round( metadata->value( "average_vote" ).toFloat() ) ) );
voteSlider->setValue( std::round( metadata->value( "average_vote" ).toFloat() ) );
mCurrentPluginId = metadata->value( "plugin_id" ).toInt();
}
else

View File

@ -61,7 +61,7 @@ struct QgsAlignRasterDialogProgress : public QgsAlignRaster::ProgressHandler
explicit QgsAlignRasterDialogProgress( QProgressBar *pb ) : mPb( pb ) {}
virtual bool progress( double complete ) override
{
mPb->setValue( ( int ) qRound( complete * 100 ) );
mPb->setValue( ( int ) std::round( complete * 100 ) );
qApp->processEvents(); // to actually show the progress in GUI
return true;
}

View File

@ -790,7 +790,7 @@ bool QgsDecorationGrid::getIntervalFromExtent( double *values, bool useXAxis )
int factor = pow( 10, floor( log10( interval ) ) );
if ( factor != 0 )
{
interval2 = qRound( interval / factor ) * factor;
interval2 = std::round( interval / factor ) * factor;
QgsDebugMsg( QString( "interval2: %1" ).arg( interval2 ) );
if ( !qgsDoubleNear( interval2, 0.0 ) )
interval = interval2;

View File

@ -164,7 +164,7 @@ void QgsDecorationScaleBar::render( const QgsMapSettings &mapSettings, QgsRender
if ( mSnapping )
{
double scaler = pow( 10.0, myPowerOf10 );
myActualSize = qRound( myActualSize / scaler ) * scaler;
myActualSize = std::round( myActualSize / scaler ) * scaler;
myScaleBarWidth = myActualSize / myMapUnitsPerPixelDouble;
}

View File

@ -89,7 +89,7 @@ void QgsAngleMagnetWidget::setAngle( double angle )
const int magnet = mMagnetSpinBox->value();
if ( magnet )
{
mAngleSpinBox->setValue( qRound( angle / magnet ) * magnet );
mAngleSpinBox->setValue( std::round( angle / magnet ) * magnet );
}
else
{

View File

@ -280,7 +280,7 @@ QString QgsMeasureDialog::formatDistance( double distance, bool convertUnits ) c
{
// special handling for degrees - because we can't use smaller units (eg m->mm), we need to make sure there's
// enough decimal places to show a usable measurement value
int minPlaces = qRound( log10( 1.0 / distance ) ) + 1;
int minPlaces = std::round( log10( 1.0 / distance ) ) + 1;
decimals = qMax( decimals, minPlaces );
}
return QgsDistanceArea::formatDistance( distance, decimals, mDistanceUnits, baseUnit );

View File

@ -1445,7 +1445,7 @@ QString QgsComposerMapGrid::gridAnnotationString( double value, QgsComposerMapGr
{
QString hemisphere;
double coordRounded = qRound( value * pow( 10.0, mGridAnnotationPrecision ) ) / pow( 10.0, mGridAnnotationPrecision );
double coordRounded = std::round( value * pow( 10.0, mGridAnnotationPrecision ) ) / pow( 10.0, mGridAnnotationPrecision );
if ( coord == QgsComposerMapGrid::Longitude )
{
//don't use E/W suffixes if ambiguous (e.g., 180 degrees)

View File

@ -349,7 +349,7 @@ void QgsImageOperation::MultiplyOpacityPixelOperation::operator()( QRgb &rgb, co
{
Q_UNUSED( x );
Q_UNUSED( y );
rgb = qRgba( qRed( rgb ), qGreen( rgb ), qBlue( rgb ), qBound( 0, qRound( mFactor * qAlpha( rgb ) ), 255 ) );
rgb = qRgba( qRed( rgb ), qGreen( rgb ), qBlue( rgb ), qBound( 0.0, std::round( mFactor * qAlpha( rgb ) ), 255.0 ) );
}
// overlay color

View File

@ -2884,13 +2884,13 @@ static QVariant fcnRound( const QVariantList &values, const QgsExpressionContext
{
double number = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
double scaler = pow( 10.0, QgsExpressionUtils::getIntValue( values.at( 1 ), parent ) );
return QVariant( qRound( number * scaler ) / scaler );
return QVariant( std::round( number * scaler ) / scaler );
}
if ( values.length() >= 1 )
{
double number = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
return QVariant( qRound( number ) );
return QVariant( qlonglong( std::round( number ) ) );
}
return QVariant();

View File

@ -1701,11 +1701,11 @@ GEOSCoordSequence *QgsGeos::createCoordinateSequence( const QgsCurve *curve, dou
{
for ( int i = 0; i < numOutPoints; ++i )
{
GEOSCoordSeq_setX_r( geosinit.ctxt, coordSeq, i, qgsRound( line->xAt( i % numPoints ) / precision ) * precision );
GEOSCoordSeq_setY_r( geosinit.ctxt, coordSeq, i, qgsRound( line->yAt( i % numPoints ) / precision ) * precision );
GEOSCoordSeq_setX_r( geosinit.ctxt, coordSeq, i, std::round( line->xAt( i % numPoints ) / precision ) * precision );
GEOSCoordSeq_setY_r( geosinit.ctxt, coordSeq, i, std::round( line->yAt( i % numPoints ) / precision ) * precision );
if ( hasZ )
{
GEOSCoordSeq_setOrdinate_r( geosinit.ctxt, coordSeq, i, 2, qgsRound( line->zAt( i % numPoints ) / precision ) * precision );
GEOSCoordSeq_setOrdinate_r( geosinit.ctxt, coordSeq, i, 2, std::round( line->zAt( i % numPoints ) / precision ) * precision );
}
if ( hasM )
{
@ -1765,11 +1765,11 @@ GEOSGeometry *QgsGeos::createGeosPointXY( double x, double y, bool hasZ, double
}
if ( precision > 0. )
{
GEOSCoordSeq_setX_r( geosinit.ctxt, coordSeq, 0, qgsRound( x / precision ) * precision );
GEOSCoordSeq_setY_r( geosinit.ctxt, coordSeq, 0, qgsRound( y / precision ) * precision );
GEOSCoordSeq_setX_r( geosinit.ctxt, coordSeq, 0, std::round( x / precision ) * precision );
GEOSCoordSeq_setY_r( geosinit.ctxt, coordSeq, 0, std::round( y / precision ) * precision );
if ( hasZ )
{
GEOSCoordSeq_setOrdinate_r( geosinit.ctxt, coordSeq, 0, 2, qgsRound( z / precision ) * precision );
GEOSCoordSeq_setOrdinate_r( geosinit.ctxt, coordSeq, 0, 2, std::round( z / precision ) * precision );
}
}
else

View File

@ -112,13 +112,13 @@ int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinit
//work around this by first converting to double, and then checking whether the double is convertible to int
if ( ok )
{
double round = qgsRound( dbl );
double round = std::round( dbl );
if ( round > INT_MAX || round < -INT_MAX )
{
//double too large to fit in int
return 0;
}
return qRound( dbl );
return std::round( dbl );
}
return val.toInt();

View File

@ -236,13 +236,7 @@ inline bool qgsDoubleNearSig( double a, double b, int significantDigits = 10 )
double br = frexp( b, &bexp );
return aexp == bexp &&
qRound( ar * pow( 10.0, significantDigits ) ) == qRound( br * pow( 10.0, significantDigits ) );
}
//! A round function which returns a double to guard against overflows
inline double qgsRound( double x )
{
return x < 0.0 ? std::ceil( x - 0.5 ) : std::floor( x + 0.5 );
std::round( ar * pow( 10.0, significantDigits ) ) == std::round( br * pow( 10.0, significantDigits ) );
}
/**

View File

@ -396,7 +396,7 @@ QList<QColor> QgsLimitedRandomColorRamp::randomColors( int count,
//see http://basecase.org/env/on-rainbows for more details
currentHueAngle += 137.50776;
//scale hue to between hueMax and hueMin
h = qBound( 0, qRound( ( fmod( currentHueAngle, 360.0 ) / 360.0 ) * ( safeHueMax - safeHueMin ) + safeHueMin ), 359 );
h = qBound( 0.0, std::round( ( fmod( currentHueAngle, 360.0 ) / 360.0 ) * ( safeHueMax - safeHueMin ) + safeHueMin ), 359.0 );
s = qBound( 0, ( qrand() % ( safeSatMax - safeSatMin + 1 ) ) + safeSatMin, 255 );
v = qBound( 0, ( qrand() % ( safeValMax - safeValMin + 1 ) ) + safeValMin, 255 );
colors.append( QColor::fromHsv( h, s, v ) );
@ -468,7 +468,7 @@ void QgsRandomColorRamp::setTotalColorCount( const int colorCount )
//build up a list of colors
for ( int idx = 0; idx < colorCount; ++ idx )
{
int h = qRound( currentHue ) % 360;
int h = static_cast< int >( std::round( currentHue ) ) % 360;
int s = ( qrand() % ( DEFAULT_RANDOM_SAT_MAX - DEFAULT_RANDOM_SAT_MIN + 1 ) ) + DEFAULT_RANDOM_SAT_MIN;
int v = ( qrand() % ( DEFAULT_RANDOM_VAL_MAX - DEFAULT_RANDOM_VAL_MIN + 1 ) ) + DEFAULT_RANDOM_VAL_MIN;
mPrecalculatedColors << QColor::fromHsv( h, s, v );

View File

@ -156,9 +156,9 @@ void QgsDataDefinedSizeLegend::drawCollapsedLegend( QgsRenderContext &context, Q
// make sure we draw bigger symbols first
std::sort( classes.begin(), classes.end(), []( const SizeClass & a, const SizeClass & b ) { return a.size > b.size; } );
int hLengthLine = qRound( context.convertToPainterUnits( hLengthLineMM, QgsUnitTypes::RenderMillimeters ) );
int hSpaceLineText = qRound( context.convertToPainterUnits( hSpaceLineTextMM, QgsUnitTypes::RenderMillimeters ) );
int dpm = qRound( context.scaleFactor() * 1000 ); // scale factor = dots per millimeter
int hLengthLine = std::round( context.convertToPainterUnits( hLengthLineMM, QgsUnitTypes::RenderMillimeters ) );
int hSpaceLineText = std::round( context.convertToPainterUnits( hSpaceLineTextMM, QgsUnitTypes::RenderMillimeters ) );
int dpm = std::round( context.scaleFactor() * 1000 ); // scale factor = dots per millimeter
// get font metrics - we need a temporary image just to get the metrics right for the given DPI
QImage tmpImg( QSize( 1, 1 ), QImage::Format_ARGB32_Premultiplied );
@ -194,10 +194,10 @@ void QgsDataDefinedSizeLegend::drawCollapsedLegend( QgsRenderContext &context, Q
switch ( mVAlign )
{
case AlignCenter:
symbolTopY << qRound( outputLargestSize / 2 - outputSymbolSize / 2 );
symbolTopY << std::round( outputLargestSize / 2 - outputSymbolSize / 2 );
break;
case AlignBottom:
symbolTopY << qRound( outputLargestSize - outputSymbolSize );
symbolTopY << std::round( outputLargestSize - outputSymbolSize );
break;
}
}
@ -222,7 +222,7 @@ void QgsDataDefinedSizeLegend::drawCollapsedLegend( QgsRenderContext &context, Q
int totalTextHeight = textBottomY - textTopY;
int fullWidth = outputLargestSize + hLengthLine + hSpaceLineText + maxTextWidth;
int fullHeight = qMax( qRound( outputLargestSize ) - textTopY, totalTextHeight );
int fullHeight = qMax( static_cast< int >( std::round( outputLargestSize ) ) - textTopY, totalTextHeight );
if ( outputSize )
*outputSize = QSize( fullWidth, fullHeight );
@ -292,8 +292,8 @@ QImage QgsDataDefinedSizeLegend::collapsedLegendImage( QgsRenderContext &context
QSize contentSize;
drawCollapsedLegend( context, &contentSize );
int padding = qRound( context.convertToPainterUnits( paddingMM, QgsUnitTypes::RenderMillimeters ) );
int dpm = qRound( context.scaleFactor() * 1000 ); // scale factor = dots per millimeter
int padding = std::round( context.convertToPainterUnits( paddingMM, QgsUnitTypes::RenderMillimeters ) );
int dpm = std::round( context.scaleFactor() * 1000 ); // scale factor = dots per millimeter
QImage img( contentSize.width() + padding * 2, contentSize.height() + padding * 2, QImage::Format_ARGB32_Premultiplied );
img.setDotsPerMeterX( dpm );

View File

@ -249,14 +249,14 @@ bool QgsField::convertCompatible( QVariant &v ) const
return false;
}
double round = qgsRound( dbl );
double round = std::round( dbl );
if ( round > INT_MAX || round < -INT_MAX )
{
//double too large to fit in int
v = QVariant( d->type );
return false;
}
v = QVariant( qRound( dbl ) );
v = QVariant( static_cast< int >( std::round( dbl ) ) );
return true;
}

View File

@ -47,12 +47,12 @@ float QgsMapToPixelSimplifier::calculateLengthSquared2D( double x1, double y1, d
bool QgsMapToPixelSimplifier::equalSnapToGrid( double x1, double y1, double x2, double y2, double gridOriginX, double gridOriginY, float gridInverseSizeXY )
{
int grid_x1 = qRound( ( x1 - gridOriginX ) * gridInverseSizeXY );
int grid_x2 = qRound( ( x2 - gridOriginX ) * gridInverseSizeXY );
int grid_x1 = std::round( ( x1 - gridOriginX ) * gridInverseSizeXY );
int grid_x2 = std::round( ( x2 - gridOriginX ) * gridInverseSizeXY );
if ( grid_x1 != grid_x2 ) return false;
int grid_y1 = qRound( ( y1 - gridOriginY ) * gridInverseSizeXY );
int grid_y2 = qRound( ( y2 - gridOriginY ) * gridInverseSizeXY );
int grid_y1 = std::round( ( y1 - gridOriginY ) * gridInverseSizeXY );
int grid_y2 = std::round( ( y2 - gridOriginY ) * gridInverseSizeXY );
if ( grid_y1 != grid_y2 ) return false;
return true;

View File

@ -95,7 +95,7 @@ QString QgsPointXY::toDegreesMinutesSeconds( int precision, const bool useSuffix
double mySecondsY = double( myFloatMinutesY - myIntMinutesY ) * 60;
//make sure rounding to specified precision doesn't create seconds >= 60
if ( qRound( mySecondsX * pow( 10.0, precision ) ) >= 60 * pow( 10.0, precision ) )
if ( std::round( mySecondsX * pow( 10.0, precision ) ) >= 60 * pow( 10.0, precision ) )
{
mySecondsX = qMax( mySecondsX - 60, 0.0 );
myIntMinutesX++;
@ -105,7 +105,7 @@ QString QgsPointXY::toDegreesMinutesSeconds( int precision, const bool useSuffix
myDegreesX++;
}
}
if ( qRound( mySecondsY * pow( 10.0, precision ) ) >= 60 * pow( 10.0, precision ) )
if ( std::round( mySecondsY * pow( 10.0, precision ) ) >= 60 * pow( 10.0, precision ) )
{
mySecondsY = qMax( mySecondsY - 60, 0.0 );
myIntMinutesY++;
@ -138,18 +138,18 @@ QString QgsPointXY::toDegreesMinutesSeconds( int precision, const bool useSuffix
}
//check if coordinate is all zeros for the specified precision, and if so,
//remove the sign and hemisphere strings
if ( myDegreesX == 0 && myIntMinutesX == 0 && qRound( mySecondsX * pow( 10.0, precision ) ) == 0 )
if ( myDegreesX == 0 && myIntMinutesX == 0 && std::round( mySecondsX * pow( 10.0, precision ) ) == 0 )
{
myXSign = QString();
myXHemisphere = QString();
}
if ( myDegreesY == 0 && myIntMinutesY == 0 && qRound( mySecondsY * pow( 10.0, precision ) ) == 0 )
if ( myDegreesY == 0 && myIntMinutesY == 0 && std::round( mySecondsY * pow( 10.0, precision ) ) == 0 )
{
myYSign = QString();
myYHemisphere = QString();
}
//also remove directional prefix from 180 degree longitudes
if ( myDegreesX == 180 && myIntMinutesX == 0 && qRound( mySecondsX * pow( 10.0, precision ) ) == 0 )
if ( myDegreesX == 180 && myIntMinutesX == 0 && std::round( mySecondsX * pow( 10.0, precision ) ) == 0 )
{
myXHemisphere = QString();
}
@ -193,12 +193,12 @@ QString QgsPointXY::toDegreesMinutes( int precision, const bool useSuffix, const
double myFloatMinutesY = double( ( qAbs( mY ) - myDegreesY ) * 60 );
//make sure rounding to specified precision doesn't create minutes >= 60
if ( qRound( myFloatMinutesX * pow( 10.0, precision ) ) >= 60 * pow( 10.0, precision ) )
if ( std::round( myFloatMinutesX * pow( 10.0, precision ) ) >= 60 * pow( 10.0, precision ) )
{
myFloatMinutesX = qMax( myFloatMinutesX - 60, 0.0 );
myDegreesX++;
}
if ( qRound( myFloatMinutesY * pow( 10.0, precision ) ) >= 60 * pow( 10.0, precision ) )
if ( std::round( myFloatMinutesY * pow( 10.0, precision ) ) >= 60 * pow( 10.0, precision ) )
{
myFloatMinutesY = qMax( myFloatMinutesY - 60, 0.0 );
myDegreesY++;
@ -226,18 +226,18 @@ QString QgsPointXY::toDegreesMinutes( int precision, const bool useSuffix, const
}
//check if coordinate is all zeros for the specified precision, and if so,
//remove the sign and hemisphere strings
if ( myDegreesX == 0 && qRound( myFloatMinutesX * pow( 10.0, precision ) ) == 0 )
if ( myDegreesX == 0 && std::round( myFloatMinutesX * pow( 10.0, precision ) ) == 0 )
{
myXSign = QString();
myXHemisphere = QString();
}
if ( myDegreesY == 0 && qRound( myFloatMinutesY * pow( 10.0, precision ) ) == 0 )
if ( myDegreesY == 0 && std::round( myFloatMinutesY * pow( 10.0, precision ) ) == 0 )
{
myYSign = QString();
myYHemisphere = QString();
}
//also remove directional prefix from 180 degree longitudes
if ( myDegreesX == 180 && qRound( myFloatMinutesX * pow( 10.0, precision ) ) == 0 )
if ( myDegreesX == 180 && std::round( myFloatMinutesX * pow( 10.0, precision ) ) == 0 )
{
myXHemisphere = QString();
}

View File

@ -605,7 +605,7 @@ int QgsProperty::valueAsInt( const QgsExpressionContext &context, int defaultVal
{
if ( ok )
*ok = true;
return qRound( dbl );
return std::round( dbl );
}
else
{

View File

@ -203,7 +203,7 @@ std::unique_ptr<QgsMarkerSymbolLayer> backgroundToMarkerLayer( const QgsTextBack
QColor strokeColor = settings.strokeColor();
if ( settings.opacity() < 1 )
{
int alpha = qRound( settings.opacity() * 255 );
int alpha = std::round( settings.opacity() * 255 );
fillColor.setAlpha( alpha );
strokeColor.setAlpha( alpha );
}

View File

@ -286,7 +286,7 @@ void QgsColorRampShader::classifyColorRamp( const int classes, const int band, c
// calculate a reasonable number of decimals to display
double maxabs = log10( qMax( qAbs( max ), qAbs( min ) ) );
int nDecimals = qRound( qMax( 3.0 + maxabs - log10( max - min ), maxabs <= 15.0 ? maxabs + 0.49 : 0.0 ) );
int nDecimals = std::round( qMax( 3.0 + maxabs - log10( max - min ), maxabs <= 15.0 ? maxabs + 0.49 : 0.0 ) );
QList<QgsColorRampShader::ColorRampItem> colorRampItems;
for ( ; value_it != entryValues.end(); ++value_it, ++color_it )

View File

@ -960,20 +960,20 @@ QRect QgsRasterBlock::subRect( const QgsRectangle &extent, int width, int height
if ( subExtent.yMaximum() < extent.yMaximum() )
{
top = qRound( ( extent.yMaximum() - subExtent.yMaximum() ) / yRes );
top = std::round( ( extent.yMaximum() - subExtent.yMaximum() ) / yRes );
}
if ( subExtent.yMinimum() > extent.yMinimum() )
{
bottom = qRound( ( extent.yMaximum() - subExtent.yMinimum() ) / yRes ) - 1;
bottom = std::round( ( extent.yMaximum() - subExtent.yMinimum() ) / yRes ) - 1;
}
if ( subExtent.xMinimum() > extent.xMinimum() )
{
left = qRound( ( subExtent.xMinimum() - extent.xMinimum() ) / xRes );
left = std::round( ( subExtent.xMinimum() - extent.xMinimum() ) / xRes );
}
if ( subExtent.xMaximum() < extent.xMaximum() )
{
right = qRound( ( subExtent.xMaximum() - extent.xMinimum() ) / xRes ) - 1;
right = std::round( ( subExtent.xMaximum() - extent.xMinimum() ) / xRes ) - 1;
}
QRect subRect = QRect( left, top, right - left + 1, bottom - top + 1 );
QgsDebugMsgLevel( QString( "subRect: %1 %2 %3 %4" ).arg( subRect.x() ).arg( subRect.y() ).arg( subRect.width() ).arg( subRect.height() ), 4 );

View File

@ -203,7 +203,7 @@ double QgsRasterChecker::tolerance( double val, int places )
{
// float precision is about 7 decimal digits, double about 16
// default places = 6
return 1. * qPow( 10, qRound( log10( qAbs( val ) ) - places ) );
return 1. * qPow( 10, std::round( log10( qAbs( val ) ) - places ) );
}
QString QgsRasterChecker::compareHead()

View File

@ -102,10 +102,10 @@ QgsRasterBlock *QgsRasterDataProvider::block( int bandNo, QgsRectangle const &b
}
// Calculate row/col limits (before tmpExtent is aligned)
int fromRow = qRound( ( boundingBox.yMaximum() - tmpExtent.yMaximum() ) / yRes );
int toRow = qRound( ( boundingBox.yMaximum() - tmpExtent.yMinimum() ) / yRes ) - 1;
int fromCol = qRound( ( tmpExtent.xMinimum() - boundingBox.xMinimum() ) / xRes );
int toCol = qRound( ( tmpExtent.xMaximum() - boundingBox.xMinimum() ) / xRes ) - 1;
int fromRow = std::round( ( boundingBox.yMaximum() - tmpExtent.yMaximum() ) / yRes );
int toRow = std::round( ( boundingBox.yMaximum() - tmpExtent.yMinimum() ) / yRes ) - 1;
int fromCol = std::round( ( tmpExtent.xMinimum() - boundingBox.xMinimum() ) / xRes );
int toCol = std::round( ( tmpExtent.xMaximum() - boundingBox.xMinimum() ) / xRes ) - 1;
QgsDebugMsgLevel( QString( "fromRow = %1 toRow = %2 fromCol = %3 toCol = %4" ).arg( fromRow ).arg( toRow ).arg( fromCol ).arg( toCol ), 4 );
@ -133,8 +133,8 @@ QgsRasterBlock *QgsRasterDataProvider::block( int bandNo, QgsRectangle const &b
row = ceil( ( extent().yMaximum() - tmpExtent.yMinimum() ) / providerYRes );
tmpExtent.setYMinimum( extent().yMaximum() - row * providerYRes );
}
int tmpWidth = qRound( tmpExtent.width() / tmpXRes );
int tmpHeight = qRound( tmpExtent.height() / tmpYRes );
int tmpWidth = std::round( tmpExtent.width() / tmpXRes );
int tmpHeight = std::round( tmpExtent.height() / tmpYRes );
tmpXRes = tmpExtent.width() / tmpWidth;
tmpYRes = tmpExtent.height() / tmpHeight;

View File

@ -536,8 +536,8 @@ void QgsRasterInterface::cumulativeCut( int bandNo,
double myBinXStep = ( myHistogram.maximum - myHistogram.minimum ) / myHistogram.binCount;
int myCount = 0;
int myMinCount = static_cast< int >( qRound( lowerCount * myHistogram.nonNullCount ) );
int myMaxCount = static_cast< int >( qRound( upperCount * myHistogram.nonNullCount ) );
int myMinCount = static_cast< int >( std::round( lowerCount * myHistogram.nonNullCount ) );
int myMaxCount = static_cast< int >( std::round( upperCount * myHistogram.nonNullCount ) );
bool myLowerFound = false;
QgsDebugMsgLevel( QString( "binCount = %1 minimum = %2 maximum = %3 myBinXStep = %4" ).arg( myHistogram.binCount ).arg( myHistogram.minimum ).arg( myHistogram.maximum ).arg( myBinXStep ), 4 );
QgsDebugMsgLevel( QString( "myMinCount = %1 myMaxCount = %2" ).arg( myMinCount ).arg( myMaxCount ), 4 );

View File

@ -369,8 +369,8 @@ void ProjectorData::calcSrcRowsCols()
QgsDebugMsgLevel( QString( "mSrcExtent.width = %1 mSrcExtent.height = %2" ).arg( mSrcExtent.width() ).arg( mSrcExtent.height() ), 4 );
// we have to round to keep alignment set in calcSrcExtent
mSrcRows = static_cast< int >( qRound( mSrcExtent.height() / myMinYSize ) );
mSrcCols = static_cast< int >( qRound( mSrcExtent.width() / myMinXSize ) );
mSrcRows = static_cast< int >( std::round( mSrcExtent.height() / myMinYSize ) );
mSrcCols = static_cast< int >( std::round( mSrcExtent.width() / myMinXSize ) );
QgsDebugMsgLevel( QString( "mSrcRows = %1 mSrcCols = %2" ).arg( mSrcRows ).arg( mSrcCols ), 4 );
}

View File

@ -2561,8 +2561,8 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolRenderContext &
{
// We have to adjust marker intervals to integer pixel size to get
// repeatable pattern.
double intervalScale = qRound( outputPixelInterval ) / outputPixelInterval;
outputPixelInterval = qRound( outputPixelInterval );
double intervalScale = std::round( outputPixelInterval ) / outputPixelInterval;
outputPixelInterval = std::round( outputPixelInterval );
for ( int i = 0; i < fillLineSymbol->symbolLayerCount(); i++ )
{
@ -2607,7 +2607,7 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolRenderContext &
// Round offset to correspond to one pixel height, otherwise lines may
// be shifted on tile border if offset falls close to pixel center
int offsetHeight = qRound( qAbs( outputPixelOffset / cos( lineAngle * M_PI / 180 ) ) );
int offsetHeight = std::round( qAbs( outputPixelOffset / cos( lineAngle * M_PI / 180 ) ) );
outputPixelOffset = offsetHeight * cos( lineAngle * M_PI / 180 );
}

View File

@ -59,7 +59,7 @@ void QgsHeatmapRenderer::initializeValues( QgsRenderContext &context )
mValues.fill( 0 );
mCalculatedMaxValue = 0;
mFeaturesRendered = 0;
mRadiusPixels = qRound( context.convertToPainterUnits( mRadius, mRadiusUnit, mRadiusMapUnitScale ) / mRenderQuality );
mRadiusPixels = std::round( context.convertToPainterUnits( mRadius, mRadiusUnit, mRadiusMapUnitScale ) / mRenderQuality );
mRadiusSquared = mRadiusPixels * mRadiusPixels;
}

View File

@ -862,7 +862,7 @@ bool QgsSimpleMarkerSymbolLayer::prepareCache( QgsSymbolRenderContext &context )
double scaledSize = context.renderContext().convertToPainterUnits( mSize, mSizeUnit, mSizeMapUnitScale );
// calculate necessary image size for the cache
double pw = qRound( ( ( qgsDoubleNear( mPen.widthF(), 0.0 ) ? 1 : mPen.widthF() * 4 ) + 1 ) ) / 2 * 2; // make even (round up); handle cosmetic pen
double pw = static_cast< int >( std::round( ( ( qgsDoubleNear( mPen.widthF(), 0.0 ) ? 1 : mPen.widthF() * 4 ) + 1 ) ) ) / 2 * 2; // make even (round up); handle cosmetic pen
int imageSize = ( static_cast< int >( scaledSize ) + pw ) / 2 * 2 + 1; // make image width, height odd; account for pen width
double center = imageSize / 2.0;

View File

@ -3412,9 +3412,9 @@ QColor QgsSymbolLayerUtils::parseColorWithAlpha( const QString &colorStr, bool &
QRegExp rgbPercentFormatRx( "^\\s*(?:rgb)?\\(?\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(100|0*\\d{1,2})\\s*%\\s*\\)?\\s*;?\\s*$" );
if ( rgbPercentFormatRx.indexIn( colorStr ) != -1 )
{
int r = qRound( rgbPercentFormatRx.cap( 1 ).toDouble() * 2.55 );
int g = qRound( rgbPercentFormatRx.cap( 2 ).toDouble() * 2.55 );
int b = qRound( rgbPercentFormatRx.cap( 3 ).toDouble() * 2.55 );
int r = std::round( rgbPercentFormatRx.cap( 1 ).toDouble() * 2.55 );
int g = std::round( rgbPercentFormatRx.cap( 2 ).toDouble() * 2.55 );
int b = std::round( rgbPercentFormatRx.cap( 3 ).toDouble() * 2.55 );
parsedColor.setRgb( r, g, b );
if ( parsedColor.isValid() )
{
@ -3430,7 +3430,7 @@ QColor QgsSymbolLayerUtils::parseColorWithAlpha( const QString &colorStr, bool &
int r = rgbaFormatRx.cap( 1 ).toInt();
int g = rgbaFormatRx.cap( 2 ).toInt();
int b = rgbaFormatRx.cap( 3 ).toInt();
int a = qRound( rgbaFormatRx.cap( 4 ).toDouble() * 255.0 );
int a = std::round( rgbaFormatRx.cap( 4 ).toDouble() * 255.0 );
parsedColor.setRgb( r, g, b, a );
if ( parsedColor.isValid() )
{
@ -3443,10 +3443,10 @@ QColor QgsSymbolLayerUtils::parseColorWithAlpha( const QString &colorStr, bool &
QRegExp rgbaPercentFormatRx( "^\\s*(?:rgba)?\\(?\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(0|0?\\.\\d*|1(?:\\.0*)?)\\s*\\)?\\s*;?\\s*$" );
if ( rgbaPercentFormatRx.indexIn( colorStr ) != -1 )
{
int r = qRound( rgbaPercentFormatRx.cap( 1 ).toDouble() * 2.55 );
int g = qRound( rgbaPercentFormatRx.cap( 2 ).toDouble() * 2.55 );
int b = qRound( rgbaPercentFormatRx.cap( 3 ).toDouble() * 2.55 );
int a = qRound( rgbaPercentFormatRx.cap( 4 ).toDouble() * 255.0 );
int r = std::round( rgbaPercentFormatRx.cap( 1 ).toDouble() * 2.55 );
int g = std::round( rgbaPercentFormatRx.cap( 2 ).toDouble() * 2.55 );
int b = std::round( rgbaPercentFormatRx.cap( 3 ).toDouble() * 2.55 );
int a = std::round( rgbaPercentFormatRx.cap( 4 ).toDouble() * 255.0 );
parsedColor.setRgb( r, g, b, a );
if ( parsedColor.isValid() )
{
@ -4075,7 +4075,7 @@ double QgsSymbolLayerUtils::rescaleUom( double size, QgsUnitTypes::RenderUnit un
// of pixels as integers, even if SLD allows for float values in there
if ( roundToUnit )
{
rescaled = qRound( rescaled );
rescaled = std::round( rescaled );
}
return rescaled;
}

View File

@ -150,7 +150,7 @@ int QgsSpinBox::valueFromText( const QString &text ) const
return mShowClearButton ? clearValue() : value();
}
return qRound( QgsExpression::evaluateToDouble( trimmedText, value() ) );
return std::round( QgsExpression::evaluateToDouble( trimmedText, value() ) );
}
QValidator::State QgsSpinBox::validate( QString &input, int &pos ) const

View File

@ -655,7 +655,7 @@ bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent *e )
previousPt.x() - penultimatePt.x() );
softAngle -= deltaAngle;
}
int quo = qRound( softAngle / commonAngle );
int quo = std::round( softAngle / commonAngle );
if ( qAbs( softAngle - quo * commonAngle ) * 180.0 * M_1_PI <= SOFT_CONSTRAINT_TOLERANCE_DEGREES )
{
// also check the distance in pixel to the line, otherwise it's too sticky at long ranges

View File

@ -566,8 +566,8 @@ void QgsColorWheel::setColorFromPos( const QPointF pos )
double newL = ( ( -sin( rad0 ) * r ) / triangleSideLength ) + 0.5;
double widthShare = 1.0 - ( fabs( newL - 0.5 ) * 2.0 );
double newS = ( ( ( cos( rad0 ) * r ) + ( triangleLength / 2.0 ) ) / ( 1.5 * triangleLength ) ) / widthShare;
s = qMin( qRound( qMax( 0.0, newS ) * 255.0 ), 255 );
l = qMin( qRound( qMax( 0.0, newL ) * 255.0 ), 255 );
s = qMin( static_cast< int >( std::round( qMax( 0.0, newS ) * 255.0 ) ), 255 );
l = qMin( static_cast< int >( std::round( qMax( 0.0, newL ) * 255.0 ) ), 255 );
newColor = QColor::fromHsl( h, s, l );
//explicitly set the hue again, so that it's exact
newColor.setHsv( h, newColor.hsvSaturation(), newColor.value(), alpha );
@ -1375,7 +1375,7 @@ int QgsColorSliderWidget::convertRealToDisplay( const int realValue ) const
//for whom "255" is a totally arbitrary value!
if ( mComponent == QgsColorWidget::Saturation || mComponent == QgsColorWidget::Value || mComponent == QgsColorWidget::Alpha )
{
return qRound( 100.0 * realValue / 255.0 );
return std::round( 100.0 * realValue / 255.0 );
}
//leave all other values intact
@ -1387,7 +1387,7 @@ int QgsColorSliderWidget::convertDisplayToReal( const int displayValue ) const
//scale saturation, value or alpha from 0->100 range (see note in convertRealToDisplay)
if ( mComponent == QgsColorWidget::Saturation || mComponent == QgsColorWidget::Value || mComponent == QgsColorWidget::Alpha )
{
return qRound( 255.0 * displayValue / 100.0 );
return std::round( 255.0 * displayValue / 100.0 );
}
//leave all other values intact
@ -1584,7 +1584,7 @@ void QgsColorPreviewWidget::paintEvent( QPaintEvent *event )
if ( mColor2.isValid() )
{
//drawing with two color sections
int verticalSplit = qRound( height() / 2.0 );
int verticalSplit = std::round( height() / 2.0 );
drawColor( mCurrentColor, QRect( 0, 0, width(), verticalSplit ), painter );
drawColor( mColor2, QRect( 0, verticalSplit, width(), height() - verticalSplit ), painter );
}
@ -1634,7 +1634,7 @@ void QgsColorPreviewWidget::mouseReleaseEvent( QMouseEvent *e )
if ( mColor2.isValid() )
{
//two color sections, check if dragged color was the second color
int verticalSplit = qRound( height() / 2.0 );
int verticalSplit = std::round( height() / 2.0 );
if ( mDragStartPosition.y() >= verticalSplit )
{
clickedColor = mColor2;
@ -1669,7 +1669,7 @@ void QgsColorPreviewWidget::mouseMoveEvent( QMouseEvent *e )
if ( mColor2.isValid() )
{
//two color sections, check if dragged color was the second color
int verticalSplit = qRound( height() / 2.0 );
int verticalSplit = std::round( height() / 2.0 );
if ( mDragStartPosition.y() >= verticalSplit )
{
dragColor = mColor2;

View File

@ -392,7 +392,7 @@ void QgsGradientStopEditor::drawStopMarker( QPainter &painter, QPoint topMiddle,
painter.setBrush( selected ? QColor( 150, 150, 150 ) : Qt::white );
painter.setPen( selected ? Qt::black : QColor( 150, 150, 150 ) );
// 0.5 offsets to make edges pixel grid aligned
painter.translate( qRound( topMiddle.x() - MARKER_WIDTH / 2.0 ) + 0.5, topMiddle.y() + 0.5 );
painter.translate( std::round( topMiddle.x() - MARKER_WIDTH / 2.0 ) + 0.5, topMiddle.y() + 0.5 );
painter.drawPolygon( sOuterTriangle );
// draw the checkerboard background for marker

View File

@ -60,7 +60,7 @@ QRectF QgsMapCanvasMap::boundingRect() const
void QgsMapCanvasMap::paint( QPainter *painter )
{
int w = qRound( mItemSize.width() ) - 2, h = qRound( mItemSize.height() ) - 2; // setRect() makes the size +2 :-(
int w = std::round( mItemSize.width() ) - 2, h = std::round( mItemSize.height() ) - 2; // setRect() makes the size +2 :-(
if ( mImage.size() != QSize( w, h ) )
{
QgsDebugMsg( QString( "map paint DIFFERENT SIZE: img %1,%2 item %3,%4" ).arg( mImage.width() ).arg( mImage.height() ).arg( w ).arg( h ) );

View File

@ -135,5 +135,5 @@ QPoint QgsMapMouseEvent::mapToPixelCoordinates( const QgsPointXY &point )
mMapCanvas->mapSettings().mapToPixel().transformInPlace( x, y );
return QPoint( qRound( x ), qRound( y ) );
return QPoint( std::round( x ), std::round( y ) );
}

View File

@ -77,7 +77,7 @@ QPoint QgsMapTool::toCanvasCoordinates( const QgsPointXY &point )
{
qreal x = point.x(), y = point.y();
mCanvas->getCoordinateTransform()->transformInPlace( x, y );
return QPoint( qRound( x ), qRound( y ) );
return QPoint( std::round( x ), std::round( y ) );
}

View File

@ -540,8 +540,8 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
// are similar to source width and height used to reproject layer for drawing.
// TODO: may be very dangerous, because it may result in different resolutions
// in source CRS, and WMS server (QGIS server) calcs wrong coor using average resolution.
int width = qRound( viewExtent.width() / mapUnitsPerPixel );
int height = qRound( viewExtent.height() / mapUnitsPerPixel );
int width = std::round( viewExtent.width() / mapUnitsPerPixel );
int height = std::round( viewExtent.height() / mapUnitsPerPixel );
QgsDebugMsg( QString( "viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.width() ).arg( viewExtent.height() ) );
QgsDebugMsg( QString( "width = %1 height = %2" ).arg( width ).arg( height ) );

View File

@ -366,8 +366,8 @@ void QgsRasterLayerSaveAsDialog::setResolution( double xRes, double yRes, const
void QgsRasterLayerSaveAsDialog::recalcSize()
{
QgsRectangle extent = outputRectangle();
int xSize = xResolution() != 0 ? static_cast<int>( qRound( extent.width() / xResolution() ) ) : 0;
int ySize = yResolution() != 0 ? static_cast<int>( qRound( extent.height() / yResolution() ) ) : 0;
int xSize = xResolution() != 0 ? static_cast<int>( std::round( extent.width() / xResolution() ) ) : 0;
int ySize = yResolution() != 0 ? static_cast<int>( std::round( extent.height() / yResolution() ) ) : 0;
mColumnsLineEdit->setText( QString::number( xSize ) );
mRowsLineEdit->setText( QString::number( ySize ) );
updateResolutionStateMsg();

View File

@ -185,11 +185,11 @@ QString QgsScaleComboBox::toString( double scale )
}
else if ( scale <= 1 )
{
return QStringLiteral( "%1:1" ).arg( QLocale::system().toString( qRound( 1.0 / scale ) ) );
return QStringLiteral( "%1:1" ).arg( QLocale::system().toString( static_cast< int >( std::round( 1.0 / scale ) ) ) );
}
else
{
return QStringLiteral( "1:%1" ).arg( QLocale::system().toString( qRound( scale ) ) );
return QStringLiteral( "1:%1" ).arg( QLocale::system().toString( static_cast< int >( std::round( scale ) ) ) );
}
}

View File

@ -51,7 +51,7 @@ QgsEllipseSymbolLayerWidget::QgsEllipseSymbolLayerWidget( const QgsVectorLayer *
names << QStringLiteral( "circle" ) << QStringLiteral( "rectangle" ) << QStringLiteral( "diamond" ) << QStringLiteral( "cross" ) << QStringLiteral( "triangle" ) << QStringLiteral( "right_half_triangle" ) << QStringLiteral( "left_half_triangle" ) << QStringLiteral( "semi_circle" );
int size = mShapeListWidget->iconSize().width();
size = qMax( 30, qRound( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXX" ) ) ) );
size = qMax( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXX" ) ) ) ) );
mShapeListWidget->setGridSize( QSize( size * 1.2, size * 1.2 ) );
mShapeListWidget->setIconSize( QSize( size, size ) );

View File

@ -377,7 +377,7 @@ QgsSvgSelectorWidget::QgsSvgSelectorWidget( QWidget *parent )
// TODO: in-code gui setup with option to vertically or horizontally stack SVG groups/images widgets
setupUi( this );
mIconSize = qMax( 30, qRound( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXX" ) ) ) );
mIconSize = qMax( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXX" ) ) ) ) );
mImagesListView->setGridSize( QSize( mIconSize * 1.2, mIconSize * 1.2 ) );
mGroupsTreeView->setHeaderHidden( true );

View File

@ -400,7 +400,7 @@ QgsSimpleMarkerSymbolLayerWidget::QgsSimpleMarkerSymbolLayerWidget( const QgsVec
mSizeDDBtn->setSymbol( mAssistantPreviewSymbol );
int size = lstNames->iconSize().width();
size = qMax( 30, qRound( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXX" ) ) ) );
size = qMax( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXX" ) ) ) ) );
lstNames->setGridSize( QSize( size * 1.2, size * 1.2 ) );
lstNames->setIconSize( QSize( size, size ) );
@ -1747,7 +1747,7 @@ QgsSvgMarkerSymbolLayerWidget::QgsSvgMarkerSymbolLayerWidget( const QgsVectorLay
spinOffsetY->setClearValue( 0.0 );
spinAngle->setClearValue( 0.0 );
mIconSize = qMax( 30, qRound( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXX" ) ) ) );
mIconSize = qMax( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( QStringLiteral( "XXXX" ) ) ) ) );
viewImages->setGridSize( QSize( mIconSize * 1.2, mIconSize * 1.2 ) );
populateList();

File diff suppressed because it is too large Load Diff

View File

@ -485,20 +485,20 @@ void QgsGdalProvider::readBlock( int bandNo, QgsRectangle const &extent, int pi
if ( myRasterExtent.yMaximum() < extent.yMaximum() )
{
top = qRound( ( extent.yMaximum() - myRasterExtent.yMaximum() ) / yRes );
top = std::round( ( extent.yMaximum() - myRasterExtent.yMaximum() ) / yRes );
}
if ( myRasterExtent.yMinimum() > extent.yMinimum() )
{
bottom = qRound( ( extent.yMaximum() - myRasterExtent.yMinimum() ) / yRes ) - 1;
bottom = std::round( ( extent.yMaximum() - myRasterExtent.yMinimum() ) / yRes ) - 1;
}
if ( myRasterExtent.xMinimum() > extent.xMinimum() )
{
left = qRound( ( myRasterExtent.xMinimum() - extent.xMinimum() ) / xRes );
left = std::round( ( myRasterExtent.xMinimum() - extent.xMinimum() ) / xRes );
}
if ( myRasterExtent.xMaximum() < extent.xMaximum() )
{
right = qRound( ( myRasterExtent.xMaximum() - extent.xMinimum() ) / xRes ) - 1;
right = std::round( ( myRasterExtent.xMaximum() - extent.xMinimum() ) / xRes ) - 1;
}
#endif
QRect subRect = QgsRasterBlock::subRect( extent, pixelWidth, pixelHeight, myRasterExtent );
@ -585,11 +585,11 @@ void QgsGdalProvider::readBlock( int bandNo, QgsRectangle const &extent, int pi
if ( xRes > srcXRes )
{
tmpWidth = static_cast<int>( qRound( srcWidth * srcXRes / xRes ) );
tmpWidth = static_cast<int>( std::round( srcWidth * srcXRes / xRes ) );
}
if ( yRes > fabs( srcYRes ) )
{
tmpHeight = static_cast<int>( qRound( -1.*srcHeight * srcYRes / yRes ) );
tmpHeight = static_cast<int>( std::round( -1.*srcHeight * srcYRes / yRes ) );
}
double tmpXMin = mExtent.xMinimum() + srcLeft * srcXRes;

View File

@ -19,6 +19,7 @@
#include "qgsapplication.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsrectangle.h"
#include "qgstestutils.h"
#include <QDir>
@ -227,11 +228,11 @@ class TestAlignRaster : public QObject
QgsCoordinateReferenceSystem outCRS( out.crs() );
QCOMPARE( outCRS, destCRS );
QCOMPARE( out.rasterSize(), QSize( 4, 4 ) );
// let's stick to integers to keep the test more robust
QCOMPARE( qRound( out.cellSize().width() ), 22293 ); // ~ 22293.256065
QCOMPARE( qRound( out.cellSize().height() ), 22293 ); // ~ 22293.256065
QCOMPARE( qRound( out.gridOffset().x() ), 4327 ); // ~ 4327.168434
QCOMPARE( qRound( out.gridOffset().y() ), 637 ); // ~ 637.007990
// tolerance of 1 to keep the test more robust
QGSCOMPARENEAR( out.cellSize().width(), 22293, 1 ); // ~ 22293.256065
QGSCOMPARENEAR( out.cellSize().height(), 22293, 1 ); // ~ 22293.256065
QGSCOMPARENEAR( out.gridOffset().x(), 4327, 1 ); // ~ 4327.168434
QGSCOMPARENEAR( out.gridOffset().y(), 637, 1 ); // ~ 637.007990
QCOMPARE( out.identify( 1308405, -746611 ), 10. );
}

View File

@ -194,8 +194,8 @@ void TestQgisAppClipboard::copyToText()
QStringList list = regex.capturedTexts();
QCOMPARE( list.count(), 3 );
int x = qRound( list.at( 1 ).toDouble() );
int y = qRound( list.at( 2 ).toDouble() );
int x = std::round( list.at( 1 ).toDouble() );
int y = std::round( list.at( 2 ).toDouble() );
QCOMPARE( x, 145 );
QCOMPARE( y, -38 );

View File

@ -68,7 +68,7 @@ class TestQgsNodeTool : public QObject
QPoint mapToScreen( double mapX, double mapY )
{
QgsPointXY pt = mCanvas->mapSettings().mapToPixel().transform( mapX, mapY );
return QPoint( qRound( pt.x() ), qRound( pt.y() ) );
return QPoint( std::round( pt.x() ), std::round( pt.y() ) );
}
void mouseMove( double mapX, double mapY )

View File

@ -38,7 +38,6 @@ class TestQgis : public QObject
void permissiveToDouble();
void permissiveToInt();
void doubleToString();
void qgsround();
void signalBlocker();
void qVariantCompare_data();
void qVariantCompare();
@ -142,20 +141,6 @@ void TestQgis::doubleToString()
QCOMPARE( qgsDoubleToString( 12345, -1 ), QString( "12345" ) );
}
void TestQgis::qgsround()
{
QCOMPARE( qgsRound( 3.141592653589793 ), 3. );
QCOMPARE( qgsRound( 2.718281828459045 ), 3. );
QCOMPARE( qgsRound( -3.141592653589793 ), -3. );
QCOMPARE( qgsRound( -2.718281828459045 ), -3. );
QCOMPARE( qgsRound( 314159265358979.3 ), 314159265358979. );
QCOMPARE( qgsRound( 2718281828459.045 ), 2718281828459. );
QCOMPARE( qgsRound( -314159265358979.3 ), -314159265358979. );
QCOMPARE( qgsRound( -2718281828459.045 ), -2718281828459. );
QCOMPARE( qgsRound( 1.5 ), 2. );
QCOMPARE( qgsRound( -1.5 ), -2. );
}
void TestQgis::signalBlocker()
{
std::unique_ptr< QCheckBox > checkbox( new QCheckBox() );

View File

@ -489,14 +489,14 @@ void TestQgsTaskManager::subTask()
// test progress calculation
QSignalSpy spy( parent, &QgsTask::progressChanged );
parent->emitProgressChanged( 50 );
QCOMPARE( qRound( parent->progress() ), 17 );
QCOMPARE( std::round( parent->progress() ), 17 );
//QCOMPARE( spy.count(), 1 );
QCOMPARE( qRound( spy.last().at( 0 ).toDouble() ), 17 );
QCOMPARE( std::round( spy.last().at( 0 ).toDouble() ), 17 );
subTask->emitProgressChanged( 100 );
QCOMPARE( qRound( parent->progress() ), 50 );
QCOMPARE( std::round( parent->progress() ), 50 );
//QCOMPARE( spy.count(), 2 );
QCOMPARE( qRound( spy.last().at( 0 ).toDouble() ), 50 );
QCOMPARE( std::round( spy.last().at( 0 ).toDouble() ), 50 );
subTask2->finish();
while ( subTask2->status() != QgsTask::Complete )
@ -504,14 +504,14 @@ void TestQgsTaskManager::subTask()
QCoreApplication::processEvents();
}
flushEvents();
QCOMPARE( qRound( parent->progress() ), 83 );
QCOMPARE( std::round( parent->progress() ), 83 );
//QCOMPARE( spy.count(), 3 );
QCOMPARE( qRound( spy.last().at( 0 ).toDouble() ), 83 );
QCOMPARE( std::round( spy.last().at( 0 ).toDouble() ), 83 );
parent->emitProgressChanged( 100 );
QCOMPARE( qRound( parent->progress() ), 100 );
QCOMPARE( std::round( parent->progress() ), 100 );
//QCOMPARE( spy.count(), 4 );
QCOMPARE( qRound( spy.last().at( 0 ).toDouble() ), 100 );
QCOMPARE( std::round( spy.last().at( 0 ).toDouble() ), 100 );
parent->terminate();
subTask->terminate();

View File

@ -90,7 +90,7 @@ void TestQgsVectorDataProvider::cleanupTestCase()
static double keep6digits( double x )
{
return qRound( x * 1e6 ) / 1e6;
return std::round( x * 1e6 ) / 1e6;
}
static void checkFid4( QgsFeature &f, bool hasGeometry, bool hasAttrs, int onlyOneAttribute )

View File

@ -401,7 +401,7 @@ void TestQgsWcsPublicServers::test()
int myHeight = 100;
if ( myCoverage.hasSize )
{
myHeight = static_cast<int>( qRound( 1.0 * myWidth * myCoverage.height / myCoverage.width ) );
myHeight = static_cast<int>( std::round( 1.0 * myWidth * myCoverage.height / myCoverage.width ) );
}
myLog << QStringLiteral( "hasSize:%1" ).arg( myCoverage.hasSize );