Skip to content

Commit

Permalink
Export aliases is an option
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Jan 28, 2019
1 parent 3b45286 commit eee940d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/core/qgsjsonutils.cpp
Expand Up @@ -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;
}
Expand Down
16 changes: 16 additions & 0 deletions src/core/qgsjsonutils.h
Expand Up @@ -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.
Expand Down Expand Up @@ -239,6 +253,8 @@ class CORE_EXPORT QgsJsonExporter
QgsCoordinateTransform mTransform;

bool mIncludeName = false;

bool mAttributeDisplayName = false;
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -2337,6 +2337,7 @@ namespace QgsWms

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

0 comments on commit eee940d

Please sign in to comment.