Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make QgsMapLayerProxyModel::exceptedLayers a property
  • Loading branch information
m-kuhn committed Mar 29, 2016
1 parent 54219c5 commit d06c4f8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/gui/qgsmaplayerproxymodel.sip
Expand Up @@ -45,8 +45,14 @@ class QgsMapLayerProxyModel : QSortFilterProxyModel

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

//! Set the list of maplayer ids which are excluded from the list
void setExceptedLayerIds( const QStringList& ids );
//! Get the list of maplayer ids which are excluded from the list
QStringList exceptedLayerIds() const;

// QSortFilterProxyModel interface
public:
bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const;
Expand Down
27 changes: 27 additions & 0 deletions src/gui/qgsmaplayerproxymodel.cpp
Expand Up @@ -16,6 +16,7 @@
#include "qgsmaplayerproxymodel.h"
#include "qgsmaplayermodel.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"

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

void QgsMapLayerProxyModel::setExceptedLayerList( const QList<QgsMapLayer*>& exceptList )
{
if ( mExceptList == exceptList )
return;

mExceptList = exceptList;
invalidateFilter();
}

void QgsMapLayerProxyModel::setExceptedLayerIds( const QStringList& ids )
{
mExceptList.clear();

Q_FOREACH ( const QString& id, ids )
{
QgsMapLayer* l = QgsMapLayerRegistry::instance()->mapLayer( id );
if ( l )
mExceptList << l;
}
invalidateFilter();
}

QStringList QgsMapLayerProxyModel::exceptedLayerIds() const
{
QStringList lst;

Q_FOREACH ( QgsMapLayer* l, mExceptList )
lst << l->id();

return lst;
}

bool QgsMapLayerProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
{
if ( mFilters.testFlag( All ) && mExceptList.isEmpty() )
Expand Down
9 changes: 9 additions & 0 deletions src/gui/qgsmaplayerproxymodel.h
Expand Up @@ -17,6 +17,7 @@
#define QGSMAPLAYERPROXYMODEL_H

#include <QSortFilterProxyModel>
#include <QStringList>

class QgsMapLayerModel;
class QgsMapLayer;
Expand All @@ -31,6 +32,8 @@ class GUI_EXPORT QgsMapLayerProxyModel : public QSortFilterProxyModel
Q_FLAGS( Filters )

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

public:
enum Filter
Expand Down Expand Up @@ -68,8 +71,14 @@ class GUI_EXPORT QgsMapLayerProxyModel : public QSortFilterProxyModel

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

//! Set the list of maplayer ids which are excluded from the list
void setExceptedLayerIds( const QStringList& ids );
//! Get the list of maplayer ids which are excluded from the list
QStringList exceptedLayerIds() const;

private:
Filters mFilters;
QList<QgsMapLayer*> mExceptList;
Expand Down

0 comments on commit d06c4f8

Please sign in to comment.