12 using QSortFilterProxyModel::QSortFilterProxyModel;
14 const QString& pattern()
const noexcept {
return m_textPattern; }
15 void setPattern(
const QString& p)
26 QString m_textPattern;
28 int columnCount(
const QModelIndex& parent = QModelIndex())
const override {
return 1; }
29 bool filterAcceptsRow(
int srcRow,
const QModelIndex& srcParent)
const override
31 if(filterAcceptsRowItself(srcRow, srcParent))
37 for(QModelIndex parent = srcParent; parent.isValid(); parent = parent.parent())
38 if(filterAcceptsRowItself(parent.row(), parent.parent()))
44 return hasAcceptedChildren(srcRow, srcParent);
47 bool filterAcceptsRowItself(
int srcRow,
const QModelIndex& srcParent)
const
49 QModelIndex index = sourceModel()->index(srcRow, 0, srcParent);
50 const QVariant& data = sourceModel()->data(index);
52 return data.toString().contains(m_textPattern, Qt::CaseInsensitive);
55 bool hasAcceptedChildren(
int srcRow,
const QModelIndex& srcParent)
const
57 QModelIndex index = sourceModel()->index(srcRow, 0, srcParent);
62 SCORE_ASSERT(index.model());
63 const int childCount = index.model()->rowCount(index);
68 for(
int i = 0; i < childCount; ++i)
70 if(filterAcceptsRowItself(i, index))
73 if(hasAcceptedChildren(i, index))
84 using RecursiveFilterProxy::RecursiveFilterProxy;
86 QModelIndex fixedRootIndex{};
89 bool isChildOfRoot(
const QModelIndex& m)
const noexcept
95 if(m == fixedRootIndex)
97 if(
auto parent = m.parent(); parent == fixedRootIndex)
103 return isChildOfRoot(parent);
107 QFileSystemModel* sourceModel()
const noexcept
109 return static_cast<QFileSystemModel*
>(QSortFilterProxyModel::sourceModel());
111 bool filterAcceptsRow(
int srcRow,
const QModelIndex& srcParent)
const override
113 const QModelIndex index = sourceModel()->index(srcRow, 0, srcParent);
114 if(!isChildOfRoot(index))
119 if(filterAcceptsRowItself(srcRow, srcParent))
125 for(QModelIndex parent = srcParent; parent.isValid(); parent = parent.parent())
128 if(parent == fixedRootIndex)
131 if(filterAcceptsRowItself(parent.row(), parent.parent()))
138 return hasAcceptedChildren(srcRow, srcParent);