Skip to content

Commit

Permalink
Ban deprecated qMin/qMax/etc methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 16, 2018
1 parent c705670 commit da487e2
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/3d/qgs3dmapscene.cpp
Expand Up @@ -163,7 +163,7 @@ Qgs3DMapScene::Qgs3DMapScene( const Qgs3DMapSettings &map, Qt3DExtras::QForwardR
void Qgs3DMapScene::viewZoomFull()
{
QgsRectangle extent = mMap.terrainGenerator()->extent();
float side = qMax( extent.width(), extent.height() );
float side = std::max( extent.width(), extent.height() );
mCameraController->resetView( side ); // assuming FOV being 45 degrees
}

Expand All @@ -179,7 +179,7 @@ QgsChunkedEntity::SceneState _sceneState( QgsCameraController *cameraController
state.cameraFov = camera->fieldOfView();
state.cameraPos = camera->position();
QRect rect = cameraController->viewport();
state.screenSizePx = qMax( rect.width(), rect.height() ); // TODO: is this correct?
state.screenSizePx = std::max( rect.width(), rect.height() ); // TODO: is this correct?
state.viewProjectionMatrix = camera->projectionMatrix() * camera->viewMatrix();
return state;
}
Expand Down
6 changes: 3 additions & 3 deletions src/3d/qgsaabb.cpp
Expand Up @@ -44,9 +44,9 @@ bool QgsAABB::intersects( float x, float y, float z ) const

float QgsAABB::distanceFromPoint( float x, float y, float z ) const
{
float dx = qMax( xMin - x, qMax( 0.f, x - xMax ) );
float dy = qMax( yMin - y, qMax( 0.f, y - yMax ) );
float dz = qMax( zMin - z, qMax( 0.f, z - zMax ) );
float dx = std::max( xMin - x, std::max( 0.f, x - xMax ) );
float dy = std::max( yMin - y, std::max( 0.f, y - yMax ) );
float dz = std::max( zMin - z, std::max( 0.f, z - zMax ) );
return sqrt( dx * dx + dy * dy + dz * dz );
}

Expand Down
2 changes: 1 addition & 1 deletion src/3d/qgstilingscheme.cpp
Expand Up @@ -21,7 +21,7 @@ QgsTilingScheme::QgsTilingScheme( const QgsRectangle &fullExtent, const QgsCoord
: mCrs( crs )
{
mMapOrigin = QgsPointXY( fullExtent.xMinimum(), fullExtent.yMinimum() );
mBaseTileSide = qMax( fullExtent.width(), fullExtent.height() );
mBaseTileSide = std::max( fullExtent.width(), fullExtent.height() );
}

QgsPointXY QgsTilingScheme::tileToMap( int x, int y, int z ) const
Expand Down
4 changes: 2 additions & 2 deletions src/3d/terrain/qgsdemterraintileloader_p.cpp
Expand Up @@ -44,8 +44,8 @@ static void _heightMapMinMax( const QByteArray &heightMap, float &zMin, float &z
zMin = zMax = z;
first = false;
}
zMin = qMin( zMin, z );
zMax = qMax( zMax, z );
zMin = std::min( zMin, z );
zMax = std::max( zMax, z );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/3d/terrain/quantizedmeshgeometry.cpp
Expand Up @@ -62,7 +62,7 @@ bool gzipDecompress( QByteArray input, QByteArray &output )
do
{
// Determine current chunk size
int chunk_size = qMin( GZIP_CHUNK_SIZE, input_data_left );
int chunk_size = std::min( GZIP_CHUNK_SIZE, input_data_left );

// Check for termination
if ( chunk_size <= 0 )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -10675,7 +10675,7 @@ void QgisApp::new3DMapCanvas()
dock->setMapSettings( map );

QgsRectangle extent = mMapCanvas->extent();
float dist = qMax( extent.width(), extent.height() );
float dist = std::max( extent.width(), extent.height() );
dock->mapCanvas3D()->setViewFromTop( mMapCanvas->extent().center(), dist, mMapCanvas->rotation() );
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgspuzzlewidget.cpp
Expand Up @@ -92,7 +92,7 @@ void QgsPuzzleWidget::mousePressEvent( QMouseEvent *event )
int dx = cMouse - cEmpty;
int dy = rMouse - rEmpty;

if ( ( dx == 0 && qAbs( dy ) == 1 ) || ( dy == 0 && qAbs( dx ) == 1 ) )
if ( ( dx == 0 && std::abs( dy ) == 1 ) || ( dy == 0 && std::abs( dx ) == 1 ) )
{
std::swap( mPositions[idxEmpty], mPositions[idxMouse] );
updateTilePositions();
Expand Down
2 changes: 1 addition & 1 deletion src/core/mesh/qgsmeshvectorrenderer.cpp
Expand Up @@ -165,7 +165,7 @@ bool QgsMeshVectorRenderer::calcVectorLineEnd(
// Flip the Y axis (pixel vs real-world axis)
yDist *= -1.0;

if ( qAbs( xDist ) < 1 && qAbs( yDist ) < 1 )
if ( std::abs( xDist ) < 1 && std::abs( yDist ) < 1 )
return true;

// Determine the line coords
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp
Expand Up @@ -236,7 +236,7 @@ void QgsValueRelationWidgetWrapper::setFeature( const QgsFeature &feature )

int QgsValueRelationWidgetWrapper::columnCount() const
{
return qMax( 1, config( QStringLiteral( "NofColumns" ) ).toInt() );
return std::max( 1, config( QStringLiteral( "NofColumns" ) ).toInt() );
}

void QgsValueRelationWidgetWrapper::populate( )
Expand Down
2 changes: 1 addition & 1 deletion src/gui/processing/qgsprocessingconfigurationwidgets.cpp
Expand Up @@ -124,7 +124,7 @@ void QgsFilterAlgorithmConfigurationWidget::removeSelectedOutputs()
rows.append( index.row() );
}

qSort( rows );
std::sort( rows );

int prev = -1;
for ( int i = rows.count() - 1; i >= 0; i -= 1 )
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/globe/qgsglobetilesource.cpp
Expand Up @@ -155,7 +155,7 @@ void QgsGlobeTileUpdateManager::addTile( QgsGlobeTileImage *tile )
#ifdef GLOBE_SHOW_TILE_STATS
QgsGlobeTileStatistics::instance()->updateQueueTileCount( mTileQueue.size() );
#endif
qSort( mTileQueue.begin(), mTileQueue.end(), QgsGlobeTileImage::lodSort );
std::sort( mTileQueue.begin(), mTileQueue.end(), QgsGlobeTileImage::lodSort );
}
emit startRendering();
}
Expand Down
4 changes: 2 additions & 2 deletions src/providers/oracle/qgsoracleprovider.cpp
Expand Up @@ -1250,7 +1250,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist, QgsFeatureSink::Flag

// look for unique attribute values to place in statement instead of passing as parameter
// e.g. for defaults
for ( int idx = 0; idx < qMin( attributevec.size(), mAttributeFields.size() ); ++idx )
for ( int idx = 0; idx < std::min( attributevec.size(), mAttributeFields.size() ); ++idx )
{
QVariant v = attributevec[idx];
if ( !v.isValid() )
Expand Down Expand Up @@ -1560,7 +1560,7 @@ bool QgsOracleProvider::deleteAttributes( const QgsAttributeIds &ids )
qry.finish();

QList<int> idsList = ids.values();
qSort( idsList.begin(), idsList.end(), qGreater<int>() );
std::sort( idsList.begin(), idsList.end(), qGreater<int>() );

Q_FOREACH ( int id, idsList )
{
Expand Down
17 changes: 16 additions & 1 deletion tests/code_layout/test_banned_keywords.sh
Expand Up @@ -23,14 +23,29 @@ HINTS[4]="Use the type-safe method std::numeric_limits<int>::min() instead"
KEYWORDS[5]="INT_MAX"
HINTS[5]="Use the type-safe method std::numeric_limits<int>::max() instead"

KEYWORDS[6]="\bqMin("
HINTS[6]="Use std::min instead"

KEYWORDS[7]="\bqMax("
HINTS[7]="Use std::max instead"

KEYWORDS[8]="\bqAbs("
HINTS[8]="Use std::fabs instead"

KEYWORDS[9]="\bqRound("
HINTS[9]="Use std::round instead"

KEYWORDS[10]="\bqSort("
HINTS[10]="Use std::sort instead"

RES=
DIR=$(git rev-parse --show-toplevel)

pushd "${DIR}" > /dev/null || exit

for i in "${!KEYWORDS[@]}"
do
FOUND=$(git grep "${KEYWORDS[$i]}" -- 'src/*.h' 'src/*.cpp')
FOUND=$(git grep "${KEYWORDS[$i]}" -- 'src/*.h' 'src/*.cpp' -- ':!*qtermwidget*')

if [[ ${FOUND} ]]; then
echo "Found source files with banned keyword: ${KEYWORDS[$i]}!"
Expand Down

0 comments on commit da487e2

Please sign in to comment.