23 #include <QDomElement>
24 #include <QStringList>
31 , mChangingChildVisibility( false )
32 , mMutuallyExclusive( false )
33 , mMutuallyExclusiveChildIndex( -1 )
40 , mName( other.mName )
41 , mChecked( other.mChecked )
42 , mChangingChildVisibility( false )
43 , mMutuallyExclusive( false )
44 , mMutuallyExclusiveChildIndex( -1 )
140 if ( childLayer->
layer() == layer )
197 if ( childLayer->
layerId() == layerId )
245 if ( element.
tagName() !=
"layer-tree-group" )
252 int mutuallyExclusiveChildIndex = element.
attribute(
"mutually-exclusive-child",
"-1" ).
toInt();
291 while ( !childElem.
isNull() )
308 childrenDump << node->
dump().
split(
"\n" );
309 for (
int i = 0; i < childrenDump.
count(); ++i )
310 childrenDump[i].prepend(
" " );
311 return header + childrenDump.
join(
"\n" );
329 if ( mMutuallyExclusiveChildIndex < 0 || mMutuallyExclusiveChildIndex >=
mChildren.
count() )
358 Qt::CheckState state;
366 return state == Qt::Checked || state == Qt::PartiallyChecked;
386 if ( mMutuallyExclusiveChildIndex < 0 || mMutuallyExclusiveChildIndex >=
mChildren.
count() )
428 if ( childIndex == -1 )
462 if ( mMutuallyExclusiveChildIndex < 0 || mMutuallyExclusiveChildIndex >=
mChildren.
count() )
471 bool hasVisible =
false, hasHidden =
false;
478 if ( layerVisible ) hasVisible =
true;
479 if ( !layerVisible ) hasHidden =
true;
484 if ( state == Qt::Checked || state == Qt::PartiallyChecked ) hasVisible =
true;
485 if ( state == Qt::Unchecked || state == Qt::PartiallyChecked ) hasHidden =
true;
489 Qt::CheckState newState;
490 if ( hasVisible && !hasHidden )
491 newState = Qt::Checked;
492 else if ( hasHidden && !hasVisible )
493 newState = Qt::Unchecked;
495 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.
void readChildrenFromXML(QDomElement &element)
Read children from XML and append them to the group.
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)
QString attribute(const QString &name, const QString &defValue) const
static QgsLayerTreeGroup * readXML(QDomElement &element)
Read group (tree) from XML element and return the newly created group (or null on ...
QgsMapLayer * layer() const
bool isMutuallyExclusive() const
Return whether the group is mutually exclusive (only one child can be checked at a time) ...
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
NodeType nodeType()
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree...
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
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
Qt::CheckState isVisible() 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
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...
void insertChildrenPrivate(int index, QList< QgsLayerTreeNode * > nodes)
Low-level insertion of children to the node. The children must not have any parent yet! ...
int toInt(bool *ok, int base) const
bool mChangingChildVisibility
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes. Searches recursively the whole sub-tree.
This class is a base class for nodes in a layer tree.
static Qt::CheckState checkStateFromXml(const QString &txt)
Convert QString to Qt::CheckState.
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
void setVisible(Qt::CheckState visible)
virtual QgsLayerTreeNode * clone() const override
Return a clone of the group. The children are cloned too.
static QgsLayerTreeNode * readXML(QDomElement &element)
Read layer tree from XML. Returns new instance.
bool isExpanded() const
Return whether the node should be shown as expanded or collapsed in GUI.
int mMutuallyExclusiveChildIndex
Keeps track which child has been most recently selected (so if the whole group is unchecked and check...
QString name() const
Get group's name.
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.
Qt::CheckState isVisible() const
Return the check state of the group node.
virtual void writeXML(QDomElement &parentElement) override
Write group (tree) as XML element and add it to the given parent element...
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.
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.
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)
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...
QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer. No type checking is done - use isLayer() to find out whether this operation is ...
QStringList findLayerIds() const
Find layer IDs used in all layer nodes. Searches recursively the whole sub-tree.
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...
QgsLayerTreeLayer * findLayer(const QString &layerId) const
Find layer node representing the map layer specified by its ID. Searches recursively the whole sub-tr...
QDomElement createElement(const QString &tagName)
container of other groups and layers
void updateVisibilityFromChildren()
Set check state of this group from its children.
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)