Skip to content

Commit

Permalink
QgsMapLayer: make it obvious to cppcheck that nullptr deref cannot oc…
Browse files Browse the repository at this point in the history
…cur, and make code slightly more efficient
  • Loading branch information
rouault committed Oct 2, 2020
1 parent b993fbd commit 97e2e5e
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,11 @@ void QgsMapLayer::writeCommonStyle( QDomElement &layerElement, QDomDocument &doc
layerElement.appendChild( layerFlagsElem );
}

if ( categories.testFlag( Temporal ) && const_cast< QgsMapLayer * >( this )->temporalProperties() )
if ( categories.testFlag( Temporal ) )
{
const_cast< QgsMapLayer * >( this )->temporalProperties()->writeXml( layerElement, document, context );
QgsMapLayerTemporalProperties *lTemporalProperties = const_cast< QgsMapLayer * >( this )->temporalProperties();
if ( lTemporalProperties )
lTemporalProperties->writeXml( layerElement, document, context );
}

// custom properties
Expand Down Expand Up @@ -782,7 +784,8 @@ void QgsMapLayer::setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSign

QgsCoordinateTransformContext QgsMapLayer::transformContext() const
{
return dataProvider() ? dataProvider()->transformContext() : QgsCoordinateTransformContext();
const QgsDataProvider *lDataProvider = dataProvider();
return lDataProvider ? lDataProvider->transformContext() : QgsCoordinateTransformContext();
}

QString QgsMapLayer::formatLayerName( const QString &name )
Expand Down Expand Up @@ -1679,9 +1682,11 @@ void QgsMapLayer::readCommonStyle( const QDomElement &layerElement, const QgsRea
setFlags( flags );
}

if ( categories.testFlag( Temporal ) && temporalProperties() )
if ( categories.testFlag( Temporal ) )
{
temporalProperties()->readXml( layerElement.toElement(), context );
QgsMapLayerTemporalProperties *lTemporalProperties = temporalProperties();
if ( lTemporalProperties )
lTemporalProperties->readXml( layerElement.toElement(), context );
}
}

Expand Down Expand Up @@ -1918,18 +1923,19 @@ bool QgsMapLayer::setDependencies( const QSet<QgsMapLayerDependency> &oDeps )

void QgsMapLayer::setRefreshOnNotifyEnabled( bool enabled )
{
if ( !dataProvider() )
QgsDataProvider *lDataProvider = dataProvider();
if ( !lDataProvider )
return;

if ( enabled && !isRefreshOnNotifyEnabled() )
{
dataProvider()->setListening( enabled );
connect( dataProvider(), &QgsVectorDataProvider::notify, this, &QgsMapLayer::onNotifiedTriggerRepaint );
lDataProvider->setListening( enabled );
connect( lDataProvider, &QgsVectorDataProvider::notify, this, &QgsMapLayer::onNotifiedTriggerRepaint );
}
else if ( !enabled && isRefreshOnNotifyEnabled() )
{
// we don't want to disable provider listening because someone else could need it (e.g. actions)
disconnect( dataProvider(), &QgsVectorDataProvider::notify, this, &QgsMapLayer::onNotifiedTriggerRepaint );
disconnect( lDataProvider, &QgsVectorDataProvider::notify, this, &QgsMapLayer::onNotifiedTriggerRepaint );
}
mIsRefreshOnNofifyEnabled = enabled;
}
Expand Down

0 comments on commit 97e2e5e

Please sign in to comment.