WOrk on correct expand after filtered in.

This commit is contained in:
Martin Rotter 2016-04-30 14:49:05 +02:00
parent e0016d10a1
commit eb3f2e0174
3 changed files with 26 additions and 1 deletions

View file

@ -28,7 +28,7 @@
FeedsProxyModel::FeedsProxyModel(QObject *parent)
: QSortFilterProxyModel(parent), m_selectedItem(NULL), m_showUnreadOnly(false) {
: QSortFilterProxyModel(parent), m_selectedItem(NULL), m_showUnreadOnly(false), m_hiddenIndices(QList<QPair<int,QModelIndex> >()) {
m_sourceModel = new FeedsModel(this);
setObjectName(QSL("FeedsProxyModel"));
@ -183,6 +183,22 @@ 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);
if (should_show && m_hiddenIndices.contains(QPair<int,QModelIndex>(source_row, source_parent))) {
// TODO: dodělat
m_hiddenIndices.removeAll(QPair<int,QModelIndex>(source_row, source_parent));
// Load status.
emit expandAfterFilterIn(m_sourceModel->index(source_row, 0, source_parent));
}
return should_show;
}
bool FeedsProxyModel::filterAcceptsRowInternal(int source_row, const QModelIndex &source_parent) const {
if (!m_showUnreadOnly) {
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
}

View file

@ -56,15 +56,20 @@ class FeedsProxyModel : public QSortFilterProxyModel {
private slots:
void invalidateFilter();
signals:
void expandAfterFilterIn(const QModelIndex &idx);
private:
// Compares two rows of data.
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
bool filterAcceptsRowInternal(int source_row, const QModelIndex &source_parent) const;
// Source model pointer.
FeedsModel *m_sourceModel;
const RootItem *m_selectedItem;
bool m_showUnreadOnly;
QList<QPair<int,QModelIndex> > m_hiddenIndices;
};
#endif // FEEDSPROXYMODEL_H

View file

@ -60,6 +60,10 @@ FeedsView::FeedsView(QWidget *parent)
connect(m_sourceModel, SIGNAL(itemExpandStateSaveRequested(RootItem*)), this, SLOT(onItemExpandStateSaveRequested(RootItem*)));
connect(header(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(saveSortState(int,Qt::SortOrder)));
connect(m_proxyModel, &FeedsProxyModel::expandAfterFilterIn, [=](const QModelIndex &idx) {
});
setModel(m_proxyModel);
setupAppearance();
}