Commit 62f034db authored by Ronan Abhamon's avatar Ronan Abhamon

feat(MainWindow/Contacts): use a proxy filter from c++ (in progress)

parent ba371b3f
......@@ -8,22 +8,24 @@ RESOURCES = resources.qrc
SOURCES = \
src/app.cpp \
src/components/contacts/ContactModel.cpp \
src/components/contacts/ContactsListModel.cpp \
src/components/contacts/ContactsListProxyModel.cpp \
src/components/notification/Notification.cpp \
src/components/settings/AccountSettingsListModel.cpp \
src/components/settings/AccountSettingsModel.cpp \
src/components/settings/SettingsModel.cpp \
src/main.cpp \
src/models/contacts/ContactModel.cpp \
src/models/contacts/ContactsListModel.cpp \
src/models/notification/NotificationModel.cpp \
src/models/settings/AccountSettingsListModel.cpp \
src/models/settings/AccountSettingsModel.cpp \
src/models/settings/SettingsModel.cpp \
HEADERS = \
src/app.hpp \
src/models/contacts/ContactModel.hpp \
src/models/contacts/ContactsListModel.hpp \
src/models/notification/NotificationModel.hpp \
src/models/settings/AccountSettingsListModel.hpp \
src/models/settings/AccountSettingsModel.hpp \
src/models/settings/SettingsModel.hpp \
src/components/contacts/ContactModel.hpp \
src/components/contacts/ContactsListModel.hpp \
src/components/contacts/ContactsListProxyModel.hpp \
src/components/notification/Notification.hpp \
src/components/settings/AccountSettingsListModel.hpp \
src/components/settings/AccountSettingsModel.hpp \
src/components/settings/SettingsModel.hpp \
TRANSLATIONS = \
languages/en.ts \
......
......@@ -76,14 +76,14 @@ public:
m_sip_addresses = sip_addresses;
}
signals:
void contactUpdated ();
private:
QString getUsername () const {
return m_username;
}
signals:
void contactUpdated ();
private:
void setUsername (const QString &username) {
m_username = username;
}
......
#include "ContactsListModel.hpp"
// ===================================================================
ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(parent) {
m_list << new ContactModel("Toto Roi", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Mary Boreno", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Cecelia Cyler", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Daniel Elliott", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Effie Forton", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Agnes Hurner", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Luke Lemin", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Olga Manning", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Isabella Ahornton", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Mary Boreno", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
}
int ContactsListModel::rowCount (const QModelIndex &) const {
return m_list.count();
}
QHash<int, QByteArray> ContactsListModel::roleNames () const {
QHash<int, QByteArray> roles;
roles[ContactRole] = "$contact";
return roles;
}
QVariant ContactsListModel::data (const QModelIndex &index, int role) const {
int row = index.row();
if (row < 0 || row >= m_list.count())
return QVariant();
if (role == ContactRole)
return QVariant::fromValue(m_list[row]);
return QVariant();
}
#ifndef CONTACTS_LIST_MODEL_H
#define CONTACTS_LIST_MODEL_H
#include <QAbstractListModel>
#include "ContactModel.hpp"
// ===================================================================
class ContactsListModel : public QAbstractListModel {
Q_OBJECT;
public:
enum Roles {
ContactRole = Qt::UserRole + 1
};
ContactsListModel (QObject *parent = Q_NULLPTR);
int rowCount (const QModelIndex &) const;
QHash<int, QByteArray> roleNames () const;
QVariant data (const QModelIndex &index, int role) const;
private:
QList<ContactModel *> m_list;
};
#endif // CONTACTS_LIST_MODEL_H
#include "ContactsListProxyModel.hpp"
#include <QDebug>
// ===================================================================
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)
);
return contact->getUsername().contains(
filterRegExp().pattern(),
Qt::CaseInsensitive
);
}
#ifndef CONTACTS_LIST_PROXY_MODEL_H
#define CONTACTS_LIST_PROXY_MODEL_H
#include <QSortFilterProxyModel>
#include "ContactsListModel.hpp"
// ===================================================================
class ContactsListProxyModel : public QSortFilterProxyModel {
Q_OBJECT;
public:
ContactsListProxyModel (QObject *parent = Q_NULLPTR) : QSortFilterProxyModel(parent) {
setSourceModel(&m_list);
setDynamicSortFilter(true);
sort(0);
}
protected:
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const;
private:
ContactsListModel m_list;
};
#endif // CONTACTS_LIST_PROXY_MODEL_H
#include <QtDebug>
#include "NotificationModel.hpp"
#include "Notification.hpp"
// ===================================================================
NotificationModel::NotificationModel (QObject *parent) :
Notification::Notification (QObject *parent) :
QObject(parent) {
}
void NotificationModel::showMessage (
void Notification::showMessage (
const QString &summary,
const QString &body,
const QString &icon,
......
#ifndef NOTIFICATION_MODEL_H_
#define NOTIFICATION_MODEL_H_
#ifndef NOTIFICATION_H_
#define NOTIFICATION_H_
#include <QObject>
// ===================================================================
class NotificationModel : public QObject {
class Notification : public QObject {
Q_OBJECT
public:
NotificationModel (QObject *parent = Q_NULLPTR);
Notification (QObject *parent = Q_NULLPTR);
public slots:
void showMessage (
......@@ -20,4 +20,4 @@ public slots:
);
};
#endif // NOTIFICATION_MODEL_H_
#endif // NOTIFICATION_H_
......@@ -9,8 +9,8 @@
#include <QtDebug>
#include "app.hpp"
#include "models/contacts/ContactsListModel.hpp"
#include "models/notification/NotificationModel.hpp"
#include "components/contacts/ContactsListProxyModel.hpp"
#include "components/notification/Notification.hpp"
// ===================================================================
......@@ -56,8 +56,8 @@ void registerTypes () {
void addContextProperties (QQmlApplicationEngine &engine) {
QQmlContext *context = engine.rootContext();
context->setContextProperty("Notification", new NotificationModel());
context->setContextProperty("ContactsList", new ContactsListModel());
context->setContextProperty("Notification", new Notification());
context->setContextProperty("ContactsListModel", new ContactsListProxyModel());
}
int main (int argc, char *argv[]) {
......
#include "ContactsListModel.hpp"
// ===================================================================
#ifndef CONTACTS_LIST_MODEL_H
#define CONTACTS_LIST_MODEL_H
#include <QAbstractListModel>
#include "ContactModel.hpp"
// ===================================================================
class ContactsListModel : public QAbstractListModel {
Q_OBJECT
public:
enum Roles {
ContactRole = Qt::UserRole + 1
};
ContactsListModel (QObject *parent = Q_NULLPTR): QAbstractListModel(parent) {
m_list << new ContactModel("Toto Roi", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Mary Boreno", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Cecelia Cyler", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Daniel Elliott", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Effie Forton", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Agnes Hurner", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Luke Lemin", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Olga Manning", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Isabella Ahornton", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
m_list << new ContactModel("Mary Boreno", "", ContactModel::Online, QStringList("toto.linphone.sip.linphone.org"));
}
int rowCount (const QModelIndex &) const {
return m_list.count();
}
QHash<int, QByteArray> roleNames () const {
QHash<int, QByteArray> roles;
roles[ContactRole] = "$contact";
return roles;
}
QVariant data (const QModelIndex &index, int role) const {
if (index.row() < 0 || index.row() >= m_list.count())
return QVariant();
if (role == ContactRole)
return QVariant::fromValue(m_list[index.row()]);
return QVariant();
}
private:
QList<ContactModel *> m_list;
};
#endif // CONTACTS_LIST_MODEL_H
......@@ -31,6 +31,10 @@ ColumnLayout {
implicitHeight: 30
}
placeholderText: qsTr('searchContactPlaceholder')
Component.onCompleted: ContactsListModel.setFilterRegExp('')
onTextChanged: ContactsListModel.setFilterRegExp(text)
}
ExclusiveButtons {
......@@ -58,17 +62,19 @@ ColumnLayout {
anchors.fill: parent
spacing: 2
model: ContactsList
model: ContactsListModel
delegate: Rectangle {
id: contact
color: '#FFFFFF'
height: 50
id: contact
width: parent.width
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: contact.state = 'hover'
onExited: contact.state = ''
}
......@@ -104,24 +110,21 @@ ColumnLayout {
}
// Username.
Item {
Text {
Layout.fillHeight: parent.height
Layout.fillWidth: true
Text {
anchors.fill: parent
clip: true
color: '#5A585B'
font.bold: true
text: $contact.username
verticalAlignment: Text.AlignVCenter
}
clip: true
color: '#5A585B'
font.bold: true
text: $contact.username
verticalAlignment: Text.AlignVCenter
}
// Actions.
Row {
Layout.fillHeight: true
id: actions
Layout.fillHeight: true
spacing: 50
visible: false
......
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