55 lines
1.7 KiB
C++
55 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <XCEditor/Collections/UIEditorTreeView.h>
|
|
|
|
#include <XCEngine/UI/Types.h>
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace XCEngine::UI::Editor::App {
|
|
|
|
struct ProductHierarchyNode {
|
|
std::string nodeId = {};
|
|
std::string label = {};
|
|
std::vector<ProductHierarchyNode> children = {};
|
|
};
|
|
|
|
class ProductHierarchyModel {
|
|
public:
|
|
static ProductHierarchyModel BuildDefault();
|
|
|
|
bool Empty() const;
|
|
bool ContainsNode(std::string_view nodeId) const;
|
|
const ProductHierarchyNode* FindNode(std::string_view nodeId) const;
|
|
ProductHierarchyNode* FindNode(std::string_view nodeId);
|
|
|
|
std::optional<std::string> GetParentId(std::string_view nodeId) const;
|
|
bool RenameNode(std::string_view nodeId, std::string label);
|
|
std::string CreateChild(std::string_view parentId, std::string_view label);
|
|
bool DeleteNode(std::string_view nodeId);
|
|
|
|
bool CanReparent(std::string_view sourceNodeId, std::string_view targetParentId) const;
|
|
bool Reparent(std::string_view sourceNodeId, std::string_view targetParentId);
|
|
bool MoveToRoot(std::string_view sourceNodeId);
|
|
|
|
std::vector<Widgets::UIEditorTreeViewItem> BuildTreeItems(
|
|
const ::XCEngine::UI::UITextureHandle& icon) const;
|
|
|
|
private:
|
|
std::string AllocateNodeId();
|
|
bool CanAdopt(
|
|
std::string_view sourceNodeId,
|
|
const ProductHierarchyNode* targetParent) const;
|
|
bool ContainsDescendant(
|
|
const ProductHierarchyNode& node,
|
|
std::string_view candidateId) const;
|
|
|
|
std::vector<ProductHierarchyNode> m_roots = {};
|
|
std::uint64_t m_nextGeneratedNodeId = 1u;
|
|
};
|
|
|
|
} // namespace XCEngine::UI::Editor::App
|