24 #include <QDomElement>    37   for ( 
int i = 0; i < legendChildren.
size(); ++i )
    40     if ( currentChildElem.
tagName() == 
"legendlayer" )
    44     else if ( currentChildElem.
tagName() == 
"legendgroup" )
    59   for ( 
int i = 0; i < legendChildren.
size(); ++i )
    62     if ( currentChildElem.
tagName() == 
"legendlayer" )
    66       int layerIndex = currentChildElem.
attribute( 
"drawingOrder" ).
toInt();
    67       if ( layerIndex == -1 )
    69       layerIndexes.
insert( layerIndex, layerFileElem.
attribute( 
"layerid" ) );
    71     else if ( currentChildElem.
tagName() == 
"legendgroup" )
    87   hasCustomOrder = legendElem.
attribute( 
"updateDrawingOrder" ) == 
"false";
    95   if ( !res && hasCustomOrder )
    98   Q_FOREACH ( 
const QString& layerId, layerIndexes )
   110   int drawingOrder = -1;
   111   if ( hasCustomOrder )
   175   legendElem.
setAttribute( 
"updateDrawingOrder", hasCustomOrder ? 
"false" : 
"true" );
   188       return "Qt::Unchecked";
   189     case Qt::PartiallyChecked:
   190       return "Qt::PartiallyChecked";
   193       return "Qt::Checked";
   199   if ( txt == 
"Qt::Unchecked" )
   200     return Qt::Unchecked;
   201   else if ( txt == 
"Qt::PartiallyChecked" )
   202     return Qt::PartiallyChecked;
   218   if ( groupElem.
attribute( 
"embedded" ) == 
"1" )
   224   for ( 
int i = 0; i < groupChildren.
size(); ++i )
   227     if ( currentChildElem.
tagName() == 
"legendlayer" )
   231     else if ( currentChildElem.
tagName() == 
"legendgroup" )
   249   if ( layerFileElem.
attribute( 
"isInOverview" ) == 
"1" )
   252   if ( layerElem.
attribute( 
"embedded" ) == 
"1" )
   255   if ( layerElem.
attribute( 
"showFeatureCount" ) == 
"1" )
   303         nodesToRemove << node;
   390     if ( exprEnabled && !expr.
isEmpty() )
 static QDomElement _writeOldLegendLayer(QDomDocument &doc, QgsLayerTreeLayer *nodeLayer, bool hasCustomOrder, const QStringList &order)
 
static bool readOldLegendLayerOrder(const QDomElement &legendElem, bool &hasCustomOrder, QStringList &order)
Try to load custom layer order from. 
 
Layer tree group node serves as a container for layers and further groups. 
 
static bool layersEditable(const QList< QgsLayerTreeLayer *> &layerNodes)
Return true if any of the layers is editable. 
 
static void _writeOldLegendGroupChildren(QDomDocument &doc, QDomElement &groupElem, QgsLayerTreeGroup *nodeGroup, bool hasCustomOrder, const QStringList &order)
 
Base class for all map layer types. 
 
static void removeInvalidLayers(QgsLayerTreeGroup *group)
Remove layer nodes that refer to invalid layers. 
 
static QString checkStateToXml(Qt::CheckState state)
Convert Qt::CheckState to QString. 
 
QDomNode appendChild(const QDomNode &newChild)
 
QString attribute(const QString &name, const QString &defValue) const
 
void removeAllChildren()
Remove all child nodes. The nodes will be deleted. 
 
NodeType nodeType()
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree...
 
Qt::CheckState isVisible() const
 
static bool readOldLegend(QgsLayerTreeGroup *root, const QDomElement &legendElem)
Try to load layer tree from. 
 
static bool layersModified(const QList< QgsLayerTreeLayer *> &layerNodes)
Return true if any of the layers is modified. 
 
void removeChildNode(QgsLayerTreeNode *node)
Remove a child node from this group. The node will be deleted. 
 
bool isExpanded() const
Return whether the node should be shown as expanded or collapsed in GUI. 
 
QDomNodeList childNodes() const
 
virtual bool isEditable() const override
Returns true if the provider is in editing mode. 
 
QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group. No type checking is done - use isGroup() to find out whether this operation is ...
 
QDomElement toElement() const
 
void append(const T &value)
 
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry. 
 
int toInt(bool *ok) const
 
static void _readOldLegendLayer(const QDomElement &layerElem, QgsLayerTreeGroup *parent)
 
void setAttribute(const QString &name, const QString &value)
 
QgsLayerTreeLayer * insertLayer(int index, QgsMapLayer *layer)
Insert a new layer node for given map layer at specified position. Newly created node is owned by thi...
 
int toInt(bool *ok, int base) const
 
static QDomElement _writeOldLegendGroup(QDomDocument &doc, QgsLayerTreeGroup *nodeGroup, bool hasCustomOrder, const QStringList &order)
 
QgsLayerTreeNode * parent()
Get pointer to the parent. If parent is a null pointer, the node is a root node. 
 
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer. 
 
static QDomElement writeOldLegend(QDomDocument &doc, QgsLayerTreeGroup *root, bool hasCustomOrder, const QStringList &order)
Return. 
 
static void replaceChildrenOfEmbeddedGroups(QgsLayerTreeGroup *group)
Remove subtree of embedded groups and replaces it with a custom property embedded-visible-layers. 
 
static void _readOldLegendGroup(const QDomElement &groupElem, QgsLayerTreeGroup *parent)
 
This class is a base class for nodes in a layer tree. 
 
static Qt::CheckState checkStateFromXml(const QString &txt)
Convert QString to Qt::CheckState. 
 
static void updateEmbeddedGroupsProjectPath(QgsLayerTreeGroup *group)
 
void setVisible(Qt::CheckState visible)
 
QList< QgsLayerTreeNode * > children()
Get list of children of the node. Children are owned by the parent. 
 
static bool hasLegendFilterExpression(const QgsLayerTreeGroup &group)
Test if one of the layers in a group has an expression filter. 
 
bool isLayer(QgsLayerTreeNode *node)
Check whether the node is a valid layer node. 
 
void setExpanded(bool expanded)
Set whether the node should be shown as expanded or collapsed in GUI. 
 
QgsLayerTreeLayer * findLayer(const QString &layerId) const
Find layer node representing the map layer specified by its ID. Searches recursively the whole sub-tr...
 
QgsMapLayer * layer() const
 
leaf node pointing to a layer 
 
static QgsLayerTreeLayer * insertLayerBelow(QgsLayerTreeGroup *group, const QgsMapLayer *refLayer, QgsMapLayer *layerToInsert)
Insert a QgsMapLayer just below another one. 
 
static void setLegendFilterByExpression(QgsLayerTreeLayer &layer, const QString &expr, bool enabled=true)
Set the expression filter of a legend layer. 
 
QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer. No type checking is done - use isLayer() to find out whether this operation is ...
 
static QgsProject * instance()
Returns the QgsProject singleton instance. 
 
QDomElement firstChildElement(const QString &tagName) const
 
virtual bool isModified() const
Returns true if the provider has been modified since the last commit. 
 
void addChildNode(QgsLayerTreeNode *node)
Append an existing node. The node must not have a parent yet. The node will be owned by this group...
 
Qt::CheckState isVisible() const
Return the check state of the group node. 
 
static bool _readOldLegendLayerOrderGroup(const QDomElement &groupElem, QMap< int, QString > &layerIndexes)
 
QString layerName() const
 
int indexOf(const QRegExp &rx, int from) const
 
iterator insert(const Key &key, const T &value)
 
QString name() const override
Get group's name. 
 
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes. Searches recursively the whole sub-tree. 
 
QDomElement createElement(const QString &tagName)
 
Represents a vector layer which manages a vector based data sets. 
 
static QStringList invisibleLayerList(QgsLayerTreeNode *node)
get invisible layers 
 
void setVisible(Qt::CheckState state)
Set check state of the group node - will also update children. 
 
bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node. 
 
static QString legendFilterByExpression(const QgsLayerTreeLayer &layer, bool *enabled=nullptr)
Return the expression filter of a legend layer. 
 
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the node. 
 
Layer tree node points to a map layer. 
 
QDomNode at(int index) const
 
QString writePath(const QString &filename, const QString &relativeBasePath=QString()) const
Prepare a filename to save it to the project file.