Skip to content
Permalink
Browse files

Fix for filtering in qgis server

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Jun 24, 2011
1 parent 44bfb2d commit 891003911516dd098112355f272bc4f3fb2cd061
Showing with 23 additions and 20 deletions.
  1. +23 −20 src/mapserver/qgswmsserver.cpp
@@ -1524,31 +1524,34 @@ QMap<QString, QString> QgsWMSServer::applyRequestedLayerFilters( const QStringLi
"AND,OR,IN,<,>=,>,>=,!=,',',(,). Not allowed are semicolons in the filter expression." );
}

//we know the layer name, but need to go through the list because a layer could be there several times...
int listPos = 1;
QStringList::const_iterator layerIt = layerList.constBegin();
for ( ; layerIt != layerList.constEnd(); ++layerIt )
//we need to find the maplayer objects matching the layer name
QList<QgsMapLayer*> layersToFilter;
QMap<QString, QgsMapLayer*>& layerMap = QgsMapLayerRegistry::instance()->mapLayers();

QMap<QString, QgsMapLayer*>::iterator layerIt = layerMap.begin();
for ( ; layerIt != layerMap.end(); ++layerIt )
{
if ( layerIt.value() && layerIt.value()->name() == eqSplit.at( 0 ) )
{
layersToFilter.push_back( layerIt.value() );
}
}

QList<QgsMapLayer*>::iterator filterIt = layersToFilter.begin();
for ( ; filterIt != layersToFilter.end(); ++filterIt )
{
if ( *layerIt == eqSplit.at( 0 ) )
QgsVectorLayer* filteredLayer = dynamic_cast<QgsVectorLayer*>( *filterIt );
if ( filteredLayer )
{
QString layerId = layerIds.at( layerIds.size() - listPos );
QgsVectorLayer* filteredLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerId ) );
if ( filteredLayer )
filterMap.insert( filteredLayer->id(), filteredLayer->subsetString() );
QString newSubsetString = eqSplit.at( 1 );
if ( !filteredLayer->subsetString().isEmpty() )
{
if ( filteredLayer )
{
filterMap.insert( layerId, filteredLayer->subsetString() );
QString newSubsetString = eqSplit.at( 1 );
if ( !filteredLayer->subsetString().isEmpty() )
{
newSubsetString.prepend( " AND " );
newSubsetString.prepend( filteredLayer->subsetString() );
}
filteredLayer->setSubsetString( newSubsetString );
}
newSubsetString.prepend( " AND " );
newSubsetString.prepend( filteredLayer->subsetString() );
}
filteredLayer->setSubsetString( newSubsetString );
}
++listPos;
}
}

0 comments on commit 8910039

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