From 581eb69cd029a12af5ec8ffd2d5346fd51a26169 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 12 Jan 2017 15:29:33 +0100 Subject: [PATCH] feat(app): many changes: - display correctly selected chat in timeline - fix weight computation in `ContactsListProxyModel` - `SmartConnect` supports unlimited handlers --- tests/src/components/chat/ChatModel.cpp | 2 +- .../contacts/ContactsListProxyModel.cpp | 4 +- tests/ui/modules/Common/SmartConnect.qml | 21 ++++++--- tests/ui/modules/Linphone/Timeline.qml | 45 ++++++++++++++----- 4 files changed, 53 insertions(+), 19 deletions(-) diff --git a/tests/src/components/chat/ChatModel.cpp b/tests/src/components/chat/ChatModel.cpp index 937778d85..7fb3cc2e1 100644 --- a/tests/src/components/chat/ChatModel.cpp +++ b/tests/src/components/chat/ChatModel.cpp @@ -128,7 +128,7 @@ bool ChatModel::removeRow (int row, const QModelIndex &) { bool ChatModel::removeRows (int row, int count, const QModelIndex &parent) { int limit = row + count - 1; - if (!parent.isValid() || row < 0 || count < 0 || limit >= m_entries.count()) + if (row < 0 || count < 0 || limit >= m_entries.count()) return false; beginRemoveRows(parent, row, limit); diff --git a/tests/src/components/contacts/ContactsListProxyModel.cpp b/tests/src/components/contacts/ContactsListProxyModel.cpp index 0e42679a2..2b6a4322f 100644 --- a/tests/src/components/contacts/ContactsListProxyModel.cpp +++ b/tests/src/components/contacts/ContactsListProxyModel.cpp @@ -1,5 +1,7 @@ #include +#include + #include "../../utils.hpp" #include "../core/CoreManager.hpp" @@ -52,7 +54,7 @@ bool ContactsListProxyModel::filterAcceptsRow ( const QModelIndex &index = sourceModel()->index(source_row, 0, source_parent); const ContactModel *contact = index.data().value(); - m_weights[contact] = static_cast(computeContactWeight(*contact)); + m_weights[contact] = static_cast(round(computeContactWeight(*contact))); return m_weights[contact] > 0 && ( !m_use_connected_filter || diff --git a/tests/ui/modules/Common/SmartConnect.qml b/tests/ui/modules/Common/SmartConnect.qml index 94d4bab5a..b6f2d3049 100644 --- a/tests/ui/modules/Common/SmartConnect.qml +++ b/tests/ui/modules/Common/SmartConnect.qml @@ -5,16 +5,23 @@ import Utils 1.0 // ============================================================================= Item { - property bool _connected: false + property var handlers: ({}) function connect (emitter, signalName, handler) { - Utils.assert(!_connected, 'SmartConnect is already connected!') - emitter[signalName].connect(handler) - _connected = true - Component.onDestruction.connect(function () { - emitter[signalName].disconnect(handler) - }) + if (!handlers[signalName]) { + handlers[signalName] = [] + } + + handlers[signalName].push([emitter, handler]) + } + + Component.onDestruction: { + for (var signalName in handlers) { + handlers[signalName].forEach(function (value) { + value[0][signalName].disconnect(value[1]) + }) + } } } diff --git a/tests/ui/modules/Linphone/Timeline.qml b/tests/ui/modules/Linphone/Timeline.qml index 5cdf09fb5..a5e5678c1 100644 --- a/tests/ui/modules/Linphone/Timeline.qml +++ b/tests/ui/modules/Linphone/Timeline.qml @@ -27,9 +27,10 @@ ColumnLayout { var n = model.rowCount() for (var i = 0; i < n; i++) { + _selectedSipAddress = sipAddress + if (sipAddress === model.data(model.index(i, 0)).sipAddress) { view.currentIndex = i - _selectedSipAddress = sipAddress return } } @@ -45,15 +46,39 @@ ColumnLayout { spacing: 0 SmartConnect { - Component.onCompleted: this.connect(model, 'dataChanged', function () { - var index = view.currentIndex - if ( - index !== -1 && - _selectedSipAddress !== model.data(model.index(index, 0)).sipAddress - ) { - setSelectedEntry(_selectedSipAddress) - } - }) + Component.onCompleted: { + // Handle if current entry was moved in timeline. + this.connect(model, 'dataChanged', function () { + var index = view.currentIndex + if ( + index !== -1 && + _selectedSipAddress !== model.data(model.index(index, 0)).sipAddress + ) { + setSelectedEntry(_selectedSipAddress) + } + }) + + // A timeline entry is removed from timeline if there is no history entry. + this.connect(model, 'rowsAboutToBeRemoved', function (_, first, last) { + var index = view.currentIndex + if (index >= first && index <= last) { + view.currentIndex = -1 + } + }) + + // A entry is added when history is created. + this.connect(model, 'rowsInserted', function (_, first, last) { + if (_selectedSipAddress.length === 0) { + return + } + + for (var i = first; i <= last; i++) { + if (_selectedSipAddress === model.data(model.index(i, 0)).sipAddress) { + view.currentIndex = i + } + } + }) + } } // ---------------------------------------------------------------------------