From 0db134c8df946a4559a8e705a392836c01df15d5 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Mon, 28 Nov 2016 10:33:17 +0100 Subject: [PATCH] feat(components/chat): supports proxy --- tests/src/app/App.cpp | 1 + tests/src/components/chat/ChatModel.hpp | 2 +- tests/src/components/chat/ChatProxyModel.cpp | 14 ++++++++++---- tests/src/components/chat/ChatProxyModel.hpp | 12 +++++++++--- tests/ui/modules/Linphone/Chat/Chat.qml | 10 ++-------- tests/ui/views/App/MainWindow/Conversation.qml | 12 +++++++++++- 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/tests/src/app/App.cpp b/tests/src/app/App.cpp index 4362886a4..e02582734 100644 --- a/tests/src/app/App.cpp +++ b/tests/src/app/App.cpp @@ -78,6 +78,7 @@ void App::registerTypes () { qmlRegisterUncreatableType( "Linphone", 1, 0, "Presence", "Presence is uncreatable" ); + qRegisterMetaType("ChatModel::EntryType"); // Register Application/Core. qmlRegisterSingletonType( diff --git a/tests/src/components/chat/ChatModel.hpp b/tests/src/components/chat/ChatModel.hpp index 2bea6cd1b..edca10683 100644 --- a/tests/src/components/chat/ChatModel.hpp +++ b/tests/src/components/chat/ChatModel.hpp @@ -30,7 +30,7 @@ public: }; enum EntryType { - BaseEntry, + GenericEntry, MessageEntry, CallEntry }; diff --git a/tests/src/components/chat/ChatProxyModel.cpp b/tests/src/components/chat/ChatProxyModel.cpp index afeaa02ae..c33a8ae35 100644 --- a/tests/src/components/chat/ChatProxyModel.cpp +++ b/tests/src/components/chat/ChatProxyModel.cpp @@ -1,6 +1,5 @@ #include "ChatProxyModel.hpp" -#include // =================================================================== 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( index.data() ); - qDebug() << data["type"]; - - return true; // TODO. + return (data["type"].toInt() == m_entry_type_filter); } diff --git a/tests/src/components/chat/ChatProxyModel.hpp b/tests/src/components/chat/ChatProxyModel.hpp index 6ee61203d..78f3a46f9 100644 --- a/tests/src/components/chat/ChatProxyModel.hpp +++ b/tests/src/components/chat/ChatProxyModel.hpp @@ -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_ diff --git a/tests/ui/modules/Linphone/Chat/Chat.qml b/tests/ui/modules/Linphone/Chat/Chat.qml index 1a4aad23d..b923d4628 100644 --- a/tests/ui/modules/Linphone/Chat/Chat.qml +++ b/tests/ui/modules/Linphone/Chat/Chat.qml @@ -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 { diff --git a/tests/ui/views/App/MainWindow/Conversation.qml b/tests/ui/views/App/MainWindow/Conversation.qml index 6cc25ecea..45193fb50 100644 --- a/tests/ui/views/App/MainWindow/Conversation.qml +++ b/tests/ui/views/App/MainWindow/Conversation.qml @@ -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