22 #include "entityrightsfiltermodel.h"
24 #include "entitytreemodel.h"
28 using namespace Akonadi;
35 class EntityRightsFilterModelPrivate
38 EntityRightsFilterModelPrivate( EntityRightsFilterModel *parent )
39 : q_ptr( parent ), mAccessRights( Collection::AllRights )
43 bool rightsMatches(
const QModelIndex &index )
const
45 if ( mAccessRights == Collection::AllRights || mAccessRights == Collection::ReadOnly )
48 const Collection collection = index.data( EntityTreeModel::CollectionRole ).value<Collection>();
49 if ( collection.isValid() ) {
50 return (mAccessRights & collection.rights());
52 const Item item = index.data( EntityTreeModel::ItemRole ).value<Item>();
53 if ( item.isValid() ) {
54 const Collection collection = index.data( EntityTreeModel::ParentCollectionRole ).value<Collection>();
55 return (mAccessRights & collection.rights());
62 Q_DECLARE_PUBLIC(EntityRightsFilterModel)
63 EntityRightsFilterModel *q_ptr;
65 Collection::Rights mAccessRights;
71 : KRecursiveFilterProxyModel( parent ),
72 d_ptr( new EntityRightsFilterModelPrivate( this ) )
76 EntityRightsFilterModel::~EntityRightsFilterModel()
81 void EntityRightsFilterModel::setAccessRights( Collection::Rights rights )
84 d->mAccessRights = rights;
88 Collection::Rights EntityRightsFilterModel::accessRights()
const
91 return d->mAccessRights;
94 bool EntityRightsFilterModel::acceptRow(
int sourceRow,
const QModelIndex &sourceParent)
const
98 const QModelIndex modelIndex = sourceModel()->index( sourceRow, 0, sourceParent );
100 return d->rightsMatches( modelIndex );
103 Qt::ItemFlags EntityRightsFilterModel::flags(
const QModelIndex &index )
const
107 if ( d->rightsMatches( index ) )
108 return KRecursiveFilterProxyModel::flags( index );
110 return KRecursiveFilterProxyModel::flags( index ) & ~(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
113 QModelIndexList EntityRightsFilterModel::match(
const QModelIndex& start,
int role,
const QVariant& value,
int hits, Qt::MatchFlags flags )
const
115 if ( role < Qt::UserRole )
116 return QSortFilterProxyModel::match( start, role, value, hits, flags );
118 QModelIndexList list;
119 QModelIndex proxyIndex;
120 foreach (
const QModelIndex &idx, sourceModel()->match( mapToSource( start ), role, value, hits, flags ) ) {
121 proxyIndex = mapFromSource( idx );
122 if ( proxyIndex.isValid() )
129 #include "entityrightsfiltermodel.moc"