Skip to content
Permalink
Browse files
Server: consider there can be multi selection mode in value relation
  • Loading branch information
mhugent committed May 21, 2014
1 parent 9551349 commit c0a56970437bb19d8bf553e66c71c5ff10eba903
Showing with 52 additions and 0 deletions.
  1. +51 −0 src/mapserver/qgswmsserver.cpp
  2. +1 −0 src/mapserver/qgswmsserver.h
@@ -2882,6 +2882,30 @@ QString QgsWMSServer::replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, c
return attributeVal;
}

QString outputString;
if ( vrdata.mAllowMulti )
{
QString valueString = attributeVal;
QStringList valueList = valueString.remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( "," );
outputString += "{";
for ( int i = 0; i < valueList.size(); ++i )
{
if ( i > 0 )
{
outputString += ",";
}
outputString += relationValue( valueList.at( i ), layer, vrdata.mKey, vrdata.mValue );
}
outputString += "}";
}
else
{
outputString = relationValue( attributeVal, layer, vrdata.mKey, vrdata.mValue );
}

return outputString;

/*
int keyId = layer->fieldNameIndex( vrdata.mKey );
int valueId = layer->fieldNameIndex( vrdata.mValue );
if ( keyId == -1 || valueId == -1 )
@@ -2897,6 +2921,33 @@ QString QgsWMSServer::replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, c
{
return f.attribute( vrdata.mValue ).toString();
}
}*/

}
return attributeVal;
}

QString QgsWMSServer::relationValue( const QString& attributeVal, QgsVectorLayer* layer, const QString& key, const QString& value )
{
if ( !layer )
{
return attributeVal;
}

int keyId = layer->fieldNameIndex( key );
int valueId = layer->fieldNameIndex( value );
if ( keyId == -1 || valueId == -1 )
{
return attributeVal;
}

QgsFeatureIterator fIt = layer->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( QgsAttributeList() << keyId << valueId ) );
QgsFeature f;
while ( fIt.nextFeature( f ) )
{
if ( f.attribute( key ).toString() == attributeVal )
{
return f.attribute( value ).toString();
}
}
return attributeVal;
@@ -250,6 +250,7 @@ class QgsWMSServer: public QgsOWSServer

/**Replaces attribute value with ValueRelation or ValueRelation if defined. Otherwise returns the original value*/
static QString replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, const QString& attributeVal );
static QString relationValue( const QString& attributeVal, QgsVectorLayer* layer, const QString& key, const QString& value );
};

#endif

0 comments on commit c0a5697

Please sign in to comment.