#pragma once #include #include #include #include #include namespace Flex_Qt { class Tree_Node { public: explicit Tree_Node(); // 判断状态 int index(); bool is_root(); bool is_leaf(); bool is_first(); bool is_last(); Tree_Node* previous(); Tree_Node* next(); Tree_Node* last_child(); Tree_Node* first_child(); Tree_Node* root(); int get_deep(); // 遍历值 std::vector deep_traversed(); std::vector sequence_traversed(); std::vector descendants(); Tree_Node* par = nullptr; std::vector sons; QString text; bool expand = true; int height = 20; void add_child(Tree_Node* child) { sons.push_back(child); child->par = this; } }; struct Tree_Pos { Tree_Node* p{}; int depth{}; int node_pos{}; int offset{}; int pos() { return node_pos + offset; } std::stack> rest; }; class Tree_Model { public: std::vector roots; int tab_pixel_size = 8; int png_len = 20; int tab_width = 10; int space = 4; int height(); int width() { return 1000; } }; Tree_Pos get_pos(int pos, const std::vector& roots, int space); std::vector deep_traversed(const std::vector& nodes); using Node_Call_Back = const std::function&; void select_node(const std::vector& roots, int view_y, int length, int space, Node_Call_Back call_back); }