00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "selectionproxymodel.h"
00021
00022 #include "entitytreemodel.h"
00023
00024 using namespace Akonadi;
00025
00026 namespace Akonadi
00027 {
00028
00029 class SelectionProxyModelPrivate
00030 {
00031 public:
00032 SelectionProxyModelPrivate( SelectionProxyModel *selectionProxyModel )
00033 : q_ptr( selectionProxyModel )
00034 {
00035 Q_Q( SelectionProxyModel );
00036 foreach ( const QModelIndex &rootIndex, q->sourceRootIndexes() ) {
00037 rootIndexAdded( rootIndex );
00038 q->sourceModel()->fetchMore( rootIndex );
00039 }
00040 }
00041
00045 void rootIndexAdded( const QModelIndex &newRootIndex )
00046 {
00047 Q_Q( SelectionProxyModel );
00048
00049 q->sourceModel()->setData( newRootIndex, QVariant(), EntityTreeModel::CollectionRefRole );
00050 q->sourceModel()->fetchMore( newRootIndex );
00051 }
00052
00056 void rootIndexAboutToBeRemoved( const QModelIndex &removedRootIndex )
00057 {
00058 Q_Q( SelectionProxyModel );
00059 q->sourceModel()->setData( removedRootIndex, QVariant(), EntityTreeModel::CollectionDerefRole );
00060 }
00061
00062 Q_DECLARE_PUBLIC( SelectionProxyModel )
00063 SelectionProxyModel *q_ptr;
00064 };
00065
00066 }
00067
00068 SelectionProxyModel::SelectionProxyModel( QItemSelectionModel *selectionModel, QObject *parent )
00069 : KSelectionProxyModel( selectionModel, parent ), d_ptr( new SelectionProxyModelPrivate( this ) )
00070 {
00071 connect( this, SIGNAL( rootIndexAdded( const QModelIndex& ) ), SLOT( rootIndexAdded( const QModelIndex& ) ) );
00072 connect( this, SIGNAL( rootIndexAboutToBeRemoved( const QModelIndex& ) ), SLOT( rootIndexAboutToBeRemoved( const QModelIndex& ) ) );
00073 }
00074
00075 #include "selectionproxymodel.moc"
00076
00077