Commit cb598949 authored by Ronan's avatar Ronan
Browse files

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

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