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

feat(components/chat): supports proxy

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