Skip to content

Commit c2eab08

Browse files
committed
search pattern adapted to new tree displaying
1 parent 957895e commit c2eab08

File tree

4 files changed

+42
-29
lines changed

4 files changed

+42
-29
lines changed

src/headers/LogToGraphBuild.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#define LogToGraph_Prefix "LogToGraph"
4-
#define LogToGraph_BuildNumber 1038
4+
#define LogToGraph_BuildNumber 1046
55
#define LogToGraph_MinorNumber 2
66
#define LogToGraph_MajorNumber 0
7-
#define LogToGraph_BuildId "0.2.1038"
7+
#define LogToGraph_BuildId "0.2.1046"

src/models/log/SignalTree.cpp

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3323
void 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

5959
void 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
}

src/models/log/SignalTree.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct SignalItem {
1212
SignalContainerWeak signals;
1313
SignalItemContainer childs;
1414
bool isLeaf() const { return childs.empty(); }
15+
bool isEmpty() const { return childs.empty() && signals.empty(); }
1516
void clear() {
1617
signals.clear();
1718
childs.clear();
@@ -31,5 +32,5 @@ class SignalTree {
3132

3233
private:
3334
void prepareRecurs(const std::string& vSearchString, const SignalCategory& vCategory, const SignalContainer& vSignals, SignalItem& vSignalItemRef);
34-
void displayItemRecurs(SignalItem& vSignalItemRef);
35+
void displayItemRecurs(SignalItem& vSignalItemRef, bool vCollapseAll, bool vExpandAll);
3536
};

src/panes/ToolPane.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,15 @@ void ToolPane::DrawTree() {
259259

260260
const float fw = ImGui::GetContentRegionAvail().x;
261261

262-
if (search_string.empty()) {
263-
const float aw = (fw - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
264-
if (ImGui::ContrastedButton("Collapse All##ToolPane_DrawTree", nullptr, nullptr, aw)) {
265-
_collapse_all = true;
266-
}
262+
const float aw = (fw - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
263+
if (ImGui::ContrastedButton("Collapse All##ToolPane_DrawTree", nullptr, nullptr, aw)) {
264+
_collapse_all = true;
265+
}
267266

268-
ImGui::SameLine();
267+
ImGui::SameLine();
269268

270-
if (ImGui::ContrastedButton("Expand All##ToolPane_DrawTree", nullptr, nullptr, aw)) {
271-
_expand_all = true;
272-
}
269+
if (ImGui::ContrastedButton("Expand All##ToolPane_DrawTree", nullptr, nullptr, aw)) {
270+
_expand_all = true;
273271
}
274272

275273
if (ImGui::ContrastedButton("Hide All Graphs##ToolPane_DrawTree", nullptr, nullptr, fw)) {

0 commit comments

Comments
 (0)