R E C U R S I V E T R E E (1st version) OK

This commit is contained in:
Jean Sirmai 2023-12-18 16:31:04 +01:00
parent 6724424219
commit 4e616b6381
Signed by: jean
GPG Key ID: FB3115C340E057E3
1 changed files with 24 additions and 15 deletions

View File

@ -89,22 +89,33 @@ static TreeItem A[] = {{ "C", C }, { "D", D }, { NULL }};
static TreeItem R[] = {{ "A", A }, { "B", B }, { NULL }}; // ROOT static TreeItem R[] = {{ "A", A }, { "B", B }, { NULL }}; // ROOT
static TreeItem O[] = {{ "R", R }, { NULL }}; // Artefact added for symmetry static TreeItem O[] = {{ "R", R }, { NULL }}; // Artefact added for symmetry
static GtkTreeStore create_node_recursive (GtkTreeStore *model, TreeItem *current_item) static GtkTreeModel *create_node_recursive (GtkTreeStore *model,
TreeItem *current_item,
GtkTreeIter *iter_parent,
int depth)
{ {
TreeItem *item_children; GtkTreeIter iter;
GtkTreeIter iter_children, iter_parent;
if (current_item->children) { if (model == NULL)
item_children = current_item->children; model = gtk_tree_store_new (NUM_COLUMNS, G_TYPE_STRING);
while (item_children->label) { while (current_item->label) {
gtk_tree_store_append (model, &iter_children, &iter_parent); if (0) printf("[%d] Current label : %s\n", depth, current_item->label);
gtk_tree_store_set (model, &iter_children, COLUMN_0, item_children->label, -1); gtk_tree_store_append (model, &iter, iter_parent);
item_children++; gtk_tree_store_set (model, &iter, COLUMN_0, current_item->label, -1);
create_node_recursive (model, item_children);
if (current_item->children)
create_node_recursive (model, current_item->children, &iter, depth+1);
else
break;
current_item++;
} }
}
return *model; if (depth == 0)
return GTK_TREE_MODEL(model);
else
return NULL;
} }
static void create_node (GtkTreeStore *model, static void create_node (GtkTreeStore *model,
@ -209,9 +220,7 @@ do_tree_store (GtkWidget *do_widget)
gtk_box_append (GTK_BOX (vbox), sw); gtk_box_append (GTK_BOX (vbox), sw);
/* create tree_model */ /* create tree_model */
tree_model = create_model (); // GtkTreeStore *model = gtk_tree_store_new (NUM_COLUMNS, G_TYPE_STRING); tree_model = create_node_recursive (tree_store, R, NULL, 0);
/* tree_store = gtk_tree_store_new (NUM_COLUMNS, G_TYPE_STRING); */
/* tree_model = create_node_recursive (*tree_store, O); */
/* create tree view */ /* create tree view */
treeview = gtk_tree_view_new_with_model (tree_model); treeview = gtk_tree_view_new_with_model (tree_model);