dropdown list filtering takes categories and labels into filtering logic

This commit is contained in:
Martin Rotter 2025-05-26 07:49:28 +02:00
parent e68317fdcd
commit f81f06ca3d
4 changed files with 53 additions and 34 deletions

View file

@ -1,3 +1,7 @@
Donations Donations
========= =========
You can support author of RSS Guard via [donations](https://github.com/sponsors/martinrotter). You can support author of RSS Guard via [donations](https://github.com/sponsors/martinrotter).
Or you can use:
* Liberapay - [https://liberapay.com/martinrotter](https://liberapay.com/martinrotter)
* Patreon - [https://www.patreon.com/c/martinrotter](https://www.patreon.com/c/martinrotter)

View file

@ -400,37 +400,48 @@ bool FeedsProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source
} }
void FeedsProxyModel::initializeFilters() { void FeedsProxyModel::initializeFilters() {
m_filters[FeedListFilter::ShowEmpty] = [this](const Feed* feed) { m_filters[FeedListFilter::ShowEmpty] = [this](const RootItem* item) {
return feed->countOfAllMessages() == 0; return item->countOfAllMessages() == 0;
}; };
m_filters[FeedListFilter::ShowNonEmpty] = [this](const Feed* feed) { m_filters[FeedListFilter::ShowNonEmpty] = [this](const RootItem* item) {
return feed->countOfAllMessages() != 0; return item->countOfAllMessages() != 0;
}; };
m_filters[FeedListFilter::ShowQuiet] = [this](const Feed* feed) { m_filters[FeedListFilter::ShowQuiet] = [this](const RootItem* item) {
return feed->isQuiet(); Feed* feed = item->toFeed();
return feed == nullptr || feed->isQuiet();
}; };
m_filters[FeedListFilter::ShowSwitchedOff] = [this](const Feed* feed) { m_filters[FeedListFilter::ShowSwitchedOff] = [this](const RootItem* item) {
return feed->isSwitchedOff(); Feed* feed = item->toFeed();
return feed == nullptr || feed->isSwitchedOff();
}; };
m_filters[FeedListFilter::ShowUnread] = [this](const Feed* feed) { m_filters[FeedListFilter::ShowUnread] = [this](const RootItem* item) {
return feed->countOfUnreadMessages() > 0; return item->countOfUnreadMessages() > 0;
}; };
m_filters[FeedListFilter::ShowWithArticleFilters] = [this](const Feed* feed) { m_filters[FeedListFilter::ShowWithArticleFilters] = [this](const RootItem* item) {
return !feed->messageFilters().isEmpty(); Feed* feed = item->toFeed();
return feed == nullptr || !feed->messageFilters().isEmpty();
}; };
m_filters[FeedListFilter::ShowWithError] = [this](const Feed* feed) { m_filters[FeedListFilter::ShowWithError] = [this](const RootItem* item) {
return feed->status() == Feed::Status::AuthError || feed->status() == Feed::Status::NetworkError || Feed* feed = item->toFeed();
feed->status() == Feed::Status::OtherError || feed->status() == Feed::Status::ParsingError;
return feed == nullptr || feed->status() == Feed::Status::AuthError ||
feed->status() == Feed::Status::NetworkError || feed->status() == Feed::Status::OtherError ||
feed->status() == Feed::Status::ParsingError;
}; };
m_filters[FeedListFilter::ShowWithNewArticles] = [this](const Feed* feed) { m_filters[FeedListFilter::ShowWithNewArticles] = [this](const RootItem* item) {
return feed->status() == Feed::Status::NewMessages; Feed* feed = item->toFeed();
return feed == nullptr || feed->status() == Feed::Status::NewMessages;
}; };
m_filterKeys = m_filters.keys(); m_filterKeys = m_filters.keys();
@ -473,26 +484,26 @@ bool FeedsProxyModel::filterAcceptsRowInternal(int source_row, const QModelIndex
bool should_show = QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); bool should_show = QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
if (item->kind() == RootItem::Kind::Feed) { // if (item->kind() == RootItem::Kind::Feed) {
const Feed* feed = item->toFeed(); // const Feed* feed = item->toFeed();
for (FeedListFilter val : m_filterKeys) { for (FeedListFilter val : m_filterKeys) {
if (Globals::hasFlag(m_filter, val)) { if (Globals::hasFlag(m_filter, val)) {
// This particular filter is enabled. // This particular filter is enabled.
if (m_filters[val](feed)) { if (m_filters[val](item)) {
// The item matches the feed filter. // The item matches the feed filter.
// Display it if it matches internal string-based filter too. // Display it if it matches internal string-based filter too.
return should_show; return should_show;
}
} }
} }
if (m_filter != FeedListFilter::NoFiltering) {
// Some filter is enabled but this item does not meet it.
return false;
}
} }
if (m_filter != FeedListFilter::NoFiltering) {
// Some filter is enabled but this item does not meet it.
return false;
}
//}
return should_show; return should_show;
} }

View file

@ -93,7 +93,9 @@ class FeedsProxyModel : public QSortFilterProxyModel {
QList<QPair<int, QModelIndex>> m_hiddenIndices; QList<QPair<int, QModelIndex>> m_hiddenIndices;
FeedListFilter m_filter; FeedListFilter m_filter;
QMap<FeedListFilter, std::function<bool(const Feed*)>> m_filters;
// NOTE: The parameter type can be Category, Feed or Label only.
QMap<FeedListFilter, std::function<bool(const RootItem*)>> m_filters;
QList<FeedListFilter> m_filterKeys; QList<FeedListFilter> m_filterKeys;
}; };

View file

@ -374,9 +374,11 @@ void Application::loadDynamicShortcuts() {
} }
void Application::offerPolls() const { void Application::offerPolls() const {
/*
if (isFirstRunCurrentVersion()) { if (isFirstRunCurrentVersion()) {
qApp->web()->openUrlInExternalBrowser(QSL("https://forms.gle/3CZm95W6vrBLfi5K9")); qApp->web()->openUrlInExternalBrowser(QSL("https://forms.gle/3CZm95W6vrBLfi5K9"));
} }
*/
} }
void Application::offerChanges() const { void Application::offerChanges() const {