Skip to content

Commit d06c4f8

Browse files
committed
Make QgsMapLayerProxyModel::exceptedLayers a property
1 parent 54219c5 commit d06c4f8

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

python/gui/qgsmaplayerproxymodel.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@ class QgsMapLayerProxyModel : QSortFilterProxyModel
4545

4646
//! offer the possibility to except some layers to be listed
4747
void setExceptedLayerList( const QList<QgsMapLayer*>& exceptList );
48+
//! Get the list of maplayers which are excluded from the list
4849
QList<QgsMapLayer*> exceptedLayerList();
4950

51+
//! Set the list of maplayer ids which are excluded from the list
52+
void setExceptedLayerIds( const QStringList& ids );
53+
//! Get the list of maplayer ids which are excluded from the list
54+
QStringList exceptedLayerIds() const;
55+
5056
// QSortFilterProxyModel interface
5157
public:
5258
bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const;

src/gui/qgsmaplayerproxymodel.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "qgsmaplayerproxymodel.h"
1717
#include "qgsmaplayermodel.h"
1818
#include "qgsmaplayer.h"
19+
#include "qgsmaplayerregistry.h"
1920
#include "qgsvectorlayer.h"
2021

2122
QgsMapLayerProxyModel::QgsMapLayerProxyModel( QObject *parent )
@@ -40,10 +41,36 @@ QgsMapLayerProxyModel *QgsMapLayerProxyModel::setFilters( const Filters& filters
4041

4142
void QgsMapLayerProxyModel::setExceptedLayerList( const QList<QgsMapLayer*>& exceptList )
4243
{
44+
if ( mExceptList == exceptList )
45+
return;
46+
4347
mExceptList = exceptList;
4448
invalidateFilter();
4549
}
4650

51+
void QgsMapLayerProxyModel::setExceptedLayerIds( const QStringList& ids )
52+
{
53+
mExceptList.clear();
54+
55+
Q_FOREACH ( const QString& id, ids )
56+
{
57+
QgsMapLayer* l = QgsMapLayerRegistry::instance()->mapLayer( id );
58+
if ( l )
59+
mExceptList << l;
60+
}
61+
invalidateFilter();
62+
}
63+
64+
QStringList QgsMapLayerProxyModel::exceptedLayerIds() const
65+
{
66+
QStringList lst;
67+
68+
Q_FOREACH ( QgsMapLayer* l, mExceptList )
69+
lst << l->id();
70+
71+
return lst;
72+
}
73+
4774
bool QgsMapLayerProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
4875
{
4976
if ( mFilters.testFlag( All ) && mExceptList.isEmpty() )

src/gui/qgsmaplayerproxymodel.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define QGSMAPLAYERPROXYMODEL_H
1818

1919
#include <QSortFilterProxyModel>
20+
#include <QStringList>
2021

2122
class QgsMapLayerModel;
2223
class QgsMapLayer;
@@ -31,6 +32,8 @@ class GUI_EXPORT QgsMapLayerProxyModel : public QSortFilterProxyModel
3132
Q_FLAGS( Filters )
3233

3334
Q_PROPERTY( QgsMapLayerProxyModel::Filters filters READ filters WRITE setFilters )
35+
Q_PROPERTY( QList<QgsMapLayer*> exceptedLayerList READ exceptedLayerList WRITE setExceptedLayerList )
36+
Q_PROPERTY( QStringList exceptedLayerIds READ exceptedLayerIds WRITE setExceptedLayerIds )
3437

3538
public:
3639
enum Filter
@@ -68,8 +71,14 @@ class GUI_EXPORT QgsMapLayerProxyModel : public QSortFilterProxyModel
6871

6972
//! offer the possibility to except some layers to be listed
7073
void setExceptedLayerList( const QList<QgsMapLayer*>& exceptList );
74+
//! Get the list of maplayers which are excluded from the list
7175
QList<QgsMapLayer*> exceptedLayerList() {return mExceptList;}
7276

77+
//! Set the list of maplayer ids which are excluded from the list
78+
void setExceptedLayerIds( const QStringList& ids );
79+
//! Get the list of maplayer ids which are excluded from the list
80+
QStringList exceptedLayerIds() const;
81+
7382
private:
7483
Filters mFilters;
7584
QList<QgsMapLayer*> mExceptList;

0 commit comments

Comments
 (0)