23 #include <QDomElement> 24 #include <QStringList> 31 , mChangingChildVisibility( false )
32 , mMutuallyExclusive( false )
33 , mMutuallyExclusiveChildIndex( -1 )
154 if ( childLayer->
layer() == layer )
211 if ( childLayer->
layerId() == layerId )
259 if ( element.
tagName() !=
"layer-tree-group" )
266 int mutuallyExclusiveChildIndex = element.
attribute(
"mutually-exclusive-child",
"-1" ).
toInt();
305 while ( !childElem.
isNull() )
322 childrenDump << node->
dump().
split(
'\n' );
323 for (
int i = 0; i < childrenDump.
count(); ++i )
324 childrenDump[i].prepend(
" " );
325 return header + childrenDump.
join(
"\n" );
343 if ( mMutuallyExclusiveChildIndex < 0 || mMutuallyExclusiveChildIndex >=
mChildren.
count() )
372 Qt::CheckState state;
380 return state == Qt::Checked || state == Qt::PartiallyChecked;
400 if ( mMutuallyExclusiveChildIndex < 0 || mMutuallyExclusiveChildIndex >=
mChildren.
count() )
442 if ( childIndex == -1 )
476 if ( mMutuallyExclusiveChildIndex < 0 || mMutuallyExclusiveChildIndex >=
mChildren.
count() )
485 bool hasVisible =
false, hasHidden =
false;
492 if ( layerVisible ) hasVisible =
true;
493 if ( !layerVisible ) hasHidden =
true;
498 if ( state == Qt::Checked || state == Qt::PartiallyChecked ) hasVisible =
true;
499 if ( state == Qt::Unchecked || state == Qt::PartiallyChecked ) hasHidden =
true;
503 Qt::CheckState newState;
504 if ( hasVisible && !hasHidden )
505 newState = Qt::Checked;
506 else if ( hasHidden && !hasVisible )
507 newState = Qt::Unchecked;
509 newState = Qt::PartiallyChecked;
void nodeVisibilityChanged(QgsLayerTreeNode *node)
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
Layer tree group node serves as a container for layers and further groups.
void removeChildren(int from, int count)
Remove child nodes from index "from". The nodes will be deleted.
void removeChildrenGroupWithoutLayers()
Remove all child group nodes without layers. The groupnodes will be deleted.
Base class for all map layer types.
QgsLayerTreeGroup * addGroup(const QString &name)
Append a new group node with given name. Newly created node is owned by this group.
static QgsLayerTreeGroup * readXML(QDomElement &element, bool looseMatch=false)
Read group (tree) from XML element <layer-tree-group> and return the newly created group (or null on ...
static QString checkStateToXml(Qt::CheckState state)
Convert Qt::CheckState to QString.
void setIsMutuallyExclusive(bool enabled, int initialChildIndex=-1)
Set whether the group is mutually exclusive (only one child can be checked at a time).
QDomNode appendChild(const QDomNode &newChild)
void insertChildrenPrivate(int index, QList< QgsLayerTreeNode *> nodes)
Low-level insertion of children to the node. The children must not have any parent yet! ...
QString attribute(const QString &name, const QString &defValue) const
void removeAllChildren()
Remove all child nodes. The nodes will be deleted.
bool mExpanded
whether the node should be shown in GUI as expanded
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
const T & at(int i) const
NodeType nodeType()
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree...
Qt::CheckState isVisible() const
virtual QString dump() const =0
Return string with layer tree structure. For debug purposes only.
QDomElement nextSiblingElement(const QString &tagName) const
void readCommonXML(QDomElement &element)
void removeChildNode(QgsLayerTreeNode *node)
Remove a child node from this group. The node will be deleted.
QString join(const QString &separator) const
bool isExpanded() const
Return whether the node should be shown as expanded or collapsed in GUI.
bool isMutuallyExclusive() const
Return whether the group is mutually exclusive (only one child can be checked at a time) ...
virtual void writeXML(QDomElement &parentElement)=0
Write layer tree to XML.
void removeLayer(QgsMapLayer *layer)
Remove map layer's node from this group. The node will be deleted.
QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group. No type checking is done - use isGroup() to find out whether this operation is ...
QgsLayerTreeLayer * addLayer(QgsMapLayer *layer)
Append a new layer node for given map layer. Newly created node is owned by this group.
int indexOf(const T &value, int from) const
void visibilityChanged(QgsLayerTreeNode *node, Qt::CheckState state)
Emitted when check state of a node within the tree has been changed.
int count(const T &value) const
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
QDomDocument ownerDocument() const
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
bool mChangingChildVisibility
void setName(const QString &n) override
Set group's name.
This class is a base class for nodes in a layer tree.
static Qt::CheckState checkStateFromXml(const QString &txt)
Convert QString to Qt::CheckState.
void setVisible(Qt::CheckState visible)
void insertChildNodes(int index, const QList< QgsLayerTreeNode *> &nodes)
Insert existing nodes at specified position. The nodes must not have a parent yet. The nodes will be owned by this group.
int mMutuallyExclusiveChildIndex
Keeps track which child has been most recently selected (so if the whole group is unchecked and check...
QList< QgsLayerTreeNode * > mChildren
list of children - node is responsible for their deletion
void updateChildVisibility()
Set check state of children (when this group's check state changes) - if not mutually exclusive...
QList< QgsLayerTreeNode * > children()
Get list of children of the node. Children are owned by the parent.
bool isLayer(QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
virtual void writeXML(QDomElement &parentElement) override
Write group (tree) as XML element <layer-tree-group> and add it to the given parent element...
void setExpanded(bool expanded)
Set whether the node should be shown as expanded or collapsed in GUI.
void removeChildrenPrivate(int from, int count, bool destroy=true)
Low-level removal of children from the node.
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
void updateChildVisibilityMutuallyExclusive()
Set check state of children - if mutually exclusive.
static bool _nodeIsChecked(QgsLayerTreeNode *node)
virtual QString dump() const override
Return text representation of the tree. For debugging purposes only.
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
void writeCommonXML(QDomElement &element)
static QgsLayerTreeNode * readXML(QDomElement &element, bool looseMatch=false)
Read layer tree from XML.
void insertChildNode(int index, QgsLayerTreeNode *node)
Insert existing node at specified position. The node must not have a parent yet. The node will be own...
virtual QgsLayerTreeGroup * clone() const override
Return a clone of the group. The children are cloned too.
QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer. No type checking is done - use isLayer() to find out whether this operation is ...
QgsLayerTreeGroup * findGroup(const QString &name)
Find group node with specified name. Searches recursively the whole sub-tree.
bool mMutuallyExclusive
Whether the group is mutually exclusive (i.e. only one child can be checked at a time) ...
QDomElement firstChildElement(const QString &tagName) const
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.
QString name() const override
Get group's name.
QStringList findLayerIds() const
Find layer IDs used in all layer nodes. Searches recursively the whole sub-tree.
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes. Searches recursively the whole sub-tree.
QDomElement createElement(const QString &tagName)
void readChildrenFromXML(QDomElement &element, bool looseMatch=false)
Read children from XML and append them to the group.
container of other groups and layers
void updateVisibilityFromChildren()
Set check state of this group from its children.
void nameChanged(QgsLayerTreeNode *node, QString name)
Emitted when the name of the node is changed.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QgsLayerTreeGroup * insertGroup(int index, const QString &name)
Insert a new group node with given name at specified position. Newly created node is owned by this gr...
Layer tree node points to a map layer.
QgsLayerTreeGroup(const QString &name=QString(), Qt::CheckState checked=Qt::Checked)