|
45 | 45 | #include "qgspaintenginehack.h"
|
46 | 46 | #include "qgsogcutils.h"
|
47 | 47 | #include "qgsfeature.h"
|
| 48 | +#include "qgseditorwidgetregistry.h" |
48 | 49 |
|
49 | 50 | #include <QImage>
|
50 | 51 | #include <QPainter>
|
@@ -2094,16 +2095,12 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
|
2094 | 2095 |
|
2095 | 2096 | QDomElement attributeElement = infoDocument.createElement( "Attribute" );
|
2096 | 2097 | attributeElement.setAttribute( "name", attributeName );
|
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 |
| - |
2106 |
| - attributeElement.setAttribute( "value", value ); |
| 2098 | + attributeElement.setAttribute( "value", |
| 2099 | + replaceValueMapAndRelation( |
| 2100 | + layer, i, |
| 2101 | + QgsExpression::replaceExpressionText( featureAttributes[i].toString(), &feature, layer ) |
| 2102 | + ) |
| 2103 | + ); |
2107 | 2104 | featureElement.appendChild( attributeElement );
|
2108 | 2105 | }
|
2109 | 2106 |
|
@@ -3051,82 +3048,18 @@ QDomElement QgsWMSServer::createFeatureGML(
|
3051 | 3048 |
|
3052 | 3049 | QString QgsWMSServer::replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, const QString& attributeVal )
|
3053 | 3050 | {
|
3054 |
| - if ( !vl ) |
3055 |
| - { |
3056 |
| - return attributeVal; |
3057 |
| - } |
3058 |
| - |
3059 |
| - QString type = vl->editorWidgetV2( idx ); |
3060 |
| - if ( type == "ValueMap" ) |
| 3051 | + if ( QgsEditorWidgetFactory *factory = QgsEditorWidgetRegistry::instance()->factory( vl->editorWidgetV2( idx ) ) ) |
3061 | 3052 | {
|
3062 | 3053 | QgsEditorWidgetConfig cfg( vl->editorWidgetV2Config( idx ) );
|
3063 |
| - QMap<QString, QVariant>::const_iterator vmapIt = cfg.constBegin(); |
3064 |
| - for ( ; vmapIt != cfg.constEnd(); ++vmapIt ) |
| 3054 | + QString value( factory->representValue( vl, idx, cfg, QVariant(), attributeVal ) ); |
| 3055 | + if ( cfg.value( "AllowMulti" ).toBool() && value.startsWith( "{" ) && value.endsWith( "}" ) ) |
3065 | 3056 | {
|
3066 |
| - if ( vmapIt.key() == attributeVal ) |
3067 |
| - { |
3068 |
| - return vmapIt.value().toString(); |
3069 |
| - } |
| 3057 | + value = value.mid( 1, value.size() - 2 ); |
3070 | 3058 | }
|
3071 |
| - return QString( "(%1)" ).arg( attributeVal ); |
| 3059 | + return value; |
3072 | 3060 | }
|
3073 |
| - else if ( type == "ValueRelation" ) |
3074 |
| - { |
3075 |
| - QgsEditorWidgetConfig cfg( vl->editorWidgetV2Config( idx ) ); |
3076 |
| - QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( cfg.value( "Layer" ).toString() ) ); |
3077 |
| - if ( !layer ) |
3078 |
| - { |
3079 |
| - return QString( "(%1)" ).arg( attributeVal ); |
3080 |
| - } |
3081 |
| - |
3082 |
| - QString outputString; |
3083 |
| - QString valueString = attributeVal; |
3084 |
| - QStringList valueList = cfg.value( "AllowMulti" ).toBool() |
3085 |
| - ? valueString.remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( "," ) |
3086 |
| - : QStringList( valueString ); |
3087 |
| - for ( int i = 0; i < valueList.size(); ++i ) |
3088 |
| - { |
3089 |
| - if ( i > 0 ) |
3090 |
| - { |
3091 |
| - outputString += ";"; |
3092 |
| - } |
3093 |
| - outputString += relationValue( |
3094 |
| - valueList.at( i ), |
3095 |
| - layer, |
3096 |
| - cfg.value( "Key" ).toString(), |
3097 |
| - cfg.value( "Value" ).toString() |
3098 |
| - ); |
3099 |
| - } |
3100 |
| - return outputString; |
3101 |
| - } |
3102 |
| - |
3103 |
| - return attributeVal; |
3104 |
| -} |
3105 |
| - |
3106 |
| -QString QgsWMSServer::relationValue( const QString& attributeVal, QgsVectorLayer* layer, const QString& key, const QString& value ) |
3107 |
| -{ |
3108 |
| - if ( !layer ) |
3109 |
| - { |
3110 |
| - return attributeVal; |
3111 |
| - } |
3112 |
| - |
3113 |
| - int keyId = layer->fieldNameIndex( key ); |
3114 |
| - int valueId = layer->fieldNameIndex( value ); |
3115 |
| - if ( keyId == -1 || valueId == -1 ) |
3116 |
| - { |
3117 |
| - return attributeVal; |
3118 |
| - } |
3119 |
| - |
3120 |
| - QgsFeatureIterator fIt = layer->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( QgsAttributeList() << keyId << valueId ) ); |
3121 |
| - QgsFeature f; |
3122 |
| - while ( fIt.nextFeature( f ) ) |
3123 |
| - { |
3124 |
| - if ( f.attribute( key ).toString() == attributeVal ) |
3125 |
| - { |
3126 |
| - return f.attribute( value ).toString(); |
3127 |
| - } |
3128 |
| - } |
3129 |
| - return attributeVal; |
| 3061 | + else |
| 3062 | + return QString( "(%1)" ).arg( attributeVal ); |
3130 | 3063 | }
|
3131 | 3064 |
|
3132 | 3065 | int QgsWMSServer::getImageQuality() const
|
|
0 commit comments