Skip to content
Permalink
Browse files

Fix some coverity before/after null deference checks

  • Loading branch information
nyalldawson committed Jan 27, 2017
1 parent 799b833 commit d259cdf5d6b086934c1a61747c8808aaca26f652
@@ -3917,28 +3917,26 @@ void QgsComposer::cleanupAfterTemplateRead()
{
//test if composer map extent intersects extent of all layers
bool intersects = false;
QgsMapCanvas* canvas = mQgis && mQgis->mapCanvas() ? mQgis->mapCanvas() : nullptr;

QgsRectangle composerMapExtent = mapItem->extent();
if ( mQgis )
if ( canvas )
{
QgsMapCanvas* canvas = mQgis->mapCanvas();
if ( canvas )
QgsRectangle mapCanvasExtent = mQgis->mapCanvas()->fullExtent();
if ( composerMapExtent.intersects( mapCanvasExtent ) )
{
QgsRectangle mapCanvasExtent = mQgis->mapCanvas()->fullExtent();
if ( composerMapExtent.intersects( mapCanvasExtent ) )
{
intersects = true;
}
intersects = true;
}
}

//if not: apply current canvas extent
if ( !intersects )
if ( canvas && !intersects )
{
double currentWidth = mapItem->rect().width();
double currentHeight = mapItem->rect().height();
if ( currentWidth - 0 > 0.0 ) //don't divide through zero
{
QgsRectangle canvasExtent = mQgis->mapCanvas()->mapSettings().visibleExtent();
QgsRectangle canvasExtent = canvas->mapSettings().visibleExtent();
//adapt min y of extent such that the size of the map item stays the same
double newCanvasExtentHeight = currentHeight / currentWidth * canvasExtent.width();
canvasExtent.setYMinimum( canvasExtent.yMaximum() - newCanvasExtentHeight );
@@ -78,7 +78,8 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend )
mRasterBorderColorButton->setAllowAlpha( true );
mRasterBorderColorButton->setContext( QStringLiteral( "composer " ) );

mMapComboBox->setComposition( legend->composition() );
if ( legend )
mMapComboBox->setComposition( legend->composition() );
mMapComboBox->setItemType( QgsComposerItem::ComposerMap );
connect( mMapComboBox, SIGNAL( itemChanged( QgsComposerItem* ) ), this, SLOT( composerMapChanged( QgsComposerItem* ) ) );

@@ -160,8 +160,9 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
if ( eww )
{
eww->setValue( attrs.at( idx ) );
mTableWidget->setCellWidget( i + 1, j, eww->widget() );
mTableWidget->setCellWidget( i + 1, j, eww->widget() );
}
mTableWidget->setCellWidget( i + 1, j, eww->widget() );
}
}

@@ -819,7 +819,8 @@ bool QgsComposerPicture::readXml( const QDomElement& itemElem, const QDomDocumen
mDataDefinedProperties.setProperty( QgsComposerObject::PictureSource, QgsProperty::fromExpression( sourceExpression, expressionActive ) );
}

mSourcePath = mComposition->project()->readPath( itemElem.attribute( QStringLiteral( "file" ) ) );
mSourcePath = mComposition ? mComposition->project()->readPath( itemElem.attribute( QStringLiteral( "file" ) ) )
: itemElem.attribute( QStringLiteral( "file" ) );

//picture rotation
if ( !qgsDoubleNear( itemElem.attribute( QStringLiteral( "pictureRotation" ), QStringLiteral( "0" ) ).toDouble(), 0.0 ) )
@@ -1248,7 +1248,7 @@ void QgsWmsProjectParser::addLayers( QDomDocument &doc,
}

QString layerName = currentLayer->name();
if ( mProjectParser && mProjectParser->useLayerIds() )
if ( mProjectParser->useLayerIds() )
layerName = currentLayer->id();
else if ( !currentLayer->shortName().isEmpty() )
layerName = currentLayer->shortName();
@@ -1626,7 +1626,7 @@ void QgsWmsProjectParser::addOWSLayers( QDomDocument &doc,
layerElem.setAttribute( QStringLiteral( "opacity" ), 1 );

QString lyrname = currentLayer->name();
if ( mProjectParser && mProjectParser->useLayerIds() )
if ( mProjectParser->useLayerIds() )
lyrname = currentLayer->id();
else if ( !currentLayer->shortName().isEmpty() )
lyrname = currentLayer->shortName();
@@ -106,10 +106,7 @@ namespace QgsWcs
/*
* Adding layer list in contentMetadataElement
*/
if ( configParser )
{
configParser->wcsContentMetadata( contentMetadataElement, doc );
}
configParser->wcsContentMetadata( contentMetadataElement, doc );

return doc;

@@ -1013,7 +1013,7 @@ namespace QgsWms
{
layerElement = result.createElement( QStringLiteral( "Layer" ) );
QString layerName = currentLayer->name();
if ( mConfigParser && mConfigParser->useLayerIds() )
if ( mConfigParser->useLayerIds() )
layerName = currentLayer->id();
else if ( !currentLayer->shortName().isEmpty() )
layerName = currentLayer->shortName();
@@ -1792,7 +1792,7 @@ namespace QgsWms
if ( theMapLayer )
{
QString lName = theMapLayer->name();
if ( mConfigParser && mConfigParser->useLayerIds() )
if ( mConfigParser->useLayerIds() )
lName = theMapLayer->id();
else if ( !theMapLayer->shortName().isEmpty() )
lName = theMapLayer->shortName();

0 comments on commit d259cdf

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