@@ -17,50 +17,50 @@ void SignalTree::prepare(const std::string& vSearchString) {
1717
1818 for (const auto & signal_cnt : LogEngine::Instance ()->GetSignalSeries ()) {
1919 prepareRecurs (vSearchString, signal_cnt.first , signal_cnt.second , m_RootItem);
20- /* const auto& arr = ez::str::splitStringToVector(item_cat.first, "/");
21- for (auto& item_name : item_cat.second) {
22- if (item_name.second) {
23- if (item_name.second->low_case_name_for_search.find(searchPattern) == std::string::npos) {
24- continue;
25- }
26- m_SignalSeriesOld[item_name.first] = item_name.second;
27- m_SignalSeries[item_name.first];
28- }
29- }*/
3020 }
3121}
3222
3323void SignalTree::prepareRecurs (const std::string& vSearchString, const SignalCategory& vCategory, const SignalContainer& vSignals, SignalItem& vSignalItemRef) {
34- // split category
3524 std::string left_category = vCategory, right_category;
3625 size_t p = left_category.find (' /' );
3726 if (p != std::string::npos) {
3827 right_category = left_category.substr (p + 1 ); // right part
3928 left_category = left_category.substr (0 , p); // legt part
4029 }
4130
42- if (vSignalItemRef.childs .find (left_category) == vSignalItemRef.childs .end ()) { // we need to insert a item
31+ if (vSignalItemRef.childs .find (left_category) == vSignalItemRef.childs .end ()) { // not found, we need to insert a item
4332 vSignalItemRef.childs [left_category];
4433 }
4534
4635 auto & item = vSignalItemRef.childs .at (left_category);
4736 if (!right_category.empty ()) { // no leaf, recurs
4837 prepareRecurs (vSearchString, right_category, vSignals, item);
4938 item.count = static_cast <uint32_t >(item.childs .size ());
39+
5040 } else { // leaf : add
5141 item.count = static_cast <uint32_t >(vSignals.size ());
5242 for (const auto & sig : vSignals) {
53- item.signals [sig.first ] = sig.second ;
43+ if (sig.second != nullptr ) {
44+ if (vSearchString.empty () || sig.second ->low_case_name_for_search .find (vSearchString) != std::string::npos) {
45+ item.signals [sig.first ] = sig.second ;
46+ }
47+ }
5448 }
5549 }
5650 item.label = ez::str::toStr (" %s (%u)" , left_category.c_str (), item.count );
51+
52+ // we will remove items with empty childs and empty signals
53+ // can be the case if search pattern filtering blocked some insertions
54+ if (item.isEmpty ()) {
55+ vSignalItemRef.childs .erase (left_category);
56+ }
5757}
5858
5959void SignalTree::displayTree (bool vCollapseAll, bool vExpandAll) {
60- displayItemRecurs (m_RootItem);
60+ displayItemRecurs (m_RootItem, vCollapseAll, vExpandAll );
6161}
6262
63- void SignalTree::displayItemRecurs (SignalItem& vSignalItemRef) {
63+ void SignalTree::displayItemRecurs (SignalItem& vSignalItemRef, bool vCollapseAll, bool vExpandAll ) {
6464 if (vSignalItemRef.isLeaf ()) {
6565 for (auto & signal : vSignalItemRef.signals ) {
6666 if (!signal.second .expired ()) {
@@ -79,9 +79,23 @@ void SignalTree::displayItemRecurs(SignalItem& vSignalItemRef) {
7979 }
8080 } else { // display categories
8181 for (auto & child : vSignalItemRef.childs ) {
82- if (ImGui::TreeNode (child.second .label .c_str ())) {
82+ if (vCollapseAll) {
83+ // can close only the first item for now
84+ // or we need to reach the leaf
85+ // and close from leaf so to do on many frames
86+ // can be anoying for the user
87+ // todo : by the way
88+ ImGui::SetNextItemOpen (false );
89+ }
90+
91+ if (vExpandAll) {
92+ // will open all tree during recursion
93+ ImGui::SetNextItemOpen (true );
94+ }
95+
96+ if (ImGui::TreeNode (&child.second , " %s" , child.second .label .c_str ())) {
8397 ImGui::Indent ();
84- displayItemRecurs (child.second );
98+ displayItemRecurs (child.second , vCollapseAll, vExpandAll );
8599 ImGui::Unindent ();
86100 ImGui::TreePop ();
87101 }
0 commit comments