QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Classes | Signals | Public Member Functions | Static Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | List of all members
QgsLayerTreeLayer Class Reference

Layer tree node points to a map layer. More...

#include <qgslayertreelayer.h>

Inheritance diagram for QgsLayerTreeLayer:
Inheritance graph
[legend]

Classes

struct  LayerMatchParams
 Parameters for loose layer matching. 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, Qt::CheckState state)
 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 (QgsMapLayer *layer)
 
 QgsLayerTreeLayer (const QgsLayerTreeLayer &other)
 
 QgsLayerTreeLayer (const QString &layerId, const QString &name=QString())
 
void attachToSource (const LayerMatchParams &source)
 Attempts to attach this layer node to a layer with a matching QgsMapLayer::publicSource(). More...
 
virtual QgsLayerTreeLayerclone () const override
 Create a copy of the node. Returns new instance. More...
 
virtual QString dump () const override
 Return string with layer tree structure. For debug purposes only. More...
 
Qt::CheckState isVisible () const
 
QgsMapLayerlayer () const
 
QString layerId () const
 
QString layerName () const
 
QString name () const override
 Get layer's name. More...
 
void setLayerName (const QString &n)
 
void setName (const QString &n) override
 Set layer's name. More...
 
void setVisible (Qt::CheckState visible)
 
virtual void writeXML (QDomElement &parentElement) override
 Write layer tree to XML. More...
 
- Public Member Functions inherited from QgsLayerTreeNode
 ~QgsLayerTreeNode ()
 
QList< QgsLayerTreeNode * > children ()
 Get list of children of the node. Children are owned by the parent. More...
 
QStringList customProperties () const
 Return list of keys stored in custom properties. More...
 
QVariant customProperty (const QString &key, const QVariant &defaultValue=QVariant()) const
 Read a custom property from layer. More...
 
bool isExpanded () const
 Return whether the node should be shown as expanded or collapsed in GUI. More...
 
NodeType nodeType ()
 Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree namespace for that. More...
 
QgsLayerTreeNodeparent ()
 Get pointer to the parent. If parent is a null pointer, the node is a root node. More...
 
void removeCustomProperty (const QString &key)
 Remove a custom property from layer. More...
 
void setCustomProperty (const QString &key, const QVariant &value)
 Set a custom property for the node. More...
 
void setExpanded (bool expanded)
 Set whether the node should be shown as expanded or collapsed in GUI. More...
 
bool takeChild (QgsLayerTreeNode *node)
 Remove a child from a node. More...
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
 QObject (QObject *parent, const char *name)
 
virtual ~QObject ()
 
bool blockSignals (bool block)
 
QObjectchild (const char *objName, const char *inheritsClass, bool recursiveSearch) const
 
const QObjectList & children () const
 
const char * className () const
 
bool connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const QObject *receiver, const char *method)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method)
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArraydynamicPropertyNames () const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) const
 
QList< T > findChildren (const QString &name) const
 
bool inherits (const char *className) const
 
void insertChild (QObject *object)
 
void installEventFilter (QObject *filterObj)
 
bool isA (const char *className) const
 
bool isWidgetType () const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObjectparent () const
 
QVariant property (const char *name) const
 
void removeChild (QObject *object)
 
void removeEventFilter (QObject *obj)
 
void setName (const char *name)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval)
 
QThreadthread () const
 

Static Public Member Functions

static QgsLayerTreeLayercreateLayerFromParams (const LayerMatchParams &source)
 Creates a layer node which will attach to a layer with matching parameters. More...
 
static QgsLayerTreeLayerreadXML (QDomElement &element, bool looseMatch=false)
 Creates a new layer from an XML definition. More...
 
- Static Public Member Functions inherited from QgsLayerTreeNode
static QgsLayerTreeNodereadXML (QDomElement &element, bool looseMatch=false)
 Read layer tree from XML. More...
 
- Static Public Member Functions inherited from QObject
bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Protected Slots

void layerNameChanged ()
 Emits a nameChanged() signal if layer's name has changed. More...
 
void registryLayersAdded (const QList< QgsMapLayer *> &layers)
 
void registryLayersWillBeRemoved (const QStringList &layerIds)
 

Protected Member Functions

void attachToLayer ()
 
- Protected Member Functions inherited from QgsLayerTreeNode
 QgsLayerTreeNode (NodeType t)
 
 QgsLayerTreeNode (const QgsLayerTreeNode &other)
 
void insertChildrenPrivate (int index, QList< QgsLayerTreeNode *> nodes)
 Low-level insertion of children to the node. The children must not have any parent yet! More...
 
void readCommonXML (QDomElement &element)
 
void removeChildrenPrivate (int from, int count, bool destroy=true)
 Low-level removal of children from the node. More...
 
void writeCommonXML (QDomElement &element)
 
- Protected Member Functions inherited from QObject
bool checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const char *signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const char *signal)
 
int receivers (const char *signal) const
 
QObjectsender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Protected Attributes

QgsMapLayermLayer
 
QString mLayerId
 
QString mLayerName
 
LayerMatchParams mLooseMatchParams
 Only used when loosely matching to layers - eg when creating a composer legend from template If set this will attach to the first matching layer with equal parameters. More...
 
Qt::CheckState mVisible
 
- Protected Attributes inherited from QgsLayerTreeNode
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...
 
QgsLayerTreeNodemParent
 pointer to the parent node - null in case of root node More...
 
QgsObjectCustomProperties mProperties
 custom properties attached to the node More...
 

Additional Inherited Members

- Public Types inherited from QgsLayerTreeNode
enum  NodeType { NodeGroup, NodeLayer }
 Enumeration of possible tree node types. More...
 
- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

Layer tree node points to a map layer.

When using with existing QgsMapLayer instance, it is expected that the layer has been registered in QgsMapLayerRegistry earlier.

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, the node will start listening to map layer registry updates in expectation that the layer (identified by its ID) will be loaded later.

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.

Note
added in 2.4

Definition at line 41 of file qgslayertreelayer.h.

Constructor & Destructor Documentation

◆ QgsLayerTreeLayer() [1/3]

QgsLayerTreeLayer::QgsLayerTreeLayer ( QgsMapLayer layer)
explicit

Definition at line 26 of file qgslayertreelayer.cpp.

◆ QgsLayerTreeLayer() [2/3]

QgsLayerTreeLayer::QgsLayerTreeLayer ( const QgsLayerTreeLayer other)

Definition at line 46 of file qgslayertreelayer.cpp.

◆ QgsLayerTreeLayer() [3/3]

QgsLayerTreeLayer::QgsLayerTreeLayer ( const QString layerId,
const QString name = QString() 
)
explicit

Definition at line 36 of file qgslayertreelayer.cpp.

Member Function Documentation

◆ attachToLayer()

void QgsLayerTreeLayer::attachToLayer ( )
protected

Definition at line 63 of file qgslayertreelayer.cpp.

◆ attachToSource()

void QgsLayerTreeLayer::attachToSource ( const LayerMatchParams source)

Attempts to attach this layer node to a layer with a matching QgsMapLayer::publicSource().

This can be used for "looser" layer matching, avoiding the usual layer id check in favour of attaching to any layer with an equal source.

Definition at line 123 of file qgslayertreelayer.cpp.

◆ clone()

QgsLayerTreeLayer * QgsLayerTreeLayer::clone ( ) const
overridevirtual

Create a copy of the node. Returns new instance.

Implements QgsLayerTreeNode.

Definition at line 260 of file qgslayertreelayer.cpp.

◆ createLayerFromParams()

QgsLayerTreeLayer * QgsLayerTreeLayer::createLayerFromParams ( const LayerMatchParams source)
static

Creates a layer node which will attach to a layer with matching parameters.

This can be used for "looser" layer matching, avoiding the usual layer id check in favour of attaching to any layer with an equal source/name/provider.

Definition at line 56 of file qgslayertreelayer.cpp.

◆ dump()

QString QgsLayerTreeLayer::dump ( ) const
overridevirtual

Return string with layer tree structure. For debug purposes only.

Implements QgsLayerTreeNode.

Definition at line 255 of file qgslayertreelayer.cpp.

◆ isVisible()

Qt::CheckState QgsLayerTreeLayer::isVisible ( ) const
inline

Definition at line 92 of file qgslayertreelayer.h.

◆ layer()

QgsMapLayer* QgsLayerTreeLayer::layer ( ) const
inline

Definition at line 72 of file qgslayertreelayer.h.

◆ layerId()

QString QgsLayerTreeLayer::layerId ( ) const
inline

Definition at line 70 of file qgslayertreelayer.h.

◆ layerLoaded

void QgsLayerTreeLayer::layerLoaded ( )
signal

emitted when a previously unavailable layer got loaded

◆ layerName()

QString QgsLayerTreeLayer::layerName ( ) const

Definition at line 146 of file qgslayertreelayer.cpp.

◆ layerNameChanged

void QgsLayerTreeLayer::layerNameChanged ( )
protectedslot

Emits a nameChanged() signal if layer's name has changed.

Note
added in 2.18.1

Definition at line 299 of file qgslayertreelayer.cpp.

◆ layerWillBeUnloaded

void QgsLayerTreeLayer::layerWillBeUnloaded ( )
signal

emitted when a previously available layer got unloaded (from layer registry)

Note
added in 2.6

◆ name()

QString QgsLayerTreeLayer::name ( ) const
overridevirtual

Get layer's name.

Note
added in 2.18.1

Implements QgsLayerTreeNode.

Definition at line 113 of file qgslayertreelayer.cpp.

◆ readXML()

QgsLayerTreeLayer * QgsLayerTreeLayer::readXML ( QDomElement element,
bool  looseMatch = false 
)
static

Creates a new layer from an XML definition.

If the looseMatch parameter is true then legend layers will use looser matching criteria, eg testing layer source instead of layer IDs.

Definition at line 178 of file qgslayertreelayer.cpp.

◆ registryLayersAdded

void QgsLayerTreeLayer::registryLayersAdded ( const QList< QgsMapLayer *> &  layers)
protectedslot

Definition at line 265 of file qgslayertreelayer.cpp.

◆ registryLayersWillBeRemoved

void QgsLayerTreeLayer::registryLayersWillBeRemoved ( const QStringList layerIds)
protectedslot

Definition at line 285 of file qgslayertreelayer.cpp.

◆ setLayerName()

void QgsLayerTreeLayer::setLayerName ( const QString n)

Definition at line 151 of file qgslayertreelayer.cpp.

◆ setName()

void QgsLayerTreeLayer::setName ( const QString n)
overridevirtual

Set layer's name.

Note
added in 2.18.1

Implements QgsLayerTreeNode.

Definition at line 118 of file qgslayertreelayer.cpp.

◆ setVisible()

void QgsLayerTreeLayer::setVisible ( Qt::CheckState  visible)

Definition at line 169 of file qgslayertreelayer.cpp.

◆ writeXML()

void QgsLayerTreeLayer::writeXML ( QDomElement parentElement)
overridevirtual

Write layer tree to XML.

Implements QgsLayerTreeNode.

Definition at line 216 of file qgslayertreelayer.cpp.

Member Data Documentation

◆ mLayer

QgsMapLayer* QgsLayerTreeLayer::mLayer
protected

Definition at line 132 of file qgslayertreelayer.h.

◆ mLayerId

QString QgsLayerTreeLayer::mLayerId
protected

Definition at line 125 of file qgslayertreelayer.h.

◆ mLayerName

QString QgsLayerTreeLayer::mLayerName
protected

Definition at line 126 of file qgslayertreelayer.h.

◆ mLooseMatchParams

LayerMatchParams QgsLayerTreeLayer::mLooseMatchParams
protected

Only used when loosely matching to layers - eg when creating a composer legend from template If set this will attach to the first matching layer with equal parameters.

Definition at line 130 of file qgslayertreelayer.h.

◆ mVisible

Qt::CheckState QgsLayerTreeLayer::mVisible
protected

Definition at line 133 of file qgslayertreelayer.h.


The documentation for this class was generated from the following files: