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 ...@@ -8,22 +8,24 @@ RESOURCES = resources.qrc
SOURCES = \ SOURCES = \
src/app.cpp \ 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/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 = \ HEADERS = \
src/app.hpp \ src/app.hpp \
src/models/contacts/ContactModel.hpp \ src/components/contacts/ContactModel.hpp \
src/models/contacts/ContactsListModel.hpp \ src/components/contacts/ContactsListModel.hpp \
src/models/notification/NotificationModel.hpp \ src/components/contacts/ContactsListProxyModel.hpp \
src/models/settings/AccountSettingsListModel.hpp \ src/components/notification/Notification.hpp \
src/models/settings/AccountSettingsModel.hpp \ src/components/settings/AccountSettingsListModel.hpp \
src/models/settings/SettingsModel.hpp \ src/components/settings/AccountSettingsModel.hpp \
src/components/settings/SettingsModel.hpp \
TRANSLATIONS = \ TRANSLATIONS = \
languages/en.ts \ languages/en.ts \
......
...@@ -76,14 +76,14 @@ public: ...@@ -76,14 +76,14 @@ public:
m_sip_addresses = sip_addresses; m_sip_addresses = sip_addresses;
} }
signals:
void contactUpdated ();
private:
QString getUsername () const { QString getUsername () const {
return m_username; return m_username;
} }
signals:
void contactUpdated ();
private:
void setUsername (const QString &username) { void setUsername (const QString &username) {
m_username = 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 <QtDebug>
#include "NotificationModel.hpp" #include "Notification.hpp"
// =================================================================== // ===================================================================
NotificationModel::NotificationModel (QObject *parent) : Notification::Notification (QObject *parent) :
QObject(parent) { QObject(parent) {
} }
void NotificationModel::showMessage ( void Notification::showMessage (
const QString &summary, const QString &summary,
const QString &body, const QString &body,
const QString &icon, const QString &icon,
......
#ifndef NOTIFICATION_MODEL_H_ #ifndef NOTIFICATION_H_
#define NOTIFICATION_MODEL_H_ #define NOTIFICATION_H_
#include <QObject> #include <QObject>
// =================================================================== // ===================================================================
class NotificationModel : public QObject { class Notification : public QObject {
Q_OBJECT Q_OBJECT
public: public:
NotificationModel (QObject *parent = Q_NULLPTR); Notification (QObject *parent = Q_NULLPTR);
public slots: public slots:
void showMessage ( void showMessage (
...@@ -20,4 +20,4 @@ public slots: ...@@ -20,4 +20,4 @@ public slots:
); );
}; };
#endif // NOTIFICATION_MODEL_H_ #endif // NOTIFICATION_H_
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include <QtDebug> #include <QtDebug>
#include "app.hpp" #include "app.hpp"
#include "models/contacts/ContactsListModel.hpp" #include "components/contacts/ContactsListProxyModel.hpp"
#include "models/notification/NotificationModel.hpp" #include "components/notification/Notification.hpp"
// =================================================================== // ===================================================================
...@@ -56,8 +56,8 @@ void registerTypes () { ...@@ -56,8 +56,8 @@ void registerTypes () {
void addContextProperties (QQmlApplicationEngine &engine) { void addContextProperties (QQmlApplicationEngine &engine) {
QQmlContext *context = engine.rootContext(); QQmlContext *context = engine.rootContext();
context->setContextProperty("Notification", new NotificationModel()); context->setContextProperty("Notification", new Notification());
context->setContextProperty("ContactsList", new ContactsListModel()); context->setContextProperty("ContactsListModel", new ContactsListProxyModel());
} }
int main (int argc, char *argv[]) { 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 { ...@@ -31,6 +31,10 @@ ColumnLayout {
implicitHeight: 30 implicitHeight: 30
} }
placeholderText: qsTr('searchContactPlaceholder') placeholderText: qsTr('searchContactPlaceholder')
Component.onCompleted: ContactsListModel.setFilterRegExp('')
onTextChanged: ContactsListModel.setFilterRegExp(text)
} }
ExclusiveButtons { ExclusiveButtons {
...@@ -58,17 +62,19 @@ ColumnLayout { ...@@ -58,17 +62,19 @@ ColumnLayout {
anchors.fill: parent anchors.fill: parent
spacing: 2 spacing: 2
model: ContactsList model: ContactsListModel
delegate: Rectangle { delegate: Rectangle {
id: contact
color: '#FFFFFF' color: '#FFFFFF'
height: 50 height: 50
id: contact
width: parent.width width: parent.width
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
onEntered: contact.state = 'hover' onEntered: contact.state = 'hover'
onExited: contact.state = '' onExited: contact.state = ''
} }
...@@ -104,24 +110,21 @@ ColumnLayout { ...@@ -104,24 +110,21 @@ ColumnLayout {
} }
// Username. // Username.
Item { Text {
Layout.fillHeight: parent.height Layout.fillHeight: parent.height
Layout.fillWidth: true Layout.fillWidth: true
clip: true
Text { color: '#5A585B'
anchors.fill: parent font.bold: true
clip: true text: $contact.username
color: '#5A585B' verticalAlignment: Text.AlignVCenter
font.bold: true
text: $contact.username
verticalAlignment: Text.AlignVCenter
}
} }
// Actions. // Actions.
Row { Row {
Layout.fillHeight: true
id: actions id: actions
Layout.fillHeight: true
spacing: 50 spacing: 50
visible: false 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