Update SortFilterProxyModel and fix #92.

This commit is contained in:
Black Hat 2018-10-18 12:46:45 +08:00
parent 7af8ce9920
commit db59d035a9
4 changed files with 48 additions and 60 deletions

View File

@ -21,7 +21,6 @@ Rectangle {
roomContextMenu.popup()
}
onPrimaryClicked: {
listView.currentIndex = index
if (category === RoomType.Invited) {
inviteDialog.currentRoom = currentRoom
inviteDialog.open()

View File

@ -4,7 +4,14 @@ import QtQuick.Controls 2.2
import SortFilterProxyModel 0.2
RoomListPanelForm {
sortedRoomListModel.proxyRoles: ExpressionRole {
model: sortedRoomListModel
SortFilterProxyModel {
id: sortedRoomListModel
sourceModel: listModel
proxyRoles: ExpressionRole {
name: "display"
expression: {
switch (category) {
@ -17,6 +24,35 @@ RoomListPanelForm {
}
}
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 {
sequence: StandardKey.Find
onActivated: searchField.forceActiveFocus()

View File

@ -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 {}

@ -1 +1 @@
Subproject commit 1efea2b6003dcc23e0b0d9787cbdef2cf557636d
Subproject commit c558ef25f6d7f05cb6c4b2afdd8b0a2783288322