WIP: how to walk the tree ?
This commit is contained in:
parent
7a0abbc5b3
commit
125aea2127
|
@ -51,9 +51,25 @@ enum
|
|||
|
||||
static void iterating_a_model_in_a_depth_first_fashion (GtkTreeModel *model)
|
||||
{
|
||||
g_print ("iterating_a_model_in_a_depth_first_fashion (GtkTreeModel *model) is not yet implemented (line 54)\n");
|
||||
// gtk_tree_model_foreach (model, TRUE, my_user_data); https://developer-old.gnome.org/gtk4/stable/GtkTreeModel.html#GtkTreeModelForeachFunc
|
||||
// gboolean (*GtkTreeModelForeachFunc) (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data);
|
||||
GtkTreeIter iter;
|
||||
gboolean valid;
|
||||
int row_count = 0;
|
||||
valid = gtk_tree_model_get_iter_first (model, &iter);
|
||||
while (valid)
|
||||
{
|
||||
char *str_data;
|
||||
// Make sure you terminate calls to gtk_tree_model_get() with a “-1” value
|
||||
gtk_tree_model_get (model, &iter, STRING_COLUMN, &str_data, -1);
|
||||
g_print ("Row %d: (%s) <> gtk_tree_model_get_iter_first (model, &iter) &iter = [%s] (line 67) ", row_count, str_data, &iter);
|
||||
g_free (str_data);
|
||||
valid = gtk_tree_model_iter_next (model, &iter);
|
||||
// valid = gtk_tree_model_iter_children (model, &iter, parent); << how to get the parent ??
|
||||
g_print ("valid = %d = gtk_tree_model_iter_next (model, &iter) %s (line 71)\n",\
|
||||
valid, gtk_tree_model_get_string_from_iter (model, &iter));
|
||||
row_count++;
|
||||
}
|
||||
}
|
||||
|
||||
static void /* https://developer-old.gnome.org/gtk4/stable/GtkTreeModel.html#GtkTreePath-struct and #gtk-tree-row-reference-new */
|
||||
|
@ -89,7 +105,7 @@ static void acquiring_a_GtkTreeIter (GtkTreeModel *my_tree_model, GtkTreePath *m
|
|||
{
|
||||
GtkTreeIter iter; // get the iterator from a string
|
||||
gtk_tree_model_get_iter_from_string (my_tree_model, &iter, "3:2:5");
|
||||
g_print ("acquiring_a_GtkTreeIter from path : [ %s ]\n", gtk_tree_path_to_string (my_tree_path));
|
||||
g_print ("acquiring_a_GtkTreeIter from path : [ %s ] (lines 225 & 108)\n", gtk_tree_path_to_string (my_tree_path));
|
||||
|
||||
my_tree_path = gtk_tree_path_new_from_string ("3:2:5"); // get the iterator from a path
|
||||
gtk_tree_model_get_iter (my_tree_model, &iter, my_tree_path);
|
||||
|
@ -100,25 +116,6 @@ static void acquiring_a_GtkTreeIter (GtkTreeModel *my_tree_model, GtkTreePath *m
|
|||
/* parent_iter = iter; gtk_tree_model_iter_nth_child (my_tree_model, &iter, &parent_iter, 5); */
|
||||
}
|
||||
|
||||
static void reading_data_from_a_GtkTreeModel(GtkTreeModel *my_tree_model)
|
||||
{
|
||||
GtkTreeIter iter; // Get the first iter in the list, check it is valid and walk through the list, reading each row.
|
||||
int row_count = 0;
|
||||
char *my_str_data;
|
||||
|
||||
gboolean valid = gtk_tree_model_get_iter_first (my_tree_model, &iter);
|
||||
|
||||
while (valid) { // Make sure you terminate calls to gtk_tree_model_get() with a “-1” value
|
||||
gtk_tree_model_get (my_tree_model, &iter, STRING_COLUMN, &my_str_data, -1);
|
||||
g_print ("Row %d: (%s)\n", row_count, my_str_data);
|
||||
valid = gtk_tree_model_iter_next (my_tree_model, &iter); // ? if (gtk_tree_model_iter_next (my_tree_model, &iter)) row_count++; ?
|
||||
row_count++;
|
||||
}
|
||||
|
||||
g_free (my_str_data); // ? g_free (iter);
|
||||
}
|
||||
|
||||
|
||||
/* TreeItem structure */
|
||||
typedef struct _TreeItem TreeItem;
|
||||
struct _TreeItem
|
||||
|
@ -204,9 +201,8 @@ do_tree_store (GtkWidget *do_widget)
|
|||
|
||||
/* create tree_model */
|
||||
my_tree_model = create_node_recursive (my_tree_store, O, NULL, 0);
|
||||
reading_data_from_a_GtkTreeModel(my_tree_model);
|
||||
iterating_a_model_in_a_depth_first_fashion (my_tree_model);
|
||||
GtkTreePath *my_path = gtk_tree_path_new_from_string ("1:1:1");
|
||||
GtkTreePath *my_path = gtk_tree_path_new_from_string ("0:0:1:0:1");
|
||||
acquiring_a_GtkTreeIter (my_tree_model, my_path);
|
||||
// GtkTreeIter *my_iter; edit_a_cell (my_tree_model, NULL, my_iter, NULL, my_path);
|
||||
|
||||
|
|
Loading…
Reference in New Issue