@@ -2094,7 +2094,26 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
20942094
20952095 QDomElement attributeElement = infoDocument.createElement ( " Attribute" );
20962096 attributeElement.setAttribute ( " name" , attributeName );
2097- attributeElement.setAttribute ( " value" , replaceValueMapAndRelation ( layer, i, QgsExpression::replaceExpressionText ( featureAttributes[i].toString (), &feature, layer ) ) );
2097+
2098+ QString value;
2099+ if ( featureAttributes[i].isNull () )
2100+ value = QSettings ().value ( " qgis/nullValue" , " NULL" ).toString ();
2101+ else
2102+ {
2103+ value = replaceValueMapAndRelation ( layer, i, QgsExpression::replaceExpressionText ( featureAttributes[i].toString (), &feature, layer ) );
2104+
2105+ switch ( featureAttributes[i].type () )
2106+ {
2107+ case QVariant::Int:
2108+ case QVariant::LongLong:
2109+ case QVariant::Double:
2110+ break ;
2111+ default :
2112+ value = " '" + value + " '" ;
2113+ }
2114+ }
2115+
2116+ attributeElement.setAttribute ( " value" , value );
20982117 featureElement.appendChild ( attributeElement );
20992118 }
21002119
@@ -3054,42 +3073,43 @@ QString QgsWMSServer::replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, c
30543073 QMap<QString, QVariant>::const_iterator vmapIt = cfg.constBegin ();
30553074 for ( ; vmapIt != cfg.constEnd (); ++vmapIt )
30563075 {
3057- if ( vmapIt.value (). toString () == attributeVal )
3076+ if ( vmapIt.key () == attributeVal )
30583077 {
3059- return vmapIt.key ();
3078+ return vmapIt.value (). toString ();
30603079 }
30613080 }
3081+ return QString ( " (%1)" ).arg ( attributeVal );
30623082 }
30633083 else if ( type == " ValueRelation" )
30643084 {
30653085 QgsEditorWidgetConfig cfg ( vl->editorWidgetV2Config ( idx ) );
30663086 QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance ()->mapLayer ( cfg.value ( " Layer" ).toString () ) );
30673087 if ( !layer )
30683088 {
3069- return attributeVal;
3089+ return QString ( " (%1) " ). arg ( attributeVal ) ;
30703090 }
30713091
30723092 QString outputString;
3073- if ( cfg.value ( " AllowMulti" ).toBool () )
3093+ QString valueString = attributeVal;
3094+ QStringList valueList = cfg.value ( " AllowMulti" ).toBool ()
3095+ ? valueString.remove ( QChar ( ' {' ) ).remove ( QChar ( ' }' ) ).split ( " ," )
3096+ : QStringList ( valueString );
3097+ for ( int i = 0 ; i < valueList.size (); ++i )
30743098 {
3075- QString valueString = attributeVal;
3076- QStringList valueList = valueString.remove ( QChar ( ' {' ) ).remove ( QChar ( ' }' ) ).split ( " ," );
3077- for ( int i = 0 ; i < valueList.size (); ++i )
3099+ if ( i > 0 )
30783100 {
3079- if ( i > 0 )
3080- {
3081- outputString += " ;" ;
3082- }
3083- outputString += relationValue (
3084- valueList.at ( i ),
3085- layer,
3086- cfg.value ( " Key" ).toString (),
3087- cfg.value ( " Value" ).toString ()
3088- );
3101+ outputString += " ;" ;
30893102 }
3103+ outputString += relationValue (
3104+ valueList.at ( i ),
3105+ layer,
3106+ cfg.value ( " Key" ).toString (),
3107+ cfg.value ( " Value" ).toString ()
3108+ );
30903109 }
30913110 return outputString;
30923111 }
3112+
30933113 return attributeVal;
30943114}
30953115
0 commit comments