Compare commits
No commits in common. "4f7996b1ea40f497ada1d79ede522bb7870d576a" and "e6e1addbcb719fa1cacfcb593a760fe637ad3823" have entirely different histories.
4f7996b1ea
...
e6e1addbcb
|
@ -56,55 +56,34 @@ void TreeSearch::_clean_callable_cache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeSearch::_filter_tree(const String &p_search_mask) {
|
void TreeSearch::_filter_tree(const String &p_search_mask) {
|
||||||
if (matching_entries.is_empty()) {
|
if (matching_entries.size() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<bool> item_visibilities;
|
|
||||||
item_visibilities.resize(ordered_tree_items.size());
|
|
||||||
item_visibilities.fill(false);
|
|
||||||
|
|
||||||
// Make all entries visible that have any matching descendents. O(n)
|
|
||||||
for (int i = 0; i < ordered_tree_items.size(); i++) {
|
for (int i = 0; i < ordered_tree_items.size(); i++) {
|
||||||
TreeItem *entry = ordered_tree_items[i];
|
TreeItem *cur_item = ordered_tree_items[i];
|
||||||
if (number_matches.has(entry) && number_matches[entry] > 0) {
|
|
||||||
item_visibilities.set(i, true);
|
if (number_matches.has(cur_item)) {
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make all descendents of matching entries visible. O(n) * log(|matching_entries|)
|
TreeItem *first_counting_ancestor = cur_item;
|
||||||
for (int i = 0; i < ordered_tree_items.size(); i++) {
|
bool parents_visible = true;
|
||||||
TreeItem *entry = ordered_tree_items[i];
|
while (first_counting_ancestor && !number_matches.has(first_counting_ancestor)) {
|
||||||
if (_vector_has_bsearch(matching_entries, entry)) {
|
// Performance: we only need to check the first visible ancestor. This is already optimal because of the ordering in ordered_tree_items.
|
||||||
// the [next_entry] at the same depth or depth above.
|
if (!first_counting_ancestor->is_visible()){
|
||||||
TreeItem *next_entry = entry->get_next();
|
parents_visible = false;
|
||||||
|
break;
|
||||||
// search above current depth if no [next_entry].
|
|
||||||
while (!next_entry && entry) {
|
|
||||||
entry = entry->get_parent();
|
|
||||||
}
|
}
|
||||||
if (entry) {
|
first_counting_ancestor = first_counting_ancestor->get_parent();
|
||||||
next_entry = entry->get_next();
|
|
||||||
}
|
}
|
||||||
|
if (!parents_visible || !first_counting_ancestor || !_vector_has_bsearch(matching_entries, first_counting_ancestor)) {
|
||||||
// mark visible all successors upto next entry at the same depth or above
|
cur_item->set_visible(false);
|
||||||
int j = i;
|
|
||||||
for (; j < ordered_tree_items.size() && ordered_tree_items[j] != next_entry; j++) {
|
|
||||||
item_visibilities.set(j, true);
|
|
||||||
}
|
|
||||||
i = j - 1; // every entry is only processed once.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply visibility. O(n)
|
|
||||||
for (int i = 0; i < ordered_tree_items.size(); i++) {
|
|
||||||
if (!item_visibilities[i]) {
|
|
||||||
ordered_tree_items[i]->set_visible(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Makes all tree items visible.
|
// makes all tree items visible.
|
||||||
void TreeSearch::_clear_filter() {
|
void TreeSearch::_clear_filter() {
|
||||||
ERR_FAIL_COND(!tree_reference);
|
ERR_FAIL_COND(!tree_reference);
|
||||||
Vector<TreeItem *> items = { tree_reference->get_root() };
|
Vector<TreeItem *> items = { tree_reference->get_root() };
|
||||||
|
|
Loading…
Reference in New Issue