From db59d035a9c08ee520ebd041498c6e00dbb1af45 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Thu, 18 Oct 2018 12:46:45 +0800 Subject: [PATCH] Update SortFilterProxyModel and fix #92. --- imports/Spectral/Panel/RoomListDelegate.qml | 1 - imports/Spectral/Panel/RoomListPanel.qml | 54 +++++++++++++++---- .../Spectral/Panel/RoomListPanelForm.ui.qml | 51 +----------------- include/SortFilterProxyModel | 2 +- 4 files changed, 48 insertions(+), 60 deletions(-) diff --git a/imports/Spectral/Panel/RoomListDelegate.qml b/imports/Spectral/Panel/RoomListDelegate.qml index 3a1c93c..00177cf 100644 --- a/imports/Spectral/Panel/RoomListDelegate.qml +++ b/imports/Spectral/Panel/RoomListDelegate.qml @@ -21,7 +21,6 @@ Rectangle { roomContextMenu.popup() } onPrimaryClicked: { - listView.currentIndex = index if (category === RoomType.Invited) { inviteDialog.currentRoom = currentRoom inviteDialog.open() diff --git a/imports/Spectral/Panel/RoomListPanel.qml b/imports/Spectral/Panel/RoomListPanel.qml index d89313a..6472f4a 100644 --- a/imports/Spectral/Panel/RoomListPanel.qml +++ b/imports/Spectral/Panel/RoomListPanel.qml @@ -4,17 +4,53 @@ import QtQuick.Controls 2.2 import SortFilterProxyModel 0.2 RoomListPanelForm { - sortedRoomListModel.proxyRoles: ExpressionRole { - name: "display" - expression: { - switch (category) { - case 1: return "Invited" - case 2: return "Favorites" - case 3: return "Rooms" - case 4: return "People" - case 5: return "Low Priority" + model: sortedRoomListModel + + SortFilterProxyModel { + id: sortedRoomListModel + + sourceModel: listModel + + proxyRoles: ExpressionRole { + name: "display" + expression: { + switch (category) { + case 1: return "Invited" + case 2: return "Favorites" + case 3: return "Rooms" + case 4: return "People" + case 5: return "Low Priority" + } } } + + sorters: [ + RoleSorter { roleName: "category" }, + RoleSorter { + roleName: "lastActiveTime" + sortOrder: Qt.DescendingOrder + } + ] + + filters: [ + RegExpFilter { + roleName: "name" + pattern: searchField.text + caseSensitivity: Qt.CaseInsensitive + }, + ExpressionFilter { + enabled: filter === 1 + expression: unreadCount > 0 + }, + ExpressionFilter { + enabled: filter === 2 + expression: category === 1 || category === 2 || category === 4 + }, + ExpressionFilter { + enabled: filter === 3 + expression: category === 3 || category === 5 + } + ] } Shortcut { diff --git a/imports/Spectral/Panel/RoomListPanelForm.ui.qml b/imports/Spectral/Panel/RoomListPanelForm.ui.qml index a7a2767..2ae9444 100644 --- a/imports/Spectral/Panel/RoomListPanelForm.ui.qml +++ b/imports/Spectral/Panel/RoomListPanelForm.ui.qml @@ -16,12 +16,12 @@ import SortFilterProxyModel 0.2 import "qrc:/js/util.js" as Util Rectangle { - property alias listModel: sortedRoomListModel.sourceModel + property var listModel property int filter: 0 property var enteredRoom: null property alias searchField: searchField - property alias sortedRoomListModel: sortedRoomListModel + property alias model: listView.model color: MSettings.darkTheme ? "#323232" : "#f3f3f3" @@ -56,44 +56,6 @@ Rectangle { } } - SortFilterProxyModel { - id: sortedRoomListModel - - sorters: [ - RoleSorter { roleName: "category" }, - RoleSorter { - roleName: "lastActiveTime" - sortOrder: Qt.DescendingOrder - } - ] - } - - SortFilterProxyModel { - id: roomListProxyModel - - sourceModel: sortedRoomListModel - - filters: [ - RegExpFilter { - roleName: "name" - pattern: searchField.text - caseSensitivity: Qt.CaseInsensitive - }, - ExpressionFilter { - enabled: filter === 1 - expression: unreadCount > 0 - }, - ExpressionFilter { - enabled: filter === 2 - expression: category === 1 || category === 2 || category === 4 - }, - ExpressionFilter { - enabled: filter === 3 - expression: category === 3 || category === 5 - } - ] - } - AutoListView { Layout.fillWidth: true Layout.fillHeight: true @@ -103,15 +65,6 @@ Rectangle { spacing: 1 clip: true - model: roomListProxyModel - - currentIndex: -1 - - highlightFollowsCurrentItem: true - - highlightMoveDuration: 200 - highlightResizeDuration: 0 - boundsBehavior: Flickable.DragOverBounds ScrollBar.vertical: ScrollBar {} diff --git a/include/SortFilterProxyModel b/include/SortFilterProxyModel index 1efea2b..c558ef2 160000 --- a/include/SortFilterProxyModel +++ b/include/SortFilterProxyModel @@ -1 +1 @@ -Subproject commit 1efea2b6003dcc23e0b0d9787cbdef2cf557636d +Subproject commit c558ef25f6d7f05cb6c4b2afdd8b0a2783288322