Skip to content
Permalink
Browse files
Merge branch 'server_value_relation'
  • Loading branch information
mhugent committed May 21, 2014
2 parents 5417639 + 5f12661 commit d6889a4e4c3e94c68321ebb51b8b2fa9b54c37f0
Showing with 37 additions and 11 deletions.
  1. +36 −11 src/mapserver/qgswmsserver.cpp
  2. +1 −0 src/mapserver/qgswmsserver.h
@@ -2916,21 +2916,46 @@ QString QgsWMSServer::replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, c
return attributeVal;
}

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

QgsFeatureIterator fIt = layer->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( QgsAttributeList() << keyId << valueId ) );
QgsFeature f;
while ( fIt.nextFeature( f ) )
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 )
{
if ( f.attribute( vrdata.mKey ).toString() == attributeVal )
{
return f.attribute( vrdata.mValue ).toString();
}
return f.attribute( value ).toString();
}
}
return attributeVal;
@@ -254,6 +254,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 d6889a4

Please sign in to comment.