Commit cb598949 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): filter/sorter is provided for any instances

parent 62f034db
#include "ContactModel.hpp"
// ===================================================================
ContactModel::PresenceLevel ContactModel:: getPresenceLevel () const {
if (m_presence == Online)
return Green;
if (m_presence == DoNotDisturb)
return Red;
if (m_presence == Offline)
return White;
return Orange;
}
......@@ -100,16 +100,7 @@ private:
return m_presence;
}
PresenceLevel getPresenceLevel () const {
if (m_presence == Online)
return Green;
if (m_presence == DoNotDisturb)
return Red;
if (m_presence == Offline)
return White;
return Orange;
}
PresenceLevel getPresenceLevel () const;
QStringList getSipAddresses () const {
return m_sip_addresses;
......
#include "ContactsListProxyModel.hpp"
#include <QDebug>
#include "ContactsListProxyModel.hpp"
// ===================================================================
ContactsListModel *ContactsListProxyModel::m_list = nullptr;
ContactsListProxyModel::ContactsListProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
setSourceModel(m_list);
setDynamicSortFilter(true);
sort(0);
}
void ContactsListProxyModel::initContactsListModel (ContactsListModel *list) {
if (!m_list)
m_list = list;
else
qWarning() << "Contacts list model already defined.";
}
bool ContactsListProxyModel::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const {
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
const ContactModel *contact = qvariant_cast<ContactModel *>(
index.data(ContactsListModel::ContactRole)
);
qDebug() << "A";
return contact->getUsername().contains(
filterRegExp().pattern(),
Qt::CaseInsensitive
);
}
bool ContactsListProxyModel::lessThan (const QModelIndex &left, const QModelIndex &right) const {
qDebug() << "B";
return true;
}
......@@ -11,17 +11,15 @@ class ContactsListProxyModel : public QSortFilterProxyModel {
Q_OBJECT;
public:
ContactsListProxyModel (QObject *parent = Q_NULLPTR) : QSortFilterProxyModel(parent) {
setSourceModel(&m_list);
setDynamicSortFilter(true);
sort(0);
}
ContactsListProxyModel (QObject *parent = Q_NULLPTR);
static void initContactsListModel (ContactsListModel *list);
protected:
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
private:
ContactsListModel m_list;
static ContactsListModel *m_list;
};
#endif // CONTACTS_LIST_PROXY_MODEL_H
......@@ -51,6 +51,9 @@ void registerTypes () {
qmlRegisterUncreatableType<ContactModel>(
"Linphone", 1, 0, "ContactModel", "ContactModel is uncreatable"
);
ContactsListProxyModel::initContactsListModel(new ContactsListModel());
qmlRegisterType<ContactsListProxyModel>("Linphone", 1, 0, "ContactsListModel");
}
void addContextProperties (QQmlApplicationEngine &engine) {
......
......@@ -32,9 +32,7 @@ ColumnLayout {
}
placeholderText: qsTr('searchContactPlaceholder')
Component.onCompleted: ContactsListModel.setFilterRegExp('')
onTextChanged: ContactsListModel.setFilterRegExp(text)
onTextChanged: contacts.setFilterRegExp(text)
}
ExclusiveButtons {
......@@ -62,7 +60,9 @@ ColumnLayout {
anchors.fill: parent
spacing: 2
model: ContactsListModel
model: ContactsListModel {
id: contacts
}
delegate: Rectangle {
id: contact
......
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