Skip to content
Permalink
Browse files

Coverity fixes (unchecked dynamic_cast)

  • Loading branch information
nyalldawson committed Feb 11, 2015
1 parent 868720b commit 4e0431d88b7d6ec728a880842eb4b2ad7755b09b
@@ -165,6 +165,10 @@ QTreeWidgetItem *QgsFieldsProperties::loadAttributeEditorTreeItem( QgsAttributeE
newWidget = mDesignerTree->addItem( parent, DesignerTreeItemData( DesignerTreeItemData::Container, widgetDef->name() ) );

const QgsAttributeEditorContainer* container = dynamic_cast<const QgsAttributeEditorContainer*>( widgetDef );
if ( !container )
{
break;
}

Q_FOREACH ( QgsAttributeEditorElement* wdg, container->children() )
{
@@ -3224,7 +3224,7 @@ void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, QColor
{
//write symbol directly here
const QgsMarkerSymbolLayerV2* msl = dynamic_cast< const QgsMarkerSymbolLayerV2* >( symbolLayer );
if ( symbolLayer && symbol )
if ( msl && symbol )
{
QgsRenderContext ct;
QgsSymbolV2RenderContext ctx( ct, QgsSymbolV2::MapUnit, symbol->alpha(), false, symbol->renderHints(), f );
@@ -75,6 +75,8 @@ void QgsDxfPalLabeling::drawLabel( pal::LabelPosition* label, QgsRenderContext&
if ( mDxfExport )
{
QgsPalGeometry *g = dynamic_cast< QgsPalGeometry* >( label->getFeaturePart()->getUserGeometry() );
if ( !g )
return;

//label text
QString text = g->text();
@@ -194,23 +194,21 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
QgsRasterLayer* rlayer = qobject_cast<QgsRasterLayer *>( layer );
return QIcon( rlayer->previewAsPixmap( QSize( 32, 32 ) ) );
}
else
{
return QgsLayerItem::iconRaster();
}
}

QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer*>( layer );

if ( layer->type() == QgsMapLayer::RasterLayer )
{
return QgsLayerItem::iconRaster();
}

QIcon icon;

// if there's just on legend entry that should be embedded in layer - do that!
if ( testFlag( ShowLegend ) && legendEmbeddedInParent( nodeLayer ) )
{
icon = legendIconEmbeddedInParent( nodeLayer );
}
else if ( layer->type() == QgsMapLayer::VectorLayer )
else if ( vlayer && layer->type() == QgsMapLayer::VectorLayer )
{
if ( vlayer->geometryType() == QGis::Point )
icon = QgsLayerItem::iconPoint();
@@ -659,6 +659,9 @@ bool QgsLayerItem::equal( const QgsDataItem *other )
}
//const QgsLayerItem *o = qobject_cast<const QgsLayerItem *> ( other );
const QgsLayerItem *o = dynamic_cast<const QgsLayerItem *>( other );
if ( !o )
return false;

return ( mPath == o->mPath && mName == o->mName && mUri == o->mUri && mProviderKey == o->mProviderKey );
}

@@ -529,6 +529,9 @@ class QgsPointLocator_DumpTree : public SpatialIndex::IQueryStrategy
void getNextEntry( const IEntry& entry, id_type& nextEntry, bool& hasNext ) override
{
const INode* n = dynamic_cast<const INode*>( &entry );
if ( !n )
return;

qDebug( "NODE: %ld", n->getIdentifier() );
if ( n->getLevel() > 0 )
{
@@ -1531,15 +1531,18 @@ QModelIndex QgsCptCityBrowserModel::findPath( QString path )
if ( item->type() == QgsCptCityDataItem::Selection )
{
const QgsCptCitySelectionItem* selItem = dynamic_cast<const QgsCptCitySelectionItem *>( item );
foreach ( QString childPath, selItem->selectionsList() )
if ( selItem )
{
if ( childPath.endsWith( "/" ) )
childPath.chop( 1 );
// QgsDebugMsg( "childPath= " + childPath );
if ( path.startsWith( childPath ) )
foreach ( QString childPath, selItem->selectionsList() )
{
foundParent = true;
break;
if ( childPath.endsWith( "/" ) )
childPath.chop( 1 );
// QgsDebugMsg( "childPath= " + childPath );
if ( path.startsWith( childPath ) )
{
foundParent = true;
break;
}
}
}
}
@@ -1575,12 +1575,14 @@ QgsGraduatedSymbolRendererV2* QgsGraduatedSymbolRendererV2::convertFromRenderer(
if ( renderer->type() == "pointDisplacement" )
{
const QgsPointDisplacementRenderer* pointDisplacementRenderer = dynamic_cast<const QgsPointDisplacementRenderer*>( renderer );
return convertFromRenderer( pointDisplacementRenderer->embeddedRenderer() );
if ( pointDisplacementRenderer )
return convertFromRenderer( pointDisplacementRenderer->embeddedRenderer() );
}
if ( renderer->type() == "invertedPolygonRenderer" )
{
const QgsInvertedPolygonRenderer* invertedPolygonRenderer = dynamic_cast<const QgsInvertedPolygonRenderer*>( renderer );
return convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() );
if ( invertedPolygonRenderer )
return convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() );
}

// If not one of the specifically handled renderers, then just grab the symbol from the renderer
@@ -1081,6 +1081,9 @@ QgsRuleBasedRendererV2* QgsRuleBasedRendererV2::convertFromRenderer( const QgsFe
if ( renderer->type() == "singleSymbol" )
{
const QgsSingleSymbolRendererV2* singleSymbolRenderer = dynamic_cast<const QgsSingleSymbolRendererV2*>( renderer );
if ( !singleSymbolRenderer )
return 0;

QgsSymbolV2* origSymbol = singleSymbolRenderer->symbol()->clone();
convertToDataDefinedSymbology( origSymbol, singleSymbolRenderer->sizeScaleField(), singleSymbolRenderer->rotationField() );
return new QgsRuleBasedRendererV2( origSymbol );
@@ -1141,6 +1144,8 @@ QgsRuleBasedRendererV2* QgsRuleBasedRendererV2::convertFromRenderer( const QgsFe
{

const QgsGraduatedSymbolRendererV2* graduatedRenderer = dynamic_cast<const QgsGraduatedSymbolRendererV2*>( renderer );
if ( !graduatedRenderer )
return 0;

QgsRuleBasedRendererV2::Rule* rootrule = new QgsRuleBasedRendererV2::Rule( NULL );

@@ -1181,12 +1186,14 @@ QgsRuleBasedRendererV2* QgsRuleBasedRendererV2::convertFromRenderer( const QgsFe
if ( renderer->type() == "pointDisplacement" )
{
const QgsPointDisplacementRenderer* pointDisplacementRenderer = dynamic_cast<const QgsPointDisplacementRenderer*>( renderer );
return convertFromRenderer( pointDisplacementRenderer->embeddedRenderer() );
if ( pointDisplacementRenderer )
return convertFromRenderer( pointDisplacementRenderer->embeddedRenderer() );
}
if ( renderer->type() == "invertedPolygonRenderer" )
{
const QgsInvertedPolygonRenderer* invertedPolygonRenderer = dynamic_cast<const QgsInvertedPolygonRenderer*>( renderer );
return convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() );
if ( invertedPolygonRenderer )
return convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() );
}

return NULL;
@@ -392,13 +392,14 @@ QgsSingleSymbolRendererV2* QgsSingleSymbolRendererV2::convertFromRenderer( const
if ( renderer->type() == "pointDisplacement" )
{
const QgsPointDisplacementRenderer* pointDisplacementRenderer = dynamic_cast<const QgsPointDisplacementRenderer*>( renderer );
return convertFromRenderer( pointDisplacementRenderer->embeddedRenderer() );
if ( pointDisplacementRenderer )
return convertFromRenderer( pointDisplacementRenderer->embeddedRenderer() );
}
if ( renderer->type() == "invertedPolygonRenderer" )
{
const QgsInvertedPolygonRenderer* invertedPolygonRenderer = dynamic_cast<const QgsInvertedPolygonRenderer*>( renderer );
return convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() );

if ( invertedPolygonRenderer )
return convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() );
}

QgsSymbolV2List symbols = const_cast<QgsFeatureRendererV2 *>( renderer )->symbols();
@@ -386,6 +386,9 @@ void QgsAttributeForm::init()
if ( widgDef->type() == QgsAttributeEditorElement::AeTypeContainer )
{
QgsAttributeEditorContainer* containerDef = dynamic_cast<QgsAttributeEditorContainer*>( widgDef );
if ( !containerDef )
continue;

containerDef->setIsGroupBox( false ); // Toplevel widgets are tabs not groupboxes
QString dummy1;
bool dummy2;
@@ -565,6 +568,9 @@ QWidget* QgsAttributeForm::createWidgetFromDef( const QgsAttributeEditorElement
case QgsAttributeEditorElement::AeTypeField:
{
const QgsAttributeEditorField* fieldDef = dynamic_cast<const QgsAttributeEditorField*>( widgetDef );
if ( !fieldDef )
break;

int fldIdx = fieldDef->idx();
if ( fldIdx < vl->pendingFields().count() && fldIdx >= 0 )
{
@@ -600,8 +606,10 @@ QWidget* QgsAttributeForm::createWidgetFromDef( const QgsAttributeEditorElement
case QgsAttributeEditorElement::AeTypeContainer:
{
const QgsAttributeEditorContainer* container = dynamic_cast<const QgsAttributeEditorContainer*>( widgetDef );
QWidget* myContainer;
if ( !container )
break;

QWidget* myContainer;
if ( container->isGroupBox() )
{
QGroupBox* groupBox = new QGroupBox( parent );
@@ -760,7 +768,7 @@ bool QgsAttributeForm::eventFilter( QObject* object, QEvent* e )
if ( e->type() == QEvent::KeyPress )
{
QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>( e );
if ( keyEvent->key() == Qt::Key_Escape )
if ( keyEvent && keyEvent->key() == Qt::Key_Escape )
{
// Re-emit to this form so it will be forwarded to parent
event( e );
@@ -565,7 +565,7 @@ void QgsExpressionBuilderWidget::loadSampleValues()
QgsExpressionItem* item = dynamic_cast<QgsExpressionItem*>( mModel->itemFromIndex( idx ) );
// TODO We should really return a error the user of the widget that
// the there is no layer set.
if ( !mLayer )
if ( !mLayer || !item )
return;

mValueGroupBox->show();
@@ -580,7 +580,7 @@ void QgsExpressionBuilderWidget::loadAllValues()
QgsExpressionItem* item = dynamic_cast<QgsExpressionItem*>( mModel->itemFromIndex( idx ) );
// TODO We should really return a error the user of the widget that
// the there is no layer set.
if ( !mLayer )
if ( !mLayer || !item )
return;

mValueGroupBox->show();
@@ -71,6 +71,9 @@ void QgsFieldExpressionWidget::setFilters( QgsFieldProxyModel::Filters filters )
void QgsFieldExpressionWidget::setLeftHandButtonStyle( bool isLeft )
{
QHBoxLayout* layout = dynamic_cast<QHBoxLayout*>( this->layout() );
if ( !layout )
return;

if ( isLeft )
{
QLayoutItem* item = layout->takeAt( 1 );
@@ -129,13 +129,16 @@ void QgsRendererV2Widget::changeSymbolWidth()
}

bool ok;
double width = QInputDialog::getDouble( this, tr( "Width" ), tr( "Change symbol width" ), dynamic_cast<QgsLineSymbolV2*>( symbolList.at( 0 ) )->width(), 0.0, 999999, 1, &ok );
QgsLineSymbolV2* line = dynamic_cast<QgsLineSymbolV2*>( symbolList.at( 0 ) ) ;
double width = QInputDialog::getDouble( this, tr( "Width" ), tr( "Change symbol width" ), line ? line->width() : 0.0 , 0.0, 999999, 1, &ok );
if ( ok )
{
QList<QgsSymbolV2*>::iterator symbolIt = symbolList.begin();
for ( ; symbolIt != symbolList.end(); ++symbolIt )
{
dynamic_cast<QgsLineSymbolV2*>( *symbolIt )->setWidth( width );
line = dynamic_cast<QgsLineSymbolV2*>( *symbolIt );
if ( line )
line->setWidth( width );
}
refreshSymbolView();
}
@@ -150,13 +153,17 @@ void QgsRendererV2Widget::changeSymbolSize()
}

bool ok;
double size = QInputDialog::getDouble( this, tr( "Size" ), tr( "Change symbol size" ), dynamic_cast<QgsMarkerSymbolV2*>( symbolList.at( 0 ) )->size(), 0.0, 999999, 1, &ok );
QgsMarkerSymbolV2* marker = dynamic_cast<QgsMarkerSymbolV2*>( symbolList.at( 0 ) );

double size = QInputDialog::getDouble( this, tr( "Size" ), tr( "Change symbol size" ), marker ? marker->size() : 0.0 , 0.0, 999999, 1, &ok );
if ( ok )
{
QList<QgsSymbolV2*>::iterator symbolIt = symbolList.begin();
for ( ; symbolIt != symbolList.end(); ++symbolIt )
{
dynamic_cast<QgsMarkerSymbolV2*>( *symbolIt )->setSize( size );
marker = dynamic_cast<QgsMarkerSymbolV2*>( *symbolIt );
if ( marker )
marker->setSize( size );
}
refreshSymbolView();
}
@@ -303,12 +303,14 @@ bool QgsGeorefTransform::getOriginScaleRotation( QgsPoint &origin, double &scale
if ( mTransformParametrisation == Linear )
{
rotation = 0.0;
return dynamic_cast<QgsLinearGeorefTransform *>( mGeorefTransformImplementation )->getOriginScale( origin, scaleX, scaleY );
QgsLinearGeorefTransform* transform = dynamic_cast<QgsLinearGeorefTransform *>( mGeorefTransformImplementation );
return transform && transform->getOriginScale( origin, scaleX, scaleY );
}
else if ( mTransformParametrisation == Helmert )
{
double scale;
if ( ! dynamic_cast<QgsHelmertGeorefTransform*>( mGeorefTransformImplementation )->getOriginScaleRotation( origin, scale, rotation ) )
QgsHelmertGeorefTransform* transform = dynamic_cast<QgsHelmertGeorefTransform*>( mGeorefTransformImplementation );
if ( !transform || ! transform->getOriginScaleRotation( origin, scale, rotation ) )
{
return false;
}
@@ -126,7 +126,7 @@ bool QgsOWSConnectionItem::equal( const QgsDataItem *other )
return false;
}
const QgsOWSConnectionItem *o = dynamic_cast<const QgsOWSConnectionItem *>( other );
return ( mPath == o->mPath && mName == o->mName );
return ( o && mPath == o->mPath && mName == o->mName );
}

QList<QAction*> QgsOWSConnectionItem::actions()
@@ -215,7 +215,9 @@ void TestQgsLegendRenderer::testBigMarker()
QgsMarkerSymbolV2* sym = new QgsMarkerSymbolV2();
sym->setColor( Qt::red );
sym->setSize( sym->size() * 6 );
dynamic_cast<QgsCategorizedSymbolRendererV2*>( mVL3->rendererV2() )->updateCategorySymbol( 0, sym );
QgsCategorizedSymbolRendererV2* catRenderer = dynamic_cast<QgsCategorizedSymbolRendererV2*>( mVL3->rendererV2() );
QVERIFY( catRenderer );
catRenderer->updateCategorySymbol( 0, sym );

//dynamic_cast<QgsCategorizedSymbolRendererV2*>( mVL3->rendererV2() )->updateCategoryLabel( 2, "This is a long symbol label" );

@@ -231,7 +233,9 @@ void TestQgsLegendRenderer::testLongSymbolText()
{
QString testName = "legend_long_symbol_text";

dynamic_cast<QgsCategorizedSymbolRendererV2*>( mVL3->rendererV2() )->updateCategoryLabel( 1, "This is\nthree lines\nlong label" );
QgsCategorizedSymbolRendererV2* catRenderer = dynamic_cast<QgsCategorizedSymbolRendererV2*>( mVL3->rendererV2() );
QVERIFY( catRenderer );
catRenderer->updateCategoryLabel( 1, "This is\nthree lines\nlong label" );

QgsLayerTreeModel legendModel( mRoot );

@@ -104,6 +104,7 @@ void TestQgsMapLayerStyleManager::testStyle()
void TestQgsMapLayerStyleManager::testReadWrite()
{
QgsSingleSymbolRendererV2* r0 = dynamic_cast<QgsSingleSymbolRendererV2*>( mVL->rendererV2() );
QVERIFY( r0 );
r0->symbol()->setColor( Qt::red );

// create and populate the manager with one more style
@@ -139,17 +140,24 @@ void TestQgsMapLayerStyleManager::testReadWrite()
sm1.setCurrentStyle( QString() );

QgsSingleSymbolRendererV2* r2 = dynamic_cast<QgsSingleSymbolRendererV2*>( mVL->rendererV2() );
QVERIFY( r2 );
QCOMPARE( r2->symbol()->color(), QColor( Qt::red ) );
}

static void _setVLColor( QgsVectorLayer* vl, const QColor& c )
{
dynamic_cast<QgsSingleSymbolRendererV2*>( vl->rendererV2() )->symbol()->setColor( c );
QgsSingleSymbolRendererV2* renderer = dynamic_cast<QgsSingleSymbolRendererV2*>( vl->rendererV2() );
if ( renderer )
renderer->symbol()->setColor( c );
}

static QColor _getVLColor( QgsVectorLayer* vl )
{
return dynamic_cast<QgsSingleSymbolRendererV2*>( vl->rendererV2() )->symbol()->color();
QgsSingleSymbolRendererV2* renderer = dynamic_cast<QgsSingleSymbolRendererV2*>( vl->rendererV2() );
if ( renderer )
return renderer->symbol()->color();
else
return QColor();
}

void TestQgsMapLayerStyleManager::testSwitchingStyles()

0 comments on commit 4e0431d

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