Skip to content

Commit

Permalink
Cleanup pointer comparisons to nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 11, 2017
1 parent b20b831 commit 7afec4b
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/app/dwg/qgsdwgimporter.cpp
Expand Up @@ -147,7 +147,7 @@ void QgsDwgImporter::startTransaction()

void QgsDwgImporter::commitTransaction()
{
Q_ASSERT( mDs != nullptr );
Q_ASSERT( mDs );

if ( mInTransaction && GDALDatasetCommitTransaction( mDs ) != OGRERR_NONE )
{
Expand Down Expand Up @@ -1402,7 +1402,7 @@ bool QgsDwgImporter::curveFromLWPolyline( const DRW_LWPolyline &data, QgsCompoun
{
size_t i0 = i % vertexnum;

Q_ASSERT( data.vertlist[i0] != nullptr );
Q_ASSERT( data.vertlist[i0] );
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 );

QgsPoint p( QgsWkbTypes::PointZ, data.vertlist[i0]->x, data.vertlist[i0]->y, data.elevation );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsbookmarks.cpp
Expand Up @@ -660,7 +660,7 @@ QAbstractTableModel *QgsMergedBookmarksTableModel::qgisModel()
void QgsMergedBookmarksTableModel::moveBookmark( QAbstractTableModel &modelFrom, QAbstractTableModel &modelTo, int row )
{
QSqlTableModel *qgisModel = dynamic_cast<QSqlTableModel *>( &modelTo );
if ( qgisModel == nullptr )
if ( !qgisModel )
{
modelTo.insertRow( -1 );
for ( int column = 1 ; column < modelFrom.columnCount() ; column++ )
Expand Down
2 changes: 1 addition & 1 deletion src/core/layertree/qgslayertreemodel.cpp
Expand Up @@ -1423,7 +1423,7 @@ Qt::ItemFlags QgsLayerTreeModel::legendNodeFlags( QgsLayerTreeModelLegendNode *n

bool QgsLayerTreeModel::legendEmbeddedInParent( QgsLayerTreeLayer *nodeLayer ) const
{
return mLegend[nodeLayer].embeddedNodeInParent != nullptr;
return static_cast< bool >( mLegend[nodeLayer].embeddedNodeInParent );
}

QgsLayerTreeModelLegendNode *QgsLayerTreeModel::legendNodeEmbeddedInParent( QgsLayerTreeLayer *nodeLayer ) const
Expand Down
4 changes: 2 additions & 2 deletions src/core/pal/feature.cpp
Expand Up @@ -1194,7 +1194,7 @@ int FeaturePart::createCurvedCandidatesAlongLine( QList< LabelPosition * > &lPos
}

LabelPosition *slp = curvedPlacementAtOffset( mapShape, path_distances, orientation, 1, i, reversed, flip );
if ( slp == nullptr )
if ( !slp )
continue;

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

// evaluate cost
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsgml.cpp
Expand Up @@ -904,7 +904,7 @@ void QgsGmlStreamingParser::endElement( const XML_Char *el )
QgsDebugMsg( "creation of bounding box failed" );
}
if ( !mCurrentExtent.isNull() && mLayerExtent.isNull() &&
mCurrentFeature == nullptr && mFeatureCount == 0 )
!mCurrentFeature && mFeatureCount == 0 )
{
mLayerExtent = mCurrentExtent;
mCurrentExtent = QgsRectangle();
Expand Down
10 changes: 5 additions & 5 deletions src/core/qgssqlstatement.cpp
Expand Up @@ -223,7 +223,7 @@ void QgsSQLStatementCollectTableNames::visit( const QgsSQLStatement::NodeTableDe
bool QgsSQLStatement::doBasicValidationChecks( QString &errorMsgOut ) const
{
errorMsgOut.clear();
if ( mRootNode == nullptr )
if ( !mRootNode )
{
errorMsgOut = tr( "No root node" );
return false;
Expand Down Expand Up @@ -582,7 +582,7 @@ QString QgsSQLStatement::NodeSelect::dump() const
ret += ' ';
ret += join->dump();
}
if ( mWhere != nullptr )
if ( mWhere )
{
ret += QLatin1String( " WHERE " );
ret += mWhere->dump();
Expand Down Expand Up @@ -619,7 +619,7 @@ QgsSQLStatement::Node *QgsSQLStatement::NodeSelect::clone() const
{
newSelect->appendJoin( join->cloneThis() );
}
if ( mWhere != nullptr )
if ( mWhere )
{
newSelect->setWhere( mWhere->clone() );
}
Expand All @@ -644,7 +644,7 @@ QString QgsSQLStatement::NodeJoin::dump() const
}
ret += QLatin1String( "JOIN " );
ret += mTableDef->dump();
if ( mOnExpr != nullptr )
if ( mOnExpr )
{
ret += QLatin1String( " ON " );
ret += mOnExpr->dump();
Expand Down Expand Up @@ -672,7 +672,7 @@ QgsSQLStatement::Node *QgsSQLStatement::NodeJoin::clone() const

QgsSQLStatement::NodeJoin *QgsSQLStatement::NodeJoin::cloneThis() const
{
if ( mOnExpr != nullptr )
if ( mOnExpr )
return new NodeJoin( mTableDef->cloneThis(), mOnExpr->clone(), mType );
else
return new NodeJoin( mTableDef->cloneThis(), mUsingColumns, mType );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgstracer.h
Expand Up @@ -70,7 +70,7 @@ class CORE_EXPORT QgsTracer : public QObject
bool init();

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

//! Whether there was an error during graph creation due to noding exception,
//! indicating some input data topology problems
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -658,7 +658,7 @@ QgsRectangle QgsVectorLayer::boundingBoxOfSelected() const

bool QgsVectorLayer::labelsEnabled() const
{
return mLabeling != nullptr;
return static_cast< bool >( mLabeling );
}

bool QgsVectorLayer::diagramsEnabled() const
Expand Down Expand Up @@ -4251,7 +4251,7 @@ bool QgsVectorLayer::setDependencies( const QSet<QgsMapLayerDependency> &oDeps )
Q_FOREACH ( const QgsMapLayerDependency &dep, mDependencies )
{
QgsVectorLayer *lyr = static_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( dep.layerId() ) );
if ( lyr == nullptr )
if ( !lyr )
continue;
disconnect( lyr, &QgsVectorLayer::featureAdded, this, &QgsVectorLayer::dataChanged );
disconnect( lyr, &QgsVectorLayer::featureDeleted, this, &QgsVectorLayer::dataChanged );
Expand All @@ -4271,7 +4271,7 @@ bool QgsVectorLayer::setDependencies( const QSet<QgsMapLayerDependency> &oDeps )
Q_FOREACH ( const QgsMapLayerDependency &dep, mDependencies )
{
QgsVectorLayer *lyr = static_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( dep.layerId() ) );
if ( lyr == nullptr )
if ( !lyr )
continue;
connect( lyr, &QgsVectorLayer::featureAdded, this, &QgsVectorLayer::dataChanged );
connect( lyr, &QgsVectorLayer::featureDeleted, this, &QgsVectorLayer::dataChanged );
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsziputils.cpp
Expand Up @@ -68,7 +68,7 @@ bool QgsZipUtils::unzip( const QString &zipFilename, const QString &dir, QString
int rc = 0;
struct zip *z = zip_open( zipFilename.toStdString().c_str(), ZIP_CHECKCONS, &rc );

if ( rc == ZIP_ER_OK && z != nullptr )
if ( rc == ZIP_ER_OK && z )
{
int count = zip_get_num_files( z );
if ( count != -1 )
Expand Down Expand Up @@ -130,7 +130,7 @@ bool QgsZipUtils::zip( const QString &zipFilename, const QStringList &files )
int rc = 0;
struct zip *z = zip_open( zipFilename.toStdString().c_str(), ZIP_CREATE, &rc );

if ( rc == ZIP_ER_OK && z != nullptr )
if ( rc == ZIP_ER_OK && z )
{
for ( const auto &file : files )
{
Expand All @@ -144,7 +144,7 @@ bool QgsZipUtils::zip( const QString &zipFilename, const QStringList &files )
}

zip_source *src = zip_source_file( z, file.toStdString().c_str(), 0, 0 );
if ( src != nullptr )
if ( src )
{
#if LIBZIP_VERSION_MAJOR < 1
int rc = ( int ) zip_add( z, fileInfo.fileName().toStdString().c_str(), src );
Expand Down
8 changes: 4 additions & 4 deletions src/gui/qgscolorrampbutton.cpp
Expand Up @@ -176,7 +176,7 @@ void QgsColorRampButton::showColorRampDialog()

void QgsColorRampButton::setToDefaultColorRamp()
{
if ( mDefaultColorRamp == nullptr )
if ( !mDefaultColorRamp )
{
return;
}
Expand Down Expand Up @@ -249,7 +249,7 @@ void QgsColorRampButton::prepareMenu()
mMenu->addSeparator();

//show default color option if set
if ( mDefaultColorRamp != nullptr )
if ( mDefaultColorRamp )
{
QAction *defaultColorRampAction = new QAction( tr( "Default color ramp" ), this );
defaultColorRampAction->setIcon( createMenuIcon( mDefaultColorRamp ) );
Expand Down Expand Up @@ -509,7 +509,7 @@ void QgsColorRampButton::setRandomColorRamp()
void QgsColorRampButton::setButtonBackground( QgsColorRamp *colorramp )
{
QgsColorRamp *backgroundColorRamp = colorramp;
if ( colorramp == nullptr )
if ( !colorramp )
{
backgroundColorRamp = mColorRamp;
}
Expand Down Expand Up @@ -625,7 +625,7 @@ bool QgsColorRampButton::showNull() const

bool QgsColorRampButton::isNull() const
{
return mColorRamp == nullptr;
return !mColorRamp;
}

void QgsColorRampButton::rampWidgetUpdated()
Expand Down
6 changes: 3 additions & 3 deletions src/gui/qgsnewgeopackagelayerdialog.cpp
Expand Up @@ -324,7 +324,7 @@ bool QgsNewGeoPackageLayerDialog::apply()
QString tableName( mTableNameEdit->text() );

bool overwriteTable = false;
if ( OGR_DS_GetLayerByName( hDS, tableName.toUtf8().constData() ) != nullptr )
if ( OGR_DS_GetLayerByName( hDS, tableName.toUtf8().constData() ) )
{
if ( property( "hideDialogs" ).toBool() )
{
Expand Down Expand Up @@ -389,9 +389,9 @@ bool QgsNewGeoPackageLayerDialog::apply()

OGRLayerH hLayer = OGR_DS_CreateLayer( hDS, tableName.toUtf8().constData(), hSRS, wkbType, options );
CSLDestroy( options );
if ( hSRS != nullptr )
if ( hSRS )
OSRRelease( hSRS );
if ( hLayer == nullptr )
if ( !hLayer )
{
QString msg( tr( "Creation of layer failed (OGR error:%1)" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
if ( !property( "hideDialogs" ).toBool() )
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgssqlcomposerdialog.cpp
Expand Up @@ -268,7 +268,7 @@ void QgsSQLComposerDialog::splitSQLIntoFields()
if ( sql.hasParserError() )
return;
const QgsSQLStatement::NodeSelect *nodeSelect = dynamic_cast<const QgsSQLStatement::NodeSelect *>( sql.rootNode() );
if ( nodeSelect == nullptr )
if ( !nodeSelect )
return;
mDistinct = nodeSelect->distinct();
QList<QgsSQLStatement::NodeSelectedColumn *> columns = nodeSelect->columns();
Expand All @@ -292,7 +292,7 @@ void QgsSQLComposerDialog::splitSQLIntoFields()

QString whereText;
QgsSQLStatement::Node *where = nodeSelect->where();
if ( where != nullptr )
if ( where )
whereText = where->dump();

QString orderText;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsarcgisservicesourceselect.cpp
Expand Up @@ -112,7 +112,7 @@ QgsArcGisServiceSourceSelect::~QgsArcGisServiceSourceSelect()
void QgsArcGisServiceSourceSelect::populateImageEncodings( const QStringList &availableEncodings )
{
QLayoutItem *item = nullptr;
while ( ( item = gbImageEncoding->layout()->takeAt( 0 ) ) != nullptr )
while ( ( item = gbImageEncoding->layout()->takeAt( 0 ) ) )
{
delete item->widget();
delete item;
Expand Down
8 changes: 4 additions & 4 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -1201,7 +1201,7 @@ bool QgsOgrProvider::isValid() const
// may accept any geometry type)
OGRGeometryH QgsOgrProvider::ConvertGeometryIfNecessary( OGRGeometryH hGeom )
{
if ( hGeom == nullptr )
if ( !hGeom )
return hGeom;
OGRwkbGeometryType layerGeomType = OGR_L_GetGeomType( ogrLayer );
OGRwkbGeometryType flattenLayerGeomType = wkbFlatten( layerGeomType );
Expand Down Expand Up @@ -3234,10 +3234,10 @@ void QgsOgrProviderUtils::OGRDestroyWrapper( OGRDataSourceH ogrDataSource )
OGRLayerH hSqlLyr = OGR_DS_ExecuteSQL( ogrDataSource,
"PRAGMA journal_mode = delete",
nullptr, nullptr );
if ( hSqlLyr != nullptr )
if ( hSqlLyr )
{
OGRFeatureH hFeat = OGR_L_GetNextFeature( hSqlLyr );
if ( hFeat != nullptr )
if ( hFeat )
{
const char *pszRet = OGR_F_GetFieldAsString( hFeat, 0 );
bSuccess = EQUAL( pszRet, "delete" );
Expand Down Expand Up @@ -4004,7 +4004,7 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
OGRFeatureH hFeature = OGR_L_GetNextFeature( hLayer );
bool bNew = true;

if ( hFeature != nullptr )
if ( hFeature )
{
QgsSettings settings;
// Only used in tests. Do not define it for interactive implication
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wfs/qgswfsutils.cpp
Expand Up @@ -204,7 +204,7 @@ QSharedMemory *QgsWFSUtils::createAndAttachSHM()
void QgsWFSUtils::init()
{
QSharedMemory *sharedMemory = createAndAttachSHM();
sKeepAliveWorks = sharedMemory != nullptr;
sKeepAliveWorks = static_cast< bool >( sharedMemory );
delete sharedMemory;

if ( sKeepAliveWorks )
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgsconnectionpool.cpp
Expand Up @@ -117,15 +117,15 @@ void TestQgsConnectionPool::layersFromSameDatasetGPX()
{
QgsGeometry featureGeom = layer1Features[i].geometry();
const QgsPoint *geom = dynamic_cast<const QgsPoint *>( featureGeom.geometry() );
QVERIFY( geom != nullptr );
QVERIFY( geom );
QVERIFY( qFuzzyCompare( geom->x(), i ) );
QVERIFY( qFuzzyCompare( geom->y(), i ) );
}
for ( int i = 0, n = layer2Features.count(); i < n; ++i )
{
QgsGeometry featureGeom = layer2Features[i].geometry();
const QgsLineString *geom = dynamic_cast<const QgsLineString *>( featureGeom.geometry() );
QVERIFY( geom != nullptr );
QVERIFY( geom );
int nVtx = geom->vertexCount();
QVERIFY( nVtx == nRoutePts );
for ( int j = 0; j < nVtx; ++j )
Expand Down
4 changes: 2 additions & 2 deletions tests/src/gui/testqgssqlcomposerdialog.cpp
Expand Up @@ -418,7 +418,7 @@ void TestQgsSQLComposerDialog::testJoins()

QTableWidget *table = getTableJoins( d );
QCOMPARE( table->rowCount(), 1 );
QCOMPARE( table->item( 0, 0 ) != nullptr, true );
QVERIFY( table->item( 0, 0 ) );
table->item( 0, 0 )->setText( QStringLiteral( "join_table" ) );
table->item( 0, 1 )->setText( QStringLiteral( "join_expr" ) );

Expand Down Expand Up @@ -461,7 +461,7 @@ void TestQgsSQLComposerDialog::testJoins()

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

QGSTEST_MAIN( TestQgsSQLComposerDialog )
Expand Down

0 comments on commit 7afec4b

Please sign in to comment.