2 #include <score/tools/Debug.hpp>
4 #include <QFileSystemModel>
5 #include <QSortFilterProxyModel>
12 using QSortFilterProxyModel::QSortFilterProxyModel;
14 const QString& pattern()
const noexcept {
return m_textPattern; }
15 void setPattern(
const QString& p)
18 auto old = m_textPattern;
26 QString m_textPattern;
27 bool filterAcceptsRow(
int srcRow,
const QModelIndex& srcParent)
const override
29 if(filterAcceptsRowItself(srcRow, srcParent))
35 for(QModelIndex parent = srcParent; parent.isValid(); parent = parent.parent())
36 if(filterAcceptsRowItself(parent.row(), parent.parent()))
42 return hasAcceptedChildren(srcRow, srcParent);
45 bool filterAcceptsRowItself(
int srcRow,
const QModelIndex& srcParent)
const
47 QModelIndex index = sourceModel()->index(srcRow, 0, srcParent);
48 const QVariant& data = sourceModel()->data(index);
50 return data.toString().contains(m_textPattern, Qt::CaseInsensitive);
53 bool hasAcceptedChildren(
int srcRow,
const QModelIndex& srcParent)
const
55 QModelIndex index = sourceModel()->index(srcRow, 0, srcParent);
60 SCORE_ASSERT(index.model());
61 const int childCount = index.model()->rowCount(index);
66 for(
int i = 0; i < childCount; ++i)
68 if(filterAcceptsRowItself(i, index))
71 if(hasAcceptedChildren(i, index))
82 using RecursiveFilterProxy::RecursiveFilterProxy;
84 QModelIndex fixedRootIndex{};
87 bool isChildOfRoot(
const QModelIndex& m)
const noexcept
93 if(m == fixedRootIndex)
95 if(
auto parent = m.parent(); parent == fixedRootIndex)
101 return isChildOfRoot(parent);
105 QFileSystemModel* sourceModel()
const noexcept
107 return static_cast<QFileSystemModel*
>(QSortFilterProxyModel::sourceModel());
109 bool filterAcceptsRow(
int srcRow,
const QModelIndex& srcParent)
const override
111 const QModelIndex index = sourceModel()->index(srcRow, 0, srcParent);
112 if(!isChildOfRoot(index))
117 if(filterAcceptsRowItself(srcRow, srcParent))
123 for(QModelIndex parent = srcParent; parent.isValid(); parent = parent.parent())
126 if(parent == fixedRootIndex)
129 if(filterAcceptsRowItself(parent.row(), parent.parent()))
136 return hasAcceptedChildren(srcRow, srcParent);
Definition: RecursiveFilterProxy.hpp:80
Definition: RecursiveFilterProxy.hpp:10