akonadi
subscriptionchangeproxymodel.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "subscriptionchangeproxymodel.h"
00021 #include "subscriptionmodel.h"
00022
00023 #include <kdebug.h>
00024 #include <klocale.h>
00025
00026 using namespace Akonadi;
00027
00031 class SubscriptionChangeProxyModel::Private
00032 {
00033 public:
00034 Qt::CheckState subscribed;
00035 };
00036
00037 SubscriptionChangeProxyModel::SubscriptionChangeProxyModel(bool subscribed, QObject * parent) :
00038 QSortFilterProxyModel( parent ),
00039 d( new Private )
00040 {
00041 d->subscribed = subscribed ? Qt::Checked : Qt::Unchecked;
00042 setDynamicSortFilter( true );
00043 }
00044
00045 SubscriptionChangeProxyModel::~ SubscriptionChangeProxyModel()
00046 {
00047 delete d;
00048 }
00049
00050 bool SubscriptionChangeProxyModel::filterAcceptsRow(int row, const QModelIndex & parent) const
00051 {
00052 QModelIndex index = sourceModel()->index( row, 0, parent );
00053 if ( !index.data( SubscriptionModel::SubscriptionChangedRole ).toBool() )
00054 return false;
00055 if ( index.data( Qt::CheckStateRole ) != d->subscribed )
00056 return false;
00057 return true;
00058 }
00059
00060 QVariant SubscriptionChangeProxyModel::data(const QModelIndex & index, int role) const
00061 {
00062 if ( role == Qt::CheckStateRole )
00063 return QVariant();
00064 return QSortFilterProxyModel::data( index, role );
00065 }
00066
00067 QVariant SubscriptionChangeProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
00068 {
00069 if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ) {
00070 if ( d->subscribed == Qt::Checked )
00071 return i18nc( "@title:column", "Subscribe To" );
00072 else
00073 return i18nc( "@title:column", "Unsubscribe From" );
00074 }
00075 return QSortFilterProxyModel::headerData( section, orientation, role );
00076 }
00077
00078 #include "subscriptionchangeproxymodel.moc"