Add dedicated HStringFilterModel component

This commit is contained in:
miruka 2020-05-01 00:27:02 -04:00
parent 69a525d317
commit 7418f0fe93
3 changed files with 24 additions and 14 deletions

View File

@ -0,0 +1,15 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import QtQml.Models 2.12
HFilterModel {
model: sourceModel
acceptItem: item => utils.filterMatches(filter, item[field])
onFilterChanged: refilterAll()
property string field: "id"
property string filter: ""
property ListModel sourceModel
}

View File

@ -8,14 +8,14 @@ import "../Base"
HListView { HListView {
id: roomList id: roomList
model: HFilterModel { model: HStringFilterModel {
model: ModelStore.get("every_room") id: filterModel
sourceModel: ModelStore.get("every_room")
field: "display_name"
delegate: Room { delegate: Room {
width: roomList.width width: roomList.width
onActivated: showRoomAtIndex(model.index) onActivated: showRoomAtIndex(model.index)
} }
acceptItem: item => utils.filterMatches(filter, item.display_name)
} }
section.property: "for_account" section.property: "for_account"
@ -26,10 +26,8 @@ HListView {
width: roomList.width width: roomList.width
} }
onFilterChanged: model.refilterAll()
property alias filter: filterModel.filter
property string filter: ""
readonly property var sectionIndice: { readonly property var sectionIndice: {
const sections = {} const sections = {}
const accounts = ModelStore.get("accounts") const accounts = ModelStore.get("accounts")

View File

@ -13,12 +13,11 @@ HColumnLayout {
id: memberList id: memberList
clip: true clip: true
model: HFilterModel { model: HStringFilterModel {
model: ModelStore.get(chat.userId, chat.roomId, "members") sourceModel: ModelStore.get(chat.userId, chat.roomId, "members")
field: "display_name"
filter: filterField.text
delegate: MemberDelegate { width: memberList.width } delegate: MemberDelegate { width: memberList.width }
acceptItem: item =>
utils.filterMatches(filterField.text, item.display_name)
} }
Layout.fillWidth: true Layout.fillWidth: true
@ -58,8 +57,6 @@ HColumnLayout {
// declared normally // declared normally
Component.onCompleted: placeholderText = qsTr("Filter members") Component.onCompleted: placeholderText = qsTr("Filter members")
onTextChanged: memberList.model.refilterAll()
Behavior on opacity { HNumberAnimation {} } Behavior on opacity { HNumberAnimation {} }
} }