Skip to content
Permalink
Browse files

Fix various instances of cppcheck 'clarifyCalculation' warning about …

…operator precedence
  • Loading branch information
rouault committed Jun 1, 2020
1 parent 41120d7 commit 053fe62f7fdb373f4e8da3e67a79178d2e712908
@@ -173,31 +173,31 @@ int QgsZonalStatistics::calculateStatistics( QgsFeedback *feedback )
vectorProvider->addAttributes( newFieldList );

//index of the new fields
int countIndex = mStatistics & QgsZonalStatistics::Count ? vectorProvider->fieldNameIndex( countFieldName ) : -1;
int sumIndex = mStatistics & QgsZonalStatistics::Sum ? vectorProvider->fieldNameIndex( sumFieldName ) : -1;
int meanIndex = mStatistics & QgsZonalStatistics::Mean ? vectorProvider->fieldNameIndex( meanFieldName ) : -1;
int medianIndex = mStatistics & QgsZonalStatistics::Median ? vectorProvider->fieldNameIndex( medianFieldName ) : -1;
int stdevIndex = mStatistics & QgsZonalStatistics::StDev ? vectorProvider->fieldNameIndex( stdevFieldName ) : -1;
int minIndex = mStatistics & QgsZonalStatistics::Min ? vectorProvider->fieldNameIndex( minFieldName ) : -1;
int maxIndex = mStatistics & QgsZonalStatistics::Max ? vectorProvider->fieldNameIndex( maxFieldName ) : -1;
int rangeIndex = mStatistics & QgsZonalStatistics::Range ? vectorProvider->fieldNameIndex( rangeFieldName ) : -1;
int minorityIndex = mStatistics & QgsZonalStatistics::Minority ? vectorProvider->fieldNameIndex( minorityFieldName ) : -1;
int majorityIndex = mStatistics & QgsZonalStatistics::Majority ? vectorProvider->fieldNameIndex( majorityFieldName ) : -1;
int varietyIndex = mStatistics & QgsZonalStatistics::Variety ? vectorProvider->fieldNameIndex( varietyFieldName ) : -1;
int varianceIndex = mStatistics & QgsZonalStatistics::Variance ? vectorProvider->fieldNameIndex( varianceFieldName ) : -1;

if ( ( mStatistics & QgsZonalStatistics::Count && countIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Sum && sumIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Mean && meanIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Median && medianIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::StDev && stdevIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Min && minIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Max && maxIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Range && rangeIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Minority && minorityIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Majority && majorityIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Variety && varietyIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Variance && varianceIndex == -1 )
int countIndex = ( mStatistics & QgsZonalStatistics::Count ) ? vectorProvider->fieldNameIndex( countFieldName ) : -1;
int sumIndex = ( mStatistics & QgsZonalStatistics::Sum ) ? vectorProvider->fieldNameIndex( sumFieldName ) : -1;
int meanIndex = ( mStatistics & QgsZonalStatistics::Mean ) ? vectorProvider->fieldNameIndex( meanFieldName ) : -1;
int medianIndex = ( mStatistics & QgsZonalStatistics::Median ) ? vectorProvider->fieldNameIndex( medianFieldName ) : -1;
int stdevIndex = ( mStatistics & QgsZonalStatistics::StDev ) ? vectorProvider->fieldNameIndex( stdevFieldName ) : -1;
int minIndex = ( mStatistics & QgsZonalStatistics::Min ) ? vectorProvider->fieldNameIndex( minFieldName ) : -1;
int maxIndex = ( mStatistics & QgsZonalStatistics::Max ) ? vectorProvider->fieldNameIndex( maxFieldName ) : -1;
int rangeIndex = ( mStatistics & QgsZonalStatistics::Range ) ? vectorProvider->fieldNameIndex( rangeFieldName ) : -1;
int minorityIndex = ( mStatistics & QgsZonalStatistics::Minority ) ? vectorProvider->fieldNameIndex( minorityFieldName ) : -1;
int majorityIndex = ( mStatistics & QgsZonalStatistics::Majority ) ? vectorProvider->fieldNameIndex( majorityFieldName ) : -1;
int varietyIndex = ( mStatistics & QgsZonalStatistics::Variety ) ? vectorProvider->fieldNameIndex( varietyFieldName ) : -1;
int varianceIndex = ( mStatistics & QgsZonalStatistics::Variance ) ? vectorProvider->fieldNameIndex( varianceFieldName ) : -1;

if ( ( ( mStatistics & QgsZonalStatistics::Count ) && countIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Sum ) && sumIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Mean ) && meanIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Median ) && medianIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::StDev ) && stdevIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Min ) && minIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Max ) && maxIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Range ) && rangeIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Minority ) && minorityIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Majority ) && majorityIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Variety ) && varietyIndex == -1 )
|| ( ( mStatistics & QgsZonalStatistics::Variance ) && varianceIndex == -1 )
)
{
//failed to create a required field
@@ -1470,7 +1470,7 @@ bool QgsDwgImporter::curveFromLWPolyline( const DRW_LWPolyline &data, QgsCompoun

QgsPointSequence s;
bool hadBulge( data.vertlist[0]->bulge != 0.0 );
std::vector<DRW_Vertex2D *>::size_type n = data.flags & 1 ? vertexnum + 1 : vertexnum;
std::vector<DRW_Vertex2D *>::size_type n = ( data.flags & 1 ) ? vertexnum + 1 : vertexnum;
for ( std::vector<DRW_Vertex2D *>::size_type i = 0; i < n; i++ )
{
size_t i0 = i % vertexnum;
@@ -1539,7 +1539,7 @@ void QgsDwgImporter::addLWPolyline( const DRW_LWPolyline &data )
double width = -1.0; // width is set to correct value during first loop
bool hadBulge( false );

std::vector<DRW_Vertex2D *>::size_type n = data.flags & 1 ? vertexnum : vertexnum - 1;
std::vector<DRW_Vertex2D *>::size_type n = ( data.flags & 1 ) ? vertexnum : vertexnum - 1;
for ( std::vector<DRW_Vertex2D *>::size_type i = 0; i < n; i++ )
{
size_t i0 = i % vertexnum;
@@ -1739,7 +1739,7 @@ void QgsDwgImporter::addPolyline( const DRW_Polyline &data )
double width = -1.0; // width is set to correct value during first loop
bool hadBulge( false );

std::vector<DRW_Vertex *>::size_type n = data.flags & 1 ? vertexnum : vertexnum - 1;
std::vector<DRW_Vertex *>::size_type n = ( data.flags & 1 ) ? vertexnum : vertexnum - 1;
for ( std::vector<DRW_Vertex *>::size_type i = 0; i < n; i++ )
{
size_t i0 = i % vertexnum;
@@ -348,7 +348,7 @@ QVariantMap QgsProcessingModelAlgorithm::processAlgorithm( const QVariantMap &pa
QVariantMap results = childAlg->run( childParams, context, &modelFeedback, &ok, child.configuration() );
if ( !ok )
{
const QString error = childAlg->flags() & QgsProcessingAlgorithm::FlagCustomException ? QString() : QObject::tr( "Error encountered while running %1" ).arg( child.description() );
const QString error = ( childAlg->flags() & QgsProcessingAlgorithm::FlagCustomException ) ? QString() : QObject::tr( "Error encountered while running %1" ).arg( child.description() );
throw QgsProcessingException( error );
}
childResults.insert( childId, results );
@@ -131,7 +131,7 @@ QgsFeatureIds QgsFeatureSource::allFeatureIds() const

QgsVectorLayer *QgsFeatureSource::materialize( const QgsFeatureRequest &request, QgsFeedback *feedback )
{
QgsWkbTypes::Type outWkbType = request.flags() & QgsFeatureRequest::NoGeometry ? QgsWkbTypes::NoGeometry : wkbType();
QgsWkbTypes::Type outWkbType = ( request.flags() & QgsFeatureRequest::NoGeometry ) ? QgsWkbTypes::NoGeometry : wkbType();
QgsCoordinateReferenceSystem crs = request.destinationCrs().isValid() ? request.destinationCrs() : sourceCrs();

QgsAttributeList requestedAttrs = request.subsetOfAttributes();
@@ -114,11 +114,11 @@ QString QgsField::displayType( const bool showConstraints ) const

if ( showConstraints )
{
typeStr += constraints().constraints() & QgsFieldConstraints::ConstraintNotNull
typeStr += ( constraints().constraints() & QgsFieldConstraints::ConstraintNotNull )
? QStringLiteral( " NOT NULL" )
: QStringLiteral( " NULL" );

typeStr += constraints().constraints() & QgsFieldConstraints::ConstraintUnique
typeStr += ( constraints().constraints() & QgsFieldConstraints::ConstraintUnique )
? QStringLiteral( " UNIQUE" )
: QString();
}
@@ -66,7 +66,7 @@ void QgsFieldConstraints::setConstraint( QgsFieldConstraints::Constraint constra

QString QgsFieldConstraints::constraintExpression() const
{
return mConstraints & QgsFieldConstraints::ConstraintExpression ? mExpressionConstraint : QString();
return ( mConstraints & QgsFieldConstraints::ConstraintExpression ) ? mExpressionConstraint : QString();
}

void QgsFieldConstraints::setConstraintExpression( const QString &expression, const QString &description )
@@ -507,7 +507,7 @@ QList<QgsFeatureId> QgsSpatialIndex::nearestNeighbor( const QgsPointXY &point, c
Point p( pt, 2 );

QMutexLocker locker( &d->mMutex );
QgsNearestNeighborComparator nnc( d->mFlags & QgsSpatialIndex::FlagStoreFeatureGeometries ? &d->mGeometries : nullptr,
QgsNearestNeighborComparator nnc( ( d->mFlags & QgsSpatialIndex::FlagStoreFeatureGeometries ) ? &d->mGeometries : nullptr,
point, maxDistance );
d->mRTree->nearestNeighborQuery( neighbors, p, visitor, nnc );

@@ -532,7 +532,7 @@ QList<QgsFeatureId> QgsSpatialIndex::nearestNeighbor( const QgsGeometry &geometr
SpatialIndex::Region r = QgsSpatialIndexUtils::rectangleToRegion( geometry.boundingBox() );

QMutexLocker locker( &d->mMutex );
QgsNearestNeighborComparator nnc( d->mFlags & QgsSpatialIndex::FlagStoreFeatureGeometries ? &d->mGeometries : nullptr,
QgsNearestNeighborComparator nnc( ( d->mFlags & QgsSpatialIndex::FlagStoreFeatureGeometries ) ? &d->mGeometries : nullptr,
geometry, maxDistance );
d->mRTree->nearestNeighborQuery( neighbors, r, visitor, nnc );

@@ -321,7 +321,7 @@ QString QgsProcessingToolboxModel::toolTipForAlgorithm( const QgsProcessingAlgor
algorithm->displayName(),
!algorithm->shortDescription().isEmpty() ? QStringLiteral( "<p>%1</p>" ).arg( algorithm->shortDescription() ) : QString(),
QObject::tr( "Algorithm ID: ‘%1’" ).arg( QStringLiteral( "<i>%1</i>" ).arg( algorithm->id() ) ),
algorithm->flags() & QgsProcessingAlgorithm::FlagKnownIssues ? QStringLiteral( "<b style=\"color:red\">%1</b>" ).arg( QObject::tr( "Warning: Algorithm has known issues" ) ) : QString()
( algorithm->flags() & QgsProcessingAlgorithm::FlagKnownIssues ) ? QStringLiteral( "<b style=\"color:red\">%1</b>" ).arg( QObject::tr( "Warning: Algorithm has known issues" ) ) : QString()
);
}

@@ -376,7 +376,7 @@ void QgsFontButton::wheelEvent( QWheelEvent *event )
break;
}

double increment = event->modifiers() & Qt::ControlModifier ? 0.1 : 1;
double increment = ( event->modifiers() & Qt::ControlModifier ) ? 0.1 : 1;
if ( event->delta() > 0 )
{
size += increment;

0 comments on commit 053fe62

Please sign in to comment.
You can’t perform that action at this time.