+ if (focus_)
+ tocTV->setFocus();
+}
+
+
+void TocWidget::filterContents()
+{
+ if (!tocTV->model())
+ return;
+
+ QModelIndexList indices = tocTV->model()->match(
+ tocTV->model()->index(0, 0),
+ Qt::DisplayRole, "*", -1,
+ Qt::MatchFlags(Qt::MatchWildcard|Qt::MatchRecursive));
+
+ int size = indices.size();
+ for (int i = 0; i < size; i++) {
+ QModelIndex index = indices[i];
+ bool const matches =
+ index.data().toString().contains(
+ filterLE->text(), Qt::CaseInsensitive);
+ tocTV->setRowHidden(index.row(), index.parent(), !matches);
+ }
+ // recursively unhide parents of unhidden children
+ for (int i = size - 1; i >= 0; i--) {
+ QModelIndex index = indices[i];
+ if (!tocTV->isRowHidden(index.row(), index.parent())
+ && index.parent() != QModelIndex())
+ tocTV->setRowHidden(index.parent().row(),
+ index.parent().parent(), false);
+ }