File indexing completed on 2024-12-08 12:53:31

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "adminroomsfilterproxymodel.h"
0008 #include "adminroomsmodel.h"
0009 AdminRoomsFilterProxyModel::AdminRoomsFilterProxyModel(CustomBaseModel *model, QObject *parent)
0010     : SearchTreeBaseFilterProxyModel(model, parent)
0011 {
0012     setFilterCaseSensitivity(Qt::CaseInsensitive);
0013     sort(0, Qt::DescendingOrder);
0014 }
0015 
0016 AdminRoomsFilterProxyModel::~AdminRoomsFilterProxyModel() = default;
0017 
0018 void AdminRoomsFilterProxyModel::setFilterRooms(AdminRoomsFilterProxyModel::FilterRooms filters)
0019 {
0020     if (mFilters != filters) {
0021         mFilters = filters;
0022         invalidate();
0023     }
0024 }
0025 
0026 bool AdminRoomsFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
0027 {
0028     if (!QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent)) {
0029         return false;
0030     }
0031     const QModelIndex sourceIndex = sourceModel()->index(source_row, AdminRoomsModel::AdminRoomsRoles::ChannelType, source_parent);
0032     const QString channelType = sourceModel()->data(sourceIndex).toString();
0033     if (mFilters & FilterRoom::DirectRooms) {
0034         if (channelType == QLatin1String("d")) {
0035             return true;
0036         }
0037     }
0038     if (mFilters & FilterRoom::PublicRooms) {
0039         if (channelType == QLatin1String("c")) {
0040             return true;
0041         }
0042     }
0043     if (mFilters & FilterRoom::PrivateRooms) {
0044         if (channelType == QLatin1String("p")) {
0045             return true;
0046         }
0047     }
0048     if (mFilters & FilterRoom::PrivateRooms) {
0049         if (channelType == QLatin1String("l")) {
0050             return true;
0051         }
0052     }
0053     if (mFilters & FilterRoom::TeamRooms) {
0054         const QModelIndex sourceIndexIsTeam = sourceModel()->index(source_row, AdminRoomsModel::AdminRoomsRoles::IsTeam, source_parent);
0055         const bool isTeam = sourceModel()->data(sourceIndexIsTeam).toBool();
0056         return isTeam;
0057     }
0058     return false;
0059 }
0060 
0061 #include "moc_adminroomsfilterproxymodel.cpp"