Update another method

This commit is contained in:
Blottiere Paul 2020-05-11 11:32:45 +02:00
parent 6550dad449
commit 2cbf4a12ea
2 changed files with 6 additions and 5 deletions

View File

@ -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 )
@ -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 ) )
@ -141,6 +141,7 @@ void QgsLegendRenderer::exportLegendToJson( const QgsRenderContext &context, Qgs
}
json[QStringLiteral( "nodes" )] = nodes;
return json;
}
QSizeF QgsLegendRenderer::paintAndDetermineSize( QgsRenderContext &context )

View File

@ -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.