From 4506e3a085d19e13ce60a44876ee1e837bb0b995 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 30 Mar 2019 03:49:39 +0100 Subject: GTreeView: Remove test model I was using during bringup. --- LibGUI/GTreeView.cpp | 87 ---------------------------------------------------- 1 file changed, 87 deletions(-) (limited to 'LibGUI/GTreeView.cpp') diff --git a/LibGUI/GTreeView.cpp b/LibGUI/GTreeView.cpp index fa262fc069..ee99c46491 100644 --- a/LibGUI/GTreeView.cpp +++ b/LibGUI/GTreeView.cpp @@ -4,95 +4,10 @@ //#define DEBUG_ITEM_RECTS -struct Node { - String text; - Node* parent { nullptr }; - Vector children; -}; - -class TestModel : public GModel { -public: - static Retained create() { return adopt(*new TestModel); } - - TestModel(); - - virtual int row_count(const GModelIndex& = GModelIndex()) const override; - virtual int column_count(const GModelIndex& = GModelIndex()) const override; - virtual GVariant data(const GModelIndex&, Role = Role::Display) const override; - virtual void update() override; - virtual GModelIndex index(int row, int column = 0, const GModelIndex& parent = GModelIndex()) const override; - virtual ColumnMetadata column_metadata(int) const override{ return { 100 }; } - - Node* m_root { nullptr }; -}; - -Node* make_little_tree(int depth, Node* parent) -{ - static int next_id = 0; - Node* node = new Node; - node->text = String::format("Node #%d", next_id++); - node->parent = parent; - if (depth) - node->children.append(make_little_tree(depth - 1, node)); - return node; -} - -GModelIndex TestModel::index(int row, int column, const GModelIndex& parent) const -{ - if (!parent.is_valid()) - return create_index(row, column, m_root); - auto& node = *(Node*)parent.internal_data(); - return create_index(row, column, node.children[row]); -} - -TestModel::TestModel() -{ - m_root = new Node; - m_root->text = "Root"; - - m_root->children.append(make_little_tree(3, m_root)); - m_root->children.append(make_little_tree(2, m_root)); - m_root->children.append(make_little_tree(1, m_root)); -} - -int TestModel::row_count(const GModelIndex& index) const -{ - if (!index.is_valid()) - return 1; - auto& node = *(const Node*)index.internal_data(); - return node.children.size(); -} - -int TestModel::column_count(const GModelIndex&) const -{ - return 1; -} - -void TestModel::update() -{ -} - -GVariant TestModel::data(const GModelIndex& index, Role role) const -{ - if (!index.is_valid()) - return { }; - auto& node = *(const Node*)index.internal_data(); - if (role == GModel::Role::Display) { - return node.text; - } - if (role == GModel::Role::Icon) { - if (node.children.is_empty()) - return GIcon::default_icon("filetype-unknown"); - return GIcon::default_icon("filetype-folder"); - } - return { }; -} - struct GTreeView::MetadataForIndex { bool open { false }; }; - GTreeView::MetadataForIndex& GTreeView::ensure_metadata_for_index(const GModelIndex& index) const { ASSERT(index.is_valid()); @@ -112,8 +27,6 @@ GTreeView::GTreeView(GWidget* parent) set_frame_shadow(GFrame::Shadow::Sunken); set_frame_thickness(2); - set_model(TestModel::create()); - m_expand_bitmap = GraphicsBitmap::load_from_file("/res/icons/treeview-expand.png"); m_collapse_bitmap = GraphicsBitmap::load_from_file("/res/icons/treeview-collapse.png"); } -- cgit v1.2.3