QGIS API Documentation
3.20.0-Odense (decaadbb31)
|
Layer tree node points to a map layer. More...
#include <qgslayertreelayer.h>
Public Types | |
enum | LegendNodesSplitBehavior { UseDefaultLegendSetting , AllowSplittingLegendNodesOverMultipleColumns , PreventSplittingLegendNodesOverMultipleColumns } |
Legend node column split behavior. More... | |
Public Types inherited from QgsLayerTreeNode | |
enum | NodeType { NodeGroup , NodeLayer } |
Enumeration of possible tree node types. More... | |
Signals | |
void | layerLoaded () |
Emitted when a previously unavailable layer got loaded. More... | |
void | layerWillBeUnloaded () |
Emitted when a previously available layer got unloaded (from layer registry). More... | |
Signals inherited from QgsLayerTreeNode | |
void | addedChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo) |
Emitted when one or more nodes have been added to a node within the tree. More... | |
void | customPropertyChanged (QgsLayerTreeNode *node, const QString &key) |
Emitted when a custom property of a node within the tree has been changed or removed. More... | |
void | expandedChanged (QgsLayerTreeNode *node, bool expanded) |
Emitted when the collapsed/expanded state of a node within the tree has been changed. More... | |
void | nameChanged (QgsLayerTreeNode *node, QString name) |
Emitted when the name of the node is changed. More... | |
void | removedChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo) |
Emitted when one or more nodes has been removed from a node within the tree. More... | |
void | visibilityChanged (QgsLayerTreeNode *node) |
Emitted when check state of a node within the tree has been changed. More... | |
void | willAddChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo) |
Emitted when one or more nodes will be added to a node within the tree. More... | |
void | willRemoveChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo) |
Emitted when one or more nodes will be removed from a node within the tree. More... | |
Public Member Functions | |
QgsLayerTreeLayer (const QgsLayerTreeLayer &other) | |
QgsLayerTreeLayer (const QString &layerId, const QString &name=QString(), const QString &source=QString(), const QString &provider=QString()) | |
Constructor for QgsLayerTreeLayer using weak references to layer ID, name, public source, and provider key. More... | |
QgsLayerTreeLayer (QgsMapLayer *layer) | |
QgsLayerTreeLayer * | clone () const override |
Create a copy of the node. Returns new instance. More... | |
QString | dump () const override |
Returns string with layer tree structure. For debug purposes only. More... | |
QString | labelExpression () const |
Returns the expression member of the LayerTreeNode. More... | |
QgsMapLayer * | layer () const |
Returns the map layer associated with this node. More... | |
QString | layerId () const |
Returns the ID for the map layer associated with this node. More... | |
LegendNodesSplitBehavior | legendSplitBehavior () const |
Returns the column split behavior for the node. More... | |
QString | name () const override |
Returns the layer's name. More... | |
QgsLegendPatchShape | patchShape () const |
Returns the symbol patch shape to use when rendering the legend node symbol. More... | |
QSizeF | patchSize () const |
Returns the user (overridden) size for the legend node. More... | |
void | resolveReferences (const QgsProject *project, bool looseMatching=false) override |
Resolves reference to layer from stored layer ID (if it has not been resolved already) More... | |
void | setLabelExpression (const QString &expression) |
set the expression to evaluate More... | |
void | setLegendSplitBehavior (LegendNodesSplitBehavior behavior) |
Sets the column split behavior for the node. More... | |
void | setName (const QString &n) override |
Sets the layer's name. More... | |
void | setPatchShape (const QgsLegendPatchShape &shape) |
Sets the symbol patch shape to use when rendering the legend node symbol. More... | |
void | setPatchSize (QSizeF size) |
Sets the user (overridden) size for the legend node. More... | |
void | setUseLayerName (bool use=true) |
Uses the layer's name if use is true , or the name manually set if false . More... | |
bool | useLayerName () const |
Returns whether the layer's name is used, or the name manually set. More... | |
void | writeXml (QDomElement &parentElement, const QgsReadWriteContext &context) override |
Write layer tree to XML. More... | |
Public Member Functions inherited from QgsLayerTreeNode | |
~QgsLayerTreeNode () override | |
QList< QgsLayerTreeNode * > | abandonChildren () |
Removes the childrens, disconnect all the forwarded and external signals and sets their parent to nullptr . More... | |
QList< QgsMapLayer * > | checkedLayers () const |
Returns a list of any checked layers which belong to this node or its children. More... | |
QList< QgsLayerTreeNode * > | children () |
Gets list of children of the node. Children are owned by the parent. More... | |
QList< QgsLayerTreeNode * > | children () const |
Gets list of children of the node. Children are owned by the parent. More... | |
QStringList | customProperties () const |
Returns list of keys stored in custom properties. More... | |
QVariant | customProperty (const QString &key, const QVariant &defaultValue=QVariant()) const |
Read a custom property from layer. Properties are stored in a map and saved in project file. More... | |
int | depth () const |
Returns the depth of this node, i.e. More... | |
bool | isExpanded () const |
Returns whether the node should be shown as expanded or collapsed in GUI. More... | |
bool | isItemVisibilityCheckedRecursive () const |
Returns whether this node is checked and all its children. More... | |
bool | isItemVisibilityUncheckedRecursive () const |
Returns whether this node is unchecked and all its children. More... | |
bool | isVisible () const |
Returns whether a node is really visible (ie checked and all its ancestors checked as well) More... | |
bool | itemVisibilityChecked () const |
Returns whether a node is checked (independently of its ancestors or children) More... | |
NodeType | nodeType () const |
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree namespace for that. More... | |
QgsLayerTreeNode * | parent () |
Gets pointer to the parent. If parent is nullptr , the node is a root node. More... | |
void | removeCustomProperty (const QString &key) |
Remove a custom property from layer. Properties are stored in a map and saved in project file. More... | |
void | setCustomProperty (const QString &key, const QVariant &value) |
Sets a custom property for the node. Properties are stored in a map and saved in project file. More... | |
void | setExpanded (bool expanded) |
Sets whether the node should be shown as expanded or collapsed in GUI. More... | |
void | setItemVisibilityChecked (bool checked) |
Check or uncheck a node (independently of its ancestors or children) More... | |
void | setItemVisibilityCheckedParentRecursive (bool checked) |
Check or uncheck a node and all its parents. More... | |
virtual void | setItemVisibilityCheckedRecursive (bool checked) |
Check or uncheck a node and all its children (taking into account exclusion rules) More... | |
bool | takeChild (QgsLayerTreeNode *node) |
Remove a child from a node. More... | |
Static Public Member Functions | |
static QgsLayerTreeLayer * | readXml (QDomElement &element, const QgsProject *project, const QgsReadWriteContext &context) |
Read layer node from XML. More... | |
static QgsLayerTreeLayer * | readXml (QDomElement &element, const QgsReadWriteContext &context) |
Read layer node from XML. More... | |
Static Public Member Functions inherited from QgsLayerTreeNode | |
static QgsLayerTreeNode * | readXml (QDomElement &element, const QgsProject *project) |
Read layer tree from XML. More... | |
static QgsLayerTreeNode * | readXml (QDomElement &element, const QgsReadWriteContext &context) |
Read layer tree from XML. More... | |
Protected Member Functions | |
void | attachToLayer () |
Protected Member Functions inherited from QgsLayerTreeNode | |
QgsLayerTreeNode (const QgsLayerTreeNode &other) | |
QgsLayerTreeNode (NodeType t, bool checked=true) | |
Constructor. More... | |
void | insertChildrenPrivate (int index, QList< QgsLayerTreeNode * > nodes) |
Low-level insertion of children to the node. The children must not have any parent yet! More... | |
virtual void | makeOrphan () |
Sets parent to nullptr and disconnects all external and forwarded signals. More... | |
void | readCommonXml (QDomElement &element) |
Read common XML elements. More... | |
void | removeChildrenPrivate (int from, int count, bool destroy=true) |
Low-level removal of children from the node. More... | |
void | writeCommonXml (QDomElement &element) |
Write common XML elements. More... | |
Protected Attributes | |
QString | mLabelExpression |
Expression to evaluate in the legend. More... | |
QString | mLayerName |
Layer name - only used if layer does not exist or if mUseLayerName is false. More... | |
QgsMapLayerRef | mRef |
Weak reference to the layer (or just it's ID if the reference is not resolved yet) More... | |
bool | mUseLayerName = true |
Protected Attributes inherited from QgsLayerTreeNode | |
bool | mChecked |
QList< QgsLayerTreeNode * > | mChildren |
list of children - node is responsible for their deletion More... | |
bool | mExpanded |
whether the node should be shown in GUI as expanded More... | |
NodeType | mNodeType |
type of the node - determines which subclass is used More... | |
QgsLayerTreeNode * | mParent = nullptr |
pointer to the parent node - nullptr in case of root node More... | |
QgsObjectCustomProperties | mProperties |
custom properties attached to the node More... | |
Layer tree node points to a map layer.
The node can exist also without a valid instance of a layer (just ID). That means the referenced layer does not need to be loaded in order to use it in layer tree. In such case, resolveReferences() method can be called once the layer is loaded.
A map layer is supposed to be present in one layer tree just once. It is however possible that temporarily a layer exists in one tree more than just once, e.g. while reordering items with drag and drop.
Definition at line 43 of file qgslayertreelayer.h.
Legend node column split behavior.
Definition at line 189 of file qgslayertreelayer.h.
|
explicit |
Definition at line 24 of file qgslayertreelayer.cpp.
QgsLayerTreeLayer::QgsLayerTreeLayer | ( | const QgsLayerTreeLayer & | other | ) |
Definition at line 39 of file qgslayertreelayer.cpp.
|
explicit |
Constructor for QgsLayerTreeLayer using weak references to layer ID, name, public source, and provider key.
Definition at line 32 of file qgslayertreelayer.cpp.
|
protected |
Definition at line 71 of file qgslayertreelayer.cpp.
|
overridevirtual |
Create a copy of the node. Returns new instance.
Implements QgsLayerTreeNode.
Definition at line 188 of file qgslayertreelayer.cpp.
|
overridevirtual |
Returns string with layer tree structure. For debug purposes only.
Implements QgsLayerTreeNode.
Definition at line 183 of file qgslayertreelayer.cpp.
|
inline |
Returns the expression member of the LayerTreeNode.
Definition at line 144 of file qgslayertreelayer.h.
|
inline |
Returns the map layer associated with this node.
nullptr
, e.g. in the case of a layer node representing a layer which has not yet been fully loaded into a project, or a layer node representing a layer with an invalid data source. The returned pointer must ALWAYS be checked to avoid dereferencing nullptr
.Definition at line 74 of file qgslayertreelayer.h.
|
inline |
Returns the ID for the map layer associated with this node.
Definition at line 63 of file qgslayertreelayer.h.
|
signal |
Emitted when a previously unavailable layer got loaded.
|
signal |
Emitted when a previously available layer got unloaded (from layer registry).
|
inline |
Returns the column split behavior for the node.
This value controls how legend nodes belonging the to layer may be split over multiple columns in legends.
Definition at line 204 of file qgslayertreelayer.h.
|
overridevirtual |
Returns the layer's name.
Implements QgsLayerTreeNode.
Definition at line 81 of file qgslayertreelayer.cpp.
QgsLegendPatchShape QgsLayerTreeLayer::patchShape | ( | ) | const |
Returns the symbol patch shape to use when rendering the legend node symbol.
Definition at line 227 of file qgslayertreelayer.cpp.
|
inline |
Returns the user (overridden) size for the legend node.
If either the width or height are non-zero, they will be used when rendering the legend node instead of the default symbol width or height from QgsLegendSettings.
Definition at line 171 of file qgslayertreelayer.h.
|
static |
Read layer node from XML.
Returns new instance. Also resolves textual references to layers from the project (calls resolveReferences() internally).
Definition at line 143 of file qgslayertreelayer.cpp.
|
static |
Read layer node from XML.
Returns new instance. Does not resolve textual references to layers. Call resolveReferences() afterwards to do it.
Definition at line 104 of file qgslayertreelayer.cpp.
|
overridevirtual |
Resolves reference to layer from stored layer ID (if it has not been resolved already)
Implements QgsLayerTreeNode.
Definition at line 50 of file qgslayertreelayer.cpp.
void QgsLayerTreeLayer::setLabelExpression | ( | const QString & | expression | ) |
|
inline |
Sets the column split behavior for the node.
This value controls how legend nodes belonging the to layer may be split over multiple columns in legends.
Definition at line 214 of file qgslayertreelayer.h.
|
overridevirtual |
Sets the layer's name.
Implements QgsLayerTreeNode.
Definition at line 86 of file qgslayertreelayer.cpp.
void QgsLayerTreeLayer::setPatchShape | ( | const QgsLegendPatchShape & | shape | ) |
Sets the symbol patch shape to use when rendering the legend node symbol.
Definition at line 232 of file qgslayertreelayer.cpp.
|
inline |
Sets the user (overridden) size for the legend node.
If either the width or height are non-zero, they will be used when rendering the legend node instead of the default symbol width or height from QgsLegendSettings.
Definition at line 182 of file qgslayertreelayer.h.
void QgsLayerTreeLayer::setUseLayerName | ( | bool | use = true | ) |
Uses the layer's name if use is true
, or the name manually set if false
.
Definition at line 206 of file qgslayertreelayer.cpp.
bool QgsLayerTreeLayer::useLayerName | ( | ) | const |
Returns whether the layer's name is used, or the name manually set.
Definition at line 211 of file qgslayertreelayer.cpp.
|
overridevirtual |
Write layer tree to XML.
Implements QgsLayerTreeNode.
Definition at line 151 of file qgslayertreelayer.cpp.
|
protected |
Expression to evaluate in the legend.
Definition at line 237 of file qgslayertreelayer.h.
|
protected |
Layer name - only used if layer does not exist or if mUseLayerName is false.
Definition at line 235 of file qgslayertreelayer.h.
|
protected |
Weak reference to the layer (or just it's ID if the reference is not resolved yet)
Definition at line 233 of file qgslayertreelayer.h.
|
protected |
Definition at line 240 of file qgslayertreelayer.h.