Skip to content
Permalink
Browse files

QgsMapLayer: make it obvious to cppcheck that nullptr deref cannot oc…

…cur, and make code slightly more efficient
  • Loading branch information
rouault committed Oct 2, 2020
1 parent b993fbd commit 97e2e5e87e7ac1fea7552cf3fd8fb95537fcbe93
Showing with 15 additions and 9 deletions.
  1. +15 −9 src/core/qgsmaplayer.cpp
@@ -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
@@ -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 )
@@ -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 );
}
}

@@ -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;
}

0 comments on commit 97e2e5e

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