akonadi
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 rootIndexAdded( rootIndex ); 00038 q->sourceModel()->fetchMore( rootIndex ); 00039 } 00040 } 00041 00045 void rootIndexAdded( const QModelIndex &newRootIndex ) 00046 { 00047 Q_Q( SelectionProxyModel ); 00048 // newRootIndex is already in the sourceModel. 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(QModelIndex)), SLOT(rootIndexAdded(QModelIndex)) ); 00072 connect( this, SIGNAL(rootIndexAboutToBeRemoved(QModelIndex)), SLOT(rootIndexAboutToBeRemoved(QModelIndex)) ); 00073 } 00074 00075 SelectionProxyModel::~SelectionProxyModel() 00076 { 00077 delete d_ptr; 00078 } 00079 00080 #include "selectionproxymodel.moc" 00081 00082
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:52:58 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:52:58 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.