Skip to content
Snippets Groups Projects
Commit 5fa1ad22 authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

[ #54559 ] Improve Contact view filtering

parent 086b14b1
No related branches found
No related tags found
No related merge requests found
......@@ -49,6 +49,11 @@ public:
AbstractContactBackend* m_pBackend ;
bool m_isPlaceHolder ;
//Cache
QString m_CachedFilterString;
QString filterString();
//Helper code to help handle multiple parents
QList<Contact*> m_lParents;
......@@ -61,8 +66,29 @@ public:
void phoneNumberCountAboutToChange(int,int);
};
QString ContactPrivate::filterString()
{
if (m_CachedFilterString.size())
return m_CachedFilterString;
//Also filter by phone numbers, accents are negligible
foreach(const PhoneNumber* n , m_Numbers) {
m_CachedFilterString += n->uri();
}
//Strip non essential characters like accents from the filter string
foreach(const QChar& char2,QString(m_FormattedName+'\n'+m_Organization+'\n'+m_Group+'\n'+
m_Department+'\n'+m_PreferredEmail).toLower().normalized(QString::NormalizationForm_KD) ) {
if (!char2.combiningClass())
m_CachedFilterString += char2;
}
return m_CachedFilterString;
}
void ContactPrivate::changed()
{
m_CachedFilterString.clear();
foreach (Contact* c,m_lParents) {
emit c->changed();
}
......@@ -352,6 +378,12 @@ time_t Contact::PhoneNumbers::lastUsedTimeStamp() const
return t;
}
///Recomputing the filter string is heavy, cache it
QString Contact::filterString() const
{
return d->filterString();
}
///Callback when one of the phone number presence change
void Contact::slotPresenceChanged()
{
......
......@@ -107,6 +107,9 @@ public:
const QString& department () const;
bool isActive () const;
//Cache
QString filterString () const;
//Number related getters (proxies)
bool isPresent () const;
bool isTracked () const;
......
......@@ -275,16 +275,8 @@ QVariant ContactProxyModel::data( const QModelIndex& index, int role) const
return c->isActive();
case ContactModel::Role::DatedLastUsed:
return QVariant(QDateTime::fromTime_t( c->phoneNumbers().lastUsedTimeStamp()));
case ContactModel::Role::Filter: {
//Strip non essential characters like accents from the filter string
QString normStripppedC;
foreach(QChar char2,QString(c->formattedName()+'\n'+c->organization()+'\n'+c->group()+'\n'+
c->department()+'\n'+c->preferredEmail()).toLower().normalized(QString::NormalizationForm_KD) ) {
if (!char2.combiningClass())
normStripppedC += char2;
}
return normStripppedC;
}
case ContactModel::Role::Filter:
return c->filterString();
default:
break;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment