static void _readOldLegendGroup( const QDomElement &groupElem, QgsLayerTreeGroup *parent ) { QDomNodeList groupChildren = groupElem.childNodes(); QgsLayerTreeGroup *groupNode = new QgsLayerTreeGroup( groupElem.attribute( QStringLiteral( "name" ) ) ); groupNode->setItemVisibilityChecked( QgsLayerTreeUtils::checkStateFromXml( groupElem.attribute( QStringLiteral( "checked" ) ) ) != Qt::Unchecked ); groupNode->setExpanded( groupElem.attribute( QStringLiteral( "open" ) ) == QLatin1String( "true" ) ); if ( groupElem.attribute( QStringLiteral( "embedded" ) ) == QLatin1String( "1" ) ) { groupNode->setCustomProperty( QStringLiteral( "embedded" ), 1 ); groupNode->setCustomProperty( QStringLiteral( "embedded_project" ), groupElem.attribute( QStringLiteral( "project" ) ) ); } for ( int i = 0; i < groupChildren.size(); ++i ) { QDomElement currentChildElem = groupChildren.at( i ).toElement(); if ( currentChildElem.tagName() == QLatin1String( "legendlayer" ) ) { _readOldLegendLayer( currentChildElem, groupNode ); } else if ( currentChildElem.tagName() == QLatin1String( "legendgroup" ) ) { _readOldLegendGroup( currentChildElem, groupNode ); } } parent->addChildNode( groupNode ); }
bool QgsLayerTreeUtils::readOldLegend( QgsLayerTreeGroup* root, const QDomElement& legendElem ) { if ( legendElem.isNull() ) return false; QDomNodeList legendChildren = legendElem.childNodes(); for ( int i = 0; i < legendChildren.size(); ++i ) { QDomElement currentChildElem = legendChildren.at( i ).toElement(); if ( currentChildElem.tagName() == "legendlayer" ) { _readOldLegendLayer( currentChildElem, root ); } else if ( currentChildElem.tagName() == "legendgroup" ) { _readOldLegendGroup( currentChildElem, root ); } } return true; }