Skip to content
Permalink
Browse files

[QGIS Server] Use qobject_cast when it's usefull

  • Loading branch information
rldhont committed Oct 10, 2016
1 parent d5328f6 commit 5abeac12ef87347ac46eab3e63c998b6f068116f
@@ -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 )
{
@@ -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() )
@@ -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();
@@ -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 )
@@ -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;
@@ -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;

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

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

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

@@ -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
@@ -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 );
@@ -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();
@@ -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() ) );
@@ -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 );
@@ -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 )
@@ -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" ) );
@@ -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" ) )
@@ -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() )
@@ -2578,7 +2578,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() );

0 comments on commit 5abeac1

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