akonadi
selectionproxymodel.cpp
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 {
00038 rootIndexAdded( rootIndex );
00039 q->sourceModel()->fetchMore( rootIndex );
00040 }
00041 }
00042
00046 void rootIndexAdded( const QModelIndex &newRootIndex )
00047 {
00048 Q_Q( SelectionProxyModel );
00049
00050 q->sourceModel()->setData( newRootIndex, QVariant(), EntityTreeModel::CollectionRefRole );
00051 q->sourceModel()->fetchMore( newRootIndex );
00052 }
00053
00057 void rootIndexAboutToBeRemoved( const QModelIndex &removedRootIndex )
00058 {
00059 Q_Q( SelectionProxyModel );
00060 q->sourceModel()->setData( removedRootIndex, QVariant(), EntityTreeModel::CollectionDerefRole );
00061 }
00062
00063 Q_DECLARE_PUBLIC( SelectionProxyModel )
00064 SelectionProxyModel *q_ptr;
00065 };
00066
00067 }
00068
00069 SelectionProxyModel::SelectionProxyModel( QItemSelectionModel *selectionModel, QObject *parent )
00070 : KSelectionProxyModel( selectionModel, parent ), d_ptr( new SelectionProxyModelPrivate( this ) )
00071 {
00072 connect( this, SIGNAL(rootIndexAdded(const QModelIndex &)), SLOT(rootIndexAdded(const QModelIndex &)));
00073 connect( this, SIGNAL(rootIndexAboutToBeRemoved(const QModelIndex &)), SLOT(rootIndexAboutToBeRemoved(const QModelIndex &)));
00074 }
00075
00076 #include "selectionproxymodel.moc"
00077
00078