Hi. i have a treeview. What I need is to hide parents if they don't match but their child do. As I guess it leads to tree reconstruction - changing parent of visible children. How is it better to do it?
Currently I have this, but of course it does show parents if children matches
bool TreeFilteredModel
::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent
) const {
bool ret = false;
QModelIndex subIndex
= sourceModel
()->index
(sourceRow,
0, sourceParent
);
WorkflowTreeItem* item = (WorkflowTreeItem*)subIndex.internalPointer();
int childCound = sourceModel()->rowCount(subIndex);
if (subIndex.isValid())
{
for (int i = 0; i < childCound; ++i)
{
ret = ret || filterAcceptsRow(i, subIndex);
}
}
ret |= (item->command()->getName().contains(m_commandSearchParameter, Qt::CaseInsensitive) && item->command()->getName().contains(m_textSearchParameter, Qt::CaseInsensitive));
return ret;
}
bool TreeFilteredModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
bool ret = false;
QModelIndex subIndex = sourceModel()->index(sourceRow, 0, sourceParent);
WorkflowTreeItem* item = (WorkflowTreeItem*)subIndex.internalPointer();
int childCound = sourceModel()->rowCount(subIndex);
if (subIndex.isValid())
{
for (int i = 0; i < childCound; ++i)
{
ret = ret || filterAcceptsRow(i, subIndex);
}
}
ret |= (item->command()->getName().contains(m_commandSearchParameter, Qt::CaseInsensitive) && item->command()->getName().contains(m_textSearchParameter, Qt::CaseInsensitive));
return ret;
}
To copy to clipboard, switch view to plain text mode
thanks
Bookmarks