test filtering behavior

This commit is contained in:
Martin Rotter 2022-01-08 17:30:37 +01:00
parent 35264af606
commit 70d915fc5c
4 changed files with 42 additions and 19 deletions

View File

@ -206,12 +206,20 @@ bool FeedsProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source
<< "and filter result is:"
<< QUOTE_W_SPACE_DOT(should_show);
/*
if (should_show && (!filterRegularExpression().pattern().isEmpty() ||
m_showUnreadOnly)) {
emit expandAfterFilterIn(m_sourceModel->index(source_row, 0, source_parent));
}
*/
if (should_show && m_hiddenIndices.contains(QPair<int, QModelIndex>(source_row, source_parent))) {
qDebugNN << LOGSEC_CORE << "Item was previously hidden and now shows up, expand.";
const_cast<FeedsProxyModel*>(this)->m_hiddenIndices.removeAll(QPair<int, QModelIndex>(source_row, source_parent));
// Load status.
// Now, item now should be displayed and previously it was not.
// Expand!
emit expandAfterFilterIn(m_sourceModel->index(source_row, 0, source_parent));
}

View File

@ -200,10 +200,10 @@ void FeedMessageViewer::toggleShowOnlyUnreadFeeds() {
const QAction* origin = qobject_cast<QAction*>(sender());
if (origin == nullptr) {
m_feedsView->model()->invalidateReadFeedsFilter(true, false);
m_feedsView->invalidateReadFeedsFilter(true, false);
}
else {
m_feedsView->model()->invalidateReadFeedsFilter(true, origin->isChecked());
m_feedsView->invalidateReadFeedsFilter(true, origin->isChecked());
}
}

View File

@ -30,7 +30,7 @@
FeedsView::FeedsView(QWidget* parent)
: BaseTreeView(parent), m_contextMenuService(nullptr), m_contextMenuBin(nullptr), m_contextMenuCategories(nullptr),
m_contextMenuFeeds(nullptr), m_contextMenuImportant(nullptr), m_contextMenuEmptySpace(nullptr), m_contextMenuOtherItems(nullptr),
m_contextMenuLabel(nullptr), m_isFiltering(false) {
m_contextMenuLabel(nullptr), m_dontSaveExpandState(false) {
setObjectName(QSL("FeedsView"));
// Allocate models.
@ -495,8 +495,6 @@ void FeedsView::focusInEvent(QFocusEvent* event) {
}
void FeedsView::filterItems(const QString& pattern) {
m_isFiltering = !pattern.isEmpty();
#if QT_VERSION < 0x050C00 // Qt < 5.12.0
m_proxyModel->setFilterRegExp(pattern.toLower());
#else
@ -506,15 +504,21 @@ void FeedsView::filterItems(const QString& pattern) {
if (pattern.isEmpty()) {
loadAllExpandStates();
}
else {
expandAll();
}
/*
else {
m_isDontSaveExpandState = true;
expandAll();
m_isDontSaveExpandState = false;
}
*/
}
void FeedsView::onIndexExpanded(const QModelIndex& idx) {
qDebugNN << LOGSEC_GUI << "Feed list item expanded - " << m_proxyModel->data(idx).toString();
if (m_isFiltering) {
if (m_dontSaveExpandState) {
qWarningNN << LOGSEC_GUI << "Don't saving expand state - " << m_proxyModel->data(idx).toString();
return;
}
@ -534,7 +538,8 @@ void FeedsView::onIndexExpanded(const QModelIndex& idx) {
void FeedsView::onIndexCollapsed(const QModelIndex& idx) {
qDebugNN << LOGSEC_GUI << "Feed list item collapsed - " << m_proxyModel->data(idx).toString();
if (m_isFiltering) {
if (m_dontSaveExpandState) {
qWarningNN << LOGSEC_GUI << "Don't saving collapse state - " << m_proxyModel->data(idx).toString();
return;
}
@ -598,13 +603,17 @@ void FeedsView::loadAllExpandStates() {
}
void FeedsView::expandItemDelayed(const QModelIndex& source_idx) {
if (m_isFiltering) {
QTimer::singleShot(100, this, [=] {
QModelIndex pidx = m_proxyModel->mapFromSource(source_idx);
QTimer::singleShot(100, this, [=] {
// Model requests to expand some items as they are visible and there is
// a filter active, so they maybe were not visible before.
QModelIndex pidx = m_proxyModel->mapFromSource(source_idx);
setExpanded(pidx, true);
});
}
// NOTE: These changes are caused by filtering mechanisms
// and we don't want to store the values.
m_dontSaveExpandState = true;
expandRecursively(pidx);
m_dontSaveExpandState = false;
});
}
QMenu* FeedsView::initializeContextMenuCategories(RootItem* clicked_item) {
@ -794,6 +803,10 @@ void FeedsView::setupAppearance() {
setItemDelegate(new StyledItemDelegateWithoutFocus(GUI::HeightRowFeeds, this));
}
void FeedsView::invalidateReadFeedsFilter(bool set_new_value, bool show_unread_only) {
m_proxyModel->invalidateReadFeedsFilter(set_new_value, show_unread_only);
}
void FeedsView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) {
RootItem* selected_item = selectedItem();
@ -801,7 +814,7 @@ void FeedsView::selectionChanged(const QItemSelection& selected, const QItemSele
QTreeView::selectionChanged(selected, deselected);
emit itemSelected(selected_item);
m_proxyModel->invalidateReadFeedsFilter();
invalidateReadFeedsFilter();
if (!selectedIndexes().isEmpty() &&
qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::AutoExpandOnSelection)).toBool()) {

View File

@ -77,6 +77,8 @@ class RSSGUARD_DLLSPEC FeedsView : public BaseTreeView {
void filterItems(const QString& pattern);
void invalidateReadFeedsFilter(bool set_new_value = false, bool show_unread_only = false);
signals:
void itemSelected(RootItem* item);
void requestViewNextUnreadMessage();
@ -130,7 +132,7 @@ class RSSGUARD_DLLSPEC FeedsView : public BaseTreeView {
QMenu* m_contextMenuLabel;
FeedsModel* m_sourceModel;
FeedsProxyModel* m_proxyModel;
bool m_isFiltering;
bool m_dontSaveExpandState;
};
inline FeedsProxyModel* FeedsView::model() const {