make sure selected item does not disappear in some cases when filtering
This commit is contained in:
parent
af19e5376a
commit
4de3db8000
@ -4,6 +4,7 @@
|
||||
|
||||
#include "core/feedsmodel.h"
|
||||
#include "definitions/definitions.h"
|
||||
#include "gui/feedsview.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/regexfactory.h"
|
||||
#include "services/abstract/rootitem.h"
|
||||
@ -11,7 +12,8 @@
|
||||
#include <QTimer>
|
||||
|
||||
FeedsProxyModel::FeedsProxyModel(FeedsModel* source_model, QObject* parent)
|
||||
: QSortFilterProxyModel(parent), m_sourceModel(source_model), m_selectedItem(nullptr), m_showUnreadOnly(false) {
|
||||
: QSortFilterProxyModel(parent), m_sourceModel(source_model), m_view(nullptr),
|
||||
m_selectedItem(nullptr), m_showUnreadOnly(false) {
|
||||
setObjectName(QSL("FeedsProxyModel"));
|
||||
|
||||
setSortRole(Qt::ItemDataRole::EditRole);
|
||||
@ -243,12 +245,22 @@ bool FeedsProxyModel::filterAcceptsRowInternal(int source_row, const QModelIndex
|
||||
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.
|
||||
//
|
||||
// Also, the actual selected item should not be filtered out too.
|
||||
// This is primarily to make sure that the selection does not "vanish", this
|
||||
// particularly manifests itself if user uses "next unread item" action and
|
||||
// "show unread only" is enabled too and user for example selects last unread
|
||||
// article in a feed -> then the feed would disappear from list suddenly.
|
||||
return
|
||||
item->countOfUnreadMessages() != 0 &&
|
||||
QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
|
||||
m_selectedItem == item || (item->countOfUnreadMessages() != 0 &&
|
||||
QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent));
|
||||
}
|
||||
}
|
||||
|
||||
void FeedsProxyModel::setView(FeedsView* newView) {
|
||||
m_view = newView;
|
||||
}
|
||||
|
||||
const RootItem* FeedsProxyModel::selectedItem() const {
|
||||
return m_selectedItem;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "services/abstract/rootitem.h"
|
||||
|
||||
class FeedsModel;
|
||||
class FeedsView;
|
||||
|
||||
class FeedsProxyModel : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
@ -29,6 +30,7 @@ class FeedsProxyModel : public QSortFilterProxyModel {
|
||||
const RootItem* selectedItem() const;
|
||||
|
||||
void setSelectedItem(const RootItem* selected_item);
|
||||
void setView(FeedsView* newView);
|
||||
|
||||
public slots:
|
||||
void invalidateReadFeedsFilter(bool set_new_value = false, bool show_unread_only = false);
|
||||
@ -45,6 +47,7 @@ class FeedsProxyModel : public QSortFilterProxyModel {
|
||||
|
||||
// Source model pointer.
|
||||
FeedsModel* m_sourceModel;
|
||||
FeedsView* m_view;
|
||||
const RootItem* m_selectedItem;
|
||||
bool m_showUnreadOnly;
|
||||
QList<QPair<int, QModelIndex>> m_hiddenIndices;
|
||||
|
@ -37,6 +37,8 @@ FeedsView::FeedsView(QWidget* parent)
|
||||
m_sourceModel = qApp->feedReader()->feedsModel();
|
||||
m_proxyModel = qApp->feedReader()->feedsProxyModel();
|
||||
|
||||
m_proxyModel->setView(this);
|
||||
|
||||
// Connections.
|
||||
connect(m_sourceModel, &FeedsModel::requireItemValidationAfterDragDrop, this, &FeedsView::validateItemAfterDragDrop);
|
||||
connect(m_sourceModel, &FeedsModel::itemExpandRequested, this, &FeedsView::onItemExpandRequested);
|
||||
|
Loading…
x
Reference in New Issue
Block a user