File indexing completed on 2024-12-01 07:40:36
0001 // SPDX-FileCopyrightText: 2023 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 SpaceChildSortFilterModel 0011 * 0012 * This class creates a custom QSortFilterProxyModel for filtering and sorting spaces 0013 * in a SpaceChildrenModel. 0014 * 0015 * @sa SpaceChildrenModel 0016 */ 0017 class SpaceChildSortFilterModel : public QSortFilterProxyModel 0018 { 0019 Q_OBJECT 0020 QML_ELEMENT 0021 0022 /** 0023 * @brief The text to use to filter room names. 0024 */ 0025 Q_PROPERTY(QString filterText READ filterText READ filterText WRITE setFilterText NOTIFY filterTextChanged) 0026 0027 public: 0028 SpaceChildSortFilterModel(QObject *parent = nullptr); 0029 0030 void setFilterText(const QString &filterText); 0031 [[nodiscard]] QString filterText() const; 0032 0033 protected: 0034 /** 0035 * @brief Returns true if the value of source_left is less than source_right. 0036 * 0037 * @sa QSortFilterProxyModel::lessThan 0038 */ 0039 bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override; 0040 0041 /** 0042 * @brief Custom filter function checking if an event type has been filtered out. 0043 * 0044 * The filter rejects a row if the room is known been replaced or if a search 0045 * string is set it will only return rooms that match. 0046 */ 0047 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; 0048 0049 Q_SIGNALS: 0050 void filterTextChanged(); 0051 0052 private: 0053 QString m_filterText; 0054 };