Skip to content

Commit

Permalink
[QGIS Server] Use qobject_cast when it's usefull
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Oct 10, 2016
1 parent f81bce2 commit 9610cbc
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/server/qgshostedrdsbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ QgsMapLayer* QgsHostedRDSBuilder::createMapLayer( const QDomElement& elem,
QgsRasterLayer* rl = nullptr;
if ( allowCaching )
{
rl = dynamic_cast<QgsRasterLayer*>( QgsMSLayerCache::instance()->searchLayer( uri, layerName ) );
rl = qobject_cast<QgsRasterLayer*>( QgsMSLayerCache::instance()->searchLayer( uri, layerName ) );
}
if ( !rl )
{
Expand Down
4 changes: 2 additions & 2 deletions src/server/qgsowsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/** Apply filter from AccessControl */
void QgsOWSServer::applyAccessControlLayerFilters( QgsMapLayer* mapLayer, QHash<QgsMapLayer*, QString>& originalLayerFilters ) const
{
if ( QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( mapLayer ) )
if ( QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( mapLayer ) )
{
QString sql = mAccessControl->extraSubsetString( layer );
if ( !sql.isEmpty() )
Expand Down Expand Up @@ -54,7 +54,7 @@ void QgsOWSServer::restoreLayerFilters( const QHash<QgsMapLayer*, QString>& filt
QHash<QgsMapLayer*, QString>::const_iterator filterIt = filterMap.constBegin();
for ( ; filterIt != filterMap.constEnd(); ++filterIt )
{
QgsVectorLayer* filteredLayer = dynamic_cast<QgsVectorLayer*>( filterIt.key() );
QgsVectorLayer* filteredLayer = qobject_cast<QgsVectorLayer*>( filterIt.key() );
if ( filteredLayer )
{
QgsVectorDataProvider* dp = filteredLayer->dataProvider();
Expand Down
4 changes: 2 additions & 2 deletions src/server/qgsremoteowsbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ QgsRasterLayer* QgsRemoteOWSBuilder::wmsLayerFromUrl( const QString& url, const

if ( allowCaching )
{
result = dynamic_cast<QgsRasterLayer*>( QgsMSLayerCache::instance()->searchLayer( url, layerName ) );
result = qobject_cast<QgsRasterLayer*>( QgsMSLayerCache::instance()->searchLayer( url, layerName ) );
}

if ( result )
Expand Down Expand Up @@ -414,7 +414,7 @@ QgsVectorLayer* QgsRemoteOWSBuilder::sosLayer( const QDomElement& remoteOWSElem,
QgsVectorLayer* sosLayer = nullptr;
if ( allowCaching )
{
sosLayer = dynamic_cast<QgsVectorLayer*>( QgsMSLayerCache::instance()->searchLayer( providerUrl, layerName ) );
sosLayer = qobject_cast<QgsVectorLayer*>( QgsMSLayerCache::instance()->searchLayer( providerUrl, layerName ) );
if ( sosLayer )
{
return sosLayer;
Expand Down
4 changes: 2 additions & 2 deletions src/server/qgswcsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void QgsWCSProjectParser::describeCoverage( const QString& aCoveName, QDomElemen
QString type = elem.attribute( "type" );
if ( type == "raster" )
{
QgsRasterLayer *rLayer = dynamic_cast<QgsRasterLayer *>( mProjectParser->createLayerFromElement( elem ) );
QgsRasterLayer *rLayer = qobject_cast<QgsRasterLayer *>( mProjectParser->createLayerFromElement( elem ) );
if ( !rLayer )
continue;

Expand Down Expand Up @@ -436,7 +436,7 @@ QList<QgsMapLayer*> QgsWCSProjectParser::mapLayerFromCoverage( const QString& cN
if ( type == "raster" )
{
QgsMapLayer *mLayer = mProjectParser->createLayerFromElement( elem, useCache );
QgsRasterLayer* layer = dynamic_cast<QgsRasterLayer*>( mLayer );
QgsRasterLayer* layer = qobject_cast<QgsRasterLayer*>( mLayer );
if ( !layer || !wcsLayersId.contains( layer->id() ) )
return layerList;

Expand Down
2 changes: 1 addition & 1 deletion src/server/qgswcsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ QByteArray* QgsWCSServer::getCoverage()
QgsRectangle rect( minx, miny, maxx, maxy );

QgsMapLayer* layer = layerList.at( 0 );
QgsRasterLayer* rLayer = dynamic_cast<QgsRasterLayer*>( layer );
QgsRasterLayer* rLayer = qobject_cast<QgsRasterLayer*>( layer );
if ( rLayer && wcsLayersId.contains( rLayer->id() ) )
{
#ifdef HAVE_SERVER_PYTHON_PLUGINS
Expand Down
4 changes: 2 additions & 2 deletions src/server/qgswfsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomEle
if ( type == "vector" )
{
QgsMapLayer *mLayer = mProjectParser->createLayerFromElement( elem );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( mLayer );
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( mLayer );
if ( !layer )
continue;

Expand Down Expand Up @@ -565,7 +565,7 @@ QList<QgsMapLayer*> QgsWFSProjectParser::mapLayerFromTypeName( const QString& aT
if ( type == "vector" )
{
QgsMapLayer *mLayer = mProjectParser->createLayerFromElement( elem );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( mLayer );
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( mLayer );
if ( !layer )
continue;

Expand Down
4 changes: 2 additions & 2 deletions src/server/qgswfsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
}

currentLayer = layerList.at( 0 );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( currentLayer );
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( currentLayer );
if ( layer && wfsLayersId.contains( layer->id() ) )
{
#ifdef HAVE_SERVER_PYTHON_PLUGINS
Expand Down Expand Up @@ -865,7 +865,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format

currentLayer = layerList.at( 0 );

QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( currentLayer );
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( currentLayer );
if ( layer && wfsLayersId.contains( layer->id() ) )
{
expressionContext << QgsExpressionContextUtils::layerScope( layer );
Expand Down
16 changes: 8 additions & 8 deletions src/server/qgswmsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,19 +503,19 @@ QgsComposition* QgsWMSProjectParser::initComposition( const QString& composerTem
QList<QgsComposerItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
{
QgsComposerLabel* label = dynamic_cast< QgsComposerLabel *>( *itemIt );
QgsComposerLabel* label = qobject_cast< QgsComposerLabel *>( *itemIt );
if ( label )
{
labelList.push_back( label );
continue;
}
QgsComposerMap* map = dynamic_cast< QgsComposerMap *>( *itemIt );
QgsComposerMap* map = qobject_cast< QgsComposerMap *>( *itemIt );
if ( map )
{
mapList.push_back( map );
continue;
}
QgsComposerLegend* legend = dynamic_cast< QgsComposerLegend *>( *itemIt );
QgsComposerLegend* legend = qobject_cast< QgsComposerLegend *>( *itemIt );
if ( legend )
{
QgsLegendModelV2* model = legend->modelV2();
Expand Down Expand Up @@ -567,7 +567,7 @@ QgsComposition* QgsWMSProjectParser::initComposition( const QString& composerTem
legendList.push_back( legend );
continue;
}
QgsComposerPicture* pic = dynamic_cast< QgsComposerPicture *>( *itemIt );
QgsComposerPicture* pic = qobject_cast< QgsComposerPicture *>( *itemIt );
if ( pic )
{
pic->setPicturePath( mProjectParser->convertToAbsolutePath(( pic )->picturePath() ) );
Expand All @@ -576,11 +576,11 @@ QgsComposition* QgsWMSProjectParser::initComposition( const QString& composerTem

// an html item will be a composer frame and if it is we can try to get
// its multiframe parent and then try to cast that to a composer html
const QgsComposerFrame* frame = dynamic_cast<const QgsComposerFrame *>( *itemIt );
const QgsComposerFrame* frame = qobject_cast<const QgsComposerFrame *>( *itemIt );
if ( frame )
{
const QgsComposerMultiFrame * multiFrame = frame->multiFrame();
const QgsComposerHtml* composerHtml = dynamic_cast<const QgsComposerHtml *>( multiFrame );
const QgsComposerHtml* composerHtml = qobject_cast<const QgsComposerHtml *>( multiFrame );
if ( composerHtml )
{
htmlList.push_back( composerHtml );
Expand Down Expand Up @@ -1332,7 +1332,7 @@ void QgsWMSProjectParser::addLayers( QDomDocument &doc,
bool geometryLayer = true;
if ( currentLayer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vLayer = dynamic_cast<QgsVectorLayer*>( currentLayer );
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( currentLayer );
if ( vLayer )
{
if ( vLayer->wkbType() == QGis::WKBNoGeometry )
Expand Down Expand Up @@ -1841,7 +1841,7 @@ QDomDocument QgsWMSProjectParser::getStyles( QStringList& layerList ) const
for ( int j = 0; j < currentLayerList.size(); j++ )
{
QgsMapLayer* currentLayer = currentLayerList.at( j );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( currentLayer );
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( currentLayer );
if ( !layer )
{
throw QgsMapServiceException( "Error", QString( "Could not get style because:\n%1" ).arg( "Non-vector layers not supported yet" ) );
Expand Down
6 changes: 3 additions & 3 deletions src/server/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,7 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, const QString& version )
}

//switch depending on vector or raster
QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( currentLayer );
QgsVectorLayer* vectorLayer = qobject_cast<QgsVectorLayer*>( currentLayer );

QDomElement layerElement;
if ( infoFormat.startsWith( "application/vnd.ogc.gml" ) )
Expand Down Expand Up @@ -1784,7 +1784,7 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, const QString& version )
getFeatureInfoElement.appendChild( layerElement );
}

QgsRasterLayer* rasterLayer = dynamic_cast<QgsRasterLayer*>( currentLayer );
QgsRasterLayer* rasterLayer = qobject_cast<QgsRasterLayer*>( currentLayer );
if ( rasterLayer )
{
if ( !infoPoint.data() )
Expand Down Expand Up @@ -2564,7 +2564,7 @@ void QgsWMSServer::applyRequestedLayerFilters( const QStringList& layerList , QH

Q_FOREACH ( QgsMapLayer *filter, layersToFilter )
{
QgsVectorLayer* filteredLayer = dynamic_cast<QgsVectorLayer*>( filter );
QgsVectorLayer* filteredLayer = qobject_cast<QgsVectorLayer*>( filter );
if ( filteredLayer )
{
originalFilters.insert( filteredLayer, filteredLayer->subsetString() );
Expand Down

0 comments on commit 9610cbc

Please sign in to comment.