Skip to content

Commit

Permalink
Set correct field to display
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 17, 2019
1 parent 6fd3366 commit 541fc23
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/core/layout/qgslayoutgeopdfexporter.cpp
Expand Up @@ -20,6 +20,7 @@
#include "qgslayout.h"
#include "qgslogger.h"
#include "qgsgeometry.h"
#include "qgsvectorlayer.h"
#include "qgsvectorfilewriter.h"

#include <gdal.h>
Expand Down Expand Up @@ -199,6 +200,10 @@ bool QgsLayoutGeoPdfExporter::saveTemporaryLayers()
detail.name = layer ? layer->name() : it.key();
detail.mapLayerId = it.key();
detail.sourceVectorPath = filePath;
if ( const QgsVectorLayer *vl = qobject_cast< const QgsVectorLayer * >( layer ) )
{
detail.displayAttribute = vl->displayField();
}

// write out features to disk
const QgsFeatureList features = it.value();
Expand Down Expand Up @@ -375,7 +380,8 @@ QString QgsLayoutGeoPdfExporter::createCompositionXml( const QList<ComponentLaye
vectorDataset.setAttribute( QStringLiteral( "visible" ), QStringLiteral( "false" ) );
QDomElement logicalStructure = doc.createElement( QStringLiteral( "LogicalStructure" ) );
logicalStructure.setAttribute( QStringLiteral( "displayLayerName" ), component.name );
//logicalStructure.setAttribute( QStringLiteral( "fieldToDisplay" ), it.key() ); // TODO
if ( !component.displayAttribute.isEmpty() )
logicalStructure.setAttribute( QStringLiteral( "fieldToDisplay" ), component.displayAttribute );
vectorDataset.appendChild( logicalStructure );
ifLayerOn.appendChild( vectorDataset );
content.appendChild( ifLayerOn );
Expand Down
3 changes: 3 additions & 0 deletions src/core/layout/qgslayoutgeopdfexporter.h
Expand Up @@ -139,6 +139,9 @@ class CORE_EXPORT QgsLayoutGeoPdfExporter
//! Associated map layer ID
QString mapLayerId;

//! Field name for display
QString displayAttribute;

//! File path to the (already created) vector dataset to use as the source for this component layer
QString sourceVectorPath;

Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgslayoutgeopdfexport.cpp
Expand Up @@ -83,6 +83,7 @@ void TestQgsLayoutGeoPdfExport::testCollectingFeatures()
QgsVectorLayer *pointsLayer = new QgsVectorLayer( TEST_DATA_DIR + QStringLiteral( "/points.shp" ),
QStringLiteral( "points" ), QStringLiteral( "ogr" ) );
QVERIFY( pointsLayer->isValid() );
pointsLayer->setDisplayExpression( QStringLiteral( "Staff" ) );

QgsProject p;
p.addMapLayer( linesLayer );
Expand Down

0 comments on commit 541fc23

Please sign in to comment.