Skip to content
Permalink
Browse files
[layertree] Add docs to QgsLayerTreeUtils
  • Loading branch information
wonder-sk committed May 27, 2014
1 parent 2df8f8c commit b41944ff2a559709b557acd1baddb90a30bc83df
Showing with 17 additions and 12 deletions.
  1. +11 −8 src/core/layertree/qgslayertreeutils.cpp
  2. +6 −4 src/core/layertree/qgslayertreeutils.h
@@ -21,6 +21,9 @@

#include <QDomElement>

static void _readOldLegendGroup( const QDomElement& groupElem, QgsLayerTreeGroup* parent );
static void _readOldLegendLayer( const QDomElement& layerElem, QgsLayerTreeGroup* parent );

bool QgsLayerTreeUtils::readOldLegend( QgsLayerTreeGroup* root, const QDomElement& legendElem )
{
if ( legendElem.isNull() )
@@ -33,11 +36,11 @@ bool QgsLayerTreeUtils::readOldLegend( QgsLayerTreeGroup* root, const QDomElemen
QDomElement currentChildElem = legendChildren.at( i ).toElement();
if ( currentChildElem.tagName() == "legendlayer" )
{
addLegendLayerToTreeWidget( currentChildElem, root );
_readOldLegendLayer( currentChildElem, root );
}
else if ( currentChildElem.tagName() == "legendgroup" )
{
addLegendGroupToTreeWidget( currentChildElem, root );
_readOldLegendGroup( currentChildElem, root );
}
}

@@ -196,14 +199,14 @@ Qt::CheckState QgsLayerTreeUtils::checkStateFromXml( QString txt )



void QgsLayerTreeUtils::addLegendGroupToTreeWidget( const QDomElement& groupElem, QgsLayerTreeGroup* parent )
static void _readOldLegendGroup( const QDomElement& groupElem, QgsLayerTreeGroup* parent )
{
QDomNodeList groupChildren = groupElem.childNodes();

QgsLayerTreeGroup* groupNode = new QgsLayerTreeGroup( groupElem.attribute( "name" ) );
parent->addChildNode( groupNode );

groupNode->setVisible( checkStateFromXml( groupElem.attribute( "checked" ) ) );
groupNode->setVisible( QgsLayerTreeUtils::checkStateFromXml( groupElem.attribute( "checked" ) ) );
groupNode->setExpanded( groupElem.attribute( "open" ) == "true" );

if ( groupElem.attribute( "embedded" ) == "1" )
@@ -217,22 +220,22 @@ void QgsLayerTreeUtils::addLegendGroupToTreeWidget( const QDomElement& groupElem
QDomElement currentChildElem = groupChildren.at( i ).toElement();
if ( currentChildElem.tagName() == "legendlayer" )
{
addLegendLayerToTreeWidget( currentChildElem, groupNode );
_readOldLegendLayer( currentChildElem, groupNode );
}
else if ( currentChildElem.tagName() == "legendgroup" )
{
addLegendGroupToTreeWidget( currentChildElem, groupNode );
_readOldLegendGroup( currentChildElem, groupNode );
}
}
}

void QgsLayerTreeUtils::addLegendLayerToTreeWidget( const QDomElement& layerElem, QgsLayerTreeGroup* parent )
static void _readOldLegendLayer( const QDomElement& layerElem, QgsLayerTreeGroup* parent )
{
QDomElement layerFileElem = layerElem.firstChildElement( "filegroup" ).firstChildElement( "legendlayerfile" );
QString layerId = layerFileElem.attribute( "layerid" );
QgsLayerTreeLayer* layerNode = new QgsLayerTreeLayer( layerId, layerElem.attribute( "name" ) );

layerNode->setVisible( checkStateFromXml( layerElem.attribute( "checked" ) ) );
layerNode->setVisible( QgsLayerTreeUtils::checkStateFromXml( layerElem.attribute( "checked" ) ) );
layerNode->setExpanded( layerElem.attribute( "open" ) == "true" );

if ( layerFileElem.attribute( "isInOverview" ) == "1" )
@@ -42,20 +42,22 @@ class CORE_EXPORT QgsLayerTreeUtils
//! Return <legend> tag used in QGIS 2.2 and below
static QDomElement writeOldLegend( QDomDocument& doc, QgsLayerTreeGroup* root, bool hasCustomOrder, const QStringList& order );

//! Convert Qt::CheckState to QString
static QString checkStateToXml( Qt::CheckState state );
//! Convert QString to Qt::CheckState
static Qt::CheckState checkStateFromXml( QString txt );

//! Return true if any of the layers is editable
static bool layersEditable( const QList<QgsLayerTreeLayer*>& layerNodes );
//! Return true if any of the layers is modified
static bool layersModified( const QList<QgsLayerTreeLayer*>& layerNodes );

//! Remove layer nodes that refer to invalid layers
static void removeInvalidLayers( QgsLayerTreeGroup* group );

//! Remove subtree of embedded groups. Useful when saving layer tree
static void removeChildrenOfEmbeddedGroups( QgsLayerTreeGroup* group );

protected:
static void addLegendGroupToTreeWidget( const QDomElement& groupElem, QgsLayerTreeGroup* parent );
static void addLegendLayerToTreeWidget( const QDomElement& layerElem, QgsLayerTreeGroup* parent );

};

#endif // QGSLAYERTREEUTILS_H

0 comments on commit b41944f

Please sign in to comment.