Skip to content

Commit eee940d

Browse files
committedJan 28, 2019
Export aliases is an option
1 parent 3b45286 commit eee940d

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed
 

‎src/core/qgsjsonutils.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,13 @@ QString QgsJsonExporter::exportFeature( const QgsFeature &feature, const QVarian
145145
val = fieldFormatter->representValue( mLayer.data(), i, setup.config(), QVariant(), val );
146146
}
147147

148-
properties += QStringLiteral( " \"%1\":%2" ).arg( mLayer->attributeDisplayName( i ), QgsJsonUtils::encodeValue( val ) );
148+
QString name = fields.at( i ).name();
149+
if ( mAttributeDisplayName )
150+
{
151+
name = mLayer->attributeDisplayName( i );
152+
}
153+
154+
properties += QStringLiteral( " \"%1\":%2" ).arg( name, QgsJsonUtils::encodeValue( val ) );
149155

150156
++attributeCounter;
151157
}

‎src/core/qgsjsonutils.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ class CORE_EXPORT QgsJsonExporter
118118
*/
119119
bool includeRelated() const { return mIncludeRelatedAttributes; }
120120

121+
/**
122+
* Sets whether to print original names of attributes or aliases if
123+
* defined.
124+
* \since QGIS 3.6
125+
*/
126+
void setAttributeDisplayName( bool displayName ) { mAttributeDisplayName = displayName; };
127+
128+
/**
129+
* Returns whether original names of attributes or aliases are printed.
130+
* \since QGIS 3.6
131+
*/
132+
133+
bool attributeDisplayName() const { return mAttributeDisplayName; }
134+
121135
/**
122136
* Sets the associated vector layer (required for related attribute export). This will automatically
123137
* update the sourceCrs() to match.
@@ -239,6 +253,8 @@ class CORE_EXPORT QgsJsonExporter
239253
QgsCoordinateTransform mTransform;
240254

241255
bool mIncludeName = false;
256+
257+
bool mAttributeDisplayName = false;
242258
};
243259

244260
/**

‎src/server/services/wms/qgswmsrenderer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,7 @@ namespace QgsWms
23372337

23382338
// export
23392339
QgsJsonExporter exporter( vl );
2340+
exporter.setAttributeDisplayName( true );
23402341
exporter.setAttributes( attributes );
23412342
exporter.setIncludeGeometry( withGeometry );
23422343
exporter.setIncludeName( true );

0 commit comments

Comments
 (0)
Please sign in to comment.