Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide those groups who don't have any matching children… #976

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions src/bookmarkswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class AbstractBookmarkItem
return 0;
}

int m_visible;

protected:
ItemType m_type;
AbstractBookmarkItem *m_parent;
Expand Down Expand Up @@ -369,6 +371,15 @@ void BookmarksWidget::filter(const QString& str)
{
treeView->clearSelection();
const QModelIndexList list = m_model->allChildRows(QModelIndex());

// first mark everyone hidden
for (const auto& index : list)
{
AbstractBookmarkItem *item = static_cast<AbstractBookmarkItem*>(index.internalPointer());
item->m_visible = 0;
}

// now mark the matching ones visible
for (const auto& index : list)
{
AbstractBookmarkItem *item = static_cast<AbstractBookmarkItem*>(index.internalPointer());
Expand All @@ -377,12 +388,36 @@ void BookmarksWidget::filter(const QString& str)
if (item->value().contains(str, Qt::CaseInsensitive)
|| item->display().contains(str, Qt::CaseInsensitive))
{
treeView->setRowHidden(index.row(), index.parent(), false);
}
else
{
treeView->setRowHidden(index.row(), index.parent(), true);
item->m_visible = 1;
}
}
}

// now who became visible, their parents, grandparents, grand-grandparents, etc, need to be marked too
for (const auto& index : list)
{
AbstractBookmarkItem *item = static_cast<AbstractBookmarkItem*>(index.internalPointer());
if (item->m_visible == 0)
continue;
for (;;)
{
item = item->parent();
if (item == nullptr)
break;
item->m_visible = 1;
}
}

// finally do update the view
for (const auto& index : list)
{
AbstractBookmarkItem *item = static_cast<AbstractBookmarkItem*>(index.internalPointer());
if (item->m_visible == 0)
{
treeView->setRowHidden(index.row(), index.parent(), true);
} else {
treeView->setRowHidden(index.row(), index.parent(), false);
}
}

}