Skip to content
Permalink
Browse files

Export aliases is an option

  • Loading branch information
pblottiere committed Jan 21, 2019
1 parent 3b45286 commit eee940dc8f45af357c70a32ae70fdda5ee1b356e
Showing with 24 additions and 1 deletion.
  1. +7 −1 src/core/qgsjsonutils.cpp
  2. +16 −0 src/core/qgsjsonutils.h
  3. +1 −0 src/server/services/wms/qgswmsrenderer.cpp
@@ -145,7 +145,13 @@ QString QgsJsonExporter::exportFeature( const QgsFeature &feature, const QVarian
val = fieldFormatter->representValue( mLayer.data(), i, setup.config(), QVariant(), val );
}

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

properties += QStringLiteral( " \"%1\":%2" ).arg( name, QgsJsonUtils::encodeValue( val ) );

++attributeCounter;
}
@@ -118,6 +118,20 @@ class CORE_EXPORT QgsJsonExporter
*/
bool includeRelated() const { return mIncludeRelatedAttributes; }

/**
* Sets whether to print original names of attributes or aliases if
* defined.
* \since QGIS 3.6
*/
void setAttributeDisplayName( bool displayName ) { mAttributeDisplayName = displayName; };

/**
* Returns whether original names of attributes or aliases are printed.
* \since QGIS 3.6
*/

bool attributeDisplayName() const { return mAttributeDisplayName; }

/**
* Sets the associated vector layer (required for related attribute export). This will automatically
* update the sourceCrs() to match.
@@ -239,6 +253,8 @@ class CORE_EXPORT QgsJsonExporter
QgsCoordinateTransform mTransform;

bool mIncludeName = false;

bool mAttributeDisplayName = false;
};

/**
@@ -2337,6 +2337,7 @@ namespace QgsWms

// export
QgsJsonExporter exporter( vl );
exporter.setAttributeDisplayName( true );
exporter.setAttributes( attributes );
exporter.setIncludeGeometry( withGeometry );
exporter.setIncludeName( true );

0 comments on commit eee940d

Please sign in to comment.
You can’t perform that action at this time.