mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-02-02 20:29:23 +00:00
- avoid the usage of a lot of singletons, use methods in `CoreManager` instead - create a `UnregisteredSipAddressesProxyModel` model - unstable
55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
#ifndef CONTACTS_LIST_PROXY_MODEL_H_
|
|
#define CONTACTS_LIST_PROXY_MODEL_H_
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include "../contact/ContactModel.hpp"
|
|
|
|
// =============================================================================
|
|
|
|
class ContactsListModel;
|
|
|
|
class ContactsListProxyModel : public QSortFilterProxyModel {
|
|
Q_OBJECT;
|
|
|
|
Q_PROPERTY(
|
|
bool useConnectedFilter
|
|
READ isConnectedFilterUsed
|
|
WRITE setConnectedFilter
|
|
);
|
|
|
|
public:
|
|
ContactsListProxyModel (QObject *parent = Q_NULLPTR);
|
|
~ContactsListProxyModel () = default;
|
|
|
|
public slots:
|
|
void setFilter (const QString &pattern) {
|
|
setFilterFixedString(pattern);
|
|
invalidateFilter();
|
|
}
|
|
|
|
protected:
|
|
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const override;
|
|
bool lessThan (const QModelIndex &left, const QModelIndex &right) const override;
|
|
|
|
private:
|
|
float computeStringWeight (const QString &string, float percentage) const;
|
|
float computeContactWeight (const ContactModel &contact) const;
|
|
|
|
bool isConnectedFilterUsed () const {
|
|
return m_use_connected_filter;
|
|
}
|
|
|
|
void setConnectedFilter (bool use_connected_filter);
|
|
|
|
ContactsListModel *m_list;
|
|
bool m_use_connected_filter = false;
|
|
|
|
// It's just a cache to save values computed by `filterAcceptsRow`
|
|
// and reused by `lessThan`.
|
|
mutable QHash<const ContactModel *, unsigned int> m_weights;
|
|
|
|
static const QRegExp m_search_separators;
|
|
};
|
|
|
|
#endif // CONTACTS_LIST_PROXY_MODEL_H_
|