selectionproxymodel.cpp

00001 /*
00002   Copyright (c) 2009 Stephen Kelly <steveire@gmail.com>
00003 
00004   This library is free software; you can redistribute it and/or modify it
00005   under the terms of the GNU Library General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or (at your
00007   option) any later version.
00008 
00009   This library is distributed in the hope that it will be useful, but WITHOUT
00010   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012   License for more details.
00013 
00014   You should have received a copy of the GNU Library General Public License
00015   along with this library; see the file COPYING.LIB.  If not, write to the
00016   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017   02110-1301, USA.
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     // newRootIndex is already in the sourceModel.
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 
KDE Home | KDE Accessibility Home | Description of Access Keys