diff --git a/tests/src/components/chat/ChatProxyModel.cpp b/tests/src/components/chat/ChatProxyModel.cpp index 0de300403..026a7899e 100644 --- a/tests/src/components/chat/ChatProxyModel.cpp +++ b/tests/src/components/chat/ChatProxyModel.cpp @@ -1,5 +1,7 @@ #include "ChatProxyModel.hpp" +// =================================================================== + ChatModelFilter::ChatModelFilter (QObject *parent) : QSortFilterProxyModel(parent) { setSourceModel(&m_chat_model); } @@ -30,7 +32,13 @@ ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent) } void ChatProxyModel::loadMoreEntries () { - // TODO. + int count = rowCount(); + m_n_max_displayed_entries += ENTRIES_CHUNK_SIZE; + + invalidateFilter(); + + if (count < rowCount()) + emit moreEntriesLoaded(); } void ChatProxyModel::removeEntry (int id) { diff --git a/tests/src/components/chat/ChatProxyModel.hpp b/tests/src/components/chat/ChatProxyModel.hpp index 4f3da2422..e936e35f0 100644 --- a/tests/src/components/chat/ChatProxyModel.hpp +++ b/tests/src/components/chat/ChatProxyModel.hpp @@ -9,7 +9,7 @@ // Fetch the L last filtered chat entries. // =================================================================== -// Cannot be used as a nested class by Qt and `Q_OBJECTY` macro +// Cannot be used as a nested class by Qt and `Q_OBJECT` macro // must be used in header c++ file. class ChatModelFilter : public QSortFilterProxyModel { friend class ChatProxyModel; @@ -42,6 +42,7 @@ class ChatProxyModel : public QSortFilterProxyModel { signals: void sipAddressChanged (const QString &sipAddress); + void moreEntriesLoaded (); public: ChatProxyModel (QObject *parent = Q_NULLPTR); diff --git a/tests/ui/modules/Linphone/Chat/Chat.qml b/tests/ui/modules/Linphone/Chat/Chat.qml index b0a50e0cf..7503d5a4f 100644 --- a/tests/ui/modules/Linphone/Chat/Chat.qml +++ b/tests/ui/modules/Linphone/Chat/Chat.qml @@ -14,6 +14,10 @@ ColumnLayout { // Can be a model or a proxy chat model. property alias proxyModel: chat.model + // Set the offset position to load more entries. + // Not a style property. + property int _loadMoreEntriesAtPosition: 1 + // ----------------------------------------------------------------- spacing: 0 @@ -21,16 +25,16 @@ ColumnLayout { ScrollableListView { id: chat - property bool _tryToLoadMoreEntries: false + property bool _tryToLoadMoreEntries: true function _loadMoreEntries () { - if (chat.contentY > 500 || _tryToLoadMoreEntries) { - return + if ( + chat.visibleArea.yPosition * chat.height <= _loadMoreEntriesAtPosition && + !_tryToLoadMoreEntries + ) { + _tryToLoadMoreEntries = true + proxyModel.loadMoreEntries() } - - _tryToLoadMoreEntries = true - - proxyModel.loadMoreEntries() } Layout.fillHeight: true @@ -178,6 +182,15 @@ ColumnLayout { } onContentYChanged: _loadMoreEntries() + + Component.onCompleted: { + positionViewAtEnd() + _tryToLoadMoreEntries = false + + proxyModel.moreEntriesLoaded.connect(function () { + _tryToLoadMoreEntries = false + }) + } } // -----------------------------------------------------------------