Skip to content

Commit

Permalink
Use qobject_cast instead of dynamic_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Apr 10, 2019
1 parent 2f8b9c7 commit 7bc7092
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/app/decorations/qgsdecorationgrid.cpp
Expand Up @@ -809,7 +809,7 @@ bool QgsDecorationGrid::getIntervalFromCurrentLayer( double *values )
QMessageBox::warning( nullptr, tr( "Get Interval from Layer" ), tr( "Please select a raster layer." ) );
return false;
}
QgsRasterLayer *rlayer = dynamic_cast<QgsRasterLayer *>( layer );
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( layer );
if ( !rlayer || rlayer->width() == 0 || rlayer->height() == 0 )
{
QMessageBox::warning( nullptr, tr( "Get Interval from Layer" ), tr( "Invalid raster layer" ) );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsdxfexportdialog.cpp
Expand Up @@ -124,7 +124,7 @@ QgsVectorLayer *QgsVectorLayerAndAttributeModel::vectorLayer( const QModelIndex
if ( !n || !QgsLayerTree::isLayer( n ) )
return nullptr;

return dynamic_cast<QgsVectorLayer *>( QgsLayerTree::toLayer( n )->layer() );
return qobject_cast<QgsVectorLayer *>( QgsLayerTree::toLayer( n )->layer() );
}

int QgsVectorLayerAndAttributeModel::attributeIndex( const QgsVectorLayer *vl ) const
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsjoindialog.cpp
Expand Up @@ -159,7 +159,7 @@ void QgsJoinDialog::joinedLayerChanged( QgsMapLayer *layer )
{
mJoinFieldComboBox->clear();

QgsVectorLayer *vLayer = dynamic_cast<QgsVectorLayer *>( layer );
QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );
if ( !vLayer )
{
return;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolpinlabels.cpp
Expand Up @@ -203,7 +203,7 @@ void QgsMapToolPinLabels::highlightPinnedLabels()
{
continue;
}
QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer *>( layer );
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( !vlayer )
{
QgsDebugMsg( QStringLiteral( "Failed to cast to vector layer" ) );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolshowhidelabels.cpp
Expand Up @@ -49,7 +49,7 @@ void QgsMapToolShowHideLabels::canvasPressEvent( QgsMapMouseEvent *e )
Q_UNUSED( e );

QgsMapLayer *layer = mCanvas->currentLayer();
QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer *>( layer );
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( !vlayer )
return;

Expand Down Expand Up @@ -127,7 +127,7 @@ void QgsMapToolShowHideLabels::canvasReleaseEvent( QgsMapMouseEvent *e )
void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent *e )
{
QgsMapLayer *layer = mCanvas->currentLayer();
QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer *>( layer );
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( !vlayer )
return;

Expand Down
8 changes: 4 additions & 4 deletions src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -469,7 +469,7 @@ QSizeF QgsSymbolLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemC
double dotsPerMM = context.scaleFactor();

int opacity = 255;
if ( QgsVectorLayer *vectorLayer = dynamic_cast<QgsVectorLayer *>( layerNode()->layer() ) )
if ( QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( layerNode()->layer() ) )
opacity = ( 255 * vectorLayer->opacity() );

p->save();
Expand Down Expand Up @@ -537,7 +537,7 @@ void QgsSymbolLegendNode::exportSymbolToJson( const QgsLegendSettings &settings,
QImage img( pix.toImage().convertToFormat( QImage::Format_ARGB32_Premultiplied ) );

int opacity = 255;
if ( QgsVectorLayer *vectorLayer = dynamic_cast<QgsVectorLayer *>( layerNode()->layer() ) )
if ( QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( layerNode()->layer() ) )
opacity = ( 255 * vectorLayer->opacity() );

if ( opacity != 255 )
Expand Down Expand Up @@ -702,7 +702,7 @@ QSizeF QgsRasterSymbolLegendNode::drawSymbol( const QgsLegendSettings &settings,
if ( ctx && ctx->painter )
{
QColor itemColor = mColor;
if ( QgsRasterLayer *rasterLayer = dynamic_cast<QgsRasterLayer *>( layerNode()->layer() ) )
if ( QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( layerNode()->layer() ) )
{
if ( QgsRasterRenderer *rasterRenderer = rasterLayer->renderer() )
itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
Expand Down Expand Up @@ -737,7 +737,7 @@ void QgsRasterSymbolLegendNode::exportSymbolToJson( const QgsLegendSettings &set
painter.setRenderHint( QPainter::Antialiasing );

QColor itemColor = mColor;
if ( QgsRasterLayer *rasterLayer = dynamic_cast<QgsRasterLayer *>( layerNode()->layer() ) )
if ( QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( layerNode()->layer() ) )
{
if ( QgsRasterRenderer *rasterRenderer = rasterLayer->renderer() )
itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaplayermodel.cpp
Expand Up @@ -369,7 +369,7 @@ QIcon QgsMapLayerModel::iconForLayer( QgsMapLayer *layer )

case QgsMapLayerType::VectorLayer:
{
QgsVectorLayer *vl = dynamic_cast<QgsVectorLayer *>( layer );
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
if ( !vl )
{
return QIcon();
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgssnappingconfig.cpp
Expand Up @@ -151,7 +151,7 @@ void QgsSnappingConfig::reset()
const auto constMapLayers = mProject->mapLayers();
for ( QgsMapLayer *ml : constMapLayers )
{
QgsVectorLayer *vl = dynamic_cast<QgsVectorLayer *>( ml );
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
if ( vl )
{
mIndividualLayerSettings.insert( vl, IndividualLayerSettings( enabled, type, tolerance, units ) );
Expand Down
Expand Up @@ -299,7 +299,7 @@ bool QgsGeometryCheckerResultTab::exportErrorsDo( const QString &file )
QStringList toRemove;
for ( QgsMapLayer *maplayer : QgsProject::instance()->mapLayers() )
{
if ( dynamic_cast<QgsVectorLayer *>( maplayer ) &&
if ( qobject_cast<QgsVectorLayer *>( maplayer ) &&
static_cast<QgsVectorLayer *>( maplayer )->dataProvider()->dataSourceUri() == layer->dataProvider()->dataSourceUri() )
{
toRemove.append( maplayer->id() );
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/georeferencer/qgsgcpcanvasitem.cpp
Expand Up @@ -193,7 +193,7 @@ double QgsGCPCanvasItem::residualToScreenFactor() const
QgsMapLayer *mapLayer = canvasLayers.at( 0 );
if ( mapLayer )
{
QgsRasterLayer *rasterLayer = dynamic_cast<QgsRasterLayer *>( mapLayer );
QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( mapLayer );
if ( rasterLayer )
{
mapUnitsPerRasterPixel = rasterLayer->rasterUnitsPerPixelX();
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/globe/globe_plugin.cpp
Expand Up @@ -913,7 +913,7 @@ void GlobePlugin::updateLayers()
{
if ( mapLayer )
disconnect( mapLayer, SIGNAL( repaintRequested() ), this, SLOT( layerChanged() ) );
if ( dynamic_cast<QgsVectorLayer *>( mapLayer ) )
if ( qobject_cast<QgsVectorLayer *>( mapLayer ) )
disconnect( static_cast<QgsVectorLayer *>( mapLayer ), SIGNAL( layerTransparencyChanged( int ) ), this, SLOT( layerChanged() ) );
}
osgEarth::ModelLayerVector modelLayers;
Expand All @@ -927,7 +927,7 @@ void GlobePlugin::updateLayers()
QgsMapLayer *mapLayer = QgsProject::instance()->mapLayer( QString::fromStdString( modelLayer->getName() ) );
if ( mapLayer )
disconnect( mapLayer, SIGNAL( repaintRequested() ), this, SLOT( layerChanged() ) );
if ( dynamic_cast<QgsVectorLayer *>( mapLayer ) )
if ( qobject_cast<QgsVectorLayer *>( mapLayer ) )
disconnect( static_cast<QgsVectorLayer *>( mapLayer ), SIGNAL( layerTransparencyChanged( int ) ), this, SLOT( layerChanged() ) );
if ( !selectedLayerIds.contains( QString::fromStdString( modelLayer->getName() ) ) )
mMapNode->getMap()->removeModelLayer( modelLayer );
Expand All @@ -939,7 +939,7 @@ void GlobePlugin::updateLayers()
connect( mapLayer, SIGNAL( repaintRequested() ), this, SLOT( layerChanged() ) );

QgsGlobeVectorLayerConfig *layerConfig = 0;
if ( dynamic_cast<QgsVectorLayer *>( mapLayer ) )
if ( qobject_cast<QgsVectorLayer *>( mapLayer ) )
{
layerConfig = QgsGlobeVectorLayerConfig::getConfig( static_cast<QgsVectorLayer *>( mapLayer ) );
connect( static_cast<QgsVectorLayer *>( mapLayer ), SIGNAL( layerTransparencyChanged( int ) ), this, SLOT( layerChanged() ) );
Expand Down Expand Up @@ -985,7 +985,7 @@ void GlobePlugin::layerChanged( QgsMapLayer *mapLayer )
if ( mMapNode )
{
QgsGlobeVectorLayerConfig *layerConfig = 0;
if ( dynamic_cast<QgsVectorLayer *>( mapLayer ) )
if ( qobject_cast<QgsVectorLayer *>( mapLayer ) )
{
layerConfig = QgsGlobeVectorLayerConfig::getConfig( static_cast<QgsVectorLayer *>( mapLayer ) );
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/globe/qgsglobevectorlayerproperties.cpp
Expand Up @@ -211,7 +211,7 @@ bool QgsGlobeLayerPropertiesFactory::supportsLayer( QgsMapLayer *layer ) const

void QgsGlobeLayerPropertiesFactory::readGlobeVectorLayerConfig( QgsMapLayer *mapLayer, const QDomElement &elem )
{
if ( dynamic_cast<QgsVectorLayer *>( mapLayer ) )
if ( qobject_cast<QgsVectorLayer *>( mapLayer ) )
{
QgsVectorLayer *vLayer = static_cast<QgsVectorLayer *>( mapLayer );
QgsGlobeVectorLayerConfig *config = QgsGlobeVectorLayerConfig::getConfig( vLayer );
Expand Down Expand Up @@ -254,7 +254,7 @@ void QgsGlobeLayerPropertiesFactory::readGlobeVectorLayerConfig( QgsMapLayer *ma

void QgsGlobeLayerPropertiesFactory::writeGlobeVectorLayerConfig( QgsMapLayer *mapLayer, QDomElement &elem, QDomDocument &doc )
{
if ( dynamic_cast<QgsVectorLayer *>( mapLayer ) )
if ( qobject_cast<QgsVectorLayer *>( mapLayer ) )
{
QgsVectorLayer *vLayer = static_cast<QgsVectorLayer *>( mapLayer );
QgsGlobeVectorLayerConfig *config = QgsGlobeVectorLayerConfig::getConfig( vLayer );
Expand Down

0 comments on commit 7bc7092

Please sign in to comment.