Skip to content
Permalink
Browse files

Update api of exportToJson

  • Loading branch information
pblottiere committed May 11, 2020
1 parent 2cbf4a1 commit 236db3903b139e3460eb5334f10eaa0948dd17c2
@@ -84,10 +84,12 @@ QgsLayerTreeModelLegendNode::ItemMetrics QgsLayerTreeModelLegendNode::draw( cons
return im;
}

void QgsLayerTreeModelLegendNode::exportToJson( const QgsLegendSettings &settings, const QgsRenderContext &context, QJsonObject &json )
QJsonObject QgsLayerTreeModelLegendNode::exportToJson( const QgsLegendSettings &settings, const QgsRenderContext &context )
{
QJsonObject json;
exportSymbolToJson( settings, context, json );
exportSymbolTextToJson( settings, json );
return json;
}

QSizeF QgsLayerTreeModelLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight ) const
@@ -223,7 +223,7 @@ class CORE_EXPORT QgsLayerTreeModelLegendNode : public QObject
* \param json The json object to update
* \since QGIS 3.8
*/
void exportToJson( const QgsLegendSettings &settings, const QgsRenderContext &context, QJsonObject &json );
QJsonObject exportToJson( const QgsLegendSettings &settings, const QgsRenderContext &context );

/**
* Draws symbol on the left side of the item
@@ -101,9 +101,6 @@ QJsonObject QgsLegendRenderer::exportLegendToJson( const QgsRenderContext &conte
}
else if ( QgsLayerTree::isLayer( node ) )
{
QJsonObject group;
group[ QStringLiteral( "type" ) ] = QStringLiteral( "layer" );

QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );

QString text;
@@ -120,21 +117,25 @@ QJsonObject QgsLegendRenderer::exportLegendToJson( const QgsRenderContext &conte

if ( legendNodes.count() == 1 )
{
legendNodes.at( 0 )->exportToJson( mSettings, context, group );
QJsonObject group = legendNodes.at( 0 )->exportToJson( mSettings, context );
group[ QStringLiteral( "type" ) ] = QStringLiteral( "layer" );
nodes.append( group );
}
else if ( legendNodes.count() > 1 )
{
QJsonObject group;
group[ QStringLiteral( "type" ) ] = QStringLiteral( "layer" );
group[ QStringLiteral( "title" ) ] = text;

QJsonArray symbols;
for ( int j = 0; j < legendNodes.count(); j++ )
{
QgsLayerTreeModelLegendNode *legendNode = legendNodes.at( j );
QJsonObject symbol;
legendNode->exportToJson( mSettings, context, symbol );
QJsonObject symbol = legendNode->exportToJson( mSettings, context );
symbols.append( symbol );
}
group[ QStringLiteral( "title" ) ] = text;
group[ QStringLiteral( "symbols" ) ] = symbols;

nodes.append( group );
}
}

0 comments on commit 236db39

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