- (*it)->setHidden(
- (*it)->childCount() == 0
- && !(*it)->text(0).contains(filter_->text(), cs)
- );
+ if ((*it)->childCount() > 0) {
+ // Unhide parents (will be hidden
+ // below if necessary)
+ (*it)->setHidden(false);
+ ++it;
+ continue;
+ }
+ bool const match = (*it)->text(0).contains(filter_->text(), cs);
+ if (match) {
+ // Register parents of matched entries
+ // so we don't hide those later.
+ QTreeWidgetItem * twi = *it;
+ while (true) {
+ if (!twi->parent())
+ break;
+ activeCats << twi->parent();
+ // ascend further up if possible
+ twi = twi->parent();
+ }
+ }
+ (*it)->setHidden(!match);
+ ++it;
+ }
+ // Iterate through parents once more
+ // to hide empty categories
+ it = QTreeWidgetItemIterator(filesLW);
+ while (*it) {
+ if ((*it)->childCount() == 0) {
+ ++it;
+ continue;
+ }
+ (*it)->setHidden(!activeCats.contains(*it));