QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
23 : QSortFilterProxyModel( parent )
36 mCheckedLayers = layers;
48 if ( idx.column() == 0 )
50 return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
52 return Qt::NoItemFlags;
57 QModelIndex newIndex = QSortFilterProxyModel::index( row, 0,
parent );
61 return createIndex( row, column, newIndex.internalId() );
66 return QSortFilterProxyModel::parent( createIndex( child.row(), 0, child.internalId() ) );
71 QModelIndex
parent = idx.parent();
78 if ( idx.column() == 0 )
80 node = mLayerTreeModel->
index2node( mapToSource( idx ) );
91 if ( filterText == mFilterText )
94 mFilterText = filterText;
100 return mLayerTreeModel;
118 return nodeShown( node );
123 return mCheckedLayers.contains( layer );
130 mCheckedLayers << layer;
134 mCheckedLayers.removeAll( layer );
138 void QgsLayerTreeFilterProxyModel::setLayerCheckedPrivate(
QgsMapLayer *layer,
bool checked )
146 QModelIndex
index = mapFromSource( mLayerTreeModel->
node2index( node ) );
153 bool QgsLayerTreeFilterProxyModel::layerShown(
QgsMapLayer *layer )
const
159 bool QgsLayerTreeFilterProxyModel::nodeShown(
QgsLayerTreeNode *node )
const
165 const auto constChildren = node->
children();
168 if ( nodeShown( child ) )
180 if ( !mFilterText.isEmpty() && !layer->
name().contains( mFilterText, Qt::CaseInsensitive ) )
185 return layerShown( layer );
191 if ( idx.column() == 0 )
193 if ( role == Qt::CheckStateRole )
204 return Qt::Unchecked;
210 bool hasChecked =
false, hasUnchecked =
false;
212 for ( n = 0; !hasChecked || !hasUnchecked; n++ )
214 QVariant v =
data(
index( n, 0, idx ), role );
220 case Qt::PartiallyChecked:
222 return Qt::PartiallyChecked;
236 return Qt::Unchecked;
239 if ( hasChecked && hasUnchecked )
240 return Qt::PartiallyChecked;
245 Q_ASSERT( hasUnchecked );
246 return Qt::Unchecked;
251 return mLayerTreeModel->
data( mapToSource( idx ), role );
259 if (
index.column() == 0 )
261 if ( role == Qt::CheckStateRole )
267 if ( !child.isValid() )
280 if ( value.toInt() == Qt::Checked )
281 setLayerCheckedPrivate( layer,
true );
282 else if ( value.toInt() == Qt::Unchecked )
283 setLayerCheckedPrivate( layer,
false );
291 return mLayerTreeModel->
setData( mapToSource(
index ), value, role );
@ NodeGroup
Container of other groups and layers.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override
QgsLayerTreeLayer * findLayer(QgsMapLayer *layer) const
Find layer node representing the map layer.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
static bool layerMatchesFilters(const QgsMapLayer *layer, const Filters &filters)
Returns if the layer matches the given filters.
virtual QVariant data(const QModelIndex &index, int role) const override
static QgsProject * instance()
Returns the QgsProject singleton instance.
QModelIndex parent(const QModelIndex &child) const override
void readProject(const QDomDocument &)
Emitted when a project is being read.
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
virtual void setLayerChecked(QgsMapLayer *layer, bool checked)
This will set if the layer is checked or not.
NodeType nodeType() const
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree...
void setFilters(const QgsMapLayerProxyModel::Filters &filters)
Defines the type layers (vector, raster, etc) shown in the tree If the list is empty,...
virtual bool isLayerChecked(QgsMapLayer *layer) const
Returns if the layer is checked or not.
QModelIndex node2index(QgsLayerTreeNode *node) const
Returns index for a given node. If the node does not belong to the layer tree, the result is undefine...
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QgsLayerTreeModel * layerTreeModel() const
Rerturns the layer tree model.
virtual Qt::ItemFlags flags(const QModelIndex &idx) const override
void setLayerTreeModel(QgsLayerTreeModel *layerTreeModel)
Sets the layer tree model.
void setCheckedLayers(const QList< QgsMapLayer * > layers)
Initialize the list of checked layers.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
QModelIndex sibling(int row, int column, const QModelIndex &idx) const override
QgsMapLayer * layer() const
Returns the map layer associated with this node.
QgsLayerTree * rootGroup() const
Returns pointer to the root node of the layer tree. Always a non nullptr value.
QgsLayerTreeNode * index2node(const QModelIndex &index) const
Returns layer tree node for given index.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
virtual int columnCount(const QModelIndex &parent) const override
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
QgsLayerTreeFilterProxyModel(QObject *parent=nullptr)
Constructor.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QgsMapLayer * mapLayer(const QModelIndex &idx) const
Returns the map layer at a given index.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
virtual void setFilterText(const QString &filterText=QString())
Sets the filter text to search for a layer in the tree.