akonadi/kabc
kabcmodel.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kabcmodel.h"
00021
00022 #include <kabc/addressee.h>
00023 #include <akonadi/item.h>
00024 #include <akonadi/itemfetchjob.h>
00025 #include <akonadi/itemfetchscope.h>
00026
00027 using namespace Akonadi;
00028
00029 class KABCModel::Private
00030 {
00031 public:
00032 };
00033
00034 KABCModel::KABCModel( QObject *parent )
00035 : Akonadi::ItemModel( parent ),
00036 d( new Private() )
00037 {
00038 fetchScope().fetchFullPayload();
00039 }
00040
00041 KABCModel::~KABCModel()
00042 {
00043 delete d;
00044 }
00045
00046 int KABCModel::columnCount( const QModelIndex& ) const
00047 {
00048 return 3;
00049 }
00050
00051 QVariant KABCModel::data( const QModelIndex &index, int role ) const
00052 {
00053 if ( role == ItemModel::IdRole )
00054 return ItemModel::data( index, role );
00055
00056 if ( role != Qt::DisplayRole )
00057 return QVariant();
00058
00059 if ( !index.isValid() )
00060 return QVariant();
00061
00062 if ( index.row() >= rowCount() )
00063 return QVariant();
00064
00065 const Item item = itemForIndex( index );
00066
00067 if ( !item.hasPayload<KABC::Addressee>() )
00068 return QVariant();
00069
00070 const KABC::Addressee addr = item.payload<KABC::Addressee>();
00071 switch ( index.column() ) {
00072 case 0:
00073 return addr.givenName();
00074 break;
00075 case 1:
00076 return addr.familyName();
00077 break;
00078 case 2:
00079 return addr.preferredEmail();
00080 break;
00081 default:
00082 break;
00083 }
00084
00085 return QVariant();
00086 }
00087
00088 QVariant KABCModel::headerData( int section, Qt::Orientation orientation, int role ) const
00089 {
00090 if ( role != Qt::DisplayRole )
00091 return QVariant();
00092
00093 if ( orientation != Qt::Horizontal )
00094 return QVariant();
00095
00096 switch ( section ) {
00097 case 0:
00098 return KABC::Addressee::givenNameLabel();
00099 break;
00100 case 1:
00101 return KABC::Addressee::familyNameLabel();
00102 break;
00103 case 2:
00104 return KABC::Addressee::emailLabel();
00105 break;
00106 default:
00107 break;
00108 }
00109
00110 return QVariant();
00111 }