Implement helm-like filtering (still WIP)

wilder
Jacopo De Simoi 6 years ago committed by Jacopo De Simoi
parent 611e84e2ea
commit 039e94b038
  1. 39
      src/folder/entitycollectionorderproxymodel.cpp
  2. 2
      src/folder/entitycollectionorderproxymodel.h

@ -141,6 +141,45 @@ bool EntityCollectionOrderProxyModel::lessThan(const QModelIndex &left, const QM
}
}
bool EntityCollectionOrderProxyModel::filterAcceptsRow(int source_row, const QModelIndex &parent) const
{
QStringList words = filterRegExp().pattern().split(' ',QString::SkipEmptyParts);
if (words.count()>1) { // helm style
bool accept = true;
for (int i=0;(accept && i<words.count());i++) {
EntityCollectionOrderProxyModel tmp;
tmp.setSourceModel(sourceModel());
tmp.setFilterCaseSensitivity(Qt::CaseInsensitive);
tmp.setFilterWildcard(words[i]);
accept &= tmp.filterAcceptsRow(source_row,parent);
}
if (!accept)
return false;
accept = false;
for (int i=0;(!accept && i<words.count());i++) {
EntityCollectionOrderProxyModel tmp;
tmp.setSourceModel(sourceModel());
tmp.setFilterCaseSensitivity(Qt::CaseInsensitive);
tmp.setFilterWildcard(words[i]);
accept |= tmp.QSortFilterProxyModel::filterAcceptsRow(source_row,parent);
}
return accept;
}
if (QSortFilterProxyModel::filterAcceptsRow(source_row, parent))
return true;
// walk up the hierarchy
if (parent.isValid()) {
return filterAcceptsRow(parent.row(),parent.parent());
}
return false;
}
void EntityCollectionOrderProxyModel::setManualSortingActive(bool active)
{
if (d->manualSortingActive == active) {

@ -36,6 +36,8 @@ public:
Q_REQUIRED_RESULT bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
bool filterAcceptsRow(int source_row, const QModelIndex &parent) const override;
void setManualSortingActive(bool active);
Q_REQUIRED_RESULT bool isManualSortingActive() const;

Loading…
Cancel
Save