Skip to content

Commit 766bfa1

Browse files
committed
Fix some more old style cast and float comparison warnings
1 parent 566dd4b commit 766bfa1

20 files changed

+89
-134
lines changed

python/core/qgscoordinatetransform.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class QgsCoordinateTransform : QObject
165165
/** See if the transform short circuits because src and dest are equivalent
166166
* @return bool True if it short circuits
167167
*/
168-
bool isShortCircuited();
168+
bool isShortCircuited() const;
169169

170170
/** Change the destination coordinate system by passing it a qgis srsid
171171
* A QGIS srsid is a unique key value to an entry on the tbl_srs in the

src/app/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static void dumpBacktrace( unsigned int depth )
211211
}
212212

213213
close( fd[1] ); // close writing end
214-
execl( "/usr/bin/c++filt", "c++filt", ( char * ) nullptr );
214+
execl( "/usr/bin/c++filt", "c++filt", static_cast< char * >( nullptr ) );
215215
perror( "could not start c++filt" );
216216
exit( 1 );
217217
}

src/app/qgslabelingwidget.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void QgsLabelingWidget::labelModeChanged( int index )
7373
if ( QgsLabelingGui* widgetSimple = qobject_cast<QgsLabelingGui*>( mWidget ) )
7474
{
7575
// lighter variant - just change the mode of existing widget
76-
widgetSimple->setLabelMode(( QgsLabelingGui::LabelMode ) index );
76+
widgetSimple->setLabelMode( static_cast< QgsLabelingGui::LabelMode >( index ) );
7777
return;
7878
}
7979
}
@@ -93,7 +93,7 @@ void QgsLabelingWidget::labelModeChanged( int index )
9393
else
9494
{
9595
QgsLabelingGui* w = new QgsLabelingGui( mLayer, mCanvas, nullptr, this );
96-
w->setLabelMode(( QgsLabelingGui::LabelMode ) index );
96+
w->setLabelMode( static_cast< QgsLabelingGui::LabelMode >( index ) );
9797
w->init();
9898
mWidget = w;
9999
}

src/app/qgsvectorlayerproperties.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ void QgsVectorLayerProperties::saveStyleAsMenuTriggered( QAction *action )
872872
if ( index < 0 )
873873
return;
874874

875-
saveStyleAs(( StyleType ) index );
875+
saveStyleAs( static_cast< StyleType >( index ) );
876876
}
877877

878878
void QgsVectorLayerProperties::saveStyleAs( StyleType styleType )

src/core/dxf/qgsdxfexport.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ void QgsDxfExport::writeGroup( const QColor& color, int exactMatchCode, int rgbC
420420
int minDistAt = -1;
421421
int minDist = INT_MAX;
422422

423-
for ( int i = 1; i < ( int )( sizeof( mDxfColors ) / sizeof( *mDxfColors ) ) && minDist > 0; ++i )
423+
for ( int i = 1; i < static_cast< int >( sizeof( mDxfColors ) / sizeof( *mDxfColors ) ) && minDist > 0; ++i )
424424
{
425425
int dist = color_distance( color.rgba(), i );
426426
if ( dist >= minDist )
@@ -3801,7 +3801,7 @@ int QgsDxfExport::closestColorMatch( QRgb pixel )
38013801
{
38023802
int idx = 0;
38033803
int current_distance = INT_MAX;
3804-
for ( int i = 1; i < ( int )( sizeof( mDxfColors ) / sizeof( *mDxfColors ) ); ++i )
3804+
for ( int i = 1; i < static_cast< int >( sizeof( mDxfColors ) / sizeof( *mDxfColors ) ); ++i )
38053805
{
38063806
int dist = color_distance( pixel, i );
38073807
if ( dist < current_distance )
@@ -4136,10 +4136,10 @@ QString QgsDxfExport::dxfEncoding( const QString &name )
41364136
continue;
41374137

41384138
int i;
4139-
for ( i = 0; i < ( int )( sizeof( mDxfEncodings ) / sizeof( *mDxfEncodings ) ) && name != mDxfEncodings[i][1]; ++i )
4139+
for ( i = 0; i < static_cast< int >( sizeof( mDxfEncodings ) / sizeof( *mDxfEncodings ) ) && name != mDxfEncodings[i][1]; ++i )
41404140
;
41414141

4142-
if ( i == ( int )( sizeof( mDxfEncodings ) / sizeof( *mDxfEncodings ) ) )
4142+
if ( i == static_cast< int >( sizeof( mDxfEncodings ) / sizeof( *mDxfEncodings ) ) )
41434143
continue;
41444144

41454145
return mDxfEncodings[i][0];
@@ -4154,10 +4154,10 @@ QStringList QgsDxfExport::encodings()
41544154
Q_FOREACH ( QByteArray codec, QTextCodec::availableCodecs() )
41554155
{
41564156
int i;
4157-
for ( i = 0; i < ( int )( sizeof( mDxfEncodings ) / sizeof( *mDxfEncodings ) ) && strcmp( codec.data(), mDxfEncodings[i][1] ) != 0; ++i )
4157+
for ( i = 0; i < static_cast< int >( sizeof( mDxfEncodings ) / sizeof( *mDxfEncodings ) ) && strcmp( codec.data(), mDxfEncodings[i][1] ) != 0; ++i )
41584158
;
41594159

4160-
if ( i < ( int )( sizeof( mDxfEncodings ) / sizeof( *mDxfEncodings ) ) )
4160+
if ( i < static_cast< int >( sizeof( mDxfEncodings ) / sizeof( *mDxfEncodings ) ) )
41614161
encodings << codec.data();
41624162
}
41634163
return encodings;

src/core/pal/feature.cpp

+10-13
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
*
2828
*/
2929

30-
#define _CRT_SECURE_NO_DEPRECATE
31-
32-
3330
#if defined(_VERBOSE_) || defined(_DEBUG_)
3431
#include <iostream>
3532
#endif
@@ -250,18 +247,18 @@ namespace pal
250247
double xdiff = -labelW / 2.0;
251248
double ydiff = -labelH / 2.0;
252249

253-
if ( mLF->quadOffset().x() != 0 )
250+
if ( !qgsDoubleNear( mLF->quadOffset().x(), 0.0 ) )
254251
{
255252
xdiff += labelW / 2.0 * mLF->quadOffset().x();
256253
}
257-
if ( mLF->quadOffset().y() != 0 )
254+
if ( !qgsDoubleNear( mLF->quadOffset().y(), 0.0 ) )
258255
{
259256
ydiff += labelH / 2.0 * mLF->quadOffset().y();
260257
}
261258

262259
if ( ! mLF->hasFixedPosition() )
263260
{
264-
if ( angle != 0 )
261+
if ( !qgsDoubleNear( angle, 0.0 ) )
265262
{
266263
double xd = xdiff * cos( angle ) - ydiff * sin( angle );
267264
double yd = xdiff * sin( angle ) + ydiff * cos( angle );
@@ -290,11 +287,11 @@ namespace pal
290287
}
291288
else
292289
{
293-
if ( mLF->positionOffset().x() != 0 )
290+
if ( !qgsDoubleNear( mLF->positionOffset().x(), 0.0 ) )
294291
{
295292
xdiff += mLF->positionOffset().x();
296293
}
297-
if ( mLF->positionOffset().y() != 0 )
294+
if ( !qgsDoubleNear( mLF->positionOffset().y(), 0.0 ) )
298295
{
299296
ydiff += mLF->positionOffset().y();
300297
}
@@ -359,7 +356,7 @@ namespace pal
359356
gamma2 = a90 / 3.0;
360357

361358

362-
if ( gamma1 == 0 || gamma2 == 0 )
359+
if ( qgsDoubleNear( gamma1, 0.0 ) || qgsDoubleNear( gamma2, 0.0 ) )
363360
{
364361
std::cout << "Oups... label size error..." << std::endl;
365362
}
@@ -538,7 +535,7 @@ namespace pal
538535
ad[line->nbPoints-1] = ll;
539536

540537

541-
nbls = ( int )( ll / xrm ); // ratio bw line length and label width
538+
nbls = static_cast< int >( ll / xrm ); // ratio bw line length and label width
542539

543540
#ifdef _DEBUG_FULL_
544541
std::cout << "line length :" << ll << std::endl;
@@ -707,7 +704,7 @@ namespace pal
707704
double dy = new_y - old_y;
708705

709706
double segment_length = path_distances[index];
710-
if ( segment_length == 0 )
707+
if ( qgsDoubleNear( segment_length, 0.0 ) )
711708
{
712709
// Not allowed to place across on 0 length segments or discontinuities
713710
return nullptr;
@@ -732,7 +729,7 @@ namespace pal
732729
LabelInfo::CharacterInfo& ci = ( orientation > 0 ? li->char_info[i] : li->char_info[li->char_num-i-1] );
733730

734731
// Coordinates this character will start at
735-
if ( segment_length == 0 )
732+
if ( qgsDoubleNear( segment_length, 0.0 ) )
736733
{
737734
// Not allowed to place across on 0 length segments or discontinuities
738735
delete slp;
@@ -895,7 +892,7 @@ namespace pal
895892
total_distance += path_distances[i];
896893
}
897894

898-
if ( total_distance == 0 )
895+
if ( qgsDoubleNear( total_distance, 0.0 ) )
899896
{
900897
delete[] path_distances;
901898
return 0;

src/core/pal/geomfunction.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ namespace pal
165165
b2 = x3 - x4;
166166
c2 = x4 * y3 - x3 * y4;
167167

168-
if (( denom = a1 * b2 - a2 * b1 ) == 0 )
168+
denom = a1 * b2 - a2 * b1;
169+
if ( qgsDoubleNear( denom, 0.0 ) )
169170
{
170171
return false;
171172
}
@@ -376,7 +377,7 @@ namespace pal
376377
// Should never happen, No real solutions.
377378
return;
378379

379-
if ( det == 0 )
380+
if ( qgsDoubleNear( det, 0.0 ) )
380381
{
381382
// Could potentially happen.... One solution.
382383
double t = -B / ( 2 * A );

src/core/pal/labelposition.cpp

+9-20
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
*
2828
*/
2929

30-
#define _CRT_SECURE_NO_DEPRECATE
31-
3230
#include "layer.h"
3331
#include "pal.h"
3432
#include "costcalculator.h"
@@ -395,19 +393,9 @@ namespace pal
395393
nextPart->setConflictsWithObstacle( conflicts );
396394
}
397395

398-
bool LabelPosition::costShrink( void *l, void *r )
399-
{
400-
return (( LabelPosition* ) l )->mCost < (( LabelPosition* ) r )->mCost;
401-
}
402-
403-
bool LabelPosition::costGrow( void *l, void *r )
404-
{
405-
return (( LabelPosition* ) l )->mCost > (( LabelPosition* ) r )->mCost;
406-
}
407-
408396
bool LabelPosition::polygonObstacleCallback( FeaturePart *obstacle, void *ctx )
409397
{
410-
PolygonCostCalculator *pCost = ( PolygonCostCalculator* ) ctx;
398+
PolygonCostCalculator *pCost = reinterpret_cast< PolygonCostCalculator* >( ctx );
411399

412400
LabelPosition *lp = pCost->getLabel();
413401
if (( obstacle == lp->feature ) || ( obstacle->getHoleOf() && obstacle->getHoleOf() != lp->feature ) )
@@ -443,7 +431,7 @@ namespace pal
443431

444432
bool LabelPosition::pruneCallback( LabelPosition *candidatePosition, void *ctx )
445433
{
446-
FeaturePart *obstaclePart = (( PruneCtx* ) ctx )->obstacle;
434+
FeaturePart *obstaclePart = ( reinterpret_cast< PruneCtx* >( ctx ) )->obstacle;
447435

448436
// test whether we should ignore this obstacle for the candidate. We do this if:
449437
// 1. it's not a hole, and the obstacle belongs to the same label feature as the candidate (eg
@@ -464,7 +452,7 @@ namespace pal
464452

465453
bool LabelPosition::countOverlapCallback( LabelPosition *lp, void *ctx )
466454
{
467-
LabelPosition *lp2 = ( LabelPosition* ) ctx;
455+
LabelPosition *lp2 = reinterpret_cast< LabelPosition* >( ctx );
468456

469457
//std::cerr << "checking " << lp2->getFeature()->getUID() << " x " << lp->getFeature()->getUID() << std::endl;
470458
if ( lp2->isInConflict( lp ) )
@@ -478,11 +466,12 @@ namespace pal
478466

479467
bool LabelPosition::countFullOverlapCallback( LabelPosition *lp, void *ctx )
480468
{
481-
LabelPosition *lp2 = (( CountContext* ) ctx )->lp;
482-
double *cost = (( CountContext* ) ctx )->cost;
469+
CountContext* context = reinterpret_cast< CountContext* >( ctx );
470+
LabelPosition *lp2 = context->lp;
471+
double *cost = context->cost;
483472
//int *feat = ((CountContext*)ctx)->feat;
484-
int *nbOv = (( CountContext* ) ctx )->nbOv;
485-
double *inactiveCost = (( CountContext* ) ctx )->inactiveCost;
473+
int *nbOv = context->nbOv;
474+
double *inactiveCost = context->inactiveCost;
486475
if ( lp2->isInConflict( lp ) )
487476
{
488477
#ifdef _DEBUG_FULL_
@@ -499,7 +488,7 @@ namespace pal
499488

500489
bool LabelPosition::removeOverlapCallback( LabelPosition *lp, void *ctx )
501490
{
502-
LabelPosition *lp2 = ( LabelPosition * ) ctx;
491+
LabelPosition *lp2 = reinterpret_cast< LabelPosition * >( ctx );
503492

504493
if ( lp2->isInConflict( lp ) )
505494
{

src/core/pal/labelposition.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ namespace pal
158158
*/
159159
FeaturePart * getFeaturePart();
160160

161-
double getNumOverlaps() const { return nbOverlap; }
161+
int getNumOverlaps() const { return nbOverlap; }
162162
void resetNumOverlaps() { nbOverlap = 0; } // called from problem.cpp, pal.cpp
163163

164164
int getProblemFeatureId() const { return probFeat; }
@@ -243,10 +243,6 @@ namespace pal
243243
/** Check whether the candidate in ctx overlap with obstacle feat */
244244
static bool pruneCallback( LabelPosition *candidatePosition, void *ctx );
245245

246-
// for sorting
247-
static bool costShrink( void *l, void *r );
248-
static bool costGrow( void *l, void *r );
249-
250246
// for counting number of overlaps
251247
typedef struct
252248
{

src/core/pal/pointset.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ namespace pal
157157
GEOSContextHandle_t geosctxt = geosContext();
158158

159159
bool needClose = false;
160-
if ( type == GEOS_POLYGON && ( x[0] != x[ nbPoints - 1] || y[0] != y[ nbPoints - 1 ] ) )
160+
if ( type == GEOS_POLYGON && ( !qgsDoubleNear( x[0], x[ nbPoints - 1] ) || !qgsDoubleNear( y[0], y[ nbPoints - 1 ] ) ) )
161161
{
162162
needClose = true;
163163
}

0 commit comments

Comments
 (0)