mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-04-28 11:56:20 +00:00
fix(ContactsListProxyModel): supports weight filter (use integer instead float to compare weight)
This commit is contained in:
parent
8bf12ac561
commit
cc3fff24d2
2 changed files with 7 additions and 8 deletions
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
#include "ContactsListProxyModel.hpp"
|
||||
|
||||
#define USERNAME_WEIGHT 0.5
|
||||
#define MAIN_SIP_ADDRESS_WEIGHT 0.3
|
||||
#define OTHER_SIP_ADDRESSES_WEIGHT 0.2
|
||||
#define USERNAME_WEIGHT 50.0
|
||||
#define MAIN_SIP_ADDRESS_WEIGHT 30.0
|
||||
#define OTHER_SIP_ADDRESSES_WEIGHT 20.0
|
||||
|
||||
// ===================================================================
|
||||
|
||||
|
|
@ -12,7 +12,6 @@ ContactsListModel *ContactsListProxyModel::m_list = nullptr;
|
|||
|
||||
ContactsListProxyModel::ContactsListProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
|
||||
setSourceModel(m_list);
|
||||
setDynamicSortFilter(true);
|
||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
foreach (const ContactModel *contact, m_list->m_list)
|
||||
|
|
@ -56,7 +55,7 @@ bool ContactsListProxyModel::lessThan (const QModelIndex &left, const QModelInde
|
|||
);
|
||||
}
|
||||
|
||||
float ContactsListProxyModel::computeContactWeight (const ContactModel &contact) const {
|
||||
int ContactsListProxyModel::computeContactWeight (const ContactModel &contact) const {
|
||||
float weight = 0;
|
||||
|
||||
if (filterRegExp().indexIn(contact.m_username) != -1)
|
||||
|
|
@ -74,5 +73,5 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact)
|
|||
if (filterRegExp().indexIn(*it) != -1)
|
||||
weight += OTHER_SIP_ADDRESSES_WEIGHT / size;
|
||||
|
||||
return weight;
|
||||
return static_cast<int>(weight);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ protected:
|
|||
bool lessThan (const QModelIndex &left, const QModelIndex &right) const;
|
||||
|
||||
private:
|
||||
float computeContactWeight (const ContactModel &contact) const;
|
||||
int computeContactWeight (const ContactModel &contact) const;
|
||||
|
||||
// The contacts list is shared between `ContactsListProxyModel`
|
||||
// it's necessary to initialize it with `initContactsListModel`.
|
||||
|
|
@ -27,7 +27,7 @@ private:
|
|||
|
||||
// It's just a cache to save values computed by `filterAcceptsRow`
|
||||
// and reused by `lessThan`.
|
||||
mutable QHash<const ContactModel *, float> m_weights;
|
||||
mutable QHash<const ContactModel *, int> m_weights;
|
||||
};
|
||||
|
||||
#endif // CONTACTS_LIST_PROXY_MODEL_H
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue