Skip to content

Commit c0a5697

Browse files
committed
Server: consider there can be multi selection mode in value relation
1 parent 9551349 commit c0a5697

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/mapserver/qgswmsserver.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -2882,6 +2882,30 @@ QString QgsWMSServer::replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, c
28822882
return attributeVal;
28832883
}
28842884

2885+
QString outputString;
2886+
if ( vrdata.mAllowMulti )
2887+
{
2888+
QString valueString = attributeVal;
2889+
QStringList valueList = valueString.remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( "," );
2890+
outputString += "{";
2891+
for ( int i = 0; i < valueList.size(); ++i )
2892+
{
2893+
if ( i > 0 )
2894+
{
2895+
outputString += ",";
2896+
}
2897+
outputString += relationValue( valueList.at( i ), layer, vrdata.mKey, vrdata.mValue );
2898+
}
2899+
outputString += "}";
2900+
}
2901+
else
2902+
{
2903+
outputString = relationValue( attributeVal, layer, vrdata.mKey, vrdata.mValue );
2904+
}
2905+
2906+
return outputString;
2907+
2908+
/*
28852909
int keyId = layer->fieldNameIndex( vrdata.mKey );
28862910
int valueId = layer->fieldNameIndex( vrdata.mValue );
28872911
if ( keyId == -1 || valueId == -1 )
@@ -2897,6 +2921,33 @@ QString QgsWMSServer::replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, c
28972921
{
28982922
return f.attribute( vrdata.mValue ).toString();
28992923
}
2924+
}*/
2925+
2926+
}
2927+
return attributeVal;
2928+
}
2929+
2930+
QString QgsWMSServer::relationValue( const QString& attributeVal, QgsVectorLayer* layer, const QString& key, const QString& value )
2931+
{
2932+
if ( !layer )
2933+
{
2934+
return attributeVal;
2935+
}
2936+
2937+
int keyId = layer->fieldNameIndex( key );
2938+
int valueId = layer->fieldNameIndex( value );
2939+
if ( keyId == -1 || valueId == -1 )
2940+
{
2941+
return attributeVal;
2942+
}
2943+
2944+
QgsFeatureIterator fIt = layer->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( QgsAttributeList() << keyId << valueId ) );
2945+
QgsFeature f;
2946+
while ( fIt.nextFeature( f ) )
2947+
{
2948+
if ( f.attribute( key ).toString() == attributeVal )
2949+
{
2950+
return f.attribute( value ).toString();
29002951
}
29012952
}
29022953
return attributeVal;

src/mapserver/qgswmsserver.h

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ class QgsWMSServer: public QgsOWSServer
250250

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

255256
#endif

0 commit comments

Comments
 (0)