Skip to content

Commit 7afec4b

Browse files
committed
Cleanup pointer comparisons to nullptr
1 parent b20b831 commit 7afec4b

17 files changed

+38
-38
lines changed

src/app/dwg/qgsdwgimporter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void QgsDwgImporter::startTransaction()
147147

148148
void QgsDwgImporter::commitTransaction()
149149
{
150-
Q_ASSERT( mDs != nullptr );
150+
Q_ASSERT( mDs );
151151

152152
if ( mInTransaction && GDALDatasetCommitTransaction( mDs ) != OGRERR_NONE )
153153
{
@@ -1402,7 +1402,7 @@ bool QgsDwgImporter::curveFromLWPolyline( const DRW_LWPolyline &data, QgsCompoun
14021402
{
14031403
size_t i0 = i % vertexnum;
14041404

1405-
Q_ASSERT( data.vertlist[i0] != nullptr );
1405+
Q_ASSERT( data.vertlist[i0] );
14061406
QgsDebugMsgLevel( QString( "%1: %2,%3 bulge:%4" ).arg( i ).arg( data.vertlist[i0]->x ).arg( data.vertlist[i0]->y ).arg( data.vertlist[i0]->bulge ), 5 );
14071407

14081408
QgsPoint p( QgsWkbTypes::PointZ, data.vertlist[i0]->x, data.vertlist[i0]->y, data.elevation );

src/app/qgsbookmarks.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ QAbstractTableModel *QgsMergedBookmarksTableModel::qgisModel()
660660
void QgsMergedBookmarksTableModel::moveBookmark( QAbstractTableModel &modelFrom, QAbstractTableModel &modelTo, int row )
661661
{
662662
QSqlTableModel *qgisModel = dynamic_cast<QSqlTableModel *>( &modelTo );
663-
if ( qgisModel == nullptr )
663+
if ( !qgisModel )
664664
{
665665
modelTo.insertRow( -1 );
666666
for ( int column = 1 ; column < modelFrom.columnCount() ; column++ )

src/core/layertree/qgslayertreemodel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ Qt::ItemFlags QgsLayerTreeModel::legendNodeFlags( QgsLayerTreeModelLegendNode *n
14231423

14241424
bool QgsLayerTreeModel::legendEmbeddedInParent( QgsLayerTreeLayer *nodeLayer ) const
14251425
{
1426-
return mLegend[nodeLayer].embeddedNodeInParent != nullptr;
1426+
return static_cast< bool >( mLegend[nodeLayer].embeddedNodeInParent );
14271427
}
14281428

14291429
QgsLayerTreeModelLegendNode *QgsLayerTreeModel::legendNodeEmbeddedInParent( QgsLayerTreeLayer *nodeLayer ) const

src/core/pal/feature.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition * > &lPos
11941194
}
11951195

11961196
LabelPosition *slp = curvedPlacementAtOffset( mapShape, path_distances, orientation, 1, i, reversed, flip );
1197-
if ( slp == nullptr )
1197+
if ( !slp )
11981198
continue;
11991199

12001200
// If we placed too many characters upside down
@@ -1208,7 +1208,7 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition * > &lPos
12081208
slp = curvedPlacementAtOffset( mapShape, path_distances, orientation, 1, i, reversed, flip );
12091209
}
12101210
}
1211-
if ( slp == nullptr )
1211+
if ( !slp )
12121212
continue;
12131213

12141214
// evaluate cost

src/core/qgsgml.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ void QgsGmlStreamingParser::endElement( const XML_Char *el )
904904
QgsDebugMsg( "creation of bounding box failed" );
905905
}
906906
if ( !mCurrentExtent.isNull() && mLayerExtent.isNull() &&
907-
mCurrentFeature == nullptr && mFeatureCount == 0 )
907+
!mCurrentFeature && mFeatureCount == 0 )
908908
{
909909
mLayerExtent = mCurrentExtent;
910910
mCurrentExtent = QgsRectangle();

src/core/qgssqlstatement.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ void QgsSQLStatementCollectTableNames::visit( const QgsSQLStatement::NodeTableDe
223223
bool QgsSQLStatement::doBasicValidationChecks( QString &errorMsgOut ) const
224224
{
225225
errorMsgOut.clear();
226-
if ( mRootNode == nullptr )
226+
if ( !mRootNode )
227227
{
228228
errorMsgOut = tr( "No root node" );
229229
return false;
@@ -582,7 +582,7 @@ QString QgsSQLStatement::NodeSelect::dump() const
582582
ret += ' ';
583583
ret += join->dump();
584584
}
585-
if ( mWhere != nullptr )
585+
if ( mWhere )
586586
{
587587
ret += QLatin1String( " WHERE " );
588588
ret += mWhere->dump();
@@ -619,7 +619,7 @@ QgsSQLStatement::Node *QgsSQLStatement::NodeSelect::clone() const
619619
{
620620
newSelect->appendJoin( join->cloneThis() );
621621
}
622-
if ( mWhere != nullptr )
622+
if ( mWhere )
623623
{
624624
newSelect->setWhere( mWhere->clone() );
625625
}
@@ -644,7 +644,7 @@ QString QgsSQLStatement::NodeJoin::dump() const
644644
}
645645
ret += QLatin1String( "JOIN " );
646646
ret += mTableDef->dump();
647-
if ( mOnExpr != nullptr )
647+
if ( mOnExpr )
648648
{
649649
ret += QLatin1String( " ON " );
650650
ret += mOnExpr->dump();
@@ -672,7 +672,7 @@ QgsSQLStatement::Node *QgsSQLStatement::NodeJoin::clone() const
672672

673673
QgsSQLStatement::NodeJoin *QgsSQLStatement::NodeJoin::cloneThis() const
674674
{
675-
if ( mOnExpr != nullptr )
675+
if ( mOnExpr )
676676
return new NodeJoin( mTableDef->cloneThis(), mOnExpr->clone(), mType );
677677
else
678678
return new NodeJoin( mTableDef->cloneThis(), mUsingColumns, mType );

src/core/qgstracer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class CORE_EXPORT QgsTracer : public QObject
7070
bool init();
7171

7272
//! Whether the internal data structures have been initialized
73-
bool isInitialized() const { return mGraph != nullptr; }
73+
bool isInitialized() const { return static_cast< bool >( mGraph ); }
7474

7575
//! Whether there was an error during graph creation due to noding exception,
7676
//! indicating some input data topology problems

src/core/qgsvectorlayer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ QgsRectangle QgsVectorLayer::boundingBoxOfSelected() const
658658

659659
bool QgsVectorLayer::labelsEnabled() const
660660
{
661-
return mLabeling != nullptr;
661+
return static_cast< bool >( mLabeling );
662662
}
663663

664664
bool QgsVectorLayer::diagramsEnabled() const
@@ -4251,7 +4251,7 @@ bool QgsVectorLayer::setDependencies( const QSet<QgsMapLayerDependency> &oDeps )
42514251
Q_FOREACH ( const QgsMapLayerDependency &dep, mDependencies )
42524252
{
42534253
QgsVectorLayer *lyr = static_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( dep.layerId() ) );
4254-
if ( lyr == nullptr )
4254+
if ( !lyr )
42554255
continue;
42564256
disconnect( lyr, &QgsVectorLayer::featureAdded, this, &QgsVectorLayer::dataChanged );
42574257
disconnect( lyr, &QgsVectorLayer::featureDeleted, this, &QgsVectorLayer::dataChanged );
@@ -4271,7 +4271,7 @@ bool QgsVectorLayer::setDependencies( const QSet<QgsMapLayerDependency> &oDeps )
42714271
Q_FOREACH ( const QgsMapLayerDependency &dep, mDependencies )
42724272
{
42734273
QgsVectorLayer *lyr = static_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( dep.layerId() ) );
4274-
if ( lyr == nullptr )
4274+
if ( !lyr )
42754275
continue;
42764276
connect( lyr, &QgsVectorLayer::featureAdded, this, &QgsVectorLayer::dataChanged );
42774277
connect( lyr, &QgsVectorLayer::featureDeleted, this, &QgsVectorLayer::dataChanged );

src/core/qgsziputils.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ bool QgsZipUtils::unzip( const QString &zipFilename, const QString &dir, QString
6868
int rc = 0;
6969
struct zip *z = zip_open( zipFilename.toStdString().c_str(), ZIP_CHECKCONS, &rc );
7070

71-
if ( rc == ZIP_ER_OK && z != nullptr )
71+
if ( rc == ZIP_ER_OK && z )
7272
{
7373
int count = zip_get_num_files( z );
7474
if ( count != -1 )
@@ -130,7 +130,7 @@ bool QgsZipUtils::zip( const QString &zipFilename, const QStringList &files )
130130
int rc = 0;
131131
struct zip *z = zip_open( zipFilename.toStdString().c_str(), ZIP_CREATE, &rc );
132132

133-
if ( rc == ZIP_ER_OK && z != nullptr )
133+
if ( rc == ZIP_ER_OK && z )
134134
{
135135
for ( const auto &file : files )
136136
{
@@ -144,7 +144,7 @@ bool QgsZipUtils::zip( const QString &zipFilename, const QStringList &files )
144144
}
145145

146146
zip_source *src = zip_source_file( z, file.toStdString().c_str(), 0, 0 );
147-
if ( src != nullptr )
147+
if ( src )
148148
{
149149
#if LIBZIP_VERSION_MAJOR < 1
150150
int rc = ( int ) zip_add( z, fileInfo.fileName().toStdString().c_str(), src );

src/gui/qgscolorrampbutton.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void QgsColorRampButton::showColorRampDialog()
176176

177177
void QgsColorRampButton::setToDefaultColorRamp()
178178
{
179-
if ( mDefaultColorRamp == nullptr )
179+
if ( !mDefaultColorRamp )
180180
{
181181
return;
182182
}
@@ -249,7 +249,7 @@ void QgsColorRampButton::prepareMenu()
249249
mMenu->addSeparator();
250250

251251
//show default color option if set
252-
if ( mDefaultColorRamp != nullptr )
252+
if ( mDefaultColorRamp )
253253
{
254254
QAction *defaultColorRampAction = new QAction( tr( "Default color ramp" ), this );
255255
defaultColorRampAction->setIcon( createMenuIcon( mDefaultColorRamp ) );
@@ -509,7 +509,7 @@ void QgsColorRampButton::setRandomColorRamp()
509509
void QgsColorRampButton::setButtonBackground( QgsColorRamp *colorramp )
510510
{
511511
QgsColorRamp *backgroundColorRamp = colorramp;
512-
if ( colorramp == nullptr )
512+
if ( !colorramp )
513513
{
514514
backgroundColorRamp = mColorRamp;
515515
}
@@ -625,7 +625,7 @@ bool QgsColorRampButton::showNull() const
625625

626626
bool QgsColorRampButton::isNull() const
627627
{
628-
return mColorRamp == nullptr;
628+
return !mColorRamp;
629629
}
630630

631631
void QgsColorRampButton::rampWidgetUpdated()

src/gui/qgsnewgeopackagelayerdialog.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ bool QgsNewGeoPackageLayerDialog::apply()
324324
QString tableName( mTableNameEdit->text() );
325325

326326
bool overwriteTable = false;
327-
if ( OGR_DS_GetLayerByName( hDS, tableName.toUtf8().constData() ) != nullptr )
327+
if ( OGR_DS_GetLayerByName( hDS, tableName.toUtf8().constData() ) )
328328
{
329329
if ( property( "hideDialogs" ).toBool() )
330330
{
@@ -389,9 +389,9 @@ bool QgsNewGeoPackageLayerDialog::apply()
389389

390390
OGRLayerH hLayer = OGR_DS_CreateLayer( hDS, tableName.toUtf8().constData(), hSRS, wkbType, options );
391391
CSLDestroy( options );
392-
if ( hSRS != nullptr )
392+
if ( hSRS )
393393
OSRRelease( hSRS );
394-
if ( hLayer == nullptr )
394+
if ( !hLayer )
395395
{
396396
QString msg( tr( "Creation of layer failed (OGR error:%1)" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
397397
if ( !property( "hideDialogs" ).toBool() )

src/gui/qgssqlcomposerdialog.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void QgsSQLComposerDialog::splitSQLIntoFields()
268268
if ( sql.hasParserError() )
269269
return;
270270
const QgsSQLStatement::NodeSelect *nodeSelect = dynamic_cast<const QgsSQLStatement::NodeSelect *>( sql.rootNode() );
271-
if ( nodeSelect == nullptr )
271+
if ( !nodeSelect )
272272
return;
273273
mDistinct = nodeSelect->distinct();
274274
QList<QgsSQLStatement::NodeSelectedColumn *> columns = nodeSelect->columns();
@@ -292,7 +292,7 @@ void QgsSQLComposerDialog::splitSQLIntoFields()
292292

293293
QString whereText;
294294
QgsSQLStatement::Node *where = nodeSelect->where();
295-
if ( where != nullptr )
295+
if ( where )
296296
whereText = where->dump();
297297

298298
QString orderText;

src/providers/arcgisrest/qgsarcgisservicesourceselect.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ QgsArcGisServiceSourceSelect::~QgsArcGisServiceSourceSelect()
112112
void QgsArcGisServiceSourceSelect::populateImageEncodings( const QStringList &availableEncodings )
113113
{
114114
QLayoutItem *item = nullptr;
115-
while ( ( item = gbImageEncoding->layout()->takeAt( 0 ) ) != nullptr )
115+
while ( ( item = gbImageEncoding->layout()->takeAt( 0 ) ) )
116116
{
117117
delete item->widget();
118118
delete item;

src/providers/ogr/qgsogrprovider.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ bool QgsOgrProvider::isValid() const
12011201
// may accept any geometry type)
12021202
OGRGeometryH QgsOgrProvider::ConvertGeometryIfNecessary( OGRGeometryH hGeom )
12031203
{
1204-
if ( hGeom == nullptr )
1204+
if ( !hGeom )
12051205
return hGeom;
12061206
OGRwkbGeometryType layerGeomType = OGR_L_GetGeomType( ogrLayer );
12071207
OGRwkbGeometryType flattenLayerGeomType = wkbFlatten( layerGeomType );
@@ -3234,10 +3234,10 @@ void QgsOgrProviderUtils::OGRDestroyWrapper( OGRDataSourceH ogrDataSource )
32343234
OGRLayerH hSqlLyr = OGR_DS_ExecuteSQL( ogrDataSource,
32353235
"PRAGMA journal_mode = delete",
32363236
nullptr, nullptr );
3237-
if ( hSqlLyr != nullptr )
3237+
if ( hSqlLyr )
32383238
{
32393239
OGRFeatureH hFeat = OGR_L_GetNextFeature( hSqlLyr );
3240-
if ( hFeat != nullptr )
3240+
if ( hFeat )
32413241
{
32423242
const char *pszRet = OGR_F_GetFieldAsString( hFeat, 0 );
32433243
bSuccess = EQUAL( pszRet, "delete" );
@@ -4004,7 +4004,7 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
40044004
OGRFeatureH hFeature = OGR_L_GetNextFeature( hLayer );
40054005
bool bNew = true;
40064006

4007-
if ( hFeature != nullptr )
4007+
if ( hFeature )
40084008
{
40094009
QgsSettings settings;
40104010
// Only used in tests. Do not define it for interactive implication

src/providers/wfs/qgswfsutils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ QSharedMemory *QgsWFSUtils::createAndAttachSHM()
204204
void QgsWFSUtils::init()
205205
{
206206
QSharedMemory *sharedMemory = createAndAttachSHM();
207-
sKeepAliveWorks = sharedMemory != nullptr;
207+
sKeepAliveWorks = static_cast< bool >( sharedMemory );
208208
delete sharedMemory;
209209

210210
if ( sKeepAliveWorks )

tests/src/core/testqgsconnectionpool.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ void TestQgsConnectionPool::layersFromSameDatasetGPX()
117117
{
118118
QgsGeometry featureGeom = layer1Features[i].geometry();
119119
const QgsPoint *geom = dynamic_cast<const QgsPoint *>( featureGeom.geometry() );
120-
QVERIFY( geom != nullptr );
120+
QVERIFY( geom );
121121
QVERIFY( qFuzzyCompare( geom->x(), i ) );
122122
QVERIFY( qFuzzyCompare( geom->y(), i ) );
123123
}
124124
for ( int i = 0, n = layer2Features.count(); i < n; ++i )
125125
{
126126
QgsGeometry featureGeom = layer2Features[i].geometry();
127127
const QgsLineString *geom = dynamic_cast<const QgsLineString *>( featureGeom.geometry() );
128-
QVERIFY( geom != nullptr );
128+
QVERIFY( geom );
129129
int nVtx = geom->vertexCount();
130130
QVERIFY( nVtx == nRoutePts );
131131
for ( int j = 0; j < nVtx; ++j )

tests/src/gui/testqgssqlcomposerdialog.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ void TestQgsSQLComposerDialog::testJoins()
418418

419419
QTableWidget *table = getTableJoins( d );
420420
QCOMPARE( table->rowCount(), 1 );
421-
QCOMPARE( table->item( 0, 0 ) != nullptr, true );
421+
QVERIFY( table->item( 0, 0 ) );
422422
table->item( 0, 0 )->setText( QStringLiteral( "join_table" ) );
423423
table->item( 0, 1 )->setText( QStringLiteral( "join_expr" ) );
424424

@@ -461,7 +461,7 @@ void TestQgsSQLComposerDialog::testJoins()
461461

462462
QTest::mouseClick( getAddJoinButton( d ), Qt::LeftButton );
463463
QCOMPARE( table->rowCount(), 1 );
464-
QCOMPARE( table->item( 0, 0 ) != nullptr, true );
464+
QVERIFY( table->item( 0, 0 ) );
465465
}
466466

467467
QGSTEST_MAIN( TestQgsSQLComposerDialog )

0 commit comments

Comments
 (0)