File indexing completed on 2024-02-25 16:44:37

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "filesforroomfilterproxymodel.h"
0008 #include "filesforroommodel.h"
0009 
0010 FilesForRoomFilterProxyModel::FilesForRoomFilterProxyModel(FilesForRoomModel *fileModel, QObject *parent)
0011     : QSortFilterProxyModel(parent)
0012     , mFilesForRoomModel(fileModel)
0013 {
0014     setSourceModel(mFilesForRoomModel);
0015 
0016     setFilterCaseSensitivity(Qt::CaseInsensitive);
0017     // Filter on filename for the moment
0018     setFilterRole(FilesForRoomModel::FileName);
0019 
0020     setSortRole(FilesForRoomModel::SortByTimeStamp);
0021     sort(0, Qt::DescendingOrder);
0022     connect(mFilesForRoomModel, &FilesForRoomModel::hasFullListChanged, this, &FilesForRoomFilterProxyModel::hasFullListChanged);
0023     connect(mFilesForRoomModel, &FilesForRoomModel::totalChanged, this, &FilesForRoomFilterProxyModel::totalChanged);
0024     connect(mFilesForRoomModel, &FilesForRoomModel::loadingInProgressChanged, this, &FilesForRoomFilterProxyModel::loadingInProgressChanged);
0025 }
0026 
0027 FilesForRoomFilterProxyModel::~FilesForRoomFilterProxyModel() = default;
0028 
0029 void FilesForRoomFilterProxyModel::setFilterString(const QString &string)
0030 {
0031     setFilterFixedString(string);
0032 }
0033 
0034 int FilesForRoomFilterProxyModel::total() const
0035 {
0036     return mFilesForRoomModel->total();
0037 }
0038 
0039 bool FilesForRoomFilterProxyModel::hasFullList() const
0040 {
0041     return mFilesForRoomModel->hasFullList();
0042 }
0043 
0044 int FilesForRoomFilterProxyModel::attachmentCount() const
0045 {
0046     return mFilesForRoomModel->rowCount();
0047 }
0048 
0049 void FilesForRoomFilterProxyModel::resetTypeGroup()
0050 {
0051     setTypeGroup({});
0052 }
0053 
0054 void FilesForRoomFilterProxyModel::clear()
0055 {
0056     mFilesForRoomModel->clear();
0057 }
0058 
0059 void FilesForRoomFilterProxyModel::setTypeGroup(const QString &typeGroup)
0060 {
0061     if (mTypeGroup != typeGroup) {
0062         mTypeGroup = typeGroup;
0063         invalidateFilter();
0064     }
0065 }
0066 
0067 bool FilesForRoomFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
0068 {
0069     if (mTypeGroup.isEmpty()) {
0070         return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
0071     }
0072     const QModelIndex sourceIndex = sourceModel()->index(source_row, 0, source_parent);
0073     const QString typegroup = sourceIndex.data(FilesForRoomModel::TypeGroup).toString();
0074     return (mTypeGroup == typegroup) && QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
0075 }
0076 
0077 #include "moc_filesforroomfilterproxymodel.cpp"