Commit 0db134c8 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(components/chat): supports proxy

parent b97b823f
......@@ -78,6 +78,7 @@ void App::registerTypes () {
qmlRegisterUncreatableType<Presence>(
"Linphone", 1, 0, "Presence", "Presence is uncreatable"
);
qRegisterMetaType<ChatModel::EntryType>("ChatModel::EntryType");
// Register Application/Core.
qmlRegisterSingletonType<App>(
......
......@@ -30,7 +30,7 @@ public:
};
enum EntryType {
BaseEntry,
GenericEntry,
MessageEntry,
CallEntry
};
......
#include "ChatProxyModel.hpp"
#include <QtDebug>
// ===================================================================
ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
......@@ -9,13 +8,20 @@ ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent)
setFilterCaseSensitivity(Qt::CaseInsensitive);
}
void ChatProxyModel::removeEntry (int id) {
m_chat_model.removeEntry(
mapToSource(index(id, 0)).row()
);
}
bool ChatProxyModel::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const {
if (m_entry_type_filter == ChatModel::EntryType::GenericEntry)
return true;
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
const QVariantMap &data = qvariant_cast<QVariantMap>(
index.data()
);
qDebug() << data["type"];
return true; // TODO.
return (data["type"].toInt() == m_entry_type_filter);
}
......@@ -5,6 +5,8 @@
#include "ChatModel.hpp"
// ===================================================================
class ChatProxyModel : public QSortFilterProxyModel {
Q_OBJECT;
......@@ -22,12 +24,15 @@ public:
ChatProxyModel (QObject *parent = Q_NULLPTR);
public slots:
ChatModel *getChatModel () {
return &m_chat_model;
void removeEntry (int id);
void removeAllEntries () {
m_chat_model.removeAllEntries();
}
void setEntryTypeFilter (ChatModel::EntryType type) {
// TODO.
m_entry_type_filter = type;
invalidateFilter();
}
protected:
......@@ -43,6 +48,7 @@ private:
}
ChatModel m_chat_model;
ChatModel::EntryType m_entry_type_filter = ChatModel::EntryType::GenericEntry;
};
#endif // CHAT_PROXY_MODEL_H_
......@@ -12,7 +12,7 @@ ColumnLayout {
property var contact
// Can be a model or a proxy chat model.
property alias model: chat.model
property alias proxyModel: chat.model
// -----------------------------------------------------------------
......@@ -81,18 +81,12 @@ ColumnLayout {
delegate: Rectangle {
id: entry
// Chat supports model and proxy model.
function getModel () {
var model = chat.model
return model.getChatModel ? model.getChatModel() : model
}
function isHoverEntry () {
return mouseArea.containsMouse
}
function removeEntry () {
getModel().removeEntry(index)
proxyModel.removeEntry(index)
}
anchors {
......
......@@ -134,6 +134,16 @@ ColumnLayout {
qsTr('displayCalls'),
qsTr('displayMessages')
]
onClicked: {
if (button === 0) {
chatProxyModel.setEntryTypeFilter(ChatModel.GenericEntry)
} else if (button === 1) {
chatProxyModel.setEntryTypeFilter(ChatModel.CallEntry)
} else {
chatProxyModel.setEntryTypeFilter(ChatModel.MessageEntry)
}
}
}
}
......@@ -145,7 +155,7 @@ ColumnLayout {
Layout.fillHeight: true
Layout.fillWidth: true
contact: parent._contact
model: ChatProxyModel {
proxyModel: ChatProxyModel {
id: chatProxyModel
sipAddress: conversation.sipAddress
......
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