Skip to content

Commit

Permalink
Merge pull request #37000 from 3nids/layer-tree-filter-proxy
Browse files Browse the repository at this point in the history
Use a filter proxy model for the dependencies layer tree
  • Loading branch information
3nids committed Jun 6, 2020
2 parents d357a27 + 09a36c3 commit ce17f7f
Show file tree
Hide file tree
Showing 14 changed files with 612 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -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 *
************************************************************************/
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgsmaplayerproxymodel.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Adds a properties page factory to the vector layer properties dialog.



public:
};


Expand Down
1 change: 1 addition & 0 deletions src/app/qgssnappinglayertreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/app/qgssnappingwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit ce17f7f

Please sign in to comment.