mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-24 07:08:07 +00:00
feat(app): filter/sorter is provided for any instances
This commit is contained in:
parent
62f034dbb2
commit
cb598949e7
6 changed files with 49 additions and 22 deletions
|
|
@ -1,3 +1,14 @@
|
|||
#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;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,41 @@
|
|||
#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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue