File indexing completed on 2024-04-14 04:54:41

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #include "bannerinfosfilterproxymodel.h"
0007 #include "bannerinfosmodel.h"
0008 
0009 BannerInfosFilterProxyModel::BannerInfosFilterProxyModel(QObject *parent)
0010     : QSortFilterProxyModel{parent}
0011 {
0012 }
0013 
0014 BannerInfosFilterProxyModel::~BannerInfosFilterProxyModel() = default;
0015 
0016 bool BannerInfosFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
0017 {
0018     if (!mShowUnread) {
0019         return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
0020     }
0021     const QModelIndex sourceIndex = sourceModel()->index(source_row, 0, source_parent);
0022     const bool isRead = sourceIndex.data(BannerInfosModel::Read).toBool();
0023     if (!isRead) {
0024         return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
0025     }
0026     return false;
0027 }
0028 
0029 bool BannerInfosFilterProxyModel::showUnread() const
0030 {
0031     return mShowUnread;
0032 }
0033 
0034 void BannerInfosFilterProxyModel::setShowUnread(bool newShowUnread)
0035 {
0036     if (mShowUnread != newShowUnread) {
0037         mShowUnread = newShowUnread;
0038         invalidateFilter();
0039     }
0040 }
0041 
0042 #include "moc_bannerinfosfilterproxymodel.cpp"