Skip to content

Commit da487e2

Browse files
committed
Ban deprecated qMin/qMax/etc methods
1 parent c705670 commit da487e2

13 files changed

+33
-18
lines changed

src/3d/qgs3dmapscene.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Qgs3DMapScene::Qgs3DMapScene( const Qgs3DMapSettings &map, Qt3DExtras::QForwardR
163163
void Qgs3DMapScene::viewZoomFull()
164164
{
165165
QgsRectangle extent = mMap.terrainGenerator()->extent();
166-
float side = qMax( extent.width(), extent.height() );
166+
float side = std::max( extent.width(), extent.height() );
167167
mCameraController->resetView( side ); // assuming FOV being 45 degrees
168168
}
169169

@@ -179,7 +179,7 @@ QgsChunkedEntity::SceneState _sceneState( QgsCameraController *cameraController
179179
state.cameraFov = camera->fieldOfView();
180180
state.cameraPos = camera->position();
181181
QRect rect = cameraController->viewport();
182-
state.screenSizePx = qMax( rect.width(), rect.height() ); // TODO: is this correct?
182+
state.screenSizePx = std::max( rect.width(), rect.height() ); // TODO: is this correct?
183183
state.viewProjectionMatrix = camera->projectionMatrix() * camera->viewMatrix();
184184
return state;
185185
}

src/3d/qgsaabb.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ bool QgsAABB::intersects( float x, float y, float z ) const
4444

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

src/3d/qgstilingscheme.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ QgsTilingScheme::QgsTilingScheme( const QgsRectangle &fullExtent, const QgsCoord
2121
: mCrs( crs )
2222
{
2323
mMapOrigin = QgsPointXY( fullExtent.xMinimum(), fullExtent.yMinimum() );
24-
mBaseTileSide = qMax( fullExtent.width(), fullExtent.height() );
24+
mBaseTileSide = std::max( fullExtent.width(), fullExtent.height() );
2525
}
2626

2727
QgsPointXY QgsTilingScheme::tileToMap( int x, int y, int z ) const

src/3d/terrain/qgsdemterraintileloader_p.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ static void _heightMapMinMax( const QByteArray &heightMap, float &zMin, float &z
4444
zMin = zMax = z;
4545
first = false;
4646
}
47-
zMin = qMin( zMin, z );
48-
zMax = qMax( zMax, z );
47+
zMin = std::min( zMin, z );
48+
zMax = std::max( zMax, z );
4949
}
5050
}
5151

src/3d/terrain/quantizedmeshgeometry.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bool gzipDecompress( QByteArray input, QByteArray &output )
6262
do
6363
{
6464
// Determine current chunk size
65-
int chunk_size = qMin( GZIP_CHUNK_SIZE, input_data_left );
65+
int chunk_size = std::min( GZIP_CHUNK_SIZE, input_data_left );
6666

6767
// Check for termination
6868
if ( chunk_size <= 0 )

src/app/qgisapp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10675,7 +10675,7 @@ void QgisApp::new3DMapCanvas()
1067510675
dock->setMapSettings( map );
1067610676

1067710677
QgsRectangle extent = mMapCanvas->extent();
10678-
float dist = qMax( extent.width(), extent.height() );
10678+
float dist = std::max( extent.width(), extent.height() );
1067910679
dock->mapCanvas3D()->setViewFromTop( mMapCanvas->extent().center(), dist, mMapCanvas->rotation() );
1068010680
}
1068110681
#endif

src/app/qgspuzzlewidget.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void QgsPuzzleWidget::mousePressEvent( QMouseEvent *event )
9292
int dx = cMouse - cEmpty;
9393
int dy = rMouse - rEmpty;
9494

95-
if ( ( dx == 0 && qAbs( dy ) == 1 ) || ( dy == 0 && qAbs( dx ) == 1 ) )
95+
if ( ( dx == 0 && std::abs( dy ) == 1 ) || ( dy == 0 && std::abs( dx ) == 1 ) )
9696
{
9797
std::swap( mPositions[idxEmpty], mPositions[idxMouse] );
9898
updateTilePositions();

src/core/mesh/qgsmeshvectorrenderer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ bool QgsMeshVectorRenderer::calcVectorLineEnd(
165165
// Flip the Y axis (pixel vs real-world axis)
166166
yDist *= -1.0;
167167

168-
if ( qAbs( xDist ) < 1 && qAbs( yDist ) < 1 )
168+
if ( std::abs( xDist ) < 1 && std::abs( yDist ) < 1 )
169169
return true;
170170

171171
// Determine the line coords

src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void QgsValueRelationWidgetWrapper::setFeature( const QgsFeature &feature )
236236

237237
int QgsValueRelationWidgetWrapper::columnCount() const
238238
{
239-
return qMax( 1, config( QStringLiteral( "NofColumns" ) ).toInt() );
239+
return std::max( 1, config( QStringLiteral( "NofColumns" ) ).toInt() );
240240
}
241241

242242
void QgsValueRelationWidgetWrapper::populate( )

src/gui/processing/qgsprocessingconfigurationwidgets.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void QgsFilterAlgorithmConfigurationWidget::removeSelectedOutputs()
124124
rows.append( index.row() );
125125
}
126126

127-
qSort( rows );
127+
std::sort( rows );
128128

129129
int prev = -1;
130130
for ( int i = rows.count() - 1; i >= 0; i -= 1 )

src/plugins/globe/qgsglobetilesource.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void QgsGlobeTileUpdateManager::addTile( QgsGlobeTileImage *tile )
155155
#ifdef GLOBE_SHOW_TILE_STATS
156156
QgsGlobeTileStatistics::instance()->updateQueueTileCount( mTileQueue.size() );
157157
#endif
158-
qSort( mTileQueue.begin(), mTileQueue.end(), QgsGlobeTileImage::lodSort );
158+
std::sort( mTileQueue.begin(), mTileQueue.end(), QgsGlobeTileImage::lodSort );
159159
}
160160
emit startRendering();
161161
}

src/providers/oracle/qgsoracleprovider.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist, QgsFeatureSink::Flag
12501250

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

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

15651565
Q_FOREACH ( int id, idsList )
15661566
{

tests/code_layout/test_banned_keywords.sh

+16-1
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,29 @@ HINTS[4]="Use the type-safe method std::numeric_limits<int>::min() instead"
2323
KEYWORDS[5]="INT_MAX"
2424
HINTS[5]="Use the type-safe method std::numeric_limits<int>::max() instead"
2525

26+
KEYWORDS[6]="\bqMin("
27+
HINTS[6]="Use std::min instead"
28+
29+
KEYWORDS[7]="\bqMax("
30+
HINTS[7]="Use std::max instead"
31+
32+
KEYWORDS[8]="\bqAbs("
33+
HINTS[8]="Use std::fabs instead"
34+
35+
KEYWORDS[9]="\bqRound("
36+
HINTS[9]="Use std::round instead"
37+
38+
KEYWORDS[10]="\bqSort("
39+
HINTS[10]="Use std::sort instead"
40+
2641
RES=
2742
DIR=$(git rev-parse --show-toplevel)
2843

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

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

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

0 commit comments

Comments
 (0)