Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update another method
  • Loading branch information
pblottiere committed May 13, 2020
1 parent 6550dad commit 2cbf4a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/core/qgslegendrenderer.cpp
Expand Up @@ -76,13 +76,14 @@ QJsonObject QgsLegendRenderer::exportLegendToJson( const QgsRenderContext &conte
if ( !rootGroup )
return json;

json = exportLegendToJson( context, rootGroup );
json[QStringLiteral( "title" )] = mSettings.title();
exportLegendToJson( context, rootGroup, json );
return json;
}

void QgsLegendRenderer::exportLegendToJson( const QgsRenderContext &context, QgsLayerTreeGroup *nodeGroup, QJsonObject &json )
QJsonObject QgsLegendRenderer::exportLegendToJson( const QgsRenderContext &context, QgsLayerTreeGroup *nodeGroup )
{
QJsonObject json;
QJsonArray nodes;
const QList<QgsLayerTreeNode *> childNodes = nodeGroup->children();
for ( QgsLayerTreeNode *node : childNodes )
Expand All @@ -93,10 +94,9 @@ void QgsLegendRenderer::exportLegendToJson( const QgsRenderContext &context, Qgs
const QModelIndex idx = mLegendModel->node2index( nodeGroup );
const QString text = mLegendModel->data( idx, Qt::DisplayRole ).toString();

QJsonObject group;
QJsonObject group = exportLegendToJson( context, nodeGroup );
group[ QStringLiteral( "type" ) ] = QStringLiteral( "group" );
group[ QStringLiteral( "title" ) ] = text;
exportLegendToJson( context, nodeGroup, group );
nodes.append( group );
}
else if ( QgsLayerTree::isLayer( node ) )
Expand Down Expand Up @@ -141,6 +141,7 @@ void QgsLegendRenderer::exportLegendToJson( const QgsRenderContext &context, Qgs
}

json[QStringLiteral( "nodes" )] = nodes;
return json;
}

QSizeF QgsLegendRenderer::paintAndDetermineSize( QgsRenderContext &context )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgslegendrenderer.h
Expand Up @@ -234,7 +234,7 @@ class CORE_EXPORT QgsLegendRenderer
*
* \since QGIS 3.8
*/
void exportLegendToJson( const QgsRenderContext &context, QgsLayerTreeGroup *nodeGroup, QJsonObject &json );
QJsonObject exportLegendToJson( const QgsRenderContext &context, QgsLayerTreeGroup *nodeGroup );

/**
* Draws the legend using the specified render \a context, and returns the actual size of the legend.
Expand Down

0 comments on commit 2cbf4a1

Please sign in to comment.