diff --git a/src/gui/Base/HStringFilterModel.qml b/src/gui/Base/HStringFilterModel.qml new file mode 100644 index 00000000..9e977865 --- /dev/null +++ b/src/gui/Base/HStringFilterModel.qml @@ -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 +} diff --git a/src/gui/MainPane/RoomList.qml b/src/gui/MainPane/RoomList.qml index 90d834cf..3a1db850 100644 --- a/src/gui/MainPane/RoomList.qml +++ b/src/gui/MainPane/RoomList.qml @@ -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") diff --git a/src/gui/Pages/Chat/RoomPane/MemberView.qml b/src/gui/Pages/Chat/RoomPane/MemberView.qml index 1e121038..3dcc5b52 100644 --- a/src/gui/Pages/Chat/RoomPane/MemberView.qml +++ b/src/gui/Pages/Chat/RoomPane/MemberView.qml @@ -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 {} } }