25 #include <QContextMenuEvent>
29 , mDefaultActions( 0 )
53 if ( !qobject_cast<QgsLayerTreeModel*>( model ) )
119 if ( menu && menu->
actions().count() != 0 )
135 if ( expandedNodeKeys.
isEmpty() )
141 if ( expandedNodeKeys.
contains( ruleKey ) )
148 for (
int i = start; i <= end; ++i )
172 QStringList lst = node->layerNode()->customProperty(
"expandedLegendNodes" ).toStringList();
174 bool isInList = lst.
contains( ruleKey );
175 if ( expanded && !isInList )
178 node->layerNode()->setCustomProperty(
"expandedLegendNodes", lst );
180 else if ( !expanded && isInList )
183 node->layerNode()->setCustomProperty(
"expandedLegendNodes", lst );
298 list << node->
layer();
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
Layer tree group node serves as a container for layers and further groups.
QgsLayerTreeModel * layerTreeModel() const
Get access to the model casted to QgsLayerTreeModel.
Base class for all map layer types.
QgsMapLayer * currentLayer() const
Get currently selected layer. May be null.
void setCurrentIndex(const QModelIndex ¤tIndex)
Set index of the current item. May be used by view. Item marked as current is underlined.
QgsLayerTreeViewMenuProvider * mMenuProvider
Context menu provider. Owned by the view.
QList< QgsLayerTreeNode * > indexes2nodes(const QModelIndexList &list, bool skipInternal=false) const
Convert a list of indexes to a list of layer tree nodes.
void setCurrentIndex(const QModelIndex &index)
void setSelectionMode(QAbstractItemView::SelectionMode mode)
QgsLayerTreeGroup * rootGroup() const
Return pointer to the root node of the layer tree. Always a non-null pointer.
QItemSelectionModel * selectionModel() const
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
void refreshLayerSymbology(const QString &layerId)
Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitore...
QgsMapLayer * layer() const
virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous)
void contextMenuEvent(QContextMenuEvent *event) override
void collapsed(const QModelIndex &index)
const QObjectList & children() const
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QgsLayerTreeViewMenuProvider * menuProvider() const
Return pointer to the context menu provider. May be null.
QgsLayerTreeNode * currentNode() const
Get current node. May be null.
QList< QgsMapLayer * > selectedLayers() const
Get list of selected layers.
void modelRowsInserted(const QModelIndex &index, int start, int end)
void rowsRemoved(const QModelIndex &parent, int start, int end)
QgsLayerTreeViewDefaultActions * defaultActions()
Get access to the default actions that may be used with the tree view.
QList< QgsLayerTreeNode * > selectedNodes(bool skipInternal=false) const
Return list of selected nodes.
QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group. No type checking is done - use isGroup() to find out whether this operation is ...
QString mCurrentLayerID
Keeps track of current layer ID (to check when to emit signal about change of current layer) ...
void setExpanded(const QModelIndex &index, bool expanded)
The QgsLayerTreeViewDefaultActions class serves as a factory of actions that can be used together wit...
The QgsLayerTreeModel class is model implementation for Qt item views framework.
void updateExpandedStateToNode(const QModelIndex &index)
void append(const T &value)
QModelIndex legendNode2index(QgsLayerTreeModelLegendNode *legendNode)
Return index for a given legend node.
rule key of the node (QString)
QgsLayerTreeGroup * currentGroupNode() const
Get current group node. If a layer is current node, the function will return parent group...
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
static QgsLayerTreeModelLegendNode * index2legendNode(const QModelIndex &index)
Return legend node for given index.
QgsLayerTreeNode * parent()
Get pointer to the parent. If parent is a null pointer, the node is a root node.
int removeAll(const T &value)
QgsLayerTreeLayer * layerNode() const
Return pointer to the parent layer node.
void setEditTriggers(QFlags< QAbstractItemView::EditTrigger > triggers)
This class is a base class for nodes in a layer tree.
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
bool isExpanded() const
Return whether the node should be shown as expanded or collapsed in GUI.
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.
bool isExpanded(const QModelIndex &index) const
void currentLayerChanged(QgsMapLayer *layer)
Emitted when a current layer is changed.
void refreshLayerLegend(QgsLayerTreeLayer *nodeLayer)
Force a refresh of legend nodes of a layer node.
QgsLayerTreeViewDefaultActions * mDefaultActions
helper class with default actions. Lazily initialized.
QList< QgsLayerTreeLayer * > selectedLayerNodes() const
Return list of selected nodes filtered to just layer nodes.
QModelIndex node2index(QgsLayerTreeNode *node) const
Return index for a given node. If the node does not belong to the layer tree, the result is undefined...
void updateExpandedStateFromNode(QgsLayerTreeNode *node)
void setExpandsOnDoubleClick(bool enable)
QStringList toStringList() const
void onExpandedChanged(QgsLayerTreeNode *node, bool expanded)
QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer. No type checking is done - use isLayer() to find out whether this operation is ...
virtual void setModel(QAbstractItemModel *model)
virtual QVariant data(int role) const =0
Return data associated with the item.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
virtual QModelIndexList selectedIndexes() const
virtual void setModel(QAbstractItemModel *model) override
Overridden setModel() from base class. Only QgsLayerTreeModel is an acceptable model.
QgsLayerTreeLayer * findLayer(const QString &layerId) const
Find layer node representing the map layer specified by its ID. Searches recursively the whole sub-tr...
QgsLayerTreeView(QWidget *parent=0)
void setCurrentLayer(QgsMapLayer *layer)
Set currently selected layer. Null pointer will deselect any layer.
void expanded(const QModelIndex &index)
void setMenuProvider(QgsLayerTreeViewMenuProvider *menuProvider)
Set provider for context menu. Takes ownership of the instance.
QgsLayerTreeNode * index2node(const QModelIndex &index) const
Return layer tree node for given index.
QAbstractItemModel * model() const
QModelIndex currentIndex() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
virtual QModelIndex indexAt(const QPoint &point) const
void setDropIndicatorShown(bool enable)
QgsMapLayer * layerForIndex(const QModelIndex &index) const
void setDragEnabled(bool enable)
Layer tree node points to a map layer.