void DumpTreeNG(const RefPtr<NG::FrameNode>& parent, int32_t depth, NodeId nodeID, int32_t pageId) { auto node = GetInspectorById(parent, nodeID); NG::RectF rect = node->GetTransformRectRelativeToWindow(); DumpLog::GetInstance().AddDesc("ID: " + std::to_string(node->GetAccessibilityId())); DumpLog::GetInstance().AddDesc("compid: " + node->GetInspectorId().value_or("")); std::vector<int32_t> children; for (const auto& item : node->GetChildren()) { GetFrameNodeChildren(item, children, pageId); } DumpLog::GetInstance().Print(depth, node->GetTag(), children.size()); for (auto nodeId : children) { DumpTreeNG(node, depth + 1, nodeId, pageId); } }改写此段代码,将父节点和子节点打印出的信息全部放在一个vector<ComponentInfo> com1容器中,ComponentInfo是一个struct其中的成员变量是 ComponentInfo{ std::string ID; std::string text; std::vector<ComponentInfo> children;} 并打印出来
时间: 2024-04-03 12:32:59 浏览: 230
void DumpTreeNG(const RefPtr<NG::FrameNode>& parent, int32_t depth, NodeId nodeID, int32_t pageId, std::vector<ComponentInfo>& com1) {
auto node = GetInspectorById(parent, nodeID);
NG::RectF rect = node->GetTransformRectRelativeToWindow();
ComponentInfo info;
info.ID = std::to_string(node->GetAccessibilityId());
info.text = node->GetTag();
info.children = std::vector<ComponentInfo>{};
for (const auto& item : node->GetChildren()) {
std::vector<ComponentInfo> childComponents;
GetFrameNodeChildren(item, childComponents, pageId);
info.children.insert(info.children.end(), childComponents.begin(), childComponents.end());
}
com1.push_back(info);
for (auto nodeId : info.children) {
DumpTreeNG(node, depth + 1, nodeId, pageId, com1);
}
}
// 调用该函数
std::vector<ComponentInfo> com1;
DumpTreeNG(parent, 0, nodeID, pageId, com1);
// 打印 com1 中的内容
for (const auto& info : com1) {
std::string prefix(depth, '-');
std::cout << prefix << info.text << " (ID: " << info.ID << ")" << std::endl;
for (const auto& child : info.children) {
std::string childPrefix(depth + 1, '-');
std::cout << childPrefix << child.text << " (ID: " << child.ID << ")" << std::endl;
}
}
阅读全文