From 7049e3ca6c5d3db69ea0bb01d987e823ebf6647b Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 21 Dec 2021 14:46:27 +0100 Subject: [PATCH] some work on feed list filtering, now features "show unread only" and regex filtering actually works together, still thinking about how to solve #546 --- src/librssguard/core/feedsproxymodel.cpp | 27 ++++++++++++++++-------- src/librssguard/gui/feedsview.cpp | 4 +++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/librssguard/core/feedsproxymodel.cpp b/src/librssguard/core/feedsproxymodel.cpp index e57ba1fd5..15ff0ecc2 100644 --- a/src/librssguard/core/feedsproxymodel.cpp +++ b/src/librssguard/core/feedsproxymodel.cpp @@ -198,7 +198,15 @@ bool FeedsProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right bool FeedsProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const { bool should_show = filterAcceptsRowInternal(source_row, source_parent); + qDebugNN << LOGSEC_CORE + << "Filter accepts row" + << QUOTE_W_SPACE(m_sourceModel->itemForIndex(m_sourceModel->index(source_row, 0, source_parent))->title()) + << "and filter result is:" + << QUOTE_W_SPACE_DOT(should_show); + if (should_show && m_hiddenIndices.contains(QPair(source_row, source_parent))) { + qDebugNN << LOGSEC_CORE << "Item was previously hidden and now shows up, expand."; + const_cast(this)->m_hiddenIndices.removeAll(QPair(source_row, source_parent)); // Load status. @@ -213,10 +221,6 @@ bool FeedsProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source } bool FeedsProxyModel::filterAcceptsRowInternal(int source_row, const QModelIndex& source_parent) const { - if (!m_showUnreadOnly) { - return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); - } - const QModelIndex idx = m_sourceModel->index(source_row, 0, source_parent); if (!idx.isValid()) { @@ -225,18 +229,23 @@ bool FeedsProxyModel::filterAcceptsRowInternal(int source_row, const QModelIndex const RootItem* item = m_sourceModel->itemForIndex(idx); - if (item->kind() != RootItem::Kind::Category && item->kind() != RootItem::Kind::Feed) { + if (item->kind() != RootItem::Kind::Category && + item->kind() != RootItem::Kind::Feed && + item->kind() != RootItem::Kind::Label) { // Some items are always visible. return true; } - else if (item->isParentOf(m_selectedItem) /* || item->isChildOf(m_selectedItem)*/ || m_selectedItem == item) { - // Currently selected item and all its parents and children must be displayed. - return true; + + if (!m_showUnreadOnly) { + // Take only regexp filtering into account. + return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); } else { // NOTE: If item has < 0 of unread message it may mean, that the count // of unread messages is not (yet) known, display that item too. - return item->countOfUnreadMessages() != 0; + return + item->countOfUnreadMessages() != 0 && + QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); } } diff --git a/src/librssguard/gui/feedsview.cpp b/src/librssguard/gui/feedsview.cpp index 10aa4933c..8ec8ddf46 100644 --- a/src/librssguard/gui/feedsview.cpp +++ b/src/librssguard/gui/feedsview.cpp @@ -550,7 +550,9 @@ void FeedsView::focusInEvent(QFocusEvent* event) { void FeedsView::expandItemDelayed(const QModelIndex& idx) { QTimer::singleShot(100, this, [=] { - setExpanded(m_proxyModel->mapFromSource(idx), true); + QModelIndex pidx = m_proxyModel->mapFromSource(idx); + + setExpanded(pidx, true); }); }