Skip to content

Commit

Permalink
Fix for filtering in qgis server
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Hugentobler committed Jun 24, 2011
1 parent 44bfb2d commit 8910039
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/mapserver/qgswmsserver.cpp
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 8910039

Please sign in to comment.