Skip to content
Permalink
Browse files

Make QgsMapLayerProxyModel::exceptedLayers a property

  • Loading branch information
m-kuhn committed Mar 29, 2016
1 parent 54219c5 commit d06c4f8f31e404358014fb445fa9b79dde239cfe
Showing with 42 additions and 0 deletions.
  1. +6 −0 python/gui/qgsmaplayerproxymodel.sip
  2. +27 −0 src/gui/qgsmaplayerproxymodel.cpp
  3. +9 −0 src/gui/qgsmaplayerproxymodel.h
@@ -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;
@@ -16,6 +16,7 @@
#include "qgsmaplayerproxymodel.h"
#include "qgsmaplayermodel.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"

QgsMapLayerProxyModel::QgsMapLayerProxyModel( QObject *parent )
@@ -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() )
@@ -17,6 +17,7 @@
#define QGSMAPLAYERPROXYMODEL_H

#include <QSortFilterProxyModel>
#include <QStringList>

class QgsMapLayerModel;
class QgsMapLayer;
@@ -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
@@ -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;

0 comments on commit d06c4f8

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