QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
QgsLayerTreeFilterProxyModel Class Reference

A sort filter proxy model to easily reproduce the legend/layer tree in a tree view. More...

#include <qgslayertreefilterproxymodel.h>

Inheritance diagram for QgsLayerTreeFilterProxyModel:

Public Slots

virtual void setFilterText (const QString &filterText=QString())
 Sets the filter text to search for a layer in the tree.

Public Member Functions

 QgsLayerTreeFilterProxyModel (QObject *parent=nullptr)
 Constructor.
QList< QgsMapLayer * > checkedLayers () const
 Returns the checked layers.
int columnCount (const QModelIndex &parent) const override
QVariant data (const QModelIndex &index, int role) const override
Qt::ItemFlags flags (const QModelIndex &idx) const override
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const override
QgsLayerTreeModellayerTreeModel () const
 Rerturns the layer tree model.
QgsMapLayermapLayer (const QModelIndex &idx) const
 Returns the map layer at a given index.
bool nodeShown (QgsLayerTreeNode *node) const
 Returns true if the specified node will be shown in the model.
QModelIndex parent (const QModelIndex &child) const override
void setCheckedLayers (const QList< QgsMapLayer * > layers)
 Initialize the list of checked layers.
bool setData (const QModelIndex &index, const QVariant &value, int role) override
void setFilters (Qgis::LayerFilters filters)
 Defines the type layers (vector, raster, etc) shown in the tree If the list is empty, all types are shown.
void setLayerTreeModel (QgsLayerTreeModel *layerTreeModel)
 Sets the layer tree model.
void setShowPrivateLayers (bool showPrivate)
 Determines if private layers are shown.
bool showPrivateLayers () const
 Returns if private layers are shown.
QModelIndex sibling (int row, int column, const QModelIndex &idx) const override

Protected Member Functions

bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override
virtual bool isLayerChecked (QgsMapLayer *layer) const
 Returns if the layer is checked or not.
virtual void setLayerChecked (QgsMapLayer *layer, bool checked)
 This will set if the layer is checked or not.

Detailed Description

A sort filter proxy model to easily reproduce the legend/layer tree in a tree view.

Layers are checkable by default. Symbology nodes will not be shown. Layers can be filtered by their type.

For more complex use-cases, the model can be re-implemented to allow a different interaction or to add more columns.

Since
QGIS 3.14

Definition at line 41 of file qgslayertreefilterproxymodel.h.

Constructor & Destructor Documentation

◆ QgsLayerTreeFilterProxyModel()

QgsLayerTreeFilterProxyModel::QgsLayerTreeFilterProxyModel ( QObject * parent = nullptr)

Constructor.

Definition at line 25 of file qgslayertreefilterproxymodel.cpp.

Member Function Documentation

◆ checkedLayers()

QList< QgsMapLayer * > QgsLayerTreeFilterProxyModel::checkedLayers ( ) const
inline

Returns the checked layers.

Definition at line 55 of file qgslayertreefilterproxymodel.h.

◆ columnCount()

int QgsLayerTreeFilterProxyModel::columnCount ( const QModelIndex & parent) const
override

Definition at line 43 of file qgslayertreefilterproxymodel.cpp.

◆ data()

QVariant QgsLayerTreeFilterProxyModel::data ( const QModelIndex & index,
int role ) const
override

Definition at line 210 of file qgslayertreefilterproxymodel.cpp.

◆ filterAcceptsRow()

bool QgsLayerTreeFilterProxyModel::filterAcceptsRow ( int sourceRow,
const QModelIndex & sourceParent ) const
overrideprotected

Definition at line 132 of file qgslayertreefilterproxymodel.cpp.

◆ flags()

Qt::ItemFlags QgsLayerTreeFilterProxyModel::flags ( const QModelIndex & idx) const
override

Definition at line 49 of file qgslayertreefilterproxymodel.cpp.

◆ index()

QModelIndex QgsLayerTreeFilterProxyModel::index ( int row,
int column,
const QModelIndex & parent = QModelIndex() ) const
override

Definition at line 58 of file qgslayertreefilterproxymodel.cpp.

◆ isLayerChecked()

bool QgsLayerTreeFilterProxyModel::isLayerChecked ( QgsMapLayer * layer) const
protectedvirtual

Returns if the layer is checked or not.

Definition at line 138 of file qgslayertreefilterproxymodel.cpp.

◆ layerTreeModel()

QgsLayerTreeModel * QgsLayerTreeFilterProxyModel::layerTreeModel ( ) const

Rerturns the layer tree model.

Definition at line 101 of file qgslayertreefilterproxymodel.cpp.

◆ mapLayer()

QgsMapLayer * QgsLayerTreeFilterProxyModel::mapLayer ( const QModelIndex & idx) const

Returns the map layer at a given index.

Definition at line 78 of file qgslayertreefilterproxymodel.cpp.

◆ nodeShown()

bool QgsLayerTreeFilterProxyModel::nodeShown ( QgsLayerTreeNode * node) const

Returns true if the specified node will be shown in the model.

Since
QGIS 3.40

Definition at line 176 of file qgslayertreefilterproxymodel.cpp.

◆ parent()

QModelIndex QgsLayerTreeFilterProxyModel::parent ( const QModelIndex & child) const
override

Definition at line 67 of file qgslayertreefilterproxymodel.cpp.

◆ setCheckedLayers()

void QgsLayerTreeFilterProxyModel::setCheckedLayers ( const QList< QgsMapLayer * > layers)

Initialize the list of checked layers.

Note
If the model is re-implemented, this method might become useless

Definition at line 35 of file qgslayertreefilterproxymodel.cpp.

◆ setData()

bool QgsLayerTreeFilterProxyModel::setData ( const QModelIndex & index,
const QVariant & value,
int role )
override

Definition at line 278 of file qgslayertreefilterproxymodel.cpp.

◆ setFilters()

void QgsLayerTreeFilterProxyModel::setFilters ( Qgis::LayerFilters filters)

Defines the type layers (vector, raster, etc) shown in the tree If the list is empty, all types are shown.

Definition at line 126 of file qgslayertreefilterproxymodel.cpp.

◆ setFilterText

void QgsLayerTreeFilterProxyModel::setFilterText ( const QString & filterText = QString())
virtualslot

Sets the filter text to search for a layer in the tree.

Definition at line 92 of file qgslayertreefilterproxymodel.cpp.

◆ setLayerChecked()

void QgsLayerTreeFilterProxyModel::setLayerChecked ( QgsMapLayer * layer,
bool checked )
protectedvirtual

This will set if the layer is checked or not.

Definition at line 143 of file qgslayertreefilterproxymodel.cpp.

◆ setLayerTreeModel()

void QgsLayerTreeFilterProxyModel::setLayerTreeModel ( QgsLayerTreeModel * layerTreeModel)

Sets the layer tree model.

Definition at line 106 of file qgslayertreefilterproxymodel.cpp.

◆ setShowPrivateLayers()

void QgsLayerTreeFilterProxyModel::setShowPrivateLayers ( bool showPrivate)

Determines if private layers are shown.

Defaults to true.

Since
QGIS 3.40

Definition at line 117 of file qgslayertreefilterproxymodel.cpp.

◆ showPrivateLayers()

bool QgsLayerTreeFilterProxyModel::showPrivateLayers ( ) const

Returns if private layers are shown.

Defaults to true.

Since
QGIS 3.40

Definition at line 112 of file qgslayertreefilterproxymodel.cpp.

◆ sibling()

QModelIndex QgsLayerTreeFilterProxyModel::sibling ( int row,
int column,
const QModelIndex & idx ) const
override

Definition at line 72 of file qgslayertreefilterproxymodel.cpp.


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