File indexing completed on 2025-01-12 13:02:25
0001 // SPDX-FileCopyrightText: 2020 Tobias Fella <tobias.fella@kde.org> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 #pragma once 0005 0006 #include <QSortFilterProxyModel> 0007 0008 /** 0009 * @class SortFilterRoomListModel 0010 * 0011 * This model sorts and filters the room list. 0012 * 0013 * There are numerous room sort orders available: 0014 * - Categories - sort rooms by their NeoChatRoomType and then by last activty within 0015 * each category. 0016 * - LastActivity - sort rooms by the last active time in the room. 0017 * - Alphabetical - sort the rooms alphabetically by room name. 0018 * 0019 * The model can be given a filter string that will only show rooms who's name includes 0020 * the text. 0021 * 0022 * The model can also be given an active space ID and will only show rooms within 0023 * that space. 0024 * 0025 * All space rooms and upgraded rooms will also be filtered out. 0026 */ 0027 class SortFilterRoomListModel : public QSortFilterProxyModel 0028 { 0029 Q_OBJECT 0030 0031 /** 0032 * @brief The order by which the rooms will be sorted. 0033 * 0034 * @sa RoomSortOrder 0035 */ 0036 Q_PROPERTY(RoomSortOrder roomSortOrder READ roomSortOrder WRITE setRoomSortOrder NOTIFY roomSortOrderChanged) 0037 0038 /** 0039 * @brief The text to use to filter room names. 0040 */ 0041 Q_PROPERTY(QString filterText READ filterText READ filterText WRITE setFilterText NOTIFY filterTextChanged) 0042 0043 /** 0044 * @brief Set the ID of the space to show rooms for. 0045 */ 0046 Q_PROPERTY(QString activeSpaceId READ activeSpaceId WRITE setActiveSpaceId NOTIFY activeSpaceIdChanged) 0047 0048 public: 0049 enum RoomSortOrder { 0050 Alphabetical, 0051 LastActivity, 0052 Categories, 0053 }; 0054 Q_ENUM(RoomSortOrder) 0055 0056 explicit SortFilterRoomListModel(QObject *parent = nullptr); 0057 0058 void setRoomSortOrder(RoomSortOrder sortOrder); 0059 [[nodiscard]] RoomSortOrder roomSortOrder() const; 0060 0061 void setFilterText(const QString &text); 0062 [[nodiscard]] QString filterText() const; 0063 0064 QString activeSpaceId() const; 0065 void setActiveSpaceId(const QString &spaceId); 0066 0067 protected: 0068 /** 0069 * @brief Returns true if the value of source_left is less than source_right. 0070 * 0071 * @sa QSortFilterProxyModel::lessThan 0072 */ 0073 [[nodiscard]] bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override; 0074 0075 /** 0076 * @brief Whether a row should be shown out or not. 0077 * 0078 * @sa QSortFilterProxyModel::filterAcceptsRow 0079 */ 0080 [[nodiscard]] bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; 0081 0082 Q_SIGNALS: 0083 void roomSortOrderChanged(); 0084 void filterTextChanged(); 0085 void activeSpaceIdChanged(); 0086 0087 private: 0088 RoomSortOrder m_sortOrder = Categories; 0089 QString m_filterText; 0090 QString m_activeSpaceId; 0091 };