Skip to content
Permalink
Browse files

use filters rather than list of layer types

  • Loading branch information
3nids committed Jun 6, 2020
1 parent d311aef commit 558e0b6ce8e89c7f7ee9ed1ac8307d48f784d7f5
@@ -65,7 +65,7 @@ Sets the layer tree model
This will refresh the model
%End

void setMapLayerTypeFilter( const QList<QgsMapLayerType> &types = QList<QgsMapLayerType>() );
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.
@@ -107,10 +107,10 @@ void QgsLayerTreeFilterProxyModel::resetLayerTreeModel()
endResetModel();
}

void QgsLayerTreeFilterProxyModel::setMapLayerTypeFilter( const QList<QgsMapLayerType> &types )
void QgsLayerTreeFilterProxyModel::setFilters( const QgsMapLayerProxyModel::Filters &filters )
{
beginResetModel();
mLayerTypeFilter = types;
mFilters = filters;
endResetModel();
}

@@ -181,7 +181,7 @@ bool QgsLayerTreeFilterProxyModel::nodeShown( QgsLayerTreeNode *node ) const
return false;
if ( !mFilterText.isEmpty() && !layer->name().contains( mFilterText, Qt::CaseInsensitive ) )
return false;
if ( !mLayerTypeFilter.isEmpty() && !mLayerTypeFilter.contains( layer->type() ) )
if ( !QgsMapLayerProxyModel::layerMatchesFilters( layer, mFilters ) )
return false;

return layerShown( layer );
@@ -21,6 +21,7 @@

#include "qgis_core.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerproxymodel.h"

class QgsLayerTreeModel;
class QgsLayerTreeNode;
@@ -67,7 +68,7 @@ class CORE_EXPORT QgsLayerTreeFilterProxyModel : public QSortFilterProxyModel
* Defines the type layers (vector, raster, etc) shown in the tree
* If the list is empty, all types are shown.
*/
void setMapLayerTypeFilter( const QList<QgsMapLayerType> &types = QList<QgsMapLayerType>() );
void setFilters( const QgsMapLayerProxyModel::Filters &filters );

virtual int columnCount( const QModelIndex &parent ) const override;
virtual Qt::ItemFlags flags( const QModelIndex &idx ) const override;
@@ -106,7 +107,7 @@ class CORE_EXPORT QgsLayerTreeFilterProxyModel : public QSortFilterProxyModel
QgsLayerTreeModel *mLayerTreeModel = nullptr;
QList<QgsMapLayer *> mCheckedLayers;
QString mFilterText;
QList<QgsMapLayerType> mLayerTypeFilter;
QgsMapLayerProxyModel::Filters mFilters = QgsMapLayerProxyModel::All;
};

#endif // QGSLAYERTREEFILTERPROXYMODEL_H

0 comments on commit 558e0b6

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