From 5c04eb85af440aadffd3e04d1da6c70b294241f0 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Tue, 10 Sep 2024 13:07:38 +0200 Subject: [PATCH] Fix filtering users in the member list --- src/models/userfiltermodel.cpp | 13 ++++++++++++- src/models/userfiltermodel.h | 6 ++++++ src/qml/RoomInformation.qml | 12 ++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/models/userfiltermodel.cpp b/src/models/userfiltermodel.cpp index 14bf03b37..320165402 100644 --- a/src/models/userfiltermodel.cpp +++ b/src/models/userfiltermodel.cpp @@ -8,7 +8,7 @@ bool UserFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { Q_UNUSED(sourceParent); - if (m_filterText.length() < 1) { + if (!m_allowEmpty && m_filterText.length() < 1) { return false; } return sourceModel()->data(sourceModel()->index(sourceRow, 0), UserListModel::DisplayNameRole).toString().contains(m_filterText, Qt::CaseInsensitive) @@ -27,4 +27,15 @@ void UserFilterModel::setFilterText(const QString &filterText) invalidateFilter(); } +bool UserFilterModel::allowEmpty() const +{ + return m_allowEmpty; +} + +void UserFilterModel::setAllowEmpty(bool allowEmpty) +{ + m_allowEmpty = allowEmpty; + Q_EMIT allowEmptyChanged(); +} + #include "moc_userfiltermodel.cpp" diff --git a/src/models/userfiltermodel.h b/src/models/userfiltermodel.h index 9952f0fda..363ab87e3 100644 --- a/src/models/userfiltermodel.h +++ b/src/models/userfiltermodel.h @@ -24,6 +24,7 @@ class UserFilterModel : public QSortFilterProxyModel * The text is either a desired display name or matrix id. */ Q_PROPERTY(QString filterText READ filterText WRITE setFilterText NOTIFY filterTextChanged) + Q_PROPERTY(bool allowEmpty READ allowEmpty WRITE setAllowEmpty NOTIFY allowEmptyChanged) public: /** @@ -36,9 +37,14 @@ public: QString filterText() const; void setFilterText(const QString &filterText); + bool allowEmpty() const; + void setAllowEmpty(bool allowEmpty); + Q_SIGNALS: void filterTextChanged(); + void allowEmptyChanged(); private: QString m_filterText; + bool m_allowEmpty = false; }; diff --git a/src/qml/RoomInformation.qml b/src/qml/RoomInformation.qml index c5b9a0c69..825e6c463 100644 --- a/src/qml/RoomInformation.qml +++ b/src/qml/RoomInformation.qml @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: 2023 James Graham // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Controls as QQC2 import QtQuick.Layouts @@ -188,11 +190,17 @@ QQC2.ScrollView { focusSequence: "Ctrl+Shift+F" - onAccepted: sortedMessageEventModel.filterString = text + onAccepted: userFilterModel.filterText = text } } - model: root.room.isDirectChat() ? 0 : RoomManager.userListModel + model: root.room.isDirectChat() ? 0 : userFilterModel + + UserFilterModel { + id: userFilterModel + sourceModel: RoomManager.userListModel + allowEmpty: true + } clip: true focus: true