File indexing completed on 2024-05-05 05:01:26

0001 // SPDX-FileCopyrightText: 2022 James Graham <james.h.graham@protonmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 #pragma once
0005 
0006 #include <QQmlEngine>
0007 #include <QSortFilterProxyModel>
0008 
0009 /**
0010  * @class UserFilterModel
0011  *
0012  * This class creates a custom QSortFilterProxyModel for filtering a users by either
0013  * display name or matrix ID. The filter can accept a full matrix id i.e. example:kde.org
0014  * to separate between accounts on different servers with similar names.
0015  */
0016 class UserFilterModel : public QSortFilterProxyModel
0017 {
0018     Q_OBJECT
0019     QML_ELEMENT
0020 
0021     /**
0022      * @brief This property hold the text of the filter.
0023      *
0024      * The text is either a desired display name or matrix id.
0025      */
0026     Q_PROPERTY(QString filterText READ filterText WRITE setFilterText NOTIFY filterTextChanged)
0027 
0028 public:
0029     /**
0030      * @brief Custom filter function checking boith the display name and matrix ID.
0031      *
0032      * @note The filter cannot be modified and will always use the same filter properties.
0033      */
0034     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
0035 
0036     QString filterText() const;
0037     void setFilterText(const QString &filterText);
0038 
0039 Q_SIGNALS:
0040     void filterTextChanged();
0041 
0042 private:
0043     QString m_filterText;
0044 };