Skip to content
Permalink
Browse files

Merge pull request #9768 from m-kuhn/qobject_cast

Use qobject_cast instead of dynamic_cast
  • Loading branch information
m-kuhn committed Apr 11, 2019
2 parents 33139f3 + 7bc7092 commit 6792d236c97b3fe3a5761dee1462729322bb5f84
@@ -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" ) );
@@ -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
@@ -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;
@@ -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" ) );
@@ -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;

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

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

0 comments on commit 6792d23

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