Add dedicated HStringFilterModel component
This commit is contained in:
parent
69a525d317
commit
7418f0fe93
15
src/gui/Base/HStringFilterModel.qml
Normal file
15
src/gui/Base/HStringFilterModel.qml
Normal 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
|
||||
}
|
|
@ -8,14 +8,14 @@ import "../Base"
|
|||
HListView {
|
||||
id: roomList
|
||||
|
||||
model: HFilterModel {
|
||||
model: ModelStore.get("every_room")
|
||||
model: HStringFilterModel {
|
||||
id: filterModel
|
||||
sourceModel: ModelStore.get("every_room")
|
||||
field: "display_name"
|
||||
delegate: Room {
|
||||
width: roomList.width
|
||||
onActivated: showRoomAtIndex(model.index)
|
||||
}
|
||||
|
||||
acceptItem: item => utils.filterMatches(filter, item.display_name)
|
||||
}
|
||||
|
||||
section.property: "for_account"
|
||||
|
@ -26,10 +26,8 @@ HListView {
|
|||
width: roomList.width
|
||||
}
|
||||
|
||||
onFilterChanged: model.refilterAll()
|
||||
|
||||
|
||||
property string filter: ""
|
||||
property alias filter: filterModel.filter
|
||||
readonly property var sectionIndice: {
|
||||
const sections = {}
|
||||
const accounts = ModelStore.get("accounts")
|
||||
|
|
|
@ -13,12 +13,11 @@ HColumnLayout {
|
|||
id: memberList
|
||||
clip: true
|
||||
|
||||
model: HFilterModel {
|
||||
model: ModelStore.get(chat.userId, chat.roomId, "members")
|
||||
model: HStringFilterModel {
|
||||
sourceModel: ModelStore.get(chat.userId, chat.roomId, "members")
|
||||
field: "display_name"
|
||||
filter: filterField.text
|
||||
delegate: MemberDelegate { width: memberList.width }
|
||||
|
||||
acceptItem: item =>
|
||||
utils.filterMatches(filterField.text, item.display_name)
|
||||
}
|
||||
|
||||
Layout.fillWidth: true
|
||||
|
@ -58,8 +57,6 @@ HColumnLayout {
|
|||
// declared normally
|
||||
Component.onCompleted: placeholderText = qsTr("Filter members")
|
||||
|
||||
onTextChanged: memberList.model.refilterAll()
|
||||
|
||||
Behavior on opacity { HNumberAnimation {} }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user