File indexing completed on 2024-02-18 15:43:55

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "teamroomsfilterproxymodel.h"
0008 #include "teamroomsmodel.h"
0009 
0010 TeamRoomsFilterProxyModel::TeamRoomsFilterProxyModel(TeamRoomsModel *teamModel, QObject *parent)
0011     : QSortFilterProxyModel(parent)
0012     , mTeamRoomsModel(teamModel)
0013 {
0014     setSourceModel(mTeamRoomsModel);
0015 
0016     setFilterCaseSensitivity(Qt::CaseInsensitive);
0017     // Filter on filename for the moment
0018     setFilterRole(TeamRoomsModel::Name);
0019 
0020     setSortRole(TeamRoomsModel::Name);
0021     sort(0, Qt::AscendingOrder);
0022 }
0023 
0024 TeamRoomsFilterProxyModel::~TeamRoomsFilterProxyModel() = default;
0025 
0026 void TeamRoomsFilterProxyModel::setFilterString(const QString &string)
0027 {
0028     setFilterFixedString(string);
0029 }
0030 
0031 bool TeamRoomsFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
0032 {
0033     if (!mSortByAutoJoin) {
0034         return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
0035     }
0036     const QModelIndex sourceIndex = sourceModel()->index(source_row, 0, source_parent);
0037     const bool autojoin = sourceIndex.data(TeamRoomsModel::AutoJoin).toBool();
0038     return autojoin && QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
0039 }
0040 
0041 bool TeamRoomsFilterProxyModel::sortByAutoJoin() const
0042 {
0043     return mSortByAutoJoin;
0044 }
0045 
0046 void TeamRoomsFilterProxyModel::setSortByAutoJoin(bool sortByAutoJoin)
0047 {
0048     if (mSortByAutoJoin != sortByAutoJoin) {
0049         mSortByAutoJoin = sortByAutoJoin;
0050         invalidateFilter();
0051     }
0052 }
0053 
0054 #include "moc_teamroomsfilterproxymodel.cpp"