32
33
ContactsModelPrivate(ContactsModel *model)
35
m_collectionHeaders << "Collection" << "Count";
36
m_itemHeaders << "Given Name" << "Family Name" << "Email";
36
m_collectionHeaders << QLatin1String( "Collection" ) << QLatin1String( "Count" );
37
m_itemHeaders << QLatin1String( "Given Name" ) << QLatin1String( "Family Name" ) << QLatin1String( "Email" );
39
40
Q_DECLARE_PUBLIC(ContactsModel)
47
ContactsModel::ContactsModel(Session *session, Monitor *monitor, QObject *parent)
49
bool ContactsModel::entityMatch(Item item, const QVariant& matchData, Qt::MatchFlags flags) const
52
if (!item.hasPayload<KABC::Addressee>())
55
if (!matchData.canConvert(QVariant::String))
58
const QString matchString = matchData.toString();
60
const KABC::Addressee addressee = item.payload<KABC::Addressee>();
62
if ( addressee.familyName().startsWith(matchString, Qt::CaseInsensitive)
63
|| addressee.givenName().startsWith(matchString, Qt::CaseInsensitive)
64
|| addressee.preferredEmail().startsWith(matchString, Qt::CaseInsensitive))
68
if (item.hasAttribute<EntityDisplayAttribute>() &&
69
!item.attribute<EntityDisplayAttribute>()->displayName().isEmpty() )
71
if (item.attribute<EntityDisplayAttribute>()->displayName().startsWith(matchString))
79
bool ContactsModel::entityMatch(Collection col, const QVariant& matchData, Qt::MatchFlags flags) const
82
if (!matchData.canConvert(QVariant::String))
85
const QString matchString = matchData.toString();
87
if (col.hasAttribute<EntityDisplayAttribute>() &&
88
!col.attribute<EntityDisplayAttribute>()->displayName().isEmpty() )
89
return col.attribute<EntityDisplayAttribute>()->displayName().startsWith(matchString);
90
return col.name().startsWith(matchString);
94
ContactsModel::ContactsModel(Session *session, ChangeRecorder *monitor, QObject *parent)
48
95
: EntityTreeModel(session, monitor, parent), d_ptr(new ContactsModelPrivate(this))
58
QVariant ContactsModel::getData(const Item &item, int column, int role) const
105
QVariant ContactsModel::entityData(const Item &item, int column, int role) const
60
if ( item.mimeType() == "text/directory" )
107
if ( item.mimeType() == QLatin1String( "text/directory" ) )
62
109
if ( !item.hasPayload<KABC::Addressee>() )
78
125
return addr.familyName();
80
127
return addr.preferredEmail();
82
return addr.givenName() + " " + addr.familyName() + " " + "<" + addr.preferredEmail() + ">";
86
return EntityTreeModel::getData(item, column, role);
131
return EntityTreeModel::entityData(item, column, role);
89
QVariant ContactsModel::getData(const Collection &collection, int column, int role) const
134
QVariant ContactsModel::entityData(const Collection &collection, int column, int role) const
91
136
if (role == Qt::DisplayRole)
96
return EntityTreeModel::getData(collection, column, role);
141
return EntityTreeModel::entityData(collection, column, role);
98
return rowCount(EntityTreeModel::indexForCollection(collection));
144
QModelIndexList indexList = match( QModelIndex(), collection.id(), EntityTreeModel::CollectionIdRole );
145
Q_ASSERT( indexList.size() == 1 );
146
return rowCount(indexList.at( 0 ) );
100
149
// Return a QString to pass modeltest.
101
150
return QString();
102
151
// return QVariant();
105
return EntityTreeModel::getData(collection, column, role);
154
return EntityTreeModel::entityData(collection, column, role);
108
157
int ContactsModel::columnCount(const QModelIndex &index) const
114
QVariant ContactsModel::getHeaderData( int section, Qt::Orientation orientation, int role, int headerSet ) const
163
QVariant ContactsModel::entityHeaderData( int section, Qt::Orientation orientation, int role, HeaderGroup headerGroup ) const
116
165
Q_D(const ContactsModel);
118
167
if (orientation == Qt::Horizontal)
120
if ( headerSet == EntityTreeModel::CollectionTreeHeaders )
169
if ( headerGroup == EntityTreeModel::CollectionTreeHeaders )
122
171
if (role == Qt::DisplayRole)
139
return EntityTreeModel::getHeaderData(section, orientation, role, headerSet);
188
return EntityTreeModel::entityHeaderData(section, orientation, role, headerGroup);
142
191
#include "contactsmodel.moc"