树形结构数据使用方法例子

// 定义 WbsTreeNode 结构体,继承 std::enable_shared_from_this
class ComponentLibraryTreeNode : public std::enable_shared_from_this {
public:
QString id; //唯一标识符
QString parentId; //构造父id
QString name; //节点名称
int level; //等级 1、2、3、4 对应属性层级
int libraryType; //类型 需要转成enum
int library_category; //库类别 1 标准库 2-项目库
QString desription; //描述
QString standard; //规范
QString modelFilePath; //模型文件路径 — 相对路径

std::weak_ptr<ComponentLibraryTreeNode> parent;  // 父节点指针(使用 weak_ptr 避免循环引用)
std::vector<std::shared_ptr<ComponentLibraryTreeNode>> children; // 子节点列表
// 第一层构造函数
ComponentLibraryTreeNode(const QString& id, const QString& pId, const QString& name, const int& level)
    : name(name), id(id), parentId(pId), level(level) {}

//第二层构造函数
ComponentLibraryTreeNode(const QString& id, const QString& pId, const QString& name, const int& level, const int& type, const QString& standard, const int& category, const QString& desription)
    : name(name), id(id), parentId(pId), level(level), libraryType(type), standard(standard), library_category(category), desription(desription) {}

//第三层构造函数
ComponentLibraryTreeNode(const QString& id, const QString& pId, const QString& name, const int& level, const int& type,const QString& desription)
    : name(name), id(id), parentId(pId), level(level), libraryType(type), desription(desription) {}

//第四层构造函数
ComponentLibraryTreeNode(const QString& id, const QString& pId, const QString& name, const int& level, const QString& desription, const QString& Path)
    : name(name), id(id), parentId(pId), level(level), desription(desription), modelFilePath(Path) {}

// 添加子节点
void addChild(const std::shared_ptr<ComponentLibraryTreeNode>& child) {

    child->parent = shared_from_this(); // 设置子节点的父节点
    children.push_back(child); // 将子节点添加到子节点列表
}

};
// 定义 WbsTreeNode 结构体,继承 std::enable_shared_from_this
class ComponentLibraryTreeNode : public std::enable_shared_from_this {
public:
QString id; //唯一标识符
QString parentId; //构造父id
QString name; //节点名称
int level; //等级 1、2、3、4 对应属性层级
int libraryType; //类型 需要转成enum
int library_category; //库类别 1 标准库 2-项目库
QString desription; //描述
QString standard; //规范
QString modelFilePath; //模型文件路径 — 相对路径

std::weak_ptr<ComponentLibraryTreeNode> parent;  // 父节点指针(使用 weak_ptr 避免循环引用)
std::vector<std::shared_ptr<ComponentLibraryTreeNode>> children; // 子节点列表
// 第一层构造函数
ComponentLibraryTreeNode(const QString& id, const QString& pId, const QString& name, const int& level)
    : name(name), id(id), parentId(pId), level(level) {}

//第二层构造函数
ComponentLibraryTreeNode(const QString& id, const QString& pId, const QString& name, const int& level, const int& type, const QString& standard, const int& category, const QString& desription)
    : name(name), id(id), parentId(pId), level(level), libraryType(type), standard(standard), library_category(category), desription(desription) {}

//第三层构造函数
ComponentLibraryTreeNode(const QString& id, const QString& pId, const QString& name, const int& level, const int& type,const QString& desription)
    : name(name), id(id), parentId(pId), level(level), libraryType(type), desription(desription) {}

//第四层构造函数
ComponentLibraryTreeNode(const QString& id, const QString& pId, const QString& name, const int& level, const QString& desription, const QString& Path)
    : name(name), id(id), parentId(pId), level(level), desription(desription), modelFilePath(Path) {}

// 添加子节点
void addChild(const std::shared_ptr<ComponentLibraryTreeNode>& child) {

    child->parent = shared_from_this(); // 设置子节点的父节点
    children.push_back(child); // 将子节点添加到子节点列表
}

};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值