Skip to content
Permalink
Browse files

Merge pull request #37000 from 3nids/layer-tree-filter-proxy

Use a filter proxy model for the dependencies layer tree
  • Loading branch information
3nids committed Jun 6, 2020
2 parents d357a27 + 09a36c3 commit ce17f7fa7878c55c3f14b53c6b18b5f60f58e7a7
@@ -0,0 +1,108 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layertree/qgslayertreefilterproxymodel.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsLayerTreeFilterProxyModel : QSortFilterProxyModel
{
%Docstring
QgsLayerTreeFilterProxyModel is 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 fitlered by their type.

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

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgslayertreefilterproxymodel.h"
%End
public:
QgsLayerTreeFilterProxyModel( QObject *parent = 0 );
%Docstring
Constructor
%End

void setCheckedLayers( const QList<QgsMapLayer *> layers );
%Docstring
Initialize the list of checked layers.

.. note::

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

QList<QgsMapLayer *> checkedLayers() const;
%Docstring
Returns the checked layers
%End

QgsMapLayer *mapLayer( const QModelIndex &idx ) const;
%Docstring
Returns the map layer at a given index
%End

QgsLayerTreeModel *layerTreeModel() const;
%Docstring
Rerturns the layer tree model
%End
void setLayerTreeModel( QgsLayerTreeModel *layerTreeModel );
%Docstring
Sets the layer tree model
%End

void setFilters( const QgsMapLayerProxyModel::Filters &filters );
%Docstring
Defines the type layers (vector, raster, etc) shown in the tree
If the list is empty, all types are shown.
%End

virtual int columnCount( const QModelIndex &parent ) const;
virtual Qt::ItemFlags flags( const QModelIndex &idx ) const;
virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;

virtual QModelIndex parent( const QModelIndex &child ) const;

virtual QModelIndex sibling( int row, int column, const QModelIndex &idx ) const;

virtual QVariant data( const QModelIndex &index, int role ) const;
virtual bool setData( const QModelIndex &index, const QVariant &value, int role );

public slots:
virtual void setFilterText( const QString &filterText = QString() );
%Docstring
Sets the filter text to search for a layer in the tree
%End

protected:
virtual bool isLayerChecked( QgsMapLayer *layer ) const;
%Docstring
Returns if the layer is checked or not
%End

virtual void setLayerChecked( QgsMapLayer *layer, bool checked );
%Docstring
This will set if the layer is checked or not
%End

virtual bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layertree/qgslayertreefilterproxymodel.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -67,6 +67,13 @@ Returns the filter flags which affect how layers are filtered within the model.
.. seealso:: :py:func:`setFilters`

.. versionadded:: 2.3
%End

static bool layerMatchesFilters( const QgsMapLayer *layer, const Filters &filters );
%Docstring
Returns if the ``layer`` matches the given ``filters``

.. versionadded:: 3.14
%End

void setLayerWhitelist( const QList<QgsMapLayer *> &layers );
@@ -348,6 +348,7 @@
%Include auto_generated/layertree/qgslayertreemodellegendnode.sip
%Include auto_generated/layertree/qgslayertreenode.sip
%Include auto_generated/layertree/qgslayertreeregistrybridge.sip
%Include auto_generated/layertree/qgslayertreefilterproxymodel.sip
%Include auto_generated/layertree/qgslayertreeutils.sip
%Include auto_generated/layertree/qgslegendpatchshape.sip
%Include auto_generated/layout/qgsabstractlayoutiterator.sip
@@ -42,6 +42,7 @@ Adds a properties page factory to the vector layer properties dialog.



public:
};


@@ -266,6 +266,7 @@ QgsSnappingLayerTreeModel::QgsSnappingLayerTreeModel( QgsProject *project, QgsMa
{
connect( project, &QgsProject::snappingConfigChanged, this, &QgsSnappingLayerTreeModel::onSnappingSettingsChanged );
connect( project, &QgsProject::avoidIntersectionsLayersChanged, this, &QgsSnappingLayerTreeModel::onSnappingSettingsChanged );
connect( project, &QgsProject::readProject, this, [ = ] {resetLayerTreeModel();} );
}

int QgsSnappingLayerTreeModel::columnCount( const QModelIndex &parent ) const
@@ -92,7 +92,6 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
connect( model, &QgsSnappingLayerTreeModel::rowsInserted, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
connect( model, &QgsSnappingLayerTreeModel::modelReset, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
connect( model, &QgsSnappingLayerTreeModel::rowsRemoved, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
connect( mProject, &QgsProject::readProject, this, [ = ] {model->resetLayerTreeModel();} );
connect( mProject, &QObject::destroyed, this, [ = ] {mLayerTreeView->setModel( nullptr );} );
// model->setFlags( 0 );
mLayerTreeView->setModel( model );
@@ -96,6 +96,7 @@ SET(QGIS_CORE_SRCS
layertree/qgslayertreemodellegendnode.cpp
layertree/qgslayertreenode.cpp
layertree/qgslayertreeregistrybridge.cpp
layertree/qgslayertreefilterproxymodel.cpp
layertree/qgslayertreeutils.cpp
layertree/qgslayertree.cpp
layertree/qgslegendpatchshape.cpp
@@ -1152,6 +1153,7 @@ SET(QGIS_CORE_HDRS
layertree/qgslayertreemodellegendnode.h
layertree/qgslayertreenode.h
layertree/qgslayertreeregistrybridge.h
layertree/qgslayertreefilterproxymodel.h
layertree/qgslayertreeutils.h
layertree/qgslegendpatchshape.h

0 comments on commit ce17f7f

Please sign in to comment.
You can’t perform that action at this time.