mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Fix/avoid Coverity null pointer dereference warnings
This commit is contained in:
parent
f84508a35d
commit
7619cba438
@ -481,7 +481,7 @@ void QgsGeometrySnapper::processFeature( QgsFeature& feature, double snapToleran
|
||||
|
||||
QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry& geometry, double snapTolerance, SnapMode mode ) const
|
||||
{
|
||||
QgsPointV2 center = dynamic_cast< const QgsPointV2* >( geometry.geometry() ) ? *dynamic_cast< const QgsPointV2* >( geometry.geometry() ) :
|
||||
QgsPointV2 center = dynamic_cast< const QgsPointV2* >( geometry.geometry() ) ? *static_cast< const QgsPointV2* >( geometry.geometry() ) :
|
||||
QgsPointV2( geometry.geometry()->boundingBox().center() );
|
||||
|
||||
// Get potential reference features and construct snap index
|
||||
|
@ -85,9 +85,11 @@ void QgsComposerPolygonWidget::setGuiElementValues()
|
||||
|
||||
void QgsComposerPolygonWidget::updateStyleFromWidget()
|
||||
{
|
||||
QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( sender() );
|
||||
mComposerPolygon->setPolygonStyleSymbol( dynamic_cast< QgsFillSymbol* >( w->symbol() ) );
|
||||
mComposerPolygon->update();
|
||||
if ( QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( sender() ) )
|
||||
{
|
||||
mComposerPolygon->setPolygonStyleSymbol( dynamic_cast< QgsFillSymbol* >( w->symbol() ) );
|
||||
mComposerPolygon->update();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposerPolygonWidget::cleanUpStyleSelector( QgsPanelWidget* container )
|
||||
|
@ -78,9 +78,11 @@ void QgsComposerPolylineWidget::setGuiElementValues()
|
||||
|
||||
void QgsComposerPolylineWidget::updateStyleFromWidget()
|
||||
{
|
||||
QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( sender() );
|
||||
mComposerPolyline->setPolylineStyleSymbol( dynamic_cast< QgsLineSymbol* >( w->symbol() ) );
|
||||
mComposerPolyline->update();
|
||||
if ( QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( sender() ) )
|
||||
{
|
||||
mComposerPolyline->setPolylineStyleSymbol( dynamic_cast< QgsLineSymbol* >( w->symbol() ) );
|
||||
mComposerPolyline->update();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposerPolylineWidget::cleanUpStyleSelector( QgsPanelWidget* container )
|
||||
|
@ -182,8 +182,8 @@ void QgsComposerShapeWidget::toggleRadiusSpin( const QString& shapeText )
|
||||
|
||||
void QgsComposerShapeWidget::updateSymbolFromWidget()
|
||||
{
|
||||
QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( sender() );
|
||||
mComposerShape->setShapeStyleSymbol( dynamic_cast< QgsFillSymbol* >( w->symbol() ) );
|
||||
if ( QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( sender() ) )
|
||||
mComposerShape->setShapeStyleSymbol( dynamic_cast< QgsFillSymbol* >( w->symbol() ) );
|
||||
}
|
||||
|
||||
void QgsComposerShapeWidget::cleanUpSymbolSelector( QgsPanelWidget* container )
|
||||
|
@ -199,9 +199,11 @@ void QgsCompositionWidget::updateVariables()
|
||||
|
||||
void QgsCompositionWidget::updateStyleFromWidget()
|
||||
{
|
||||
QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( sender() );
|
||||
mComposition->setPageStyleSymbol( dynamic_cast< QgsFillSymbol* >( w->symbol() ) );
|
||||
mComposition->update();
|
||||
if ( QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( sender() ) )
|
||||
{
|
||||
mComposition->setPageStyleSymbol( dynamic_cast< QgsFillSymbol* >( w->symbol() ) );
|
||||
mComposition->update();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsCompositionWidget::cleanUpStyleSelector( QgsPanelWidget* container )
|
||||
|
@ -104,8 +104,11 @@ void QgsComposerShape::createDefaultShapeStyleSymbol()
|
||||
properties.insert( QStringLiteral( "joinstyle" ), QStringLiteral( "miter" ) );
|
||||
mShapeStyleSymbol = QgsFillSymbol::createSimple( properties );
|
||||
|
||||
QgsRenderContext rc = QgsComposerUtils::createRenderContextForMap( mComposition->referenceMap(), nullptr, mComposition->printResolution() );
|
||||
mMaxSymbolBleed = ( 25.4 / mComposition->printResolution() ) * QgsSymbolLayerUtils::estimateMaxSymbolBleed( mShapeStyleSymbol, rc );
|
||||
if ( mComposition )
|
||||
{
|
||||
QgsRenderContext rc = QgsComposerUtils::createRenderContextForMap( mComposition->referenceMap(), nullptr, mComposition->printResolution() );
|
||||
mMaxSymbolBleed = ( 25.4 / mComposition->printResolution() ) * QgsSymbolLayerUtils::estimateMaxSymbolBleed( mShapeStyleSymbol, rc );
|
||||
}
|
||||
|
||||
updateBoundingRect();
|
||||
|
||||
|
@ -2765,7 +2765,7 @@ static QVariant fcnProject( const QVariantList& values, const QgsExpressionConte
|
||||
double azimuth = getDoubleValue( values.at( 2 ), parent );
|
||||
double inclination = getDoubleValue( values.at( 3 ), parent );
|
||||
|
||||
const QgsPointV2* p = dynamic_cast<const QgsPointV2*>( geom.geometry() );
|
||||
const QgsPointV2* p = static_cast<const QgsPointV2*>( geom.geometry() );
|
||||
QgsPointV2 newPoint = p->project( distance, 180.0 * azimuth / M_PI, 180.0 * inclination / M_PI );
|
||||
|
||||
return QVariant::fromValue( QgsGeometry( new QgsPointV2( newPoint ) ) );
|
||||
|
@ -321,7 +321,7 @@ void QgsProjectPropertyKey::dump( int tabs ) const
|
||||
QgsDebugMsg( QString( "%1key: <%2> subkey: <%3>" )
|
||||
.arg( tabString,
|
||||
i.key(),
|
||||
dynamic_cast<QgsProjectPropertyKey*>( i.value() )->name() ) );
|
||||
static_cast<QgsProjectPropertyKey*>( i.value() )->name() ) );
|
||||
i.value()->dump( tabs + 1 );
|
||||
}
|
||||
|
||||
|
@ -1108,20 +1108,20 @@ void QgsRasterLayer::refreshRendererIfNeeded( QgsRasterRenderer* rasterRenderer,
|
||||
|
||||
// Update main renderer so that the legends get updated
|
||||
if ( singleBandRenderer )
|
||||
dynamic_cast<QgsSingleBandGrayRenderer*>( renderer() )->setContrastEnhancement( new QgsContrastEnhancement( * singleBandRenderer->contrastEnhancement() ) );
|
||||
static_cast<QgsSingleBandGrayRenderer*>( renderer() )->setContrastEnhancement( new QgsContrastEnhancement( * singleBandRenderer->contrastEnhancement() ) );
|
||||
else if ( multiBandRenderer )
|
||||
{
|
||||
if ( multiBandRenderer->redContrastEnhancement() )
|
||||
{
|
||||
dynamic_cast<QgsMultiBandColorRenderer*>( renderer() )->setRedContrastEnhancement( new QgsContrastEnhancement( *multiBandRenderer->redContrastEnhancement() ) );
|
||||
static_cast<QgsMultiBandColorRenderer*>( renderer() )->setRedContrastEnhancement( new QgsContrastEnhancement( *multiBandRenderer->redContrastEnhancement() ) );
|
||||
}
|
||||
if ( multiBandRenderer->greenContrastEnhancement() )
|
||||
{
|
||||
dynamic_cast<QgsMultiBandColorRenderer*>( renderer() )->setGreenContrastEnhancement( new QgsContrastEnhancement( *multiBandRenderer->greenContrastEnhancement() ) );
|
||||
static_cast<QgsMultiBandColorRenderer*>( renderer() )->setGreenContrastEnhancement( new QgsContrastEnhancement( *multiBandRenderer->greenContrastEnhancement() ) );
|
||||
}
|
||||
if ( multiBandRenderer->blueContrastEnhancement() )
|
||||
{
|
||||
dynamic_cast<QgsMultiBandColorRenderer*>( renderer() )->setBlueContrastEnhancement( new QgsContrastEnhancement( *multiBandRenderer->blueContrastEnhancement() ) );
|
||||
static_cast<QgsMultiBandColorRenderer*>( renderer() )->setBlueContrastEnhancement( new QgsContrastEnhancement( *multiBandRenderer->blueContrastEnhancement() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1557,7 +1557,7 @@ void QgsWmsProjectParser::addOWSLayers( QDomDocument &doc,
|
||||
}
|
||||
|
||||
QString layerName = currentLayer->name();
|
||||
if ( mProjectParser && mProjectParser->useLayerIds() )
|
||||
if ( mProjectParser->useLayerIds() )
|
||||
layerName = currentLayer->id();
|
||||
else if ( !currentLayer->shortName().isEmpty() )
|
||||
layerName = currentLayer->shortName();
|
||||
|
@ -583,8 +583,9 @@ void TestQgsProperty::propertyTransformer()
|
||||
//install into property and test evaluation
|
||||
QgsProperty p1;
|
||||
p1.setTransformer( new TestTransformer( 10, 20 ) );
|
||||
QCOMPARE( dynamic_cast< const TestTransformer* >( p1.transformer() )->minValue(), 10.0 );
|
||||
QCOMPARE( dynamic_cast< const TestTransformer* >( p1.transformer() )->maxValue(), 20.0 );
|
||||
QVERIFY( dynamic_cast< const TestTransformer* >( p1.transformer() ) );
|
||||
QCOMPARE( static_cast< const TestTransformer* >( p1.transformer() )->minValue(), 10.0 );
|
||||
QCOMPARE( static_cast< const TestTransformer* >( p1.transformer() )->maxValue(), 20.0 );
|
||||
p1.setStaticValue( QVariant( QVariant::Double ) );
|
||||
QCOMPARE( p1.value( context, -99 ).toDouble(), -1.0 );
|
||||
p1.setStaticValue( 11.0 );
|
||||
@ -772,24 +773,25 @@ void TestQgsProperty::colorRampTransformer()
|
||||
QCOMPARE( r1.minValue(), 15.0 );
|
||||
QCOMPARE( r1.maxValue(), 25.0 );
|
||||
QCOMPARE( r1.nullColor(), QColor( 100, 150, 200 ) );
|
||||
QCOMPARE( dynamic_cast< QgsGradientColorRamp* >( r1.colorRamp() )->color1(), QColor( 10, 20, 30 ) );
|
||||
QCOMPARE( dynamic_cast< QgsGradientColorRamp* >( r1.colorRamp() )->color2(), QColor( 200, 190, 180 ) );
|
||||
QVERIFY( dynamic_cast< QgsGradientColorRamp* >( r1.colorRamp() ) );
|
||||
QCOMPARE( static_cast< QgsGradientColorRamp* >( r1.colorRamp() )->color1(), QColor( 10, 20, 30 ) );
|
||||
QCOMPARE( static_cast< QgsGradientColorRamp* >( r1.colorRamp() )->color2(), QColor( 200, 190, 180 ) );
|
||||
|
||||
// test cloning
|
||||
QScopedPointer< QgsColorRampTransformer > r2( t1.clone() );
|
||||
QCOMPARE( r2->minValue(), 15.0 );
|
||||
QCOMPARE( r2->maxValue(), 25.0 );
|
||||
QCOMPARE( r2->nullColor(), QColor( 100, 150, 200 ) );
|
||||
QCOMPARE( dynamic_cast< QgsGradientColorRamp* >( r2->colorRamp() )->color1(), QColor( 10, 20, 30 ) );
|
||||
QCOMPARE( dynamic_cast< QgsGradientColorRamp* >( r2->colorRamp() )->color2(), QColor( 200, 190, 180 ) );
|
||||
QCOMPARE( static_cast< QgsGradientColorRamp* >( r2->colorRamp() )->color1(), QColor( 10, 20, 30 ) );
|
||||
QCOMPARE( static_cast< QgsGradientColorRamp* >( r2->colorRamp() )->color2(), QColor( 200, 190, 180 ) );
|
||||
|
||||
// copy constructor
|
||||
QgsColorRampTransformer r3( t1 );
|
||||
QCOMPARE( r3.minValue(), 15.0 );
|
||||
QCOMPARE( r3.maxValue(), 25.0 );
|
||||
QCOMPARE( r3.nullColor(), QColor( 100, 150, 200 ) );
|
||||
QCOMPARE( dynamic_cast< QgsGradientColorRamp* >( r3.colorRamp() )->color1(), QColor( 10, 20, 30 ) );
|
||||
QCOMPARE( dynamic_cast< QgsGradientColorRamp* >( r3.colorRamp() )->color2(), QColor( 200, 190, 180 ) );
|
||||
QCOMPARE( static_cast< QgsGradientColorRamp* >( r3.colorRamp() )->color1(), QColor( 10, 20, 30 ) );
|
||||
QCOMPARE( static_cast< QgsGradientColorRamp* >( r3.colorRamp() )->color2(), QColor( 200, 190, 180 ) );
|
||||
|
||||
// assignment operator
|
||||
QgsColorRampTransformer r4;
|
||||
@ -797,8 +799,8 @@ void TestQgsProperty::colorRampTransformer()
|
||||
QCOMPARE( r4.minValue(), 15.0 );
|
||||
QCOMPARE( r4.maxValue(), 25.0 );
|
||||
QCOMPARE( r4.nullColor(), QColor( 100, 150, 200 ) );
|
||||
QCOMPARE( dynamic_cast< QgsGradientColorRamp* >( r4.colorRamp() )->color1(), QColor( 10, 20, 30 ) );
|
||||
QCOMPARE( dynamic_cast< QgsGradientColorRamp* >( r4.colorRamp() )->color2(), QColor( 200, 190, 180 ) );
|
||||
QCOMPARE( static_cast< QgsGradientColorRamp* >( r4.colorRamp() )->color1(), QColor( 10, 20, 30 ) );
|
||||
QCOMPARE( static_cast< QgsGradientColorRamp* >( r4.colorRamp() )->color2(), QColor( 200, 190, 180 ) );
|
||||
|
||||
//test various min/max value/color and scaling methods
|
||||
|
||||
@ -811,7 +813,7 @@ void TestQgsProperty::colorRampTransformer()
|
||||
t.setNullColor( QColor( 1, 10, 11, 21 ) );
|
||||
QCOMPARE( t.nullColor(), QColor( 1, 10, 11, 21 ) );
|
||||
t.setColorRamp( new QgsGradientColorRamp( QColor( 10, 20, 100 ), QColor( 100, 200, 200 ) ) );
|
||||
QCOMPARE( dynamic_cast< QgsGradientColorRamp* >( t.colorRamp() )->color1(), QColor( 10, 20, 100 ) );
|
||||
QCOMPARE( static_cast< QgsGradientColorRamp* >( t.colorRamp() )->color1(), QColor( 10, 20, 100 ) );
|
||||
|
||||
//test colors
|
||||
QCOMPARE( t.color( 50 ), QColor( 10, 20, 100 ) ); //out of range
|
||||
|
@ -701,15 +701,16 @@ void TestQgsRasterLayer::testRefreshRendererIfNeeded()
|
||||
{
|
||||
QVERIFY2( mpLandsatRasterLayer->isValid(), "landsat.tif layer is not valid!" );
|
||||
mpLandsatRasterLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, QgsRasterMinMaxOrigin::MinMax );
|
||||
QVERIFY( dynamic_cast<QgsMultiBandColorRenderer*>( mpLandsatRasterLayer->renderer() ) );
|
||||
mMapSettings->setLayers( QList<QgsMapLayer*>() << mpLandsatRasterLayer );
|
||||
mMapSettings->setExtent( mpLandsatRasterLayer->extent() );
|
||||
double initMinVal = dynamic_cast<QgsMultiBandColorRenderer*>( mpLandsatRasterLayer->renderer() )->redContrastEnhancement()->minimumValue();
|
||||
double initMinVal = static_cast<QgsMultiBandColorRenderer*>( mpLandsatRasterLayer->renderer() )->redContrastEnhancement()->minimumValue();
|
||||
|
||||
// Should do nothing
|
||||
QgsRectangle newExtent = QgsRectangle( 785000, 3340000, 785100, 3340100 );
|
||||
mpLandsatRasterLayer->refreshRendererIfNeeded( mpLandsatRasterLayer->renderer(), newExtent );
|
||||
QCOMPARE( mpLandsatRasterLayer->renderer()->minMaxOrigin().limits(), QgsRasterMinMaxOrigin::MinMax );
|
||||
double minVal = dynamic_cast<QgsMultiBandColorRenderer*>( mpLandsatRasterLayer->renderer() )->redContrastEnhancement()->minimumValue();
|
||||
double minVal = static_cast<QgsMultiBandColorRenderer*>( mpLandsatRasterLayer->renderer() )->redContrastEnhancement()->minimumValue();
|
||||
QGSCOMPARENEAR( initMinVal, minVal, 1e-5 );
|
||||
|
||||
// Change to UpdatedCanvas
|
||||
@ -719,7 +720,7 @@ void TestQgsRasterLayer::testRefreshRendererIfNeeded()
|
||||
mpLandsatRasterLayer->renderer()->setMinMaxOrigin( mmo );
|
||||
QCOMPARE( mpLandsatRasterLayer->renderer()->minMaxOrigin().extent(), QgsRasterMinMaxOrigin::UpdatedCanvas );
|
||||
mpLandsatRasterLayer->refreshRendererIfNeeded( mpLandsatRasterLayer->renderer(), newExtent );
|
||||
double newMinVal = dynamic_cast<QgsMultiBandColorRenderer*>( mpLandsatRasterLayer->renderer() )->redContrastEnhancement()->minimumValue();
|
||||
double newMinVal = static_cast<QgsMultiBandColorRenderer*>( mpLandsatRasterLayer->renderer() )->redContrastEnhancement()->minimumValue();
|
||||
QGSCOMPARENOTNEAR( initMinVal, newMinVal, 1e-5 );
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user