Skip to content

Commit

Permalink
Server: consider there can be multi selection mode in value relation
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed May 21, 2014
1 parent 9551349 commit c0a5697
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/mapserver/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/mapserver/qgswmsserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.