Commit cc3fff24 authored by Ronan Abhamon's avatar Ronan Abhamon

fix(ContactsListProxyModel): supports weight filter (use integer instead float to compare weight)

parent 8bf12ac5
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
#include "ContactsListProxyModel.hpp" #include "ContactsListProxyModel.hpp"
#define USERNAME_WEIGHT 0.5 #define USERNAME_WEIGHT 50.0
#define MAIN_SIP_ADDRESS_WEIGHT 0.3 #define MAIN_SIP_ADDRESS_WEIGHT 30.0
#define OTHER_SIP_ADDRESSES_WEIGHT 0.2 #define OTHER_SIP_ADDRESSES_WEIGHT 20.0
// =================================================================== // ===================================================================
...@@ -12,7 +12,6 @@ ContactsListModel *ContactsListProxyModel::m_list = nullptr; ...@@ -12,7 +12,6 @@ ContactsListModel *ContactsListProxyModel::m_list = nullptr;
ContactsListProxyModel::ContactsListProxyModel (QObject *parent) : QSortFilterProxyModel(parent) { ContactsListProxyModel::ContactsListProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
setSourceModel(m_list); setSourceModel(m_list);
setDynamicSortFilter(true);
setFilterCaseSensitivity(Qt::CaseInsensitive); setFilterCaseSensitivity(Qt::CaseInsensitive);
foreach (const ContactModel *contact, m_list->m_list) foreach (const ContactModel *contact, m_list->m_list)
...@@ -56,7 +55,7 @@ bool ContactsListProxyModel::lessThan (const QModelIndex &left, const QModelInde ...@@ -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; float weight = 0;
if (filterRegExp().indexIn(contact.m_username) != -1) if (filterRegExp().indexIn(contact.m_username) != -1)
...@@ -74,5 +73,5 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact) ...@@ -74,5 +73,5 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact)
if (filterRegExp().indexIn(*it) != -1) if (filterRegExp().indexIn(*it) != -1)
weight += OTHER_SIP_ADDRESSES_WEIGHT / size; weight += OTHER_SIP_ADDRESSES_WEIGHT / size;
return weight; return static_cast<int>(weight);
} }
...@@ -19,7 +19,7 @@ protected: ...@@ -19,7 +19,7 @@ protected:
bool lessThan (const QModelIndex &left, const QModelIndex &right) const; bool lessThan (const QModelIndex &left, const QModelIndex &right) const;
private: private:
float computeContactWeight (const ContactModel &contact) const; int computeContactWeight (const ContactModel &contact) const;
// The contacts list is shared between `ContactsListProxyModel` // The contacts list is shared between `ContactsListProxyModel`
// it's necessary to initialize it with `initContactsListModel`. // it's necessary to initialize it with `initContactsListModel`.
...@@ -27,7 +27,7 @@ private: ...@@ -27,7 +27,7 @@ private:
// It's just a cache to save values computed by `filterAcceptsRow` // It's just a cache to save values computed by `filterAcceptsRow`
// and reused by `lessThan`. // and reused by `lessThan`.
mutable QHash<const ContactModel *, float> m_weights; mutable QHash<const ContactModel *, int> m_weights;
}; };
#endif // CONTACTS_LIST_PROXY_MODEL_H #endif // CONTACTS_LIST_PROXY_MODEL_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment